Description
Description
Some WRF data does not contain the lat/lon coordinates in the same file as the data variables. This was the case in this example. There is still the added step of needing to pull in this data before XWRF can effectively do its work (it still cleans up the time coordinates nicely). I have tested this in this notebook.
Implementation
Here is a sample function that adds cleaned up lat/lon coordinates when a file is missing them:
def assign_coords_from_file(file_path, geo_path):
#open dataset
ds = xr.open_dataset(file_path, engine="xwrf")
#open coord file
ds_geo = xr.open_dataset(geo_path, engine="xwrf")
#add coords
ds_coords = ds.assign_coords(lat=ds_geo.coords['XLAT'],
lon=ds_geo.coords['XLONG'])
#rename coords to match CF conventions
ds_rename = ds_coords.rename({'south_north':'y', 'west_east':'x'})
#drop redundant coords
ds_clean = ds_rename.drop(['XLAT', 'XLONG', 'CLAT'])
return ds_clean
ds = assign_coords_from_file("data/T2_RR_F_2014_08.nc", "data/wrfinput_d02")
Tests
Perhaps we need to add a test that all variable dimensions are represented by a coordinate.
Questions
How common is it for WRF data to store the coordinate information in a separate geo-file?
Are there any patterns for where this geo-file is located that we can exploit to automatically find and pull in the correct geo-file without needing it provided?
Also I noticed that XWRF does not currently rename dimension names (south_north
to y
, e.g.). Is this something we want to do? It is done in the example.