CDAT / cdutil

Climate Utilities for CDAT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cdutil.ANNUALCYCLE.climatology() failed in cdutil 3.1.0

chengzhuzhang opened this issue · comments

As discussed in an email with @doutriaux1 and @dnadeau4 the same function works in cdutil 2.10, while failed in cdutil 3.1.0

Below is the code:

import cdms2
import cdutil

filename = 'test_data_amip_r1i1p1_mo_regrid_3x3_sgp.nc'
fin = cdms2.open(filename)
var = fin('tas')
cdutil.setTimeBoundsMonthly(var)
var_season = cdutil.ANNUALCYCLE.climatology(var).squeeze()

Below is the error:

Traceback (most recent call last):
  File "cdutil_test.py", line 8, in <module>
    var_season = cdutil.ANNUALCYCLE.climatology(var).squeeze()
  File "/Users/zhang40/anaconda2/envs/arm_diags_env_0207_1/lib/python2.7/site-packages/cdms2/avariable.py", line 1706, in squeeze
    return(MV.squeeze(self))
  File "/Users/zhang40/anaconda2/envs/arm_diags_env_0207_1/lib/python2.7/site-packages/cdms2/MV2.py", line 352, in squeeze
    maresult, axes=axes, attributes=attributes, grid=grid, id=id)
  File "/Users/zhang40/anaconda2/envs/arm_diags_env_0207_1/lib/python2.7/site-packages/cdms2/tvariable.py", line 203, in __init__
    self.initDomain(axes, copyaxes=copyaxes)
  File "/Users/zhang40/anaconda2/envs/arm_diags_env_0207_1/lib/python2.7/site-packages/cdms2/tvariable.py", line 357, in initDomain
    raise CDMSError("Wrong number of axes to initialize domain.")
cdms2.error.CDMSError: Wrong number of axes to initialize domain.

@chengzhuzhang it looks like the error is coming from using squeeze in-correctly. Please try replacing last line of your code as below:
var_season = cdutil.ANNUALCYCLE.climatology(var)(squeeze=1)

var.shape --> (324, 1, 1): monthly time series on one grid (or area-averaged)
ann = cdutil.ANNUALCYCLE.climatology(var)
ann.shape --> (12, 1, 1): annual cycle of var
var_season = cdutil.ANNUALCYCLE.climatology(var)(squeeze=1)
var_season.shape --> (12,): annual cycle of var, lat/lon dimensions removed

Thank you @lee1043. I talked to @dnadeau4 , it seems like using asma() also works. My question is, since the same line worked for an older version cdat2.10. Is it because cdat3.10 dropped support for squeeze() ?

@chengzhuzhang you're right it might needs a cleanup at the cdms level. @dnadeau4 what do you think?

@chengzhuzhang in my understanding asma returns numpy array instead of transient variable; so you lose coordinate information. I think it might be still useful to keep var type as transient variable.

>>> type(var)
<class 'cdms2.tvariable.TransientVariable'>
>>> var_season = cdutil.ANNUALCYCLE.climatology(var).asma()
>>> var_season.shape
(12, 1, 1)
>>> type(var_season)
<class 'numpy.ma.core.MaskedArray'>

@doutriaux1 this could be a candidate for migration into the https://github.com/CDAT/cdutil issue list

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 I think this is still a valid bug? no