Changeset 2061


Ignore:
Timestamp:
26/01/07 15:01:10 (13 years ago)
Author:
domlowe
Message:

lots of changes to do with subsetting

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

Legend:

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

    r1902 r2061  
    1515        #Create an Empty Dataset & FeatureCollection 
    1616        self.ds = csml.parser.Dataset() 
    17         self.fc=csml.parser.FeatureCollection() 
    1817        #Set attributes of dataset 
    1918        #if 'metadata' is a URI, set it as href attribute if MetaDataProperty instance, 
     
    3130        self.dm=[] #empty list to hold definition members (e.g. UnitDefinitions) 
    3231        self.fm=[] #empty list to hold feature members (e.g. GridFeatures, PointFeatures) 
    33         self.ad=[] #empty list to hold array descriptors (e.g. NetCDFExtract) 
     32        self.sd=[] #empty list to hold storage descriptors (e.g. NetCDFExtract) 
    3433        #the dataset is now initialised. now you can add features/defintions/arraydescriptors 
    3534        #using the methods supplied. 
     
    6261    
    6362    def getContents(self): 
    64         self.ds.arrayDescriptors=self.ad 
    65         self.ds.featureCollection=csml.parser.FeatureCollection(members=self.fm) 
     63        self.ds.storageDescriptor=self.sd 
     64        self.ds.featureCollection=csml.parser.CSMLFeatureCollection(featureMembers=self.fm) 
    6665        csmlout=self.ds.toXML() 
    6766        #parse and pretty print the result to file 
  • TI02-CSML/trunk/csml/API/ops_AbstractFeature.py

    r1932 r2061  
    1010    return ['none'] 
    1111 
    12 def _identifyTimeAxis(self,listToCheck): 
     12def _identifyTimeAxis(self,listToCheck):  
    1313    #given a list of possible axes, find the one which is most probably the time axis. 
    1414    for name in listToCheck: 
     
    1818 
    1919def __compareTimes(timemin, timecheck, timemax): 
     20    timeok=0 
    2021    try: 
    2122        year=int(timecheck.split('-')[0]) 
     
    2728            if tcheck.cmp(timemax) < 1: 
    2829                timeok = 1 
     30        print 'TMIN time  %s'%timemin 
     31        print 'CHECK time  %s'%tcheck 
     32        print 'TMAX time  %s'%timemax 
    2933    except: 
    3034        #if it's not a proper internet time e.g. time = '6' then just compare numerically 
  • TI02-CSML/trunk/csml/API/ops_Dataset.py

    r1922 r2061  
    3939    #returns a list of feature ids for the dataset 
    4040    self.featureList = [] 
    41     for member in self.featureCollection.members: 
     41    for member in self.featureCollection.featureMembers: 
    4242            self.featureList.append(member.id) 
    4343    return self.featureList 
     
    4545def getFeature(self, featureID): 
    4646    """ returns a single feature object """ 
    47     for member in self.featureCollection.members: 
     47    for member in self.featureCollection.featureMembers: 
    4848            if member.id == featureID: 
    4949                return member     
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2000 r2061  
    2222    for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
    2323        name=gridOrd.coordAxisLabel.CONTENT 
    24         if isinstance(gridOrd.coordAxisValues, csml.parser.FileExtract): 
    25             #not tested with file extracts yet: (01/01/07) 
    26             self.domain[name]=gridOrd.coordAxisValues.getData() 
     24        if hasattr(gridOrd.coordAxisValues, '__insertedExtract'): 
     25            self.domain[name]=gridOrd.coordAxisValues.__insertedExtract.getData() 
    2726        else: 
    2827            vals=gridOrd.coordAxisValues.coordinateList.CONTENT 
    2928            valList=[] 
    30             for val in vals.split(','):  #remove commas 
     29            print 'splitting' 
     30            for val in vals.split():   
    3131                valList.append(val) 
     32                print val 
    3233            self.domain[name]=valList 
    3334    return self.domain 
     
    4142     
    4243    self.getDomain() 
     44     
     45    #TODO - incoporate the crsCatalogue. into this 
    4346    #deal with longitude requests 
    4447    #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. 
    4548    kwargs=csmlutils.fixLongitude(self.domain,kwargs) 
    46     #deal with times 
    47     timeAxis=self._identifyTimeAxis(self.domain.keys()) 
    48     self.times=kwargs[timeAxis] 
     49     
     50    #deal with times    
     51    #need to find the time axis: 
     52    cat=csml.csmllibs.csmlcrs.CRSCatalogue() 
     53    crs=cat.getCRS(self.value.gridSeriesDomain.srsName) 
     54    #get the position of the time axis in crs/ axis labels 
     55    timeAxisPos=crs.timeAxis 
     56    #get the name of the time axis in the crs 
     57    timeName=crs.axes[timeAxisPos] 
     58    #get the ordinate with that name and find the original time name for the file. 
     59    for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
     60        if gridOrd.coordAxisLabel.CONTENT==timeName: 
     61            timeAxis = gridOrd.gridAxesSpanned.CONTENT  #only works for regular grids atm 
     62        else:  
     63            print 'crs not supported' 
     64    
     65     
     66    #here, timeName is the name given to the time axis by the CRS, 
     67    #and timeAxis is the name given to the time axis in the file. 
     68    #currently supporting domain subsetting only by CRS name  
     69    #(but should be easy to extend later) 
     70    self.times=kwargs[timeName] 
    4971    self.files=[] 
    5072    strTimes='' 
     
    5274     
    5375    #set the reference system for the time axis 
    54      
     76    calset=False 
    5577    for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 
    56         if gridOrd.coordAxisLabel.CONTENT==timeAxis: 
     78        if gridOrd.coordAxisLabel.CONTENT==timeName: 
    5779            try: 
    5880                caltype=gridOrd.coordAxisValues.frame.split(':',1)[0] 
     
    6991    except: 
    7092        csml.csmllibs.csmltime.setcdtimeCalendar(csml.csmllibs.csmltime.cdtime.DefaultCalendar) 
    71      
    72      
     93   
     94        
    7395    if len(self.times) == 2: 
    7496        #then this is a range of times (t1, tn) 
    7597        try: 
    76             tone=ops_AbstractFeature.__getCDtime(self.times[0]) 
     98            tone=csml.API.ops_AbstractFeature.__getCDtime(self.times[0]) 
    7799        except: 
    78100            tone=self.times[0] 
    79101        try: 
    80             ttwo=ops_AbstractFeature.__getCDtime(self.times[1]) 
     102            ttwo=csml.API.ops_AbstractFeature.__getCDtime(self.times[1]) 
    81103        except: 
    82104            ttwo=self.times[1] 
     
    86108        else: 
    87109            self.getDomain() 
    88         for time in self.domain[timeAxis][0].split(): 
     110             
     111        for time in self.domain[timeName]: 
    89112            timeok=csml.API.ops_AbstractFeature.__compareTimes(tone,time,ttwo) 
    90113            if timeok ==1: 
    91114                self.times.append(time) 
     115     #okay up to here! 
     116 
    92117    if hasattr(self.value.rangeSet, 'aggregatedArray'): 
    93118        #handle aggregatedArray 
     
    159184        straxisValues='' 
    160185        #now deal with each argument: 
    161              
    162         print "KWARGS" 
    163         print kwargs 
    164         print  "DOM" 
    165         print self.domain 
     186    
    166187        if key in kwargs: 
    167             if kwargs[key][0] < kwargs[key][1]:    
     188            if key ==timeName: 
     189                continue #dealt with time earlier             
     190            elif kwargs[key][0] < kwargs[key][1]:    
    168191                for val in self.domain[key]: 
    169                     print self.domain[key] 
    170192                    if val is not '': 
    171193                            if float(val) >= kwargs[key][0]: 
     
    173195                                    arraySize=arraySize+1 
    174196                                    straxisValues=straxisValues+ str(val) + ', ' 
    175  
    176197            else:#this if deals with selections such as longitude (330,30) where the lower limit is 'greater' than the upper limit in a mathematical sense. 
    177198                    for val in self.domain[key]: 
     
    210231        floatTimes.append(time.value) 
    211232    nc.addAxis('t',floatTimes,isTime=1,units=calunits,calendar=caltype) 
     233    #USE CRS!     
    212234    for ordinate in ordinates: 
    213235        lon,lat=None,None 
     
    223245    if len(ordinates)==3: 
    224246        axes=['t',axisorder[1],axisorder[2],axisorder[3]] 
    225     elif len(grid.ordinates)==2: 
     247    elif len(ordinates)==2: 
    226248        axes=['t',axisorder[1],axisorder[2]] 
    227249    nc.addVariable(fulldata,self.id, axes,units='') #to do, units attribute for CF compliance 
  • TI02-CSML/trunk/csml/csmllibs/csmlcrs.py

    r2060 r2061  
    3737        crs=CRSystem(srsName='ndg:crs:xyt', axes =['Lon', 'Lat','Time']) 
    3838        self.systems['ndg:crs:xyt']=crs 
     39        crs.lonAxis=0 
     40        crs.latAxis=1 
     41        crs.timeAxis=2 
    3942         
    4043        #define unknown 1D CRS: 
  • TI02-CSML/trunk/csml/csmllibs/csmldataiface.py

    r2016 r2061  
    1919import sys 
    2020import csml.csmllibs.csmltime 
     21# This is required to prevent Numeric arrays being truncated when printed. 
     22import MA 
     23MA.set_print_limit(0) 
     24 
    2125 
    2226class DataInterface(object): 
  • TI02-CSML/trunk/csml/testfiles/basictest.py

    r2060 r2061  
    1515# 1. Test parsing from CSML file 
    1616#tree = ElementTree(file='../XMLInstances/CSMLExample_SuperWrap.xml') 
    17 tree = ElementTree(file='../testfiles/gridseries/testout.xml') 
     17tree = ElementTree(file='../DDCTestfiles/DDCout.xml') 
    1818 
    1919     
Note: See TracChangeset for help on using the changeset viewer.