xarray-contrib / xwrf

A lightweight interface for working with the Weather Research and Forecasting (WRF) model output in Xarray.
https://xwrf.readthedocs.io/
Apache License 2.0
56 stars 16 forks source link

[MISC]: Cannot post-process cartesian wrfout data #163

Closed MaxEtherington closed 2 months ago

MaxEtherington commented 3 months ago

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

lpilz commented 3 months ago

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: https://github.com/xarray-contrib/xwrf/blob/3163abc64ec3650b5a67129834f9cee2efc695ed/xwrf/grid.py#L41-L58

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).