-
Notifications
You must be signed in to change notification settings - Fork 47
Add a function to produce a ManifestStore from HDF5 files #516
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
Changes from all commits
60963c8
6e77380
95c37c6
98afe8d
6e0ac41
db43d2a
33dc820
723ed33
8764fb8
de37d46
186d50a
fd7a1f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,18 @@ class TestDatasetChunkManifest: | |
def test_empty_chunks(self, empty_chunks_hdf5_file): | ||
f = h5py.File(empty_chunks_hdf5_file) | ||
ds = f["data"] | ||
with pytest.raises(ValueError, match="chunked but contains no chunks"): | ||
HDFVirtualBackend._dataset_chunk_manifest( | ||
path=empty_chunks_hdf5_file, dataset=ds | ||
) | ||
manifest = HDFVirtualBackend._dataset_chunk_manifest( | ||
path=empty_chunks_hdf5_file, dataset=ds | ||
) | ||
assert manifest.shape_chunk_grid == (0,) | ||
|
||
@pytest.mark.skip("Need to differentiate non coordinate dimensions from empty") | ||
def test_empty_dataset(self, empty_dataset_hdf5_file): | ||
f = h5py.File(empty_dataset_hdf5_file) | ||
ds = f["data"] | ||
with pytest.raises(ValueError, match="no space allocated in the file"): | ||
HDFVirtualBackend._dataset_chunk_manifest( | ||
path=empty_dataset_hdf5_file, dataset=ds | ||
) | ||
manifest = HDFVirtualBackend._dataset_chunk_manifest( | ||
path=empty_dataset_hdf5_file, dataset=ds | ||
) | ||
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally it's better to write tests that use higher-level public API instead of directly calling internals if you can help it, but that's just a nit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I think the tests will be easier to structure when we move away from |
||
assert manifest.shape_chunk_grid == (0,) | ||
|
||
def test_no_chunking(self, no_chunks_hdf5_file): | ||
f = h5py.File(no_chunks_hdf5_file) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
import pytest | ||
import xarray as xr | ||
|
||
from virtualizarr.readers.hdf import HDFVirtualBackend | ||
from virtualizarr.tests import ( | ||
requires_hdf5plugin, | ||
requires_obstore, | ||
) | ||
|
||
|
||
@pytest.fixture(name="basic_ds") | ||
def basic_ds(): | ||
x = np.arange(100) | ||
y = np.arange(100) | ||
temperature = 0.1 * x[:, None] + 0.1 * y[None, :] | ||
ds = xr.Dataset( | ||
{"temperature": (["x", "y"], temperature)}, | ||
coords={"x": np.arange(100), "y": np.arange(100)}, | ||
) | ||
return ds | ||
|
||
|
||
@requires_hdf5plugin | ||
@requires_obstore | ||
class TestHDFManifestStore: | ||
def test_rountrip_simple_virtualdataset(self, tmpdir, basic_ds): | ||
from obstore.store import LocalStore | ||
|
||
"Roundtrip a dataset to/from NetCDF with the HDF reader and ManifestStore" | ||
|
||
filepath = f"{tmpdir}/basic_ds_roundtrip.nc" | ||
basic_ds.to_netcdf(filepath, engine="h5netcdf") | ||
store = HDFVirtualBackend._create_manifest_store( | ||
filepath=filepath, store=LocalStore(), prefix="file://" | ||
) | ||
rountripped_ds = xr.open_dataset( | ||
store, engine="zarr", consolidated=False, zarr_format=3 | ||
) | ||
xr.testing.assert_allclose(basic_ds, rountripped_ds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every
staticmethod
here aside fromopen_virtual_dataset
may as well just be an actual function. You will need to do that anyway later to refactor to make the reader just one function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you could leave that to do in #498.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 That is the plan. I think @maxrjones intent here was to make a very small change set to demonstrate the feasibility of using
ManifestStore
and that we would refactor the structure in a PR for #498.