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

Add step:int remapping for coords computation #450

Merged
merged 14 commits into from
Apr 12, 2024
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ dmypy.json

# Pyre type checker
.pyre/

# VSCode settings
.vscode/
2 changes: 1 addition & 1 deletion ci/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- xarray
- xarray-datatree
- h5netcdf
- h5py<3.9
- h5py
- pandas
- cfgrib
- cftime
Expand Down
2 changes: 1 addition & 1 deletion ci/environment-py310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- xarray
- xarray-datatree
- h5netcdf
- h5py<3.9
- h5py
- pandas
- cfgrib
- cftime
Expand Down
2 changes: 1 addition & 1 deletion ci/environment-py311.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- xarray
- xarray-datatree
- h5netcdf
- h5py<3.9
- h5py
- pandas
- cfgrib
- cftime
Expand Down
8 changes: 5 additions & 3 deletions kerchunk/grib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ def scan_grib(
z[varName].attrs["_ARRAY_DIMENSIONS"] = dims

for coord in cfgrib.dataset.COORD_ATTRS:
coord2 = {"latitude": "latitudes", "longitude": "longitudes"}.get(
coord, coord
)
coord2 = {
"latitude": "latitudes",
"longitude": "longitudes",
"step": "step:int",
}.get(coord, coord)
try:
x = m.get(coord2)
except eccodes.WrongStepUnitError as e:
Expand Down
4 changes: 2 additions & 2 deletions kerchunk/tests/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def test_cftimes_to_normal(refs):
engine="zarr",
chunks={},
)
assert z.time.dtype == "M8[s]"
assert z.time.dtype.kind == "M"
assert (
z.time.values
== np.array(["1970-02-01T00:00:00", "1970-03-01T00:00:00"], dtype="M8[s]")
Expand Down Expand Up @@ -799,7 +799,7 @@ def test_chunk_error(refs):
refs1 = refs["single1"]["refs"]
refs2 = refs1.copy()
refs2.pop(".zmetadata")
fs = fsspec.filesystem("reference", fo=refs2, remote_protocol="memory")
fs = fsspec.filesystem("reference", fo=refs2, remote_protocol="memory") # noqa
refs2[
"data/.zarray"
] = b"""
Expand Down
17 changes: 10 additions & 7 deletions kerchunk/tests/test_grib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path

import eccodes
import fsspec
import numpy as np
import pytest
Expand All @@ -15,6 +16,7 @@
correct_hrrr_subhf_step,
)

eccodes_ver = tuple(int(i) for i in eccodes.__version__.split("."))
cfgrib = pytest.importorskip("cfgrib")
here = os.path.dirname(__file__)

Expand Down Expand Up @@ -49,7 +51,10 @@ def _fetch_first(url):
@pytest.mark.parametrize(
"url",
[
"s3://noaa-hrrr-bdp-pds/hrrr.20140730/conus/hrrr.t23z.wrfsubhf08.grib2",
pytest.param(
"s3://noaa-hrrr-bdp-pds/hrrr.20140730/conus/hrrr.t23z.wrfsubhf08.grib2",
marks=pytest.mark.skipif(eccodes_ver >= (2, 34), reason="eccodes too new"),
),
"s3://noaa-gefs-pds/gefs.20221011/00/atmos/pgrb2ap5/gep01.t00z.pgrb2a.0p50.f570",
"s3://noaa-gefs-retrospective/GEFSv12/reforecast/2000/2000010100/c00/Days:10-16/acpcp_sfc_2000010100_c00.grib2",
],
Expand Down Expand Up @@ -105,13 +110,11 @@ def test_grib_tree():
zg = zarr.open_group(fs.get_mapper(""))
assert isinstance(zg["refc/instant/atmosphere/refc"], zarr.Array)
assert isinstance(zg["vbdsf/avg/surface/vbdsf"], zarr.Array)
assert (
zg["vbdsf/avg/surface"].attrs["coordinates"]
== "surface latitude longitude time valid_time step"
assert set(zg["vbdsf/avg/surface"].attrs["coordinates"].split()) == set(
"surface latitude longitude step time valid_time".split()
)
assert (
zg["refc/instant/atmosphere"].attrs["coordinates"]
== "atmosphere latitude longitude step time valid_time"
assert set(zg["refc/instant/atmosphere"].attrs["coordinates"].split()) == set(
"atmosphere latitude longitude step time valid_time".split()
)
# Assert that the fill value is set correctly
assert zg.refc.instant.atmosphere.step.fill_value is np.NaN
Expand Down
Loading