From c97cbabb5f239e258d2762beb4162ba827dbed09 Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Tue, 16 Nov 2021 21:02:42 +0000 Subject: [PATCH 1/3] reverse y index of NWPs --- nowcasting_dataset/data_sources/nwp/nwp_data_source.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nowcasting_dataset/data_sources/nwp/nwp_data_source.py b/nowcasting_dataset/data_sources/nwp/nwp_data_source.py index b77ae8da..cf4d2dfd 100644 --- a/nowcasting_dataset/data_sources/nwp/nwp_data_source.py +++ b/nowcasting_dataset/data_sources/nwp/nwp_data_source.py @@ -23,7 +23,7 @@ class NWPDataSource(ZarrDataSource): Attributes: _data: xr.DataArray of Numerical Weather Predictions, opened by open(). x is left-to-right. - y is bottom-to-top. + y is top-to-bottom (after reversing the `y` index in open_nwp()). consolidated: Whether or not the Zarr store is consolidated. channels: The NWP forecast parameters to load. If None then don't filter. See: http://cedadocs.ceda.ac.uk/1334/1/uk_model_data_sheet_lores1.pdf @@ -181,6 +181,12 @@ def open_nwp(zarr_path: str, consolidated: bool) -> xr.DataArray: ukv = nwp["UKV"] + # Reverse `y` so it's top-to-bottom (so ZarrDataSource.get_example() works correctly!) + # Adapted from: + # https://stackoverflow.com/questions/54677161/xarray-reverse-an-array-along-one-coordinate + y_reversed = ukv.y[::-1] + ukv = ukv.reindex(y=y_reversed) + # Sanity checks. # If there are any duplicated init_times then drop the duplicated init_times: init_time = pd.DatetimeIndex(ukv["init_time"]) From 2c4ce3265a68afed1dc8f5e6d5274d2a6c07355c Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Tue, 16 Nov 2021 21:08:18 +0000 Subject: [PATCH 2/3] Only reverse y axis if necessary. Unittests pass. --- nowcasting_dataset/data_sources/nwp/nwp_data_source.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nowcasting_dataset/data_sources/nwp/nwp_data_source.py b/nowcasting_dataset/data_sources/nwp/nwp_data_source.py index cf4d2dfd..9f3475eb 100644 --- a/nowcasting_dataset/data_sources/nwp/nwp_data_source.py +++ b/nowcasting_dataset/data_sources/nwp/nwp_data_source.py @@ -182,10 +182,14 @@ def open_nwp(zarr_path: str, consolidated: bool) -> xr.DataArray: ukv = nwp["UKV"] # Reverse `y` so it's top-to-bottom (so ZarrDataSource.get_example() works correctly!) - # Adapted from: + # if necessary. Adapted from: # https://stackoverflow.com/questions/54677161/xarray-reverse-an-array-along-one-coordinate - y_reversed = ukv.y[::-1] - ukv = ukv.reindex(y=y_reversed) + if ukv.y[0] < ukv.y[1]: + _LOG.warning( + "NWP y axis runs from bottom-to-top. Will reverse y axis so it runs top-to-bottom." + ) + y_reversed = ukv.y[::-1] + ukv = ukv.reindex(y=y_reversed) # Sanity checks. # If there are any duplicated init_times then drop the duplicated init_times: From b55a74e924590fd2201d2b6bf2719b8ed547f2c8 Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Tue, 16 Nov 2021 21:36:44 +0000 Subject: [PATCH 3/3] adding comment about UKV --- nowcasting_dataset/data_sources/nwp/nwp_data_source.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nowcasting_dataset/data_sources/nwp/nwp_data_source.py b/nowcasting_dataset/data_sources/nwp/nwp_data_source.py index ebede13d..fd56e762 100644 --- a/nowcasting_dataset/data_sources/nwp/nwp_data_source.py +++ b/nowcasting_dataset/data_sources/nwp/nwp_data_source.py @@ -179,6 +179,11 @@ def open_nwp(zarr_path: str, consolidated: bool) -> xr.DataArray: zarr_path, engine="zarr", consolidated=consolidated, mode="r", chunks=None ) + # Select the "UKV" DataArray from the "nwp" Dataset. + # "UKV" is the one and only DataArray in the Zarr Dataset. + # "UKV" stands for "United Kingdom Variable", and it the UK Met Office's high-res deterministic + # NWP for the UK. All the NWP variables are represented in the `variable` dimension within + # the UKV DataArray. ukv = nwp["UKV"] # Reverse `y` so it's top-to-bottom (so ZarrDataSource.get_example() works correctly!)