Skip to content
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

genutil.area_weights doesn't work with non-cartesian grids (most CMIP5 ocean grids) #6

Open
chaosphere2112 opened this issue Nov 23, 2016 · 10 comments
Labels
area/grids kind/feature Categorizes issue as related to feature request
Milestone

Comments

@chaosphere2112
Copy link

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

@durack1
Copy link
Member

durack1 commented Nov 23, 2016

@chaosphere2112 @doutriaux1 same here

@doutriaux1
Copy link
Contributor

@durack1 in the mean time you can try to use zonalmeans

@doutriaux1 doutriaux1 added this to the 3.0 milestone May 8, 2017
@doutriaux1 doutriaux1 modified the milestones: 3.0, Next Release Mar 29, 2018
@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Aug 27, 2020
@durack1
Copy link
Member

durack1 commented Aug 27, 2020

@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

@jypeter
Copy link
Member

jypeter commented Aug 28, 2020

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 areacellaandareacello. Telling people about these 2 variables in averager` and an averager tutorial could be useful as well

@durack1
Copy link
Member

durack1 commented Aug 28, 2020

@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

@jasonb5
Copy link
Contributor

jasonb5 commented Aug 28, 2020

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.

@durack1
Copy link
Member

durack1 commented Aug 29, 2020

@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?

@jypeter
Copy link
Member

jypeter commented Aug 31, 2020

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!

@durack1
Copy link
Member

durack1 commented Aug 31, 2020

@jypeter I think that is a good idea, and I would add an ocean (non-cartesian) grid to the mix, so that the test case gets a little harder

@jasonb5 jasonb5 added kind/feature Categorizes issue as related to feature request area/grids labels Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/grids kind/feature Categorizes issue as related to feature request
Projects
None yet
Development

No branches or pull requests

6 participants