How to use the psyplot.data.CFDecoder 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
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_decoder(self):
        """Test the decoder property of Formatoptions with a DataArray"""
        data = xr.DataArray([])
        data.psy.init_accessor(decoder=psyd.CFDecoder(data.psy.base))
        plot_data = data.copy(True)
        plotter = TestPlotter(data)
        plotter.plot_data = plot_data

        self.assertIsInstance(plotter.fmt1.decoder, psyd.CFDecoder)
        self.assertIs(plotter.fmt1.decoder, data.psy.decoder)

        # test with index in list of plot_data outside raw_data
        plotter.plot_data_decoder = decoder = psyd.CFDecoder(data.psy.base)
        self.assertIsInstance(plotter.fmt1.decoder, psyd.CFDecoder)
        self.assertIs(plotter.fmt1.decoder, decoder)
github Chilipp / psyplot / tests / test_data.py View on Github external
def test_from_dataset_14_decoder_instance(self):
        ds = xr.Dataset(*self._from_dataset_test_variables)

        class MyDecoder(psyd.CFDecoder):
            pass

        decoder = MyDecoder(ds)

        l = self.list_class.from_dataset(ds, name="v2", decoder=decoder)
        self.assertIs(l[0].psy.decoder, decoder)
github Chilipp / psyplot / tests / test_plotter.py View on Github external
def test_decoder_list(self):
        """Test the decoder property 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)
        for arr in data:
            arr.psy.init_accessor(decoder=psyd.CFDecoder(arr.psy.base))
        plotter = TestPlotter(data)
        plotter.plot_data = plot_data
        plot_data = plotter.plot_data  # the data might have been copied

        self.assertIsInstance(plotter.fmt1.decoder, psyd.CFDecoder)
        self.assertIs(plotter.fmt1.decoder, data[0].psy.decoder)

        # test with index in list
        plotter.fmt1.index_in_list = 1
        self.assertIsInstance(plotter.fmt1.decoder, psyd.CFDecoder)
        self.assertIs(plotter.fmt1.decoder, data[1].psy.decoder)

        # test without index in list
        decoder = psyd.CFDecoder(data[0].psy.base)
        plotter.fmt2.decoder = decoder
        for i, d2 in enumerate(plotter.plot_data_decoder):
github Chilipp / psyplot / tests / test_plotter.py View on Github external
def test_any_decoder(self):
        """Test the decoder property 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)
        for arr in data:
            arr.psy.init_accessor(decoder=psyd.CFDecoder(arr.psy.base))
        plotter = TestPlotter(data)
        plotter.plot_data = plot_data
        plot_data = plotter.plot_data  # the data might have been copied

        # test without index in list
        decoder = psyd.CFDecoder(data[0].psy.base)
        plotter.fmt2.decoder = decoder
        for i, d2 in enumerate(plotter.plot_data_decoder):
            self.assertIs(d2, decoder,
                          msg='Decoder %i has been set wrong!' % i)
        self.assertEqual(plotter.fmt2.decoder, plotter.plot_data_decoder)
        self.assertIs(plotter.fmt2.any_decoder, decoder)
github Chilipp / psyplot / psyplot / project.py View on Github external
method

        Returns
        -------
        %(Plotter.check_data.returns)s
        """
        if isinstance(name, six.string_types):
            name = [name]
            dims = [dims]
            decoders = [decoder]
        else:
            dims = list(dims)
            decoders = list(decoder if decoder is not None else [None])
        variables = [ds[safe_list(n)[0]] for n in name]
        if decoders is None:
            decoders = [CFDecoder.get_decoder(ds, var) for var in variables]
        else:
            for i, (decoder, var) in enumerate(zip(decoders, variables)):
                if decoder is None:
                    decoder = {}
                if isinstance(decoder, dict):
                    decoders[i] = CFDecoder.get_decoder(ds, var, **decoder)
        default_slice = slice(None) if self._default_slice is None else \
            self._default_slice
        for i, (dim_dict, var, decoder) in enumerate(zip(
                dims, variables, decoders)):
            corrected = decoder.correct_dims(var, dict(chain(
                six.iteritems(self._default_dims),
                dim_dict.items())))
            # now use the default slice (we don't do this before because the
            # `correct_dims` method doesn't use 'x', 'y', 'z' and 't' (as used
            # for the _default_dims) if the real dimension name is already in