Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
26a72fb
add circleci config
Chilipp Sep 16, 2021
cd2e49d
compatibility fixes for xarray 0.18
Chilipp Sep 16, 2021
a6077c6
add sphinx_rtd_theme
Chilipp Sep 16, 2021
b1bf531
use latest orb version
Chilipp Sep 22, 2021
a859cb2
do not run setup_env
Chilipp Sep 22, 2021
9c1ca52
remove examples from the docs
Chilipp Sep 22, 2021
a082ddc
update orb version
Chilipp Sep 22, 2021
1f8ed3c
use psyplot-ci-orb@1.5.4
Chilipp Sep 22, 2021
10e4c46
deploy docs to github pages
Chilipp Sep 22, 2021
60b0554
run deploy after install
Chilipp Sep 22, 2021
62a6606
add deployment and release parameters
Chilipp Sep 27, 2021
4a7c564
minor
Chilipp Sep 27, 2021
80a1bc0
config fixes
Chilipp Sep 27, 2021
6828e93
use psyplot-ci-orb@1.5.11
Chilipp Sep 27, 2021
a9e82a9
minor ci fix
Chilipp Sep 28, 2021
d73dfb6
add MM_WEBHOOK via context
Chilipp Sep 28, 2021
e90f41e
use parallel tests for xarray
Chilipp Sep 28, 2021
74d98e0
minor test fixes
Chilipp Sep 28, 2021
4eb424f
restrict xarray version to 0.17
Chilipp Sep 28, 2021
6a19989
install extra packages
Chilipp Sep 28, 2021
89fbea1
do not test for xarray versions on windows
Chilipp Sep 28, 2021
6c61b42
specify python version and label for upload
Chilipp Sep 28, 2021
235df63
minor
Chilipp Sep 28, 2021
344cd7d
do not install psyplot-ci-orb dependencies
Chilipp Sep 28, 2021
f851859
use psyplot-ci-orb@1.5.13
Chilipp Sep 28, 2021
aa6d372
use psyplot-ci-orb@1.5.14
Chilipp Sep 28, 2021
a8de729
use psyplot-ci-orb@1.5.15
Chilipp Sep 28, 2021
f4fd262
use psyplot-ci-orb@1.5.16
Chilipp Sep 29, 2021
7da7504
minor
Chilipp Sep 29, 2021
8c2a994
[skip ci] update badges
Chilipp Sep 29, 2021
667566b
use LGPL-3.0 license
Chilipp Sep 22, 2021
e3780be
Change license to LGPL-3.0
Chilipp Sep 22, 2021
20d4e14
remove old reference to version.py
Chilipp Sep 28, 2021
2fb2d21
Merge branch 'master' of github.com:psyplot/psyplot into license
Chilipp Sep 29, 2021
eadaf15
update changelog with license change
Chilipp Sep 29, 2021
4f1545f
use psyplot-ci-orb@1.5.17
Chilipp Sep 29, 2021
1d36997
include COPYING and COPYING.LESSER in MANIFEST.in
Chilipp Sep 29, 2021
240172d
add Copyright statement to README.rst
Chilipp Sep 29, 2021
1f08cb3
add disclaimer to versioneer.py
Chilipp Sep 29, 2021
5e65c86
remove redundant file
Chilipp Sep 29, 2021
34c9c31
update license info
Chilipp Sep 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compatibility fixes for xarray 0.18
they changed the backend infrastructure. Now, it is only possible
to get the file name if the dataset has been opened with
psy.open_dataset or psy.open_mfdataset

The store will always be guessed.
  • Loading branch information
Chilipp committed Sep 16, 2021
commit cd2e49d788a3b50c824521afff5aef4488d93d83
84 changes: 58 additions & 26 deletions psyplot/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import xarray as xr
from xarray.core.utils import NDArrayMixin
from xarray.core.formatting import first_n_items, format_item

import xarray.backends.api as xarray_api
from pandas import to_datetime
import numpy as np
Expand All @@ -33,6 +34,11 @@
except ImportError:
with_dask = False

try:
import xarray.backends.plugins as xr_plugins
except ImportError:
xr_plugins = None # type: ignore


# No data variable. This is used for filtering if an attribute could not have
# been accessed
Expand Down Expand Up @@ -487,6 +493,38 @@ def tmp_it():
while True:
yield NamedTemporaryFile(suffix='.nc').name

def _legacy_get_filename_ds(ds):
# try to get the filename from the data store of the obj
#
# Outdated possibility since the backend plugin methodology of
# xarray 0.18
if store_mod is not None:
store = ds._file_obj
# try several engines
if hasattr(store, 'file_objs'):
fname = []
store_mod = []
store_cls = []
for obj in store.file_objs: # mfdataset
_fname = None
for func in get_fname_funcs:
if _fname is None:
_fname = func(obj)
if _fname is not None:
fname.append(_fname)
store_mod.append(obj.__module__)
store_cls.append(obj.__class__.__name__)
fname = tuple(fname)
store_mod = tuple(store_mod)
store_cls = tuple(store_cls)
else:
for func in get_fname_funcs:
fname = func(store)
if fname is not None:
break

return fname, store_mod, store_cls

fname = None
if paths is True or (dump and paths is None):
paths = tmp_it()
Expand All @@ -495,32 +533,15 @@ def tmp_it():
paths = iter([paths])
else:
paths = iter(paths)
# try to get the filename from the data store of the obj
store_mod, store_cls = ds.psy.data_store
if store_mod is not None:
store = ds._file_obj
# try several engines
if hasattr(store, 'file_objs'):
fname = []
store_mod = []
store_cls = []
for obj in store.file_objs: # mfdataset
_fname = None
for func in get_fname_funcs:
if _fname is None:
_fname = func(obj)
if _fname is not None:
fname.append(_fname)
store_mod.append(obj.__module__)
store_cls.append(obj.__class__.__name__)
fname = tuple(fname)
store_mod = tuple(store_mod)
store_cls = tuple(store_cls)
else:
for func in get_fname_funcs:
fname = func(store)
if fname is not None:
break
if xr_plugins is None:
fname, store_mod, store_cls = _legacy_get_filename_ds(ds)
elif "source" in ds.encoding:
fname = ds.encoding["source"]
store_mod = None
store_cls = None


# check if paths is provided and if yes, save the file
if fname is None and paths is not None:
fname = next(paths, None)
Expand Down Expand Up @@ -2004,6 +2025,8 @@ def open_dataset(filename_or_obj, decode_cf=True, decode_times=True,
ds = xr.open_dataset(filename_or_obj, decode_cf=decode_cf,
decode_coords=False, engine=engine,
decode_times=decode_times, **kwargs)
if isstring(filename_or_obj):
ds.psy.filename = filename_or_obj
if decode_cf:
ds = CFDecoder.decode_ds(
ds, decode_coords=decode_coords, decode_times=decode_times,
Expand Down Expand Up @@ -2060,15 +2083,21 @@ def open_mfdataset(paths, decode_cf=True, decode_times=True,
kwargs['concat_dim'] = 'time'
if xr_version > (0, 11):
kwargs['combine'] = 'nested'
if all(map(isstring, paths)):
filenames = list(paths)
else:
filenames = None
if engine == 'gdal':
from psyplot.gdal_store import GdalStore
paths = list(map(GdalStore, paths))
engine = None
kwargs['lock'] = False
if xr_version < (0, 18):
kwargs['lock'] = False

ds = xr.open_mfdataset(
paths, decode_cf=decode_cf, decode_times=decode_times, engine=engine,
decode_coords=False, **kwargs)
ds.psy.filename = filenames
if decode_cf:
ds = CFDecoder.decode_ds(ds, gridfile=gridfile,
decode_coords=decode_coords,
Expand Down Expand Up @@ -4981,6 +5010,9 @@ def _open_ds_from_store(fname, store_mod=None, store_cls=None, **kwargs):
kwargs['engine'] = None
kwargs['lock'] = False
return open_mfdataset(fname, **kwargs)
else:
# try guessing with open_dataset
return open_mfdataset(fname, **kwargs)
if store_mod is not None and store_cls is not None:
fname = _open_store(store_mod, store_cls, fname)
return open_dataset(fname, **kwargs)
Expand Down
12 changes: 10 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,10 @@ def test_array_info(self):
name=[['v1', ['v3', 'v4']], ['v1', 'v2']], prefer_list=True)
l.extend(ds2.psy.create_list(name=['t2m'], x=0, t=1),
new_name=True)
if xr_version < (0, 18):
nc_store = ('xarray.backends.netCDF4_', 'NetCDF4DataStore')
else:
nc_store = (None, None)
self.assertEqual(l.array_info(engine='netCDF4'), OrderedDict([
# first list contating an array with two variables
('arr0', OrderedDict([
Expand All @@ -1345,8 +1349,7 @@ def test_array_info(self):
('arr2', {'dims': {'z': slice(None), 'y': slice(None),
't': 1, 'x': 0},
'attrs': ds2.t2m.attrs,
'store': ('xarray.backends.netCDF4_',
'NetCDF4DataStore'),
'store': nc_store,
'name': 't2m', 'fname': fname}),
('attrs', OrderedDict())]))
return l
Expand Down Expand Up @@ -1398,6 +1401,8 @@ def test_from_dict_03_mfdataset(self):
# now open the mfdataset
ds = psyd.open_mfdataset([fname1, fname2])
l = self.list_class.from_dataset(ds, name=['v0'], time=[0, 3])
if xr_version >= (0, 18):
ds.psy.filename = [fname1, fname2]
self.assertEqual(
self.list_class.from_dict(l.array_info()).array_info(),
l.array_info())
Expand Down Expand Up @@ -1557,14 +1562,17 @@ def _test_engine(self, engine):
ds.close()
os.remove(dumped_fname)

@unittest.skipIf(xr_version >= (0, 18), "Not supported for xarray>=0.18")
@unittest.skipIf(not with_nio, 'Nio module not installed')
def test_nio(self):
self._test_engine('pynio')

@unittest.skipIf(xr_version >= (0, 18), "Not supported for xarray>=0.18")
@unittest.skipIf(not with_netcdf4, 'netCDF4 module not installed')
def test_netcdf4(self):
self._test_engine('netcdf4')

@unittest.skipIf(xr_version >= (0, 18), "Not supported for xarray>=0.18")
@unittest.skipIf(not with_scipy, 'scipy module not installed')
def test_scipy(self):
self._test_engine('scipy')
Expand Down