Personal tools
You are here: Home CDAT Tips and Tricks Time Tips Time axis in CDAT
Document Actions

Time axis in CDAT

by Renata McCoy last modified 2007-05-08 10:24

Goal: Learn about time axis in CDAT.



import cdms,sys,cdtime
f=cdms.open(sys.prefix+'/sample_data/clt.nc')
t=v.getTime()    # return the time axis              
  id: time2
    Designated a time axis.
  units: months since 1978-12
    Length: 1
    First: 1.0
    Last: 1.0
    Other axis attributes:
      calendar: proleptic_gregorian
      axis: T
    Python id: -0x48f56974
  
  #print time in a more user friendly way
   [1979-1-1 0:0:0.0]

Here is how you can go back and forth from so called 'component time' and a 'relative time'

A component time is an absolute time with representation (year, month, day, hour, minute, second). A relative time is represented as (value, units since basetime).

The component time is in this case '[1979-1-1 0:0:0.0]' and the relative time is '1.00 months since 1978-12'

Lets get the units from the time variable above
t_units = t.units  # get time 't' units
print t_units
months since 1978-12

   1.0

Now we can create the relative time:

time_rel = cdtime.reltime(t0, t_units) # t0 only rank 0 array (scalar only!!)
print time_rel
   


 # convert relative time to component time
To learn more about the time manipulation, see the cdtime module description in the Chapter 3 of the CDMS Manual
The CDAT templates plots images and the python scripts can be found here.
 

Powered by Plone