Replies: 1 comment
-
Ha, two minutes after I wrote this, I figured it out... For future me, or others: with xr.open_dataset(fname, decode_times=False) as ds:
grid = xgcm.Grid(ds, coords={'Z':{'center':'Z', 'outer':'Zp1'}}, periodic=False)
print(ds)
ds['THETA'] = ds['THETA'].where(ds.hFacC > 0)
ds['SALT'] = ds['SALT'].where(ds.hFacC > 0)
ds['pden'] = ds.THETA * -0.2 + ds.SALT * 0.75
pdlevels = ds['pden'][0, :, -20].values[::3]
# pdlevels[0] = 1.5 * pdlevels[0] - pdlevels[1] / 2
pdds = grid.transform(ds.TRAC03 * ds.drF , 'Z', pdlevels, target_data=ds.pden, method='conservative')
pdZ = grid.transform(ds.Z.values[np.newaxis,:, np.newaxis] + ds.TRAC01 * 0, 'Z', pdlevels, target_data=ds.pden)
pdDz = -pdZ.diff(dim='pden') if TRAC03 is in units of [conc], then If you want the mean value at each density level, you need only divide by the values of |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm sure I'll figure it out, but maybe someone has a quick guide. I have mitgcm output slices with density and tracers on fixed z-levels. I'd like to bin in density space, both for the mean values in each bin, and for the volume of water in each bin. This could be over the whole domain, or it might be nice to make x-pdens pooler plots of the distributions.
I think I'm close with
grid.transform(... method='conservative')
, but I'm not really understanding the units of what comes out of that.Beta Was this translation helpful? Give feedback.
All reactions