How to use the psyplot.data 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_data.py View on Github external
'multiple matches'):
                    coords = 'time lat lon lev x y latitude longitude'.split()
                    ds.t2m.attrs.pop('coordinates', None)
                    for dim in 'xytz':
                        getattr(d, dim).update(coords)
                    for coord in set(coords).intersection(ds.coords):
                        ds.coords[coord].attrs.pop('axis', None)
                    getattr(d, func_name)(ds.t2m)
        uname = uname or name
        circ_name = circ_name or name
        ds = psyd.open_dataset(os.path.join(bt.test_dir, 'test-t2m-u-v.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(name)
        ds.close()
        ds = psyd.open_dataset(os.path.join(bt.test_dir, 'icon_test.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(uname)
        ds.close()
        ds = psyd.open_dataset(
            os.path.join(bt.test_dir, 'circumpolar_test.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(circ_name)
        ds.close()
github Chilipp / psyplot / tests / test_data.py View on Github external
if six.PY3:
                # Test whether the warning is raised if the decoder finds
                # multiple dimensions
                with self.assertWarnsRegex(RuntimeWarning,
                                           'multiple matches'):
                    coords = 'time lat lon lev x y latitude longitude'.split()
                    ds.t2m.attrs.pop('coordinates', None)
                    for dim in 'xytz':
                        getattr(d, dim).update(coords)
                    for coord in set(coords).intersection(ds.coords):
                        ds.coords[coord].attrs.pop('axis', None)
                    getattr(d, func_name)(ds.t2m)
        uname = uname or name
        circ_name = circ_name or name
        ds = psyd.open_dataset(os.path.join(bt.test_dir, 'test-t2m-u-v.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(name)
        ds.close()
        ds = psyd.open_dataset(os.path.join(bt.test_dir, 'icon_test.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(uname)
        ds.close()
        ds = psyd.open_dataset(
            os.path.join(bt.test_dir, 'circumpolar_test.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(circ_name)
        ds.close()
github Chilipp / psyplot / tests / test_data.py View on Github external
def _test_engine(self, engine):
        from importlib import import_module
        fname = self.fname
        ds = psyd.open_dataset(fname, engine=engine).load()
        self.assertEqual(ds.psy.filename, fname)
        store_mod, store = ds.psy.data_store
        # try to load the dataset
        mod = import_module(store_mod)
        try:
            ds2 = psyd.open_dataset(getattr(mod, store).open(fname))
        except AttributeError:
            ds2 = psyd.open_dataset(getattr(mod, store)(fname))
        ds.close()
        ds2.close()
        ds.psy.filename = None
        dumped_fname, dumped_store_mod, dumped_store = psyd.get_filename_ds(
            ds, dump=True, engine=engine, paths=True)
        self.assertTrue(dumped_fname)
        self.assertTrue(osp.exists(dumped_fname),
                        msg='Missing %s' % fname)
        self.assertEqual(dumped_store_mod, store_mod)
        self.assertEqual(dumped_store, store)
        ds.close()
        ds.psy.filename = None
        os.remove(dumped_fname)

        dumped_fname, dumped_store_mod, dumped_store = psyd.get_filename_ds(
            ds, dump=True, engine=engine, paths=dumped_fname)
        self.assertTrue(dumped_fname)
        self.assertTrue(osp.exists(dumped_fname),
                        msg='Missing %s' % fname)
        self.assertEqual(dumped_store_mod, store_mod)
github Chilipp / psyplot / tests / test_data.py View on Github external
for dim in 'xytz':
                        getattr(d, dim).update(coords)
                    for coord in set(coords).intersection(ds.coords):
                        ds.coords[coord].attrs.pop('axis', None)
                    getattr(d, func_name)(ds.t2m)
        uname = uname or name
        circ_name = circ_name or name
        ds = psyd.open_dataset(os.path.join(bt.test_dir, 'test-t2m-u-v.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(name)
        ds.close()
        ds = psyd.open_dataset(os.path.join(bt.test_dir, 'icon_test.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(uname)
        ds.close()
        ds = psyd.open_dataset(
            os.path.join(bt.test_dir, 'circumpolar_test.nc'))
        d = psyd.CFDecoder(ds)
        check_ds(circ_name)
        ds.close()
github Chilipp / psyplot / tests / test_plotter.py View on Github external
def test_data_props_list(self):
        """Test the data properties of Formatoptions with an InteractiveList"""
        data = psyd.InteractiveList([xr.DataArray([]), xr.DataArray([])])
        plot_data = data.copy(True)
        plot_data.extend([xr.DataArray([]), xr.DataArray([])],
                         new_name=True)
        plotter = TestPlotter(data)
        plotter.plot_data = plot_data
        plot_data = plotter.plot_data  # the data might have been copied

        self.assertIs(plotter.fmt1.raw_data, data)
        self.assertIs(plotter.fmt1.data, plot_data)

        # test with index in list
        plotter.fmt1.index_in_list = 1
        self.assertIs(plotter.fmt1.raw_data, data[1])
        self.assertIs(plotter.fmt1.data, plot_data[1])

        # test with index in list of plot_data outside raw_data
github Chilipp / psyplot / tests / test_project.py View on Github external
fig, axes = plt.subplots(1, 2)
        sp = psy.Project.load_project(
            fname, alternative_paths=[bt.get_file('circumpolar_test.nc')],
            new_fig=False)
        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)
        self.assertEqual(psyd.get_filename_ds(sp[0].psy.base)[0],
                         bt.get_file('circumpolar_test.nc'))
        self.assertEqual(psyd.get_filename_ds(sp[1].psy.base)[0],
                         bt.get_file('circumpolar_test.nc'))
github Chilipp / psyplot / tests / test_data.py View on Github external
def test_get_decoder(self):
        """Test to get the right decoder"""
        ds = psyd.open_dataset(bt.get_file('simple_triangular_grid_si0.nc'))
        d = psyd.CFDecoder.get_decoder(ds, ds.Mesh2_fcvar)
        self.assertIsInstance(d, psyd.UGridDecoder)
        return ds, d
github Chilipp / psyplot / psyplot / __main__.py View on Github external
def __call__(self, parser, namespace, values, option_string=None):
        if namespace.project is None:
            print('A project is required before this argument! Call syntax:\n'
                  '%s -p .pkl %s' % (parser.prog, option_string))
            sys.exit(1)
        import psyplot.data as psyd
        import pickle
        with open(namespace.project, 'rb') as f:
            d = pickle.load(f)['arrays']
        names = list(filter(None, (
            t[0] for t in psyd.ArrayList._get_dsnames(d))))
        if names:
            print(yaml.dump(names, default_flow_style=False))
        sys.exit(0)
github ARVE-Research / gwgen / gwgen / sensitivity_analysis.py View on Github external
import matplotlib.colors as mcol
        import seaborn as sns
        from matplotlib.backends.backend_pdf import PdfPages
        import matplotlib.patches as patches
        sns.set_style('white')
        full_df = self.data.reset_index()
        plot_output = self.task_config.plot_output
        pdf = PdfPages(plot_output)
        all_exps = self.organizer.config.experiments
        for ind in self.task_config.indicators:
            for variable in self.task_config.names:
                df = full_df[full_df.vname == variable]
                vals = {
                    key: group.set_index('gp_shape').sort_index()[ind]
                    for key, group in df.groupby('thresh')}
                y = psyd._infer_interval_breaks(sorted(vals.keys()))
                fig = plt.figure(edgecolor='none', facecolor='none')
                if mpl.__version__ < '2.0':
                    ax = plt.axes(axisbg='0.9')
                else:
                    ax = plt.axes(facecolor='0.9')
                all_vals = np.concatenate(list(vals.values()))
                vmin, vmax = psyps.DataTicksCalculator._round_min_max(
                    np.nanmin(all_vals), np.nanmax(all_vals))
                norm = mcol.BoundaryNorm(
                    np.linspace(vmin, vmax, 11, endpoint=True), 10)
                cmap = plt.get_cmap('Greens', 10)
                # set missing values to (dark) red
                cmap.set_bad((0.7686274509803922, 0.3058823529411765,
                              0.3215686274509804))
                plots = []
                x_vals = {}
github Chilipp / psyplot / psyplot / gdal_store.py View on Github external
from numpy import arange, nan, dtype
from xarray import Variable
from collections import OrderedDict
try:
    from xarray.core.utils import FrozenOrderedDict
except ImportError:
    FrozenOrderedDict = dict
from xarray.backends.common import AbstractDataStore
from psyplot.compat.pycompat import range
from psyplot.warning import warn
import psyplot.data as psyd
try:
    import gdal
    from osgeo import gdal_array
except ImportError as e:
    gdal = psyd._MissingModule(e)
try:
    from dask.array import Array
    with_dask = True
except ImportError:
    with_dask = False


class GdalStore(AbstractDataStore):
    """Datastore to read raster files suitable for the gdal package

    We recommend to use the :func:`psyplot.open_dataset` function to open
    a geotiff file::

        >>> ds = psyplot.open_dataset('my_geotiff.tiff', engine='gdal')

    Notes