Skip to content

Commit

Permalink
add UKV
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Jan 21, 2025
1 parent 1c9b232 commit 5ab8980
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/nwp_consumer/internal/entities/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class NWPDimensionCoordinateMap:
longitude: list[float] | None = None
"""The longitude coordinates of the forecast grid in degrees. """

x: list[float] | None = None
y: list[float] | None = None
# These are the x and y osgb that the UKV model uses. They are not used in the other models

def __post_init__(self) -> None:
"""Rigidly set input value ordering and precision."""
self.variable = sorted(self.variable)
Expand Down
27 changes: 27 additions & 0 deletions src/nwp_consumer/internal/entities/modelmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,30 @@ class Models:
)
"""MetOffice's Unified Model, in the Global configuration, at a resolution of 10km."""

MO_UKV_2KM: ModelMetadata = ModelMetadata(
name="ukv-uk",
resolution="2km",
expected_coordinates=NWPDimensionCoordinateMap(
init_time=[],
step=list(range(0, 55)),
variable=sorted(
[
Parameter.CLOUD_COVER_TOTAL,
Parameter.CLOUD_COVER_HIGH,
Parameter.CLOUD_COVER_MEDIUM,
Parameter.CLOUD_COVER_LOW,
Parameter.VISIBILITY_SL,
Parameter.RELATIVE_HUMIDITY_SL,
Parameter.SNOW_DEPTH_GL,
Parameter.DOWNWARD_SHORTWAVE_RADIATION_FLUX_GL,
Parameter.TEMPERATURE_SL,
Parameter.WIND_U_COMPONENT_10m,
Parameter.WIND_V_COMPONENT_10m,
],
),
x=[0, 7e5],
y=[0, 1.2e6],
),
)
"""MetOffice's UKV Mode, at a resolution of approximate 2km."""

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def repository() -> entities.RawRepositoryMetadata:
name="MetOffice-Weather-Datahub",
is_archive=False,
is_order_based=True,
running_hours=[0, 12],
running_hours=[0, 12], # for UKV, we need to change this to every hour.
delay_minutes=60,
max_connections=10,
required_env=["METOFFICE_API_KEY", "METOFFICE_ORDER_ID"],
Expand All @@ -86,6 +86,7 @@ def repository() -> entities.RawRepositoryMetadata:
available_models={
"default": entities.Models.MO_UM_GLOBAL_10KM,
"um-global-10km": entities.Models.MO_UM_GLOBAL_10KM,
"ukv-uk-2km": entities.Models.MO_UKV_2KM,
},
)

Expand Down Expand Up @@ -286,10 +287,13 @@ def _convert(path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
allowed_parameters=MetOfficeDatahubRawRepository.model().expected_coordinates.variable,
)
.rename(name_dict={"time": "init_time"})
.expand_dims(dim="init_time")
.expand_dims(dim="step")
.to_dataarray(name=MetOfficeDatahubRawRepository.model().name)
)
.expand_dims(dim="init_time"))

if "step" not in ds.dims:
da = da.expand_dims(dim="step")

da = da.to_dataarray(name=MetOfficeDatahubRawRepository.model().name)

da = (
da.drop_vars(
names=[
Expand All @@ -299,10 +303,14 @@ def _convert(path: pathlib.Path) -> ResultE[list[xr.DataArray]]:
],
errors="ignore",
)
.transpose(*MetOfficeDatahubRawRepository.model().expected_coordinates.dims)
.sortby(variables=["step", "variable", "longitude"])
.sortby(variables="latitude", ascending=False)
)
.transpose(*MetOfficeDatahubRawRepository.model().expected_coordinates.dims))

if "latitude" in MetOfficeDatahubRawRepository.model().expected_coordinates.dims:
da = da.sortby(variables=["step", "variable", "longitude"])
da = da.sortby(variables="latitude", ascending=False)
else:
da = da.sortby(variables=["step", "variable"])

except Exception as e:
return Failure(
ValueError(
Expand Down

0 comments on commit 5ab8980

Please sign in to comment.