-
Notifications
You must be signed in to change notification settings - Fork 79
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
Issue with grid.transform #600
Comments
Hello Madeleine, I think that I know what is happening: the xgcm grid contains yours axes (usually X, Y, Z, T), and these are the axes that you refer to when using the grid methods. Here when you use ds['ztrans'] = ztrans
ds['ures'] = ures
grid_with_density_axis = xgcm.Grid(ds, coords={'S':{'center':'l1_c'}}, metrics={'S':['nae_of_density_metric']})
# Use S for density axis, S as in sigma And then use I haven't tested my code snippet, so you'll probably need to adapt slightly |
Thanks for the help! I think the issue may stem from the fact that although the 1RHO coordinate (l1_c) and the adjacent outer points are categorized as grid coordinates in |
Could you show the attributes you have for Otherwise, you can specify by hand the axes, by giving the |
So the attributes don't have the mandatory ds.l1_c.attrs['axis'] = 'S'
ds.l1_i.attrs['axis'] = 'S'
ds.l1_b.attrs['axis'] = 'S' You will also need to add the ds.l1_i.attrs['c_grid_axis_shift'] = 0.5
ds.l1_b.attrs['c_grid_axis_shift'] = 0.5 Here is the link to the doc: |
Regarding metrics, I don't think that xgcm parses them automatically, you have to provide them, see Cell [4] in https://xgcm.readthedocs.io/en/latest/grid_metrics.html#Using-metrics-with-xgcm metrics = {
('X',): ['dxC', 'dxG'], # X distances
('Y',): ['dyC', 'dyG'], # Y distances
('Z',): ['drW', 'drS', 'drC'], # Z distances
('X', 'Y'): ['rA', 'rAz', 'rAs', 'rAw'] # Areas
}
grid = Grid(ds, metrics=metrics) And you will need to also add the metric for the density coordinate |
Yes, that worked! Thank you. |
Hi, I am trying to calculate thickness weighted u velocity in MITgcm and transform it back to depth space using the time averaged density structure. See the code below.
zexpand = coords.Z.expand_dims(dim={"i": 1080,'j':310})
ztrans = grid.transform(zexpand, 'Z', coords.layer_1RHO_center.values, target_data=(ds.dens-1000))
ztrans = ztrans.rename(dens='l1_c')
ures = grid.interp(ds.LaUH1RHO.mean(dim='time')/ds.LaHw1RHO.mean(dim='time'),'X')
ures_z = grid.transform(ures,'l1_c',coords.Z,target_data=ztrans)
Everything seems to work right until the last step, when I get the error:
2607 def transform(self, da, axis, target, **kwargs):
2608 """Convert an array of data to new 1D-coordinates along 'axis'.
2609 The method takes a multidimensional array of data 'da' and
2610 transforms it onto another data_array 'target_data' in the
(...)
2688
2689 """
-> 2691 ax = self.axes[axis]
2692 return ax.transform(da, target, **kwargs)
KeyError: 'l1_c'
I am not sure what this means or how to fix it. Does anyone have any advice?
The text was updated successfully, but these errors were encountered: