Changeset 1932 for TI02-CSML/trunk


Ignore:
Timestamp:
02/01/07 13:54:52 (13 years ago)
Author:
domlowe
Message:

changes to !subsetGridSeries

Location:
TI02-CSML/trunk/csml
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/API/__init__.py

    r1929 r1932  
    3333 
    3434##AbstractFeature methods: 
    35 addMethods(csml.parser.AbstractFeature, [ops_AbstractFeature.testmethod, ops_AbstractFeature.getAllowedSubsettings]) 
     35addMethods(csml.parser.AbstractFeature, [ops_AbstractFeature.testmethod, ops_AbstractFeature.getAllowedSubsettings, ops_AbstractFeature._identifyTimeAxis]) 
    3636 
    3737##PointFeature methods: 
  • TI02-CSML/trunk/csml/API/ops_AbstractFeature.py

    r1483 r1932  
    11''' ops_AbstractFeature  contains operations for AbstractFeatures''' 
     2import string 
    23import cdtime 
    34 
     
    89def getAllowedSubsettings(self): 
    910    return ['none'] 
     11 
     12def _identifyTimeAxis(self,listToCheck): 
     13    #given a list of possible axes, find the one which is most probably the time axis. 
     14    for name in listToCheck: 
     15        if string.upper(name) in ['T', 'TIME']: 
     16            tname =name 
     17    return tname 
    1018 
    1119def __compareTimes(timemin, timecheck, timemax): 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r1929 r1932  
    77import csml.csmllibs.netCDFWriter 
    88 
     9import sys  #remove later 
    910 
    1011def testmethod(self): 
     
    1819def getDomain(self): 
    1920    #returns domain as a dictionary of ordinates {name: [values], ...} 
    20     domain={} 
     21    self.domain={} 
    2122    for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
    2223        name=gridOrd.coordAxisLabel.CONTENT 
    2324        if isinstance(gridOrd.coordAxisValues, csml.parser.FileExtract): 
    2425            #not tested with file extracts yet: (01/01/07) 
    25             domain[name]=gridOrd.coordAxisValues.getData() 
     26            self.domain[name]=gridOrd.coordAxisValues.getData() 
    2627        else: 
    2728            vals=gridOrd.coordAxisValues.coordinateList.CONTENT 
     
    2930            for val in vals.split(','):  #remove commas 
    3031                valList.append(val) 
    31             domain[name]=valList 
    32     return domain 
     32            self.domain[name]=valList 
     33    return self.domain 
    3334 
    34 def subsetToGridSeries(self,   csmlpath=None, ncpath=None,**kwargs): 
     35def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 
    3536    #pathToSubsetCSML = container.csmlpath 
    3637    if ncpath is not None: 
     
    4142    #deal with longitude requests 
    4243    #if the request is in -ve,+ve eg (-30,30) but the data is in (0,360) need to handle this by changing the args. 
    43     dc = self.getDomainComplement() 
     44    dc = self.getDomain() 
    4445    for key in dc.keys(): 
    4546        if key == 'longitude': #how do we test if it is longitude properly? 
     
    5253                    if kwargs[key][1] < 0: 
    5354                        kwargs[key]=(kwargs[key][0],kwargs[key][1]+360) 
    54           
    55     domainref = getDomainReference(self) 
    56     self.times=timeSubset 
     55     
     56    timeAxis=self._identifyTimeAxis(dc.keys()) 
     57    self.times=kwargs[timeAxis] 
    5758    self.files=[] 
    5859    strTimes='' 
    5960    fulldata=[] 
    6061    if len(self.times) == 2: 
     62        #then this is a range of times (t1, tn) 
    6163        try: 
    6264            tone=ops_AbstractFeature.__getCDtime(self.times[0]) 
     
    6769        except: 
    6870            ttwo=self.times[1] 
    69         dr=getDomainReference(self) 
    7071        self.times=[] 
    71         for time in dr['t'].split(): 
     72        if hasattr(self, 'domain'): 
     73            pass 
     74        else: 
     75            self.getDomain() 
     76        for time in self.domain[timeAxis][0].split(): 
    7277            timeok=csml.API.ops_AbstractFeature.__compareTimes(tone,time,ttwo) 
    7378            if timeok ==1: 
    7479                self.times.append(time) 
    75      
     80#    sys.exit() 
     81 
    7682    #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... 
    7783    numFiles=len(self.rangeSet.aggregatedArray.component[0].fileName.split()) 
     
    8288        listPosition=domainref['t'].split().index(time) 
    8389        strTimes= strTimes + ' ' + time 
    84         timedim=self.rangeSet.aggregatedArray.component[0].variableName 
    8590        for comp in self.rangeSet.aggregatedArray.component: 
    8691            filePos=(listPosition)/timeToFileRatio 
     
    121126        straxisValues='' 
    122127        #now deal with each argument: 
    123          
     128 
    124129        if key in kwargs: 
    125130            if kwargs[key][0] < kwargs[key][1]:    
  • TI02-CSML/trunk/csml/testfiles/apicalls.py

    r1929 r1932  
    2626print feature.description 
    2727 
    28 #new style domain: 
     28#get the domain of the feature 
     29 
     30print '\n The feature has domain:'  
    2931print feature.getDomain() 
    30 sys.exit() 
    31  
    32 #get the domain of the feature 
    33 print '\n The feature has domain reference:'  
    34 print feature.getDomainReference() 
    35  
    36 #get the domain complement of the feature 
    37 print '\n The feature has domain complement :'  
    38 print feature.getDomainComplement() 
    39  
    40 #get combined domain 
    41 print '\n The feature has domain:'  
    42 #print feature.getDomain() 
    4332 
    4433#get list of allowed subsettings 
     
    4736 
    4837 
    49 #define a selection (based on the domain ref/complement) 
    50 #timeSelection=['2881-3-16T0:0:0.0', '2881-4-16T0:0:0.0', '2881-5-16T0:0:0.0', '2881-6-16T0:0:0.0', '2881-7-16T0:0:0.0', '2881-8-16T0:0:0.0', '2881-9-16T0:0:0.0'] 
    51 timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0'] 
    52  
    53 spatialSubsetDictionary= {} 
    54 spatialSubsetDictionary['latitude']=(-90,90) 
    55 #spatialSubsetDictionary['longitude']=(330,359) 
    56 spatialSubsetDictionary['longitude']=(-31.265,30.258) 
    57  
     38#define a selection (based on the domain) 
     39subsetDictionary={} 
     40subsetDictionary['t']=('2794-12-1T0:0:0.0', '2814-12-1T0:0:0.0') 
     41subsetDictionary['latitude']=(-90,90) 
     42subsetDictionary['longitude']=(-31.265,30.258) 
    5843#request subsetted data from features (can set paths here) and add to container 
    5944#subset a feature 
    60 csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile.nc',**spatialSubsetDictionary)) 
     45csmlContainer.add(feature.subsetToGridSeries(ncpath='myfile.nc',**subsetDictionary)) 
    6146#subset another feature (in fact it's the same feature again, but it proves the concept) 
    62 csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile2.nc',**spatialSubsetDictionary)) 
     47#csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile2.nc',**spatialSubsetDictionary)) 
    6348 
    6449#when you have finished, get the contents of the container 
Note: See TracChangeset for help on using the changeset viewer.