source: TI02-CSML/trunk/csml/API/ops_ArrayGenerator.py @ 1483

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/API/ops_ArrayGenerator.py@1912
Revision 1483, 1.5 KB checked in by domlowe, 14 years ago (diff)

more module madness

Line 
1''' ops_ArrayGenerator '''
2import sys
3import cdtime
4   
5def getGeneratedValues(self,frame, summary=None):
6    #For times, given a CF 'frame' generate a list of times.
7    #frame of the form "calendar:units since date time")
8    #supported calendars on NDG wiki
9    #eg getGeneratedValues("360_day:days since 2001-12-18 00:00:00")
10    cal=frame.split(':',1)[0]
11    basedate=frame.split(':',1)[1]
12    csmltime.setcdtimeCalendar(cal)
13    start=int(self.expression.split(':')[0])
14    interval=int(self.expression.split(':')[1])
15    end=int(self.expression.split(':')[2])
16    print cdtime.DefaultCalendar
17    print start
18    print end
19    print interval
20    if summary is not None:
21        #return a summary of times (min, interval, max)  using cdtime
22        timelist=[]
23        tmin = cdtime.reltime(start, basedate).tocomp()
24        tmin=csmltime.UDtimeToCSMLtime(tmin)
25        tmax = cdtime.reltime(end, basedate).tocomp()
26        tmax=csmltime.UDtimeToCSMLtime(tmax)
27        timelist.append(tmin)
28        timelist.append(tmax)
29        print timelist
30       
31    else:
32        #use cdtime to return a full list of times - may take a long time..
33        timelist=[]
34        t = cdtime.reltime(start, basedate).tocomp()
35        for i in range(start, end, interval):
36            t = t.add(60,cdtime.Seconds)
37            #t = cdtime.reltime(i, basedate).tocomp()
38            #t=csmltime.UDtimeToCSMLtime(t)
39            timelist.append(t)
40        print timelist[:150]
41       
42   
43    return timelist
44   
Note: See TracBrowser for help on using the repository browser.