xarray-contrib/xwrf

[MISC]: Cannot post-process cartesian wrfout data

Closed this issue · 1 comments

What is your issue?

I am attempting to load and analyse data from an idealised run of a tropical cyclone. Because this run is idealised, the projection is Cartesian.
My code is as follows:

import xarray as xr
import xwrf

directory_path = "path/to/output/out/"

# Open the NetCDF file
ds = xr.open_mfdataset(
        directory_path + "wrfout_d01*",
        engine='netcdf4',
        concat_dim="Time",
        combine="nested"
        )
print(f"Projection No.: {ds.attrs['MAP_PROJ']}\nProjection name: {ds.attrs['MAP_PROJ_CHAR']}")
ds = ds.xwrf.postprocess()

This yields the following error:

Projection: 0
Projection name: Cartesian
Traceback (most recent call last):
  File "/g/data/x77/me5758/programs/cyclone-analysis/import_test.py", line 14, in <module>
    domain_data = domain_data.xwrf.postprocess()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/g/data/x77/me5758/programs/venv/analysis_venv/lib/python3.11/site-packages/xwrf/accessors.py", line 147, in postprocess
    ds = ds.pipe(_include_projection_coordinates)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/g/data/x77/me5758/programs/venv/analysis_venv/lib/python3.11/site-packages/xarray/core/common.py", line 815, in pipe
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/g/data/x77/me5758/programs/venv/analysis_venv/lib/python3.11/site-packages/xwrf/postprocess.py", line 95, in _include_projection_coordinates
    grid_components = _wrf_grid_from_dataset(ds)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/g/data/x77/me5758/programs/venv/analysis_venv/lib/python3.11/site-packages/xwrf/grid.py", line 58, in _wrf_grid_from_dataset
    raise NotImplementedError(f'WRF proj not implemented yet: {proj_id}')
NotImplementedError: WRF proj not implemented yet: 0

Is this simply a case where Cartesian projections are unsupported, or is there something more odd going on?

Help would be appreciated

Hi @MaxEtherington, thanks for the issue. It is indeed simply the case that the treatment of cartesian coordinates is not yet implemented in WRF as this is not a very typical use case. You can see this here:

xwrf/xwrf/grid.py

Lines 41 to 58 in 3163abc

if proj_id == 1:
# Lambert
pargs['proj'] = 'lcc'
del pargs['center_lon']
elif proj_id == 2:
# Polar stereo
pargs['proj'] = 'stere'
pargs['lat_ts'] = pargs['lat_1']
pargs['lat_0'] = 90.0
del pargs['lat_1'], pargs['lat_2'], pargs['center_lon']
elif proj_id == 3:
# Mercator
pargs['proj'] = 'merc'
pargs['lat_ts'] = pargs['lat_1']
pargs['lon_0'] = pargs['center_lon']
del pargs['lat_0'], pargs['lat_1'], pargs['lat_2'], pargs['center_lon']
else:
raise NotImplementedError(f'WRF proj not implemented yet: {proj_id}')

Unfortunately, I won't be able to do this in the near future but Pull Requests are always very welcome :)

Also, be aware that xwrf is written with mostly real simulations in mind. If there are some additional kinks in the netcdfs for idealized cases, we might not be aware of them (but would appreciate any input).