xarray-contrib / xarray-contrib/xwrf

[MISC]: Split `_wrf_grid_from_dataset` in projection and grid parts, add to public API

Open
#175 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
70
Forks
18
Avg merge
21m
Merged PRs (30d)
1

Description

What is your issue?

Hello all!

In a recent project, I started by doing some preliminary post-processing of all my wrfout files (running them through xwrf, destaggering, removing some variables and computing some others, concatenating) and storing the intermediate files before continuing with my analysis. The WRF projection is helpfully added in the wrf_projection variable but that can't be stored in a netCDF file, so you have to drop it before writing your output.

ds = (
    xr.open_dataset(
        "/path/to/wrfout"
    )
    .xwrf.postprocess()
    .xwrf.destagger()
)

# Do some more processing...

# Write to netCDF
ds.drop_vars('wrf_projection').to_netcdf("/path/to/output")

At this point, if you open your file again, there is no point in running .xwrf.postprocess() because everything is ready. But you also don't have the proj object and you can't make it with xwrf._wrf_grid_from_dataset() since it tries to find the west_east/south_north dimensions for making the grid.

The proposal here is to split _wrf_grid_from_dataset() into two functions, one for creating the proj object (e.g. get_wrf_proj()) and one for creating the (x, y) grid _get_wrf_grid(). The first could be useful outside .xwrf.postprocess() so it would be nice for it to be part of the public API.

I would be happy to write a pull request about this but I didn't want to jump the gun since it adds stuff to the public API.

Thank you for your great work :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating _wrf_grid_from_dataset() and the .xwrf.postprocess() entry point, then trace how wrf_projection and the west_east/south_north grid are created. Split projection creation from grid creation, expose the projection helper through the public API, and verify that datasets without those dimensions can still provide the projection object.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.