import cdms,sys,cdutil,genutil,MV
f=cdms.open(sys.prefix+'/sample_data/clt.nc')
s=f('clt')
Make sure bounds are correct!
cdutil.times.setTimeBoundsMonthly(s)
Remove AC
dep = cdutil.times.ANNUALCYCLE.departures(s)
Which is equivalent of doing:
ac = cdutil.times.ANNUALCYCLE.climatlogy(s)
dep = cdutil.times.ANNUALCYCLE.departures(s,ref=ac)
The second case shows how to remove climatology computed on a different period (computing ac over a different period)
trend,intercept = genutil.statistics.linearregression(dep)
time = MV.array(dep.getTime()) # makes an array of time dimension
time.setAxis(0,dep.getTime()) # passes itslef as axis...
The following "grows" trend and time so they are 3D
detrender,time = genutil.grower(time,trend)
detrended = dep - detrender*time
f=cdms.open("out.nc",'w')
f.write(detrended,id=dep.id,typecode='f')
f.close()