Changeset 1413 for TI02-CSML


Ignore:
Timestamp:
17/08/06 15:33:12 (13 years ago)
Author:
domlowe
Message:

fixed a lot of the time related issues raised by Ag, but there are still some problems. Commiting at a convenient point,

Location:
TI02-CSML/trunk/parser/API
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/parser/API/ops_AbstractFeature.py

    r1412 r1413  
    1919        if tcheck.cmp(timemin) >= 0: 
    2020            if tcheck.cmp(timemax) < 1: 
    21                 print tcheck 
    2221                timeok = 1 
    2322    except: 
     
    2625        if timecheck >=timemin: 
    2726            if timecheck <=timemax: 
    28                 print tcheck 
    2927                timeok = 1 
    3028    return timeok 
    3129 
    32 def __getCDtime(time): 
    33     try: 
    34         year=int(time.split('-')[0]) 
    35         month=int(time.split('-')[1]) 
    36         day=int(time.split('-')[2].split('T')[0]) 
    37         cdTimeVal=cdtime.comptime(year,month,day) 
    38     except: 
    39         #if it's not a proper internet time e.g. time = '6' then return the original time back. 
    40         return time 
     30def __getCDtime(time):  
     31    year=int(time.split('-')[0]) 
     32    month=int(time.split('-')[1]) 
     33    day=int(time.split('-')[2].split('T')[0]) 
     34    hour=int(time.split('-')[2].split('T')[1].split(':')[0]) 
     35    minute=int(time.split('-')[2].split('T')[1].split(':')[1]) 
     36    second=float(time.split('-')[2].split('T')[1].split(':')[2]) 
     37    cdTimeVal=cdtime.comptime(year,month,day,hour,minute,second) 
    4138    return cdTimeVal 
  • TI02-CSML/trunk/parser/API/ops_AbstractFileExtract.py

    r1186 r1413  
    88 
    99 
    10 def getData(self, fileposition=None, **kwargs): 
     10def getData(self,  fileposition=None, times=None, **kwargs): 
    1111    #should handle setAxis or setVariable as cdms netcdf model 
    1212    #file position defines the position of the filename if a list of filenames exists 
     
    1818    if fileposition is not None: 
    1919        file=self.fileName.split()[fileposition] 
     20        print file 
    2021    else: 
    2122        file=self.fileName 
    22      
    2323    #open the file 
    2424    DI = csmldataiface.DataInterface() 
  • TI02-CSML/trunk/parser/API/ops_GridSeriesFeature.py

    r1411 r1413  
    8181    fulldata=[] 
    8282    if len(self.times) == 2: 
    83         tone=ops_AbstractFeature.__getCDtime(self.times[0]) 
    84         ttwo=ops_AbstractFeature.__getCDtime(self.times[1]) 
     83        try: 
     84            tone=ops_AbstractFeature.__getCDtime(self.times[0]) 
     85        except: 
     86            tone=self.times[0] 
     87        try: 
     88            ttwo=ops_AbstractFeature.__getCDtime(self.times[1]) 
     89        except: 
     90            ttwo=self.times[1] 
    8591        dr=getDomainReference(self) 
    8692        self.times=[] 
     
    8995            if timeok ==1: 
    9096                self.times.append(time) 
    91     print self.times 
    9297     
     98    #to keep track of files that have already been fetched. eg. if multiple times are in a single file only need to get data from that file once... 
     99    numFiles=len(self.rangeSet.aggregatedArray.component[0].fileName.split()) 
     100    timeToFileRatio=len(domainref['t'].split())/numFiles 
     101    filesFetched=[] 
     102    #get data: 
    93103    for time in self.times: 
    94104        listPosition=domainref['t'].split().index(time) 
    95105        strTimes= strTimes + ' ' + time 
    96         #print self.rangeSet.aggregatedArray.component 
    97106        timedim=self.rangeSet.aggregatedArray.component[0].variableName 
    98          
    99107        for comp in self.rangeSet.aggregatedArray.component: 
    100             data=comp.getData(fileposition=listPosition, **kwargs) 
    101             self.files.append(comp.fileName.split()[listPosition]) 
    102  
     108            filePos=(listPosition)/timeToFileRatio 
     109            if filePos in filesFetched: 
     110                continue #already got data from this file, try next time 
     111            data=comp.getData(fileposition=filePos, times=self.times, **kwargs) 
     112            self.files.append(comp.fileName.split()[filePos]) 
    103113            if fulldata ==[]: 
    104114               fulldata = data.tolist() 
     115               print shape(fulldata) 
     116               sys.exit() 
    105117            else: 
    106118                for item in data.tolist(): 
    107119                    fulldata.append(item) 
     120            filesFetched.append(filePos) 
    108121        axisorder = data.getAxisIds()  #will need later! 
     122        print 'filesFetched %s'%filesFetched 
    109123    try: 
    110124        caltype=self.domain.domainReference.frame.split(':',1)[0] 
     
    177191    time_var.longname = 't' 
    178192    floatTimes=[] 
    179     #print len(fulldata[0]) 
    180193    for time in self.times: 
    181194        time=ops_AbstractFeature.__getCDtime(time).torel(calunits) 
     
    192205        for val in ordinate.axisValues.split(','): 
    193206            vals.append(float(val)) 
    194         #print ordinate.definesAxis 
    195207        if ordinate.definesAxis=='latitude': 
    196208            #this is just a fix till I work out what's going wrong 
    197209            vals.reverse() 
    198         #print vals 
    199210        item_var[:]=vals[:] 
    200211    #this needs reconsidering - do the shapes always match up?? 
Note: See TracChangeset for help on using the changeset viewer.