Skip to content
Merged
Changes from 1 commit
Commits
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
105 changes: 99 additions & 6 deletions kerchunk/_grib_idx.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,104 @@ class DynamicZarrStoreError(ValueError):

ZARR_TREE_STORE = "zarr_tree_store.json.gz"

# derived from eccodes/grib2/typeOfLevelConcept.def
ECCODES_VERTICAL_LEVEL_LIST = [
"abstractMultipleLevels",
"abstractSingleLevel",
"adiabaticCondensation",
"atmosphere",
"cloudBase",
"cloudTop",
"convectiveCondensation",
"cumulonimbusBase",
"cumulonimbusTop",
"depthBelowLand",
"depthBelowLandLayer",
"depthBelowSea",
"depthBelowSeaLayer",
"entireAtmosphere",
"entireLake",
"entireMeltPond",
"entireOcean",
"eta",
"freeConvection",
"generalVertical",
"generalVerticalLayer",
"heightAboveGround",
"heightAboveGroundLayer",
"heightAboveSea",
"heightAboveSeaLayer",
"highCloudLayer",
"hybrid",
"hybridHeight",
"hybridLayer",
"hybridPressure",
"iceBottomOnWater",
"iceLayerAboveWaterSurface",
"iceLayerOnWater",
"iceLayerUnderSnowOnWater",
"iceTopOnWater",
"iceTopUnderSnowOnWater",
"indefiniteSoilDepth",
"isobaricInPa",
"isobaricInhPa",
"isobaricLayer",
"isothermZero",
"isothermal",
"lakeBottom",
"lowCloudLayer",
"lowestLevelOfCloudCoverExceedance",
"maxWind",
"meanSea",
"mediumCloudLayer",
"meltPondBottom",
"meltPondTop",
"mixedLayerDepthByDensity",
"mixedLayerDepthByDiffusivity",
"mixedLayerDepthByTemperature",
"mixedLayerDepthGeneric",
"mixedLayerParcel",
"mixingLayer",
"mostUnstableParcel",
"neutralBuoyancy",
"nominalTop",
"oceanModel",
"oceanModelLayer",
"oceanSurface",
"oceanSurfaceToBottom",
"potentialVorticity",
"pressureFromGround",
"pressureFromGroundLayer",
"road",
"roadLayer",
"roof",
"roofLayer",
"rootZone",
"seaBottom",
"seaIce",
"seaIceLayer",
"sigma",
"sigmaLayer",
"snow",
"snowLayer",
"snowLayerOverIceOnWater",
"snowTopOverIceOnWater",
"soil",
"soilLayer",
"stratosphere",
"surface",
"theta",
"thetaLayer",
"totalSoilLayer",
"tropopause",
"troposphere",
"unknown",
"urbanCanyon",
"wall",
"wallLayer",
"waterSurfaceToIsothermalOceanLayer",
]


def repeat_steps(step_index: pd.TimedeltaIndex, to_length: int) -> np.array:
return np.tile(step_index.to_numpy(), int(np.ceil(to_length / len(step_index))))[
Expand Down Expand Up @@ -612,12 +710,7 @@ def extract_dataset_chunk_index(
for cname, cvar in dvar.coords.items():
if grib:
# Grib data has only one level coordinate
cname = (
cname
if cname
in ("valid_time", "time", "step", "latitude", "longitude")
else "level"
)
cname = "level" if cname in ECCODES_VERTICAL_LEVEL_LIST else cname
Copy link
Member

@martindurant martindurant Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this inversed? If cname="time", the previous code would return "time", but now it is "level".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the suggested implementation correct? If cname=time then it is not in the list ECCODES_VERTICAL_LEVEL_LIST and consequently cname itself will be returned i.e. "time" will map to "time"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so none of the names I had were in this list. Sorry for the confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries man :)


if all([dim_name in dim_idx for dim_name in cvar.dims]):
coord_index = tuple([dim_idx[dim_name] for dim_name in cvar.dims])
Expand Down
Loading