NCAR / ctsm_python_gallery

A place to put sample workflows and tools that use ctsm model output
Apache License 2.0
18 stars 28 forks source link

Flexible gridding; converting between longitude styles; bug fixes #38

Closed samsrabin closed 3 years ago

samsrabin commented 3 years ago

New functions lon_idl2pm() and lon_pm2idl() allow conversion between longitude axes that are [0, 360] around the Prime Meridian (like what comes out of CESM) and those that are [-180, 180] around the International Date Line.

Bugfixes for import_ds(), xr_flexsel(), and grid_one_variable(). Updates to other functions in support of these.

Finally: Setting up for supporting arbitrary dimensions in grid_one_variable() instead of just time and vegtype.

samsrabin commented 3 years ago

(Just adding a little explanation here, even though the pull request has been merged.)

Now supports gridding arbitrary dimensions! In addition, you can use xr_flexsel() with any dimension.

If you do something like xr_flexsel(my_ds, lon=SOME_SELECTION), the function will attempt to guess whether SOME_SELECTION refers to values you want to include (e.g., to include Southern Hemisphere gridcells, my_ds.lat.values[my_ds.lat.values <= 0) or indices you want to include (e.g., to include the first 12 latitude indices, np.arange(12)). It does this by checking every member of SOME_SELECTION; if it's negative or not an integer, it'll assume the selection refers to values.

This can be pretty inefficient, so the user will receive a warning for every dimension whose selection style had to be guessed. This warning can be suppressed by specifying warn_about_seltype_interp=False. Alternatively, the user can skip the guessing process by adding a double underscore followed by "indices" or "values" to the dimension's keyword. E.g., xr_flexsel(my_ds, lon__values=SOME_SELECTION).