Changeset 888


Ignore:
Timestamp:
05/05/06 14:53:19 (13 years ago)
Author:
domlowe
Message:

spatial temporal selection on any axis implemented (for netcdf)

Location:
TI02-CSML/trunk/newparser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/newparser/Parser.py

    r882 r888  
    7474        setattr(obj,attrib,[]) 
    7575 
     76def checkMandatory(obj,*args): 
     77    #check mandatory attributes/elements are present. 
     78    #should be called at the *end* of each fromXML method 
     79    for arg in args: 
     80        if not hasattr(obj, arg): 
     81            objtype = str(obj) 
     82            print 'Parse error: Mandatory value missing: '  + str(arg) 
     83            if hasattr(obj,'id'): 
     84                print 'See element with gml:id = ' + obj.id 
     85            sys.exit() 
     86 
    7687##class TemplateClass(Base): 
    7788##    def __init__(self,myarg=None,*args,**kwargs): 
     
    15971608##        else: 
    15981609##            raise Exception('Unexpected element: "'+frag.tag+'"') 
     1610        checkMandatory(self, 'variableName') 
    15991611    def toXML(self,csmlFrag): 
    16001612        csmlFrag = AbstractFileExtract.toXML(self,csmlFrag) 
     
    29933005            self.featureCollection = featureCollection 
    29943006    def fromXML(self,csmlFrag): 
     3007        if csmlFrag.tag != CSML('Dataset'): 
     3008            print 'This does not appear to be a CSML file. Does not contain a root Dataset element.' 
     3009            print ' ' 
     3010            sys.exit() 
    29953011        AbstractGML.fromXML(self,csmlFrag) 
    29963012        for frag in csmlFrag.getchildren(): 
  • TI02-CSML/trunk/newparser/csmlio.py

    r883 r888  
    154154        DI.setVariable(variable) 
    155155         
    156         sys.exit() 
     156         
    157157        if kwargs: 
    158158            data = DI.getSubsetOfDataForVar(**kwargs) 
     
    161161        return data 
    162162         
    163     def getDataForFeature(self, featureID, timeSubset=None,  **kwargs): 
     163    def getDataForFeature(self, featureID, timeSubset,  **kwargs): 
    164164        #getDataForFeature, given the gml:id of a file extract, returns the (full) data for that feature 
    165165        #i.e. the rangeSet 
    166166        #Needs to use the rangeSet, domainReference and domainComplement to work out how to 
    167  
    168167        #extract the data from file 
    169168        self.__setFeature(featureID) 
     169        if timeSubset: 
     170            pass 
     171        else: 
     172            timeSubset=None 
    170173        #The RangeSet can be one of: 
    171174        #QuantityList 
  • TI02-CSML/trunk/newparser/example.xml

    r883 r888  
    115115        <!--===== Indirect value array definitions. =====--> 
    116116        <!--===================================================================--> 
    117         <NetCDFExtract gml:id="feat04times"> 
     117    <NetCDFExtract gml:id="feat04times"> 
    118118                <arraySize>10000</arraySize> 
    119119                <fileName>radar_data.nc</fileName> 
    120                 <variableName>time</variableName> 
     120                <variablecName>time</variablecName> 
    121121        </NetCDFExtract> 
    122122        <NetCDFExtract gml:id="feat04azimuth"> 
  • TI02-CSML/trunk/newparser/ioDemo.py

    r883 r888  
    4040domain=csml.getDomain('solar_3') 
    4141#print 'domain: ' + str(domain) 
    42 featureValues=csml.getDataForFeature('solar_3') 
     42#featureValues=csml.getDataForFeature('solar_3', None) 
    4343 
    4444 
    45 axisname = 'latitude' 
    4645timelist = domainref['t'] 
    4746#make some selection from the available times: 
    4847timeSelection = timelist.split()[:2] 
    4948#featureValues=csml.getDataForFeature('solar_3',timeSelection, latitude=(0.,10.0), longitude=(90, 100.0)) 
    50 # spatialSubsetDictionary= {latitude:(0.,10.0), longitude:(90, 100.0)} 
    51 featureValues=csml.getDataForFeature('solar_3',timeSelection, spatialSubsetDictionary) 
     49spatialSubsetDictionary= {} 
     50spatialSubsetDictionary['latitude']=(0.,10.0) 
     51spatialSubsetDictionary['longitude']=(90, 100.0) 
     52 
     53featureValues=csml.getDataForFeature('solar_3', timeSelection, **spatialSubsetDictionary) 
     54 
     55#same as: 
    5256#featureValues=csml.getDataForFeature('solar_3',timeSelection, latitude=(0.,10.0), longitude=(90, 100.0)) 
    5357print featureValues 
  • TI02-CSML/trunk/newparser/parseTest.py

    r880 r888  
    1919    print "<h1>CSML Test Parser</h1>" 
    2020    print "<p>Please note this is experimental, any questions please contact d.lowe@rl.ac.uk</p>" 
     21    print "<p>Parser version - 05 May 2006</p>" 
    2122    print "<h2>Load a CSML file to test:</h2>" 
    2223     
  • TI02-CSML/trunk/newparser/test.py

    r883 r888  
    1616####################################################### 
    1717# 1. Test parsing from CSML file 
    18 #tree = ElementTree(file='example.xml') 
    19 tree = ElementTree(file='nagridseries.xml') 
     18tree = ElementTree(file='example.xml') 
     19#tree = ElementTree(file='nagridseries.xml') 
    2020dataset = Dataset() 
    2121 
    2222#Calling the fromXML method reads the CSML into memory. 
     23 
    2324dataset.fromXML(tree.getroot()) 
    24  
    2525#Reading some values from memory and printing it out:: 
    2626#print dataset.featureCollection.members[3].profileSeriesDomain.domainReference.times.href 
Note: See TracChangeset for help on using the changeset viewer.