diff --git a/kerchunk/tests/test_hdf.py b/kerchunk/tests/test_hdf.py index 49d19153..78a87f0e 100644 --- a/kerchunk/tests/test_hdf.py +++ b/kerchunk/tests/test_hdf.py @@ -4,6 +4,7 @@ import kerchunk.hdf import numpy as np +import pandas as pd import pytest import xarray as xr import zarr @@ -14,6 +15,24 @@ here = osp.dirname(__file__) +@pytest.fixture(scope="module") +def ds(): + ds = xr.Dataset( + { + "x": xr.DataArray(np.linspace(-np.pi, np.pi, 10), dims=["x"]), + "y": xr.DataArray(np.linspace(-np.pi / 2, np.pi / 2, 10), dims=["y"]), + "time": xr.DataArray(pd.date_range("2020", "2021"), dims=["time"]), + }, + ) + ds["temp"] = ( + np.cos(ds.x) + * np.sin(ds.y) + * xr.ones_like(ds.time).astype("float") + * np.random.random(ds.time.shape) + ) + return ds + + def test_single(): """Test creating references for a single HDF file""" url = "s3://noaa-nwm-retro-v2.0-pds/full_physics/2017/201704010000.CHRTOUT_DOMAIN1.comp" @@ -325,9 +344,9 @@ def test_embed(): ] -def test_hdf_to_reference_file(tmpdir): - uri = "s3://wrf-se-ak-ar5/ccsm/rcp85/daily/2060/WRFDS_2060-01-01.nc" - so = dict(anon=True, default_fill_cache=False, default_cache_type="none") +def test_hdf_to_reference_file(tmpdir, ds): + fn1 = f"{tmpdir}/test1.nc" + ds.to_netcdf(fn1) + out = reffs.LazyReferenceMapper.create(f"{tmpdir}/out.parq", record_size=1) - with fsspec.open(uri, **so) as f: - _ = SingleHdf5ToZarr(f, uri, storage_options=so, out=out).translate() + SingleHdf5ToZarr(h5f=fn1, out=out).translate() diff --git a/kerchunk/tests/test_zarr.py b/kerchunk/tests/test_zarr.py index 8acb52f2..f1c8b58a 100644 --- a/kerchunk/tests/test_zarr.py +++ b/kerchunk/tests/test_zarr.py @@ -98,10 +98,9 @@ def test_zarr_json_dump_succeeds(tmpdir, ds): ujson.dumps(one) -def test_single_zarr_to_reference_file(tmpdir, ds): +def test_zarr_to_reference_file(tmpdir, ds): fn1 = f"{tmpdir}/test1.zarr" ds.to_zarr(fn1) - fn = f"{tmpdir}/out.parq" - out = reffs.LazyReferenceMapper.create(fn, record_size=1) - kerchunk.zarr.ZarrToZarr(fn1, inline_threshold=0, **{"out": out}).translate() + out = reffs.LazyReferenceMapper.create(f"{tmpdir}/out.parq", record_size=1) + kerchunk.zarr.ZarrToZarr(url=fn1, **{"out": out}).translate()