Skip to content
Open
Changes from all commits
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
23 changes: 14 additions & 9 deletions ocf_data_sampler/load/nwp/providers/ukv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ def open_ukv(zarr_path: str | list[str]) -> xr.DataArray:
"""
ds = open_zarr_paths(zarr_path, backend="tensorstore")

ds = ds.rename(
{
"init_time": "init_time_utc",
"variable": "channel",
"x": "x_osgb",
"y": "y_osgb",
},
)
# Build rename dictionary conditionally based on existing dimensions
Copy link
Member

Choose a reason for hiding this comment

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

@aouatefm can you remove this comment. I don't think it improves the clarity of the code

rename_dict = {
"init_time": "init_time_utc",
"variable": "channel",
}

# Only rename x,y to x_osgb,y_osgb if the legacy names exist
if "x" in ds.dims:
rename_dict["x"] = "x_osgb"
if "y" in ds.dims:
rename_dict["y"] = "y_osgb"

ds = ds.rename(rename_dict)

check_time_unique_increasing(ds.init_time_utc)

Expand All @@ -37,4 +42,4 @@ def open_ukv(zarr_path: str | list[str]) -> xr.DataArray:
ds = ds.transpose("init_time_utc", "step", "channel", "x_osgb", "y_osgb")

# TODO: should we control the dtype of the DataArray?
return get_xr_data_array_from_xr_dataset(ds)
return get_xr_data_array_from_xr_dataset(ds)