source: TI02-CSML/trunk/parser/API/ops_ArrayGenerator.py @ 1366

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

Added example code to demonstrate creation of BODC PointSeries? features : demoCreateBODCPointSeries.py

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