How to use the psyplot.project.plot.test_plotter 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_project.py View on Github external
def test_save_and_load_03_alternative_ds(self):
        """Test the saving and loading of a Project providing alternative axes
        """
        psy.register_plotter('test_plotter', import_plotter=True,
                             module='test_plotter', plotter_name='TestPlotter')
        ds = psy.open_dataset(bt.get_file('test-t2m-u-v.nc'))
        plt.close('all')
        sp = psy.plot.test_plotter(ds, name=['t2m', 'u'], x=0, y=4,
                                   ax=(2, 2, 1), fmt1='test')
        self.assertEqual(len(sp), 2)
        self.assertEqual(sp[0].psy.ax.get_figure().number, 1)
        self.assertEqual(sp[0].psy.ax.rowNum, 0)
        self.assertEqual(sp[0].psy.ax.colNum, 0)
        self.assertEqual(sp[0].psy.ax.numCols, 2)
        self.assertEqual(sp[0].psy.ax.numRows, 2)
        self.assertEqual(sp[1].psy.ax.get_figure().number, 2)
        self.assertEqual(sp[1].psy.ax.rowNum, 0)
        self.assertEqual(sp[1].psy.ax.colNum, 0)
        self.assertEqual(sp[1].psy.ax.numCols, 2)
        self.assertEqual(sp[1].psy.ax.numRows, 2)
        arr_names = sp.arr_names
        self.assertEqual(tp.results[arr_names[0] + '.fmt1'], 'test')
        self.assertEqual(tp.results[arr_names[1] + '.fmt1'], 'test')
        fname = 'test.pkl'
github Chilipp / psyplot / tests / test_project.py View on Github external
shutil.copyfile(bt.get_file('test-t2m-u-v.nc'),
                        osp.join(tempdir1, 'test-t2m-u-v.nc'))
        psy.plot.test_plotter(osp.join(tempdir1, 'test-t2m-u-v.nc'),
                              name='t2m', t=[1, 2])
        # second test file
        shutil.copyfile(bt.get_file('test-t2m-u-v.nc'),
                        osp.join(tempdir2, 'test-t2m-u-v.nc'))
        psy.plot.test_plotter(osp.join(tempdir2, 'test-t2m-u-v.nc'),
                              name='t2m', t=[3, 4])
        # third test file
        shutil.copyfile(bt.get_file('test-t2m-u-v.nc'),
                        osp.join(tempdir3, 'test-t2m-u-v.nc'))
        psy.plot.test_plotter(osp.join(tempdir3, 'test-t2m-u-v.nc'),
                              name='t2m', t=[3, 4])
        # fourth test file with different name
        psy.plot.test_plotter(bt.get_file('circumpolar_test.nc'), name='t2m',
                              t=[0, 1])
        mp = psy.gcp(True)

        mp.save_project(osp.join(outdir, 'test.pkl'), pack=True)
        files = {'test-t2m-u-v.nc', 'test-t2m-u-v-1.nc',
                 'test-t2m-u-v-2.nc', 'test.pkl', 'circumpolar_test.nc'}
        self.assertEqual(set(os.listdir(outdir)), files)

        psy.close(mp)

        # move the directory to check whether it is still working
        outdir2 = tempfile.mkdtemp(prefix='psyplot_test_')
        self._created_files.add(outdir2)
        for f in files:
            shutil.move(osp.join(outdir, f), osp.join(outdir2, f))
        mp = psy.Project.load_project(osp.join(outdir2, 'test.pkl'), main=True,
github Chilipp / psyplot / tests / test_main.py View on Github external
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
github Chilipp / psyplot / tests / test_project.py View on Github external
def test_update(self):
        """Test the update of an :class:`psyplot.data.ArrayList`"""
        variables, coords = self._from_dataset_test_variables
        ds = xr.Dataset(variables, coords)
        psy.register_plotter('test_plotter', module='something',
                             plotter_name='unimportant',
                             plotter_cls=tp.TestPlotter)
        # add 2 arrays
        psy.plot.test_plotter(ds, name=['v0', 'v1'], t=0)
        # add a list
        psy.plot.test_plotter(ds, name=['v0', 'v1'], t=0, prefer_list=True)

        mp = psy.gcp(True)

        self.assertEqual(len(mp), 3, msg=mp)
        self.assertEqual(len(mp.plotters), 3, msg=mp)

        # update the list
        mp.update(t=1, fmt2='updated')

        for i, plotter in enumerate(mp.plotters):
            self.assertEqual(plotter['fmt2'], 'updated',
                             msg='Plotter of array %i not updated! %s' % (
                                i, mp[i]))
github Chilipp / psyplot / tests / test_project.py View on Github external
def test_docs(self):
        """Test the :meth:`psyplot.project.Project.docs` method"""
        import test_plotter as tp
        import psyplot.plotter as psyp
        psy.register_plotter('test_plotter', import_plotter=True,
                             module='test_plotter', plotter_name='TestPlotter')

        class TestPlotter2(tp.TestPlotter):
            fmt2 = None

        psy.register_plotter('test_plotter2', module='something',
                             plotter_name='anyway', plotter_cls=TestPlotter2)
        variables, coords = self._from_dataset_test_variables
        ds = xr.Dataset(variables, coords)
        sp1 = psy.plot.test_plotter(ds, name='v0')
        # add a second project without a fmt2 formatoption
        sp2 = psy.plot.test_plotter2(ds, name='v1')
        mp = sp1 + sp2
        self.assertEqual(sp1.docs(func=str), '\n'.join([
            'fmt1', '====', tp.SimpleFmt.__doc__, '',
            'fmt2', '====', tp.SimpleFmt2.__doc__, '',
            'fmt3', '====', tp.SimpleFmt3.__doc__, '',
            'post', '====', psyp.PostProcessing.__doc__, '',
            'post_timing', '===========', psyp.PostTiming.__doc__, '']))
        # test summed project
        self.assertEqual(mp.docs(func=str), '\n'.join([
            'fmt1', '====', tp.SimpleFmt.__doc__, '',
            'fmt3', '====', tp.SimpleFmt3.__doc__, '',
            'post', '====', psyp.PostProcessing.__doc__, '',
            'post_timing', '===========', psyp.PostTiming.__doc__, '']))
        title = psyp.groups['labels']
github Chilipp / psyplot / tests / test_project.py View on Github external
def test_summaries(self):
        """Test the :meth:`psyplot.project.Project.summaries` method"""
        import test_plotter as tp
        import psyplot.plotter as psyp
        psy.register_plotter('test_plotter', import_plotter=True,
                             module='test_plotter', plotter_name='TestPlotter')

        class TestPlotter2(tp.TestPlotter):
            fmt2 = None

        psy.register_plotter('test_plotter2', module='something',
                             plotter_name='anyway', plotter_cls=TestPlotter2)
        variables, coords = self._from_dataset_test_variables
        ds = xr.Dataset(variables, coords)
        sp1 = psy.plot.test_plotter(ds, name='v0')
        # add a second project without a fmt2 formatoption
        sp2 = psy.plot.test_plotter2(ds, name='v1')
        mp = sp1 + sp2
        self.assertEqual(sp1.summaries(func=str), '\n'.join([
            'fmt1', tp.indent(tp.SimpleFmt.__doc__.splitlines()[0], '    '),
            'fmt2', tp.indent(tp.SimpleFmt2.__doc__.splitlines()[0], '    '),
            'fmt3', tp.indent(tp.SimpleFmt3.__doc__.splitlines()[0], '    '),
            'post', tp.indent(psyp.PostProcessing.__doc__.splitlines()[0],
                              '    '),
            'post_timing', tp.indent(psyp.PostTiming.__doc__.splitlines()[0],
                                     '    ')]))
        # test summed project
        self.assertEqual(mp.summaries(func=str), '\n'.join([
            'fmt1', tp.indent(tp.SimpleFmt.__doc__.splitlines()[0], '    '),
            'fmt3', tp.indent(tp.SimpleFmt3.__doc__.splitlines()[0], '    '),
            'post', tp.indent(psyp.PostProcessing.__doc__.splitlines()[0],