@@ -23,7 +23,7 @@ class NWPDataSource(ZarrDataSource):
2323 Attributes:
2424 _data: xr.DataArray of Numerical Weather Predictions, opened by open().
2525 x is left-to-right.
26- y is bottom -to-top .
26+ y is top -to-bottom (after reversing the `y` index in open_nwp()) .
2727 consolidated: Whether or not the Zarr store is consolidated.
2828 channels: The NWP forecast parameters to load. If None then don't filter.
2929 See: http://cedadocs.ceda.ac.uk/1334/1/uk_model_data_sheet_lores1.pdf
@@ -179,8 +179,23 @@ def open_nwp(zarr_path: str, consolidated: bool) -> xr.DataArray:
179179 zarr_path , engine = "zarr" , consolidated = consolidated , mode = "r" , chunks = None
180180 )
181181
182+ # Select the "UKV" DataArray from the "nwp" Dataset.
183+ # "UKV" is the one and only DataArray in the Zarr Dataset.
184+ # "UKV" stands for "United Kingdom Variable", and it the UK Met Office's high-res deterministic
185+ # NWP for the UK. All the NWP variables are represented in the `variable` dimension within
186+ # the UKV DataArray.
182187 ukv = nwp ["UKV" ]
183188
189+ # Reverse `y` so it's top-to-bottom (so ZarrDataSource.get_example() works correctly!)
190+ # if necessary. Adapted from:
191+ # https://stackoverflow.com/questions/54677161/xarray-reverse-an-array-along-one-coordinate
192+ if ukv .y [0 ] < ukv .y [1 ]:
193+ _LOG .warning (
194+ "NWP y axis runs from bottom-to-top. Will reverse y axis so it runs top-to-bottom."
195+ )
196+ y_reversed = ukv .y [::- 1 ]
197+ ukv = ukv .reindex (y = y_reversed )
198+
184199 # Sanity checks.
185200 # If there are any duplicated init_times then drop the duplicated init_times:
186201 init_time = pd .DatetimeIndex (ukv ["init_time" ])
0 commit comments