Skip to content

Add open_datatree benchmark #9158

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

Merged
merged 44 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 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
141fe1c
passing parent argument into _iter_zarr_groups instead of group[1:] f…
aladinor Jun 23, 2024
83ce963
passing parent argument into _iter_zarr_groups instead of group[1:] f…
aladinor Jun 23, 2024
8a006ee
adding benchmark test for opening a deeply nested data tree. This inc…
aladinor Jun 23, 2024
ec1a299
Merge branch 'main' into open-dtree-benchmark
aladinor Jun 25, 2024
6033a03
Merge branch 'main' into open-dtree-benchmark
aladinor Jul 1, 2024
27747d1
Update doc/whats-new.rst
dcherian Jul 1, 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
113 changes: 112 additions & 1 deletion asv_bench/benchmarks/dataset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pandas as pd

import xarray as xr
from xarray.backends.api import open_datatree
from xarray.core.datatree import DataTree

from . import _skip_slow, parameterized, randint, randn, requires_dask

Expand All @@ -16,7 +18,6 @@
except ImportError:
pass


os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE"

_ENGINES = tuple(xr.backends.list_engines().keys() - {"store"})
Expand Down Expand Up @@ -469,6 +470,116 @@ def create_delayed_write():
return ds.to_netcdf("file.nc", engine="netcdf4", compute=False)


class IONestedDataTree:
"""
A few examples that benchmark reading/writing a heavily nested netCDF datatree with
xarray
"""

timeout = 300.0
repeat = 1
number = 5

def make_datatree(self, nchildren=10):
# multiple Dataset
self.ds = xr.Dataset()
self.nt = 1000
self.nx = 90
self.ny = 45
self.nchildren = nchildren

self.block_chunks = {
"time": self.nt / 4,
"lon": self.nx / 3,
"lat": self.ny / 3,
}

self.time_chunks = {"time": int(self.nt / 36)}

times = pd.date_range("1970-01-01", periods=self.nt, freq="D")
lons = xr.DataArray(
np.linspace(0, 360, self.nx),
dims=("lon",),
attrs={"units": "degrees east", "long_name": "longitude"},
)
lats = xr.DataArray(
np.linspace(-90, 90, self.ny),
dims=("lat",),
attrs={"units": "degrees north", "long_name": "latitude"},
)
self.ds["foo"] = xr.DataArray(
randn((self.nt, self.nx, self.ny), frac_nan=0.2),
coords={"lon": lons, "lat": lats, "time": times},
dims=("time", "lon", "lat"),
name="foo",
attrs={"units": "foo units", "description": "a description"},
)
self.ds["bar"] = xr.DataArray(
randn((self.nt, self.nx, self.ny), frac_nan=0.2),
coords={"lon": lons, "lat": lats, "time": times},
dims=("time", "lon", "lat"),
name="bar",
attrs={"units": "bar units", "description": "a description"},
)
self.ds["baz"] = xr.DataArray(
randn((self.nx, self.ny), frac_nan=0.2).astype(np.float32),
coords={"lon": lons, "lat": lats},
dims=("lon", "lat"),
name="baz",
attrs={"units": "baz units", "description": "a description"},
)

self.ds.attrs = {"history": "created for xarray benchmarking"}

self.oinds = {
"time": randint(0, self.nt, 120),
"lon": randint(0, self.nx, 20),
"lat": randint(0, self.ny, 10),
}
self.vinds = {
"time": xr.DataArray(randint(0, self.nt, 120), dims="x"),
"lon": xr.DataArray(randint(0, self.nx, 120), dims="x"),
"lat": slice(3, 20),
}
root = {f"group_{group}": self.ds for group in range(self.nchildren)}
nested_tree1 = {
f"group_{group}/subgroup_1": xr.Dataset() for group in range(self.nchildren)
}
nested_tree2 = {
f"group_{group}/subgroup_2": xr.DataArray(np.arange(1, 10)).to_dataset(
name="a"
)
for group in range(self.nchildren)
}
nested_tree3 = {
f"group_{group}/subgroup_2/sub-subgroup_1": self.ds
for group in range(self.nchildren)
}
dtree = root | nested_tree1 | nested_tree2 | nested_tree3
self.dtree = DataTree.from_dict(dtree)


class IOReadDataTreeNetCDF4(IONestedDataTree):
def setup(self):
# TODO: Lazily skipped in CI as it is very demanding and slow.
# Improve times and remove errors.
_skip_slow()

requires_dask()

self.make_datatree()
self.format = "NETCDF4"
self.filepath = "datatree.nc4.nc"
dtree = self.dtree
dtree.to_netcdf(filepath=self.filepath)

def time_load_datatree_netcdf4(self):
open_datatree(self.filepath, engine="netcdf4").load()

def time_open_datatree_netcdf4(self):
open_datatree(self.filepath, engine="netcdf4")


class IOWriteNetCDFDask:
timeout = 60
repeat = 1
Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def open_store(
stacklevel=stacklevel,
zarr_version=zarr_version,
)
group_paths = [str(group / node[1:]) for node in _iter_zarr_groups(zarr_group)]
group_paths = [node for node in _iter_zarr_groups(zarr_group, parent=group)]
return {
group: cls(
zarr_group.get(group),
Expand Down
Loading