Open navidcy opened 1 year ago
Agreed this would be good.
We currently have:
@adele157 re. your first point, I thought xesmf
and xgcm
are designed for different purposes: xesmf
for fast regridding between different grids, and xgcm
for Arakawa-grid-aware calculations (div, grad, curl, etc) on a given grid, and also vertical coordinate transformation. As far as I can see xgcm
doesn't do horizontal regridding (happy to be corrected, but even if it can I expect xesmf
would be much faster at high resolution).
xesmf
actually regrids the variables and interpolates to some other grid of your liking
xgcm
simply takes into account that some of your variables live on a slightly different locations on the same grid than others, e.g. u
lives elsewhere from T
, and it gives you the opportunity to compute quantities like ∂x( u T )
without you having to think which variable you need to interpolate first onto which grid before you take the product and how do you take the derivative and what not.
That is,
xgcm
does interpolate but only within cells to bring the variable from the u-grid to the t-grid and things like that.... xesmf
can be used to interpolate a 1/10 tripolar grid onto a 1/2 degree lat-log grid!Is this clarifying enough?
Yep, thanks, that's what I thought! So we need both xesmf
and xgcm
.
I made a regridding one with xesmf at some point: let's revisit that --> https://cosima-recipes.readthedocs.io/en/latest/documented_examples/Regridding.html#gallery-documented-examples-regridding-ipynb
Thanks, I've used xesmf
a lot, but not xgcm
. I'd just been confused by Adele's suggestion of xgcm
for horizontal regridding, but it turns out that's not a thing.
Sorry for confusion and thanks for clarification. I’ve only used xgcm before in the vertical (where it does do regridding) not the horizontal.
On Mon, Jan 23, 2023 at 12:18 PM, Andrew Kiss @.***> wrote:
Thanks, I've used xesmf a lot, but not xgcm. I'd just been confused by Adele's suggestion of xgcm for horizontal regridding, but it turns out that's not a thing.
— Reply to this email directly, view it on GitHub https://github.com/COSIMA/cosima-recipes/issues/164#issuecomment-1399673854, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACA44UYWPHZJKEMZYBYMSZ3WTXL7TANCNFSM6AAAAAARVWZUVA . You are receiving this because you were mentioned.Message ID: @.***>
[ waves ] Hi folks. I'm a 100% COSIMA Cookbook noob - with all of 1 hour under my belt.
I'm wondering if there is a CC "key" to pull in all the grid_spec
details for a particular model configuration?
like the grid specs that xgcm
requires? no there isn't... it could be something that we add after tomorrow.
but there are few examples in the recipes that use xgcm
; see, e.g., the relative vorticity example
or the vertical coords transformation example.
There have been some proposals to store grid info in the cookbook database, but none implemented as yet - e.g. see https://github.com/COSIMA/cosima-cookbook/issues/191 and https://github.com/COSIMA/cosima-recipes/issues/190
xgcm
now works with grid metrics (I tried a million times to make it work back in the day with no success)
folder = '/g/data/hh5/tmp/cosima/access-om2-025/025deg_jra55v13_iaf_gmredi6/output000/ocean/'
grid = xr.open_mfdataset(folder + 'ocean_grid.nc', combine='by_coords')
ds = xr.merge([u, v, grid])
ds.coords['xt_ocean'].attrs.update(axis='X')
ds.coords['xu_ocean'].attrs.update(axis='X', c_grid_axis_shift=0.5)
ds.coords['yt_ocean'].attrs.update(axis='Y')
ds.coords['yu_ocean'].attrs.update(axis='Y', c_grid_axis_shift=0.5)
metrics = {
('X',): ['dxt', 'dxu'], # X distances
('Y',): ['dyt', 'dyu'], # Y distances
('X', 'Y'): ['area_t', 'area_u'] # Areas
}
grid = xgcm.Grid(ds, periodic=['X'], metrics=metrics)
ζ_xgcm = grid.interp(grid.derivative(v, 'X'), 'Y', boundary='extend') - grid.interp(grid.derivative(u, 'Y'), 'X')
ζ_xgcm
We need to update the relative vorticity example. Another job for the Hackathon v2.0.
That's coming out from the discussion in Cosima workshop 2022.
cc @janjaapmeijer