genutil.area_weights doesn't work with non-cartesian grids (most CMIP5 ocean grids)
chaosphere2112 opened this issue · 10 comments
This example outlines the issue:
import cdms2 as cdm
import genutil as gutil
infile = '/work/cmip5/historical/ocn/mo/thetao/cmip5.ACCESS1-0.historical.r1i1p1.mo.ocn.Omon.thetao.ver-1.latestX.xml'
f_h = cdm.open(infile)
mask = f_h('thetao',time=slice(0,1),lev=slice(0,1))(squeeze=1)
ocean_area_frac = gutil.area_weights(mask)
>>> ocean_area_frac = gutil.area_weights(mask)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/uvcdat/latest/lib/python2.7/site-packages/genutil/averager.py", line 188, in area_weights
wt = __myGetAxisWeights(ds, 0, axisoptions)
File "/usr/local/uvcdat/latest/lib/python2.7/site-packages/genutil/averager.py", line 54, in __myGetAxisWeights
raise AveragerError, 'Bounds not available to compute weights for dimension: '+ax.id
genutil.averager.AveragerError: ('B', 'o', 'u', 'n', 'd', 's', ' ', 'n', 'o', 't', ' ', 'a', 'v', 'a', 'i', 'l', 'a', 'b', 'l', 'e', ' ', 't', 'o', ' ', 'c', 'o', 'm', 'p', 'u', 't', 'e', ' ', 'w', 'e', 'i', 'g', 'h', 't', 's', ' ', 'f', 'o', 'r', ' ', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n', ':', ' ', 'j')
Migrated from: CDAT/cdat#402
@chaosphere2112 @doutriaux1 same here
@durack1 in the mean time you can try to use zonalmeans
Marking issue as stale, since there has been no activity in 30 days.
Unless the issue is updated or the 'stale' tag is removed, this issue will be closed in 7 days.
@jasonb5 this is a pretty big standing issue, as many of the CMIP5 and now CMIP6 grids (both atmospheric and oceanic) are now non-cartesian, it would be great if these functions were updated to be grid aware and worked as you'd expect
That would be nice. The least to do would be to print a warning telling the user to try to locate a CMIPn areacella
or areacello
variable matching his/her data
Some casual CMIPn data users don't know about areacellaand
areacello. Telling people about these 2 variables in
averager` and an averager tutorial could be useful as well
@jypeter not a bad suggestion, we might have to make this a little smarter, so only if a CMIPx file is being read, but I suppose a generic warning could also be useful
For the current version of CDMS we can add an improved generialized error and update the averager tutorial to note areacella
and areacello
variable. Would it be possible for either of you to provide some examples of using these variables? This would be greatly appreciated!
We'll put most of the effort towards improving support for grids in the next-gen CDMS.
@jasonb5 the areacell*
relate to either atmospheric (*a
; cell area) or ocean (*o
) grids and these are all in 2D (lat,lon). We also have the 3D ocean grids (atmosphere too) which have a corresponding volcello
(cell volume).
I don't have an example that I can immediately provide, but should be able to work one up. @jypeter I assume you have some examples somewhere? @pochedls?
I don't have an example, but it could be useful to add an areacella variable in your test files, matching an existing CMIPn atmospheric variable already in the test files (don't remember if there is already a nicely CMORized variable in the test files)
And then you can compute a global average (of 1 time step) using
(areacella * var).sum()/areacella.sum()
or something similar, and compare it with the resultat you get when computing the global average with averager
. Hopefully a similar enough result
Or maybe use a normalized weight, in order to avoid potentially too big values
(areacella/areacella.sum() * var).sum()
Can also compare (areacella/areacella.sum())
with generated weights
This could go to an averager notebook
I'm a bit in a hurry, so I hope I have not written complete rubbish above!