Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open_datatree performance improvement on NetCDF, H5, and Zarr files #9014

Merged
merged 38 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
14aaf56
open_datatree performance improvement on NetCDF files
aladinor May 7, 2024
3a5edb4
fixing issue with forward slashes
aladinor May 7, 2024
72d7660
Merge branch 'main' into datatree-zarr
aladinor May 7, 2024
d9dde29
fixing issue with pytest
aladinor May 7, 2024
2bc5e73
fixing issue with pytest
aladinor May 7, 2024
89fb4fb
Merge branch 'main' into datatree-zarr
aladinor May 8, 2024
0343f10
open datatree in zarr format improvement
aladinor May 10, 2024
93e1d59
Merge branch 'main' into datatree-zarr
aladinor May 10, 2024
ac11b3e
fixing incompatibility in returned object
aladinor May 10, 2024
6d0ee13
Merge branch 'datatree-zarr' of https://github.com/aladinor/xarray in…
aladinor May 10, 2024
91c5f0a
Merge branch 'main' into datatree-zarr
aladinor May 12, 2024
3363e91
Merge branch 'main' into datatree-zarr
aladinor May 18, 2024
7bba52c
passing group parameter to opendatatree method and reducing duplicate…
aladinor May 18, 2024
725aed7
Merge branch 'datatree-zarr' of https://github.com/aladinor/xarray in…
aladinor May 18, 2024
903effd
passing group parameter to opendatatree method - NetCDF
aladinor May 18, 2024
d468478
Merge branch 'main' into datatree-zarr
aladinor May 19, 2024
51da175
Update xarray/backends/netCDF4_.py
aladinor May 28, 2024
24881bd
Merge branch 'main' into datatree-zarr
aladinor May 28, 2024
5f4bff1
renaming variables
aladinor May 28, 2024
41ceb4f
renaming variables
aladinor May 28, 2024
f18ead6
renaming group_store variable
aladinor May 29, 2024
33d9769
removing _open_datatree_netcdf function not used anymore in open_data…
aladinor May 29, 2024
3345b92
improving performance of open_datatree method
aladinor May 29, 2024
3cb131c
renaming 'i' variable within list comprehension in open_store method …
aladinor May 29, 2024
6a759c0
using the default generator instead of loading zarr groups in memory
aladinor May 29, 2024
6c00641
fixing issue with group path to avoid using group[1:] notation. Addin…
aladinor May 29, 2024
189b497
fixing issue with group path to avoid using group[1:] notation and ad…
aladinor May 29, 2024
a9c306d
fixing issue with group path to avoid using group[1:] notation and ad…
aladinor May 29, 2024
fad0e76
Merge branch 'main' into datatree-zarr
aladinor Jun 3, 2024
792f9c7
Merge branch 'main' into datatree-zarr
aladinor Jun 4, 2024
8c5796f
adding 'mode' parameter to open_datatree method
aladinor Jun 4, 2024
728b374
adding 'mode' parameter to H5NetCDFStore.open method
aladinor Jun 4, 2024
74b9a7c
Merge branch 'main' into datatree-zarr
kmuehlbauer Jun 5, 2024
e298ac4
Merge branch 'main' into datatree-zarr
aladinor Jun 12, 2024
833c978
Merge branch 'main' into datatree-zarr
aladinor Jun 12, 2024
4ff6035
adding new entry related to open_datatree performance improvement
aladinor Jun 12, 2024
3844dea
adding new entry related to open_datatree performance improvement
aladinor Jun 12, 2024
456ce29
Getting rid of unnecessary parameters for 'open_datatree' method for …
aladinor Jun 12, 2024
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
66 changes: 63 additions & 3 deletions xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
BackendEntrypoint,
WritableCFDataStore,
_normalize_path,
_open_datatree_netcdf,
flamingbear marked this conversation as resolved.
Show resolved Hide resolved
find_root_and_group,
robust_getitem,
)
Expand Down Expand Up @@ -672,11 +671,72 @@ def open_dataset( # type: ignore[override] # allow LSP violation, not supporti
def open_datatree(
self,
filename_or_obj: str | os.PathLike[Any] | BufferedIOBase | AbstractDataStore,
*,
mask_and_scale=True,
decode_times=True,
concat_characters=True,
decode_coords=True,
drop_variables: str | Iterable[str] | None = None,
use_cftime=None,
decode_timedelta=None,
group=None,
mode="r",
format="NETCDF4",
clobber=True,
diskless=False,
persist=False,
lock=None,
autoclose=False,
**kwargs,
) -> DataTree:
from netCDF4 import Dataset as ncDataset
from xarray.backends.api import open_dataset
from xarray.backends.common import _iter_nc_groups
from xarray.core.datatree import DataTree
from xarray.core.treenode import NodePath

return _open_datatree_netcdf(ncDataset, filename_or_obj, **kwargs)
filename_or_obj = _normalize_path(filename_or_obj)
store = NetCDF4DataStore.open(
filename_or_obj,
mode=mode,
format=format,
group=group,
clobber=clobber,
diskless=diskless,
persist=persist,
lock=lock,
autoclose=autoclose,
)
if group:
parent = NodePath("/") / NodePath(group)
else:
parent = NodePath("/")

mgr = store._manager
aladinor marked this conversation as resolved.
Show resolved Hide resolved
ds = open_dataset(store, **kwargs)
tree_root = DataTree.from_dict({str(parent): ds})
for group in _iter_nc_groups(store.ds):
gpath = str(parent / group[1:])
store = NetCDF4DataStore(mgr, group=gpath, **kwargs)
store_entrypoint = StoreBackendEntrypoint()
with close_on_error(store):
ds = store_entrypoint.open_dataset(
store,
mask_and_scale=mask_and_scale,
decode_times=decode_times,
concat_characters=concat_characters,
decode_coords=decode_coords,
drop_variables=drop_variables,
use_cftime=use_cftime,
decode_timedelta=decode_timedelta,
)
new_node: DataTree = DataTree(name=NodePath(group).name, data=ds)
tree_root._set_item(
gpath,
new_node,
allow_overwrite=False,
new_nodes_along_path=True,
)
return tree_root


BACKEND_ENTRYPOINTS["netcdf4"] = ("netCDF4", NetCDF4BackendEntrypoint)
Loading
Loading