Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_plot_creation_02_array_default_dims(self):
# add a default value for the y dimension
psy.register_plotter('test_plotter',
import_plotter=True, module='test_plotter',
plotter_name='TestPlotter',
default_dims={'y': 0})
ds = psy.open_dataset(bt.get_file('test-t2m-u-v.nc'))
sp = psy.plot.test_plotter(ds, name='t2m')
self.assertEqual(len(sp), 1)
self.assertEqual(sp[0].name, 't2m')
self.assertEqual(sp[0].shape, ds.t2m.isel(lat=0).shape)
self.assertEqual(sp[0].values.tolist(),
ds.t2m.isel(lat=0).values.tolist())
psy.close()
psy.unregister_plotter('test_plotter')
def setUp(self):
psy.close('all')
plt.close('all')
self._created_files = set()
"""Test the registration of a plotter"""
psy.register_plotter('test_plotter',
import_plotter=True, module='test_plotter',
plotter_name='TestPlotter')
self.assertTrue(hasattr(psy.plot, 'test_plotter'))
self.assertIs(psy.plot.test_plotter.plotter_cls, tp.TestPlotter)
psy.plot.test_plotter.print_func = str
self.assertEqual(psy.plot.test_plotter.fmt1(), tp.SimpleFmt.__doc__)
psy.plot.test_plotter.print_func = None
# test the warning
if not six.PY2:
with self.assertWarnsRegex(UserWarning, "not_existent_module"):
psy.register_plotter('something', "not_existent_module",
'not_important', import_plotter=True)
psy.unregister_plotter('test_plotter')
self.assertFalse(hasattr(psy.Project, 'test_plotter'))
self.assertFalse(hasattr(psy.plot, 'test_plotter'))
def _create_and_save_test_project(self):
psy.register_plotter('test_plotter', module='test_plotter',
plotter_name='TestPlotter')
sp = psy.plot.test_plotter(bt.get_file('test-t2m-u-v.nc'),
name=['t2m', 'u'], time=[0, 1])
self.assertEqual(len(sp), 4, sp)
fname = tempfile.NamedTemporaryFile(
suffix='.pkl', prefix='test_psyplot_').name
self._created_files.add(fname)
sp.save_project(fname, use_rel_paths=False)
return sp, fname
'Options that only have an effect if the `-o` option is set.')
parser.update_arg('fnames', positional=True, nargs='*')
parser.update_arg('name', short='n', nargs='*', metavar='variable_name',
const=None)
parser.update_arg('dims', short='d', nargs='+', type=_load_dims,
metavar='dim,val1[,val2[,...]]')
pm_choices = {pm for pm, d in filter(
lambda t: t[1].get('plot_func', True),
six.iteritems(rcParams['project.plotters']))}
if psyplot._project_imported:
import psyplot.project as psy
pm_choices.update(set(psy.plot._plot_methods))
parser.update_arg('plot_method', short='pm', choices=pm_choices,
metavar='{%s}' % ', '.join(map(repr, pm_choices)))
parser.update_arg('output', short='o', group=output_grp)
parser.update_arg('output_project', short='op', group=output_grp)
parser.update_arg('project', short='p')
parser.update_arg(
'formatoptions', short='fmt', type=_load_dict, help="""
The path to a yaml (``'.yml'`` or ``'.yaml'``) or pickle file
defining a dictionary of formatoption that is applied to the data
visualized by the chosen `plot_method`""", metavar='FILENAME')
parser.update_arg(
'chname', type=lambda s: s.split(','), nargs='*', help="""
def create_project(self, ds):
"""
To be reimplemented for each task with :attr:`has_run`
Parameters
----------
ds: xarray.Dataset
The dataset to plot"""
import psyplot.project as psy
return psy.gcp()
if vname == 'wind':
ylabel = '$\\sqrt{{' + ylabel + '}}$'
else:
ylabel = 'Simulated - Observed'
diff_symbol = ylabel
if vname == 'tmin':
ylabel += ' [$^\circ$C]'
# --- slope bias correction
if osp.exists(project_output) and not new_project:
mp = psy.Project.load_project(project_output, datasets=[ds])
sp2 = mp.linreg
else:
import seaborn as sns
sns.set_style('white')
sp1 = psy.plot.lineplot(ds, name=what, coord='unorm',
linewidth=0, marker='o', legend=False)
label = '$%s = %s$' % (diff_symbol, ' '.join(
'%(c{})+4.3f{}'.format(i, get_symbol(i))
for i in range(deg + 1)))
sp2 = psy.plot.linreg(
ds, name=what, ax=sp1[0].ax,
coord='unorm', fit='poly' + str(int(deg)),
ylabel=ylabel,
legendlabels=label,
legend={'fontsize': 'large', 'loc': 'upper left'},
xlabel='Random number from normal distribution')
sp2.share(sp1[0], ['color', 'xlim', 'ylim'])
attrs = sp2.plotters[0].plot_data[0].attrs
nml = self.exp_config['namelist']['weathergen_ctl']
nml[vname + '_bias_coeffs'] = [
float(attrs.get('c%i' % i, 0.0)) for i in range(6)]