How to use the psyplot.project.gcp function in psyplot

To help you get started, we’ve selected a few psyplot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Chilipp / psyplot / tests / test_main.py View on Github external
def test_main_03_dims(self):
        import yaml
        psy.register_plotter('test_plotter', module='test_plotter',
                             plotter_name='TestPlotter')
        fname2 = tempfile.NamedTemporaryFile(
            suffix='.pdf', prefix='test_psyplot_').name
        self._created_files.add(fname2)
        if not six.PY2:
            with self.assertRaisesRegex(ValueError, 'plotting method'):
                main.main([bt.get_file('test-t2m-u-v.nc'), '-o', fname2,
                           '-d', 'time,1,2', 'y,3,4', '-n', 'u', 'v'])
        main.main([bt.get_file('test-t2m-u-v.nc'), '-o', fname2,
                   '-d', 'time,1,2', 'y,3,4', '-n', 'u', 'v',
                   '-pm', 'test_plotter', '-fmt', "fmt1=fmt1", "fmt2=fmt2"])
        mp = psy.gcp(True)
        self.assertEqual(len(mp), 2*2*2, msg=mp)
        all_dims = set(product((1, 2), (3, 4), ('u', 'v')))
        for arr in mp:
            idims = arr.psy.idims
            all_dims -= {(idims['time'], idims['lat'], arr.name)}
        self.assertFalse(all_dims)
        for i, plotter in enumerate(mp.plotters):
            self.assertEqual(plotter['fmt1'], 'fmt1',
                             msg='Wrong value for fmt1 of plotter %i!' % i)
            self.assertEqual(plotter['fmt2'], 'fmt2',
                             msg='Wrong value for fmt2 of plotter %i!' % i)
github Chilipp / psyplot / tests / test_project.py View on Github external
def test_with(self):
        """Test __enter__ and __exit__ methods"""
        psy.register_plotter('test_plotter', import_plotter=True,
                             module='test_plotter', plotter_name='TestPlotter')
        self.assertFalse(psy.gcp(True))
        self.assertFalse(psy.gcp())
        with psy.plot.test_plotter(bt.get_file('test-t2m-u-v.nc')) as sp:
            self.assertTrue(psy.gcp(True))
            self.assertTrue(psy.gcp())

        self.assertFalse(psy.gcp(True))
        self.assertFalse(psy.gcp())
github Chilipp / psyplot / tests / test_project.py View on Github external
self.assertEqual(mp0[0].lev.values, lev[0])
        self.assertEqual(mp0[1].lev.values, lev[1])
        self.assertEqual(mp1[0].time.values, time[1])
        self.assertEqual(mp1[1].time.values, time[2])
        self.assertEqual(mp2[0].time.values, time[3])
        self.assertEqual(mp2[1].time.values, time[4])
        self.assertEqual(mp2[2].lev.values, lev[2])
        self.assertEqual(mp2[3].lev.values, lev[3])
        self.assertIs(psy.gcp(True), mp2)
        self.assertIs(psy.gcp(), sp2)
        # close the current subproject
        ds = mp2[2].psy.base
        psy.close()

        self.assertIs(psy.gcp(True), mp2)
        self.assertEqual(psy.gcp(), [])
        self.assertEqual(sp2, [])
        self.assertEqual(len(sp1), 2)
        self.assertEqual(mp2.arr_names, sp1.arr_names)
        # close the current mainproject
        ds = mp2[0].psy.base
        ds.v.values  # check that the data can be loaded
        psy.close(mp2.num)
        self.assertIs(psy.gcp(True), mp1)
        self.assertEqual(mp2, [])
        self.assertIs(psy.gcp().main, mp1)
        self.assertEqual(psy.gcp().arr_names, mp1.arr_names)

        # close all projects
        ds0 = mp0[0].psy.base
        ds0.v.values  # check that the data can be loaded
        ds1 = mp1[0].psy.base
github Chilipp / psyplot / tests / test_project.py View on Github external
self.assertIs(psy.gcp(True), mp2)
        self.assertIs(psy.gcp(), sp2)
        # close the current subproject
        ds = mp2[2].psy.base
        psy.close()

        self.assertIs(psy.gcp(True), mp2)
        self.assertEqual(psy.gcp(), [])
        self.assertEqual(sp2, [])
        self.assertEqual(len(sp1), 2)
        self.assertEqual(mp2.arr_names, sp1.arr_names)
        # close the current mainproject
        ds = mp2[0].psy.base
        ds.v.values  # check that the data can be loaded
        psy.close(mp2.num)
        self.assertIs(psy.gcp(True), mp1)
        self.assertEqual(mp2, [])
        self.assertIs(psy.gcp().main, mp1)
        self.assertEqual(psy.gcp().arr_names, mp1.arr_names)

        # close all projects
        ds0 = mp0[0].psy.base
        ds0.v.values  # check that the data can be loaded
        ds1 = mp1[0].psy.base
        ds1.v.values  # check that the data can be loaded
        psy.close('all')
        self.assertEqual(mp0, [])
        self.assertEqual(mp1, [])
        self.assertEqual(psy.gcp(), [])
        self.assertIsNot(psy.gcp(True), mp0)
        self.assertIsNot(psy.gcp(True), mp1)
github ARVE-Research / gwgen / gwgen / parameterization.py View on Github external
],
                            line_xlim=[
                                [limits[0], r1[1]],
                                [r1[1], 0.],
                                [0., r2[0]],
                                [r2[0], limits[1]],
                            ],
                            fit=['poly1', 'poly5', 'poly5', 'poly1'],
                            legendlabels=[
                                _range_label(None, r1[1]),
                                _range_label(r1[1], 0.0),
                                _range_label(0.0, r2[0]),
                                _range_label(r2[0], None),
                                ],
                            fmt=self.sd_fit_fmt, method='sel')
            psy.gcp(True)(ax=ax).share(keys=['xlim', 'ylim'])
            # ---- dry days ----
            ax = next(axes)
            psy.plot.density(
                ds, name=base + '_dry', ax=ax,
                coord=v + '_dry',
                ylabel='%(long_name)s [$^\circ$C]\non %(state)s days',
                text=[(middle, 0.03, '%(xlong_name)s [$^\circ$C]', 'fig', dict(
                     weight='bold', ha='center'))], fmt=self.sd_hist_fmt)
            # bars
            psy.plot.barplot(ds, name=base + '_dry_mean', ax=ax,
                             color='k', alpha=0.5, widths='data')
            limits = ax.get_xlim()
            psy.plot.linreg(ds, name=base + '_dry_mean', ax=ax,
                            temp_bins=[
                                slice(*r1),        # extrapolation < 0
                                slice(None, 0.0),  # polynomial < 0
github ARVE-Research / gwgen / gwgen / evaluation.py View on Github external
def create_project(self, ds):
        import psyplot.project as psy
        import seaborn as sns
        sns.set_style('white')
        for name, (vref, vsim) in zip(self.names, self.all_variables):
            self.logger.debug('Creating plots of %s', vsim)
            kwargs = dict(precision=0.1) if vref.startswith('prcp') else {}
            psy.plot.densityreg(ds, name='all_' + vsim, coord='all_' + vref,
                                fmt=self.fmt, title='All percentiles',
                                arr_names=['%s_all' % name],
                                **kwargs)
            arr_names = ['%s_%1.2f' % (name, p) for p in ds.pctl.values]
            psy.plot.densityreg(ds, name=vsim, coord=vref, fmt=self.fmt,
                                arr_names=arr_names, pctl=range(ds.pctl.size),
                                **kwargs)
        return psy.gcp(True)[:]
github ARVE-Research / gwgen / gwgen / parameterization.py View on Github external
ds, name='%swind_wet' % (t, ), ax=ax,
                ylabel='%(long_name)s [%(units)s]\non %(state)s days',
                text=[(middle, 0.03,
                       '%(xlong_name)s [%(xunits)s]', 'fig',
                       dict(weight='bold', ha='center'))], fmt=self.fmt,
                coord='wind' + ('_wet' if t == 'sd_' else ''), **kws)
            ax = next(axes)
            if t == 'sd_':
                psy.plot.barplot(ds, name='sd_wind_dry_mean',
                                 widths='data', alpha=0.5, color='k', ax=ax)
            psy.plot.densityreg(
                ds, name='%swind_dry' % (t, ), ax=ax,
                ylabel='on %(state)s days', fmt=self.fmt,
                coord='wind' + ('_dry' if t == 'sd_' else ''),
                **kws)
        return psy.gcp(True)[:]
github ARVE-Research / gwgen / gwgen / main.py View on Github external
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)]
        nml[vname + '_bias_min'] = float(ds.unorm.min().values)
        nml[vname + '_bias_max'] = float(ds.unorm.max().values)

        # --- save the data
        self.logger.info('Saving plots to %s', plot_output)
        mp = psy.gcp(True)
        mp.export(plot_output)
        self.logger.info('Saving project to %s', project_output)
        mp.save_project(project_output, paths=[nc_output])

        if close:
            psy.gcp(True).close(True, True, True)