KeyError when applying xgcm.Grid.cumsum on the LAYERS package output
See original GitHub issueI have a xgcm.grid object that is recognizing the layers grid:
import xgcm.grid as Grid
grid = Grid(ds, periodic=['X'])
grid
--------
<xgcm.Grid>
Z Axis (not periodic):
* center Z (40) --> left
* left Zl (40) --> center
* outer Zp1 (41) --> center
* right Zu (40) --> center
Y Axis (not periodic):
* center YC (200) --> left
* left YG (200) --> center
X Axis (periodic):
* center XC (100) --> left
* left XG (100) --> center
1TH Axis (not periodic):
* center layer_1TH_center (42) --> outer
* outer layer_1TH_bounds (43) --> center
* inner layer_1TH_interface (41) --> center
T Axis (not periodic):
* center time (3600)
However, when I try to apply the grid.cumsum
function over the 1TH Axis
, I get the following KeyError:
vname = 'LaVH1TH'
mean_thkns = ds[vname].mean(['time','XC'])
print(mean_thkns)
grid.cumsum(mean_thkns[::-1], 'layer_1TH_center')
--------
<xarray.DataArray 'LaVH1TH' (layer_1TH_center: 42, YG: 200)>
dask.array<shape=(42, 200), dtype=float32, chunksize=(42, 200)>
Coordinates:
* YG (YG) >f4 0.0 10000.0 20000.0 30000.0 40000.0 50000.0 ...
* layer_1TH_center (layer_1TH_center) float32 -0.1 0.1 0.3 0.5 0.7 0.9 ...
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-32-7d428bd4e21f> in <module>()
2 mean_thkns = ds[vname].mean(['time','XC'])
3 print(mean_thkns)
----> 4 grid.cumsum(mean_thkns, 'layer_1TH_center')
~/xgcm/xgcm/grid.py in cumsum(self, da, axis, **kwargs)
552 """
553
--> 554 ax = self.axes[axis]
555 return ax.cumsum(da, **kwargs)
556
KeyError: 'layer_1TH_center'
Is there a work around for this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Source code for xgcm.grid
"i.e. use `Grid.cumsum` instead of `Axis.cumsum`", FutureWarning, ) pos, ... except KeyError: raise KeyError("Position '%s' was not found in axis.coords.
Read more >DataSet()方法的代码示例 - Python源码库
Grid attributes are assumed to have their internal aospy names. ... and/or unlabeled arrays to which to apply the function. y : Dataset,...
Read more >The xgcm from xgcm - GithubHelp
KeyError when applying xgcm.Grid.cumsum on the LAYERS package output. I have a xgcm.grid object that is recognizing the layers grid: import xgcm.grid as ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you understand how I debugged this? The important step is to understand the nature of this error
You could have examined
grid.axes
yourself to verify that ‘layer_1TH_center’ was not a valid key.The name of the axis is
1TH
, notlayer_1TH_center
.layer_1TH_center
is the name of a coordinate, not an axis. So you should do(Also, do not reverse the data. that will not work with xgcm.)