CDAT / cdutil

Climate Utilities for CDAT
3 stars 2 forks source link

cdutil.averager should print an error message when called with 'irregular' data #5

Open chaosphere2112 opened 8 years ago

chaosphere2112 commented 8 years ago

cdutil.averager should print an explicit error message when the data is on a grid it can't handle

Ideally, of course, cdutil.averager should be able to handle data on non-rectilinear grids!

One of our post-docs got the following when trying to get a global average of a CMIP5 file on the ORCA ocean grid. The sample data file (and other files with non rectilinear grids) can be downloaded from: https://files.lsce.ipsl.fr/public.php?service=files&t=ca134197a67c3cd311df6ede04747f6f

>>> import cdms2, cdutil

>>> f = cdms2.open('ORCA_grid_sample.nc')
Warning: bounds variable not found in ORCA_grid_sample.nc: time_centered_bounds
Warning: bounds variable not found in ORCA_grid_sample.nc: time_centered_bounds

>>> v = f('sosstsst', squeeze=1)

>>> v.shape
(149, 182)

>>> v.info()
*** Description of Slab sosstsst ***
id: sosstsst
shape: (149, 182)
filename: 
missing_value: 1e+20
comments: 
grid_name: grid_2
grid_type: CurvilinearGrid
time_statistic: 
long_name: sea surface temperature
units: degC
_FillValue: [  1.00000002e+20]
autoApiInfo: <AutoAPI.AutoAPI.Info instance at 0x7fa4dd4a8e60>
interval_write: 1mo
tileIndex: None
coordinates: time_centered nav_lon nav_lat
online_operation: average
cell_methods: time_counter: mean
interval_operation: 3600s
Grid has Python id 0x7fa4dd930850.
** Dimension 1 **
   id: y
   units:  
   Length: 149
   First:  0.0
   Last:   148.0
   Python id:  0x7fa4dd930890
** Dimension 2 **
   id: x
   units:  
   Length: 182
   First:  0.0
   Last:   181.0
   Python id:  0x7fa4dd930910
*** End of description for sosstsst ***

>>> global_average = cdutil.averager(v, axis='yx')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/install/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_VB_13/lib/python2.7/site-packages/genutil/averager.py", line 1042, in averager
    axis_order = _check_axisoptions(V, axis)
  File "/usr/local/install/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_VB_13/lib/python2.7/site-packages/genutil/averager.py", line 25, in _check_axisoptions
    raise AveragerError, 'Error: You have specified an invalid axis= option.'
genutil.averager.AveragerError: ('E', 'r', 'r', 'o', 'r', ':', ' ', 'Y', 'o', 'u', ' ', 'h', 'a', 'v', 'e', ' ', 's', 'p', 'e', 'c', 'i', 'f', 'i', 'e', 'd', ' ', 'a', 'n', ' ', 'i', 'n', 'v', 'a', 'l', 'i', 'd', ' ', 'a', 'x', 'i', 's', '=', ' ', 'o', 'p', 't', 'i', 'o', 'n', '.')

>>> global_average = cdutil.averager(v, axis='12')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/install/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_VB_13/lib/python2.7/site-packages/genutil/averager.py", line 1042, in averager
    axis_order = _check_axisoptions(V, axis)
  File "/usr/local/install/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_VB_13/lib/python2.7/site-packages/genutil/averager.py", line 25, in _check_axisoptions
    raise AveragerError, 'Error: You have specified an invalid axis= option.'
genutil.averager.AveragerError: ('E', 'r', 'r', 'o', 'r', ':', ' ', 'Y', 'o', 'u', ' ', 'h', 'a', 'v', 'e', ' ', 's', 'p', 'e', 'c', 'i', 'f', 'i', 'e', 'd', ' ', 'a', 'n', ' ', 'i', 'n', 'v', 'a', 'l', 'i', 'd', ' ', 'a', 'x', 'i', 's', '=', ' ', 'o', 'p', 't', 'i', 'o', 'n', '.')

Migrated from: https://github.com/UV-CDAT/uvcdat/issues/1464

github-actions[bot] commented 4 years ago

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.

durack1 commented 4 years ago

@jasonb5 this is another issue which will require the same tweaks as https://github.com/CDAT/genutil/issues/6

github-actions[bot] commented 4 years ago

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.