-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add utility for modifying pop model output to be compatible with xgcm #21
Conversation
@matt-long, this is ready for another look. If you deem it complete, we can go ahead and merge it. I will add tests for it in a separate PR when test data is available on the FTP server. |
pop_tools/modify_pop_for_xgcm.py
Outdated
y_loc_key = int(grid_loc[2]) | ||
z_loc_key = int(grid_loc[3]) | ||
|
||
x_loc = {1: 'nlon_t', 2: 'nlon_u'}[x_loc_key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need
x_loc = {1: "nlon_t", 2: "nlon_u", 3: "nlon_u"}[x_loc_key]
y_loc = {1: "nlat_t", 2: "nlat_u", 3: "nlat_t"}[y_loc_key]
to make DZU
and DZT
work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Thank you, @dcherian
Can you point me to a small test dataset that I can use for testing purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ask Anna on that email thread. I just left work
When |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have tests?
What is the primary user-facing API that has been enabled?
Not yet. Can someone point me to some sample data to use?
To use this functionality the user would need to do the following: import xarray as xr
from pop_tools.xgcm_util import relabel_pop_dims
ds = xr.open_mfdataset('pop_netcdf_files.*.nc')
ds = relabel_pop_dims(ds)
# now you can use xgcm
import xgcm
grid = xgcm.Grid(ds) What additional user-facing functionality should we support? |
Let's wrap that in a method |
I think |
This comment has been minimized.
This comment has been minimized.
Here's some examples of computations to try out in the testing: https://xgcm.readthedocs.io/en/latest/grid_metrics.html |
This seems to be working: >>> from pop_tools import get_xgcm_grid, DATASETS
>>> import xarray as xr
>>> fname = DATASETS.fetch("iron_tracer.nc")
>>> ds = xr.open_dataset(fname)
>>> ds
<xarray.Dataset>
Dimensions: (nlat: 384, nlon: 320, time: 24, z_t: 60, z_w_bot: 60, z_w_top: 60)
Coordinates:
* time (time) object 0249-02-01 00:00:00 ... 0251-01-01 00:00:00
* z_t (z_t) float32 500.0 1500.0 2500.0 ... 487508.34 512502.8 537500.0
TLAT (nlat, nlon) float64 ...
ULONG (nlat, nlon) float64 ...
TLONG (nlat, nlon) float64 ...
ULAT (nlat, nlon) float64 ...
* z_w_top (z_w_top) float32 0.0 1000.0 2000.0 ... 500004.7 525000.94
* z_w_bot (z_w_bot) float32 1000.0 2000.0 3000.0 ... 525000.94 549999.06
Dimensions without coordinates: nlat, nlon
Data variables:
UE (time, z_t, nlat, nlon) float32 ...
VN (time, z_t, nlat, nlon) float32 ...
WT (time, z_w_top, nlat, nlon) float32 ...
HDIFE (time, z_t, nlat, nlon) float32 ...
HDIFN (time, z_t, nlat, nlon) float32 ...
HDIFB (time, z_w_bot, nlat, nlon) float32 ...
DIA_IMPVF (time, z_w_bot, nlat, nlon) float32 ...
KPP_SRC (time, z_t, nlat, nlon) float32 ...
STF (time, nlat, nlon) float32 ...
SMS (time, nlat, nlon) float32 ...
>>> grid = get_xgcm_grid(ds)
>>> grid
<xgcm.Grid>
Z Axis (periodic):
* center z_t --> left
* right z_w_bot --> center
* left z_w_top --> center
Y Axis (periodic):
* center nlat_t --> right
* right nlat_u --> center
X Axis (periodic):
* center nlon_t --> right
* right nlon_u --> center I still haven't addressed @klindsay28's comment though.
Since I am not that familiar with POP model output, it would be nice for someone to take a look at the current code in this PR, and let me know what changes need to be made to address this. |
@dcherian, @matt-long, the gentlest of bumps on this. Have two minute to take a look at this? 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know anything about bottom cells.
pop_tools/xgcm_util.py
Outdated
""" | ||
import xgcm | ||
|
||
ds = relabel_pop_dims(ds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fairly certain this doesn't work. ds
isn't returned but a copy is made deep down in the call stack and all the xgcm stuff nrequires the renamed dimensions.
How about
grid, new_ds = pop_tools.to_xgcm_grid_dataset(ds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
grid, new_ds = pop_tools.to_xgcm_grid_dataset(ds)
👍 Good catch. I've addressed this and renamed the utility function
|
||
|
||
def _label_coord_grid_locs(ds): | ||
grid_locs = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need a dataset that tests all of these. I've emailed Anna on our previous email thread. She was looking at one that had DZU & DZT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I left one minor comment but LGTM otherwise.
@dcherian, Thank you for reviewing this! I think this is ready to go. |
This looks great @andersy005! |
Closes #17, and towards #16