Skip to content

Commit

Permalink
setup testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Bell committed Mar 29, 2024
1 parent 69fd9ba commit 9b6f217
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
29 changes: 24 additions & 5 deletions kerchunk/tests/test_hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import kerchunk.hdf
import numpy as np
import pandas as pd
import pytest
import xarray as xr
import zarr
Expand All @@ -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"
Expand Down Expand Up @@ -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()
7 changes: 3 additions & 4 deletions kerchunk/tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 9b6f217

Please sign in to comment.