xarray-contrib / xarray-contrib/xwrf
[FEATURE]: Pull in coordinates from separate file
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 70
- Forks
- 18
- Avg merge
- 21m
- Merged PRs (30d)
- 1
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the example notebook and sandbox/sandbox.ipynb, then inspect the proposed assign_coords_from_file flow for opening the data and geo-files, assigning lat/lon, renaming dimensions, and dropping redundant coordinates. Define the intended geo-file discovery and dimension-renaming behavior, and add a test that every variable dimension has a coordinate. Done means separate-coordinate WRF data is handled consistently with agreed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100