How to use the psyplot.project.Project.load_project 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
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',
                                   post='self.ax.set_title("test")')
        self.assertEqual(sp.plotters[0].ax.get_title(), 'test')
        fname = 'test.pkl'
        self._created_files.add(fname)
        sp.save_project(fname)
        psy.close('all')
        # test without enabled post
        sp = psy.Project.load_project(fname)
        self.assertEqual(sp.plotters[0].ax.get_title(), '')
        psy.close('all')
        # test with enabled post
        sp = psy.Project.load_project(fname, enable_post=True)
        self.assertEqual(sp.plotters[0].ax.get_title(), 'test')
github Chilipp / psyplot / tests / test_project.py View on Github external
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'
        self._created_files.add(fname)
        sp.save_project(fname)
        psy.close()
        tp.results.clear()
        fig, axes = plt.subplots(1, 2)
        sp = psy.Project.load_project(fname, alternative_axes=axes.ravel())
        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, 1)
        self.assertEqual(sp[1].psy.ax.get_figure().number, 1)
        self.assertEqual(sp[1].psy.ax.rowNum, 0)
        self.assertEqual(sp[1].psy.ax.colNum, 1)
        self.assertEqual(sp[1].psy.ax.numCols, 2)
        self.assertEqual(sp[1].psy.ax.numRows, 1)
github Chilipp / psyplot / tests / test_project.py View on Github external
module='test_plotter', plotter_name='TestPlotter')
        ds = psy.open_dataset(bt.get_file('test-t2m-u-v.nc'))
        plt.close('all')
        fig, axes = plt.subplots(1, 3, sharey=True)
        sp = psy.plot.test_plotter(ds, name=['t2m', 'u', 'v'], x=0, y=4,
                                   ax=axes)
        axes[0].set_ylim(5, 10)
        self.assertEqual(list(axes[1].get_ylim()), [5, 10])
        # save the project
        fname = 'test.pkl'
        self._created_files.add(fname)
        sp.save_project(fname)
        psy.close('all')

        # load the project
        sp = psy.Project.load_project(fname)
        self.assertEqual(len(sp.axes), 3, msg=sp.axes)
        sp[0].psy.ax.set_ylim(10, 15)
        self.assertEqual(list(sp[1].psy.ax.get_ylim()), [10, 15])

        # now we test, if it still works, if we remove the source axes
        names2use = sp.arr_names[1:]
        psy.close('all')
        sp = psy.Project.load_project(fname, only=names2use)
        self.assertEqual(len(sp.axes), 2, msg=sp.axes)
        sp[0].psy.ax.set_ylim(10, 15)
        self.assertEqual(list(sp[1].psy.ax.get_ylim()), [10, 15])
github Chilipp / psyplot / tests / test_project.py View on Github external
mp = psy.gcp(True)
        self.assertEqual(len(mp), 4, msg=mp)
        d = mp.save_project()
        self.assertIn('versions', d)
        self.assertEqual(len(d['versions']), 2, msg=d['versions'])
        self.assertIn('psyplot', d['versions'])
        self.assertIn('psyplot_test.plugin', d['versions'])
        self.assertEqual(d['versions']['psyplot_test.plugin']['version'],
                         '1.0.0')

        # test the patch
        self.assertEqual(test_plugin.patch_check, [])
        test_plugin.checking_patch = True
        try:
            mp.close(True, True, True)
            mp = psy.Project.load_project(d)
            self.assertEqual(len(test_plugin.patch_check), 2)
            self.assertIs(test_plugin.patch_check[0]['plotter'],
                          d['arrays']['arr0']['plotter'])
            self.assertIs(test_plugin.patch_check[1]['plotter'],
                          d['arrays']['arr1']['plotter'])
            self.assertIs(test_plugin.patch_check[0]['versions'],
                          d['versions'])
            self.assertIs(test_plugin.patch_check[1]['versions'],
                          d['versions'])
        finally:
            test_plugin.checking_patch = False
github Chilipp / psyplot / tests / test_project.py View on Github external
# save the project
        fname = 'test.pkl'
        self._created_files.add(fname)
        sp.save_project(fname)
        psy.close('all')

        # load the project
        sp = psy.Project.load_project(fname)
        self.assertEqual(len(sp.axes), 3, msg=sp.axes)
        sp[0].psy.ax.set_xlim(10, 15)
        self.assertEqual(list(sp[1].psy.ax.get_xlim()), [10, 15])

        # now we test, if it still works, if we remove the source axes
        names2use = sp.arr_names[1:]
        psy.close('all')
        sp = psy.Project.load_project(fname, only=names2use)
        self.assertEqual(len(sp.axes), 2, msg=sp.axes)
        sp[0].psy.ax.set_xlim(10, 15)
        self.assertEqual(list(sp[1].psy.ax.get_xlim()), [10, 15])
github Chilipp / psyplot / psyplot / __main__.py View on Github external
"the output parameter is set!")
    elif project is None and plot_method is None:
        raise ValueError(
            "A plotting method must be provided if the output parameter "
            "is set and not the project!")
    if seaborn_style is not None:
        import seaborn as sns
        sns.set_style(seaborn_style)
    import psyplot.project as psy
    if project is not None:
        fnames = [s.split(',') for s in fnames]
        chname = dict(chname)
        single_files = (l[0] for l in fnames if len(l) == 1)
        alternative_paths = defaultdict(lambda: next(single_files, None))
        alternative_paths.update([l for l in fnames if len(l) == 2])
        p = psy.Project.load_project(
            project, alternative_paths=alternative_paths,
            engine=engine, encoding=encoding, enable_post=enable_post,
            chname=chname)
        if formatoptions is not None:
            p.update(fmt=formatoptions)
        p.export(output, tight=tight)
    else:
        pm = getattr(psy.plot, plot_method, None)
        if pm is None:
            raise ValueError("Unknown plot method %s!" % plot_method)
        kwargs = {'name': name} if name else {}
        p = pm(
            fnames, dims=dims or {}, engine=engine,
            fmt=formatoptions or {}, mf_mode=True, concat_dim=concat_dim,
            **kwargs)
        p.export(output, tight=tight)
github ARVE-Research / gwgen / gwgen / utils.py View on Github external
project_output = self.task_config.project_output
        info['nc_file'] = nc_output
        info['plot_file'] = plot_output
        info['project_file'] = project_output

        # ---- open dataset
        ds_orig = ds_list = self.ds
        if isinstance(ds_list, xr.Dataset):
            ds_list = [ds_list]

        # ---- create project
        inproject = self.task_config.project or project_output
        if not self.task_config.new_project and osp.exists(inproject):
            import psyplot.project as psy
            self.logger.debug('    Loading existing project %s', inproject)
            sp = psy.Project.load_project(inproject, datasets=ds_list)
        else:
            self.logger.debug('    Creating project...')
            sp = self.create_project(ds_orig)

        # ---- save data and project
        pdf = sp.export(plot_output, tight=True, close_pdf=False)
        if project_output:
            self.logger.debug('    Saving project to %s', project_output)
            if nc_output:
                for f in safe_list(nc_output):
                    if osp.exists(f):
                        os.remove(f)
                save_kws = dict(use_rel_paths=True, paths=safe_list(nc_output))
            else:  # save the entire dataset into the pickle file
                save_kws = dict(ds_description={'ds'})
            sp.save_project(project_output, **save_kws)
github ARVE-Research / gwgen / gwgen / main.py View on Github external
'bias', OrderedDict()).setdefault(vname, OrderedDict())
        plot_output = plot_output or d.get('plot_output')
        if plot_output is None:
            plot_output = osp.join(
                postproc_dir, vname + '_bias_correction.pdf')

        project_output = osp.splitext(plot_output)[0] + '.pkl'
        nc_output = osp.splitext(plot_output)[0] + '.nc'

        d['plot_file'] = plot_output
        d['project_file'] = project_output
        d['nc_file'] = nc_output

        # --- slope bias correction
        if osp.exists(project_output) and not new_project:
            mp = psy.Project.load_project(project_output, datasets=[ds])
            sp2 = mp.linreg(name='slope')
        else:
            import seaborn as sns
            sns.set_style('white')
            sp1 = psy.plot.lineplot(ds, name='slope', coord='unorm',
                                    linewidth=0, marker='o', legend=False)
            sp2 = psy.plot.linreg(
                 ds, name='slope', ax=sp1[0].psy.ax,
                 coord='unorm', fit=logistic_function,
                 ylabel=('$\\mathrm{{Simulated}}\\, \\mathrm{{%s}} / '
                         '\\mathrm{{Observed}}\\, \\mathrm{{%s}}$') % (
                            vname, vname),
                 legendlabels=(
                     '$\\frac{{\\mathrm{{Simulated}}}}'
                     '{{\\mathrm{{Observed}}}} = '
                     '\\frac{{%(L)4.3f}}{{1 + \\mathrm{{e}}^{{'