Changeset 1521 for TI02-CSML


Ignore:
Timestamp:
15/09/06 11:39:13 (13 years ago)
Author:
domlowe
Message:

integrating CSMLContainer class to enable subsetting across multiple features

Location:
TI02-CSML/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/Examples/parsing/apicalls.py

    r1495 r1521  
    44 
    55f='Examples/parsing/test.xml' 
     6 
     7#Initialise the CSML container 
     8csmlContainer=csml.API.csmlContainer.Container("mycsmldoc", "mymetadatastring") 
    69 
    710#Initialise and parse the dataset 
     
    5053 
    5154#request subsetted data from feature (can set paths here) 
    52 subsetCSML, subsetNetCDF, arraySize=feature.subsetToGridSeries(timeSelection,  csmlpath='myfile.xml', ncpath='myfile.nc',**spatialSubsetDictionary) 
     55feature.subsetToGridSeries(csmlContainer, timeSelection,  csmlpath='myfile.xml', ncpath='myfile.nc',**spatialSubsetDictionary) 
     56csmlbundle=csmlContainer.getContents() 
     57 
     58print csmlbundle 
    5359 
    5460#parse and pretty print the result 
     
    5662# strCSML=parser_extra.removeInlineNS(strCSML) 
    5763# print strCSML #csml document (string) 
    58 print subsetCSML 
    59 print subsetNetCDF # netcdf file (file) 
    60 print 'arraySize: %s' %arraySize 
     64# print subsetCSML 
     65# print subsetNetCDF # netcdf file (file) 
     66# print 'arraySize: %s' %arraySize 
  • TI02-CSML/trunk/csml/API/csmlContainer.py

    r1518 r1521  
    1 class CSMLContainer(object): 
     1import csml.parser 
     2import csml.parser_extra 
     3 
     4class Container(object): 
    25    '''CSMLContainer object is used to hold features before generating a CSML document. This is useful because it allows you to subset several features sequentially then build a single CSML document containing all the subsetted features ''' 
    36     
    4     def __init__(self): 
     7    def __init__(self,docID, docMetaDataProperty): 
    58        ''' Initialise CSML Dataset and FeatureCollection and populate with basic Metadata''' 
    6         #do that here 
     9        ''' 
     10        docID = gml:id of Dataset element 
     11        docMetaDataProperty = gml:metaDataProperty of Dataset element  #hmm may need to allow a list here. 
     12        ''' 
     13        #initialise a new document 
     14        #Create an Empty Dataset & FeatureCollection 
     15        self.ds = csml.parser.Dataset() 
     16        self.fc=csml.parser.FeatureCollection() 
     17        #Set attributes of dataset 
     18        #if docMetaDataProperty is a URI, set it as href attribute if MetaDataProperty instance, 
     19        #else set it as a text attribute of a MetaDataProperty instance. 
     20        mdp=csml.parser.MetaDataProperty() 
     21        if csml.parser_extra.isURI(docMetaDataProperty): 
     22            mdp.href=docMetaDataProperty 
     23        else:  
     24            mdp.text = [docMetaDataProperty] 
     25        self.ds.metaDataProperty= [mdp] 
     26        #set the id 
     27        self.ds.id=docID 
     28        self.dm=[] #empty list to hold definition members (e.g. UnitDefinitions) 
     29        self.fm=[] #empty list to hold feature members (e.g. GridFeatures, PointFeatures) 
     30        self.ad=[] #empty list to hold array descriptors (e.g. NetCDFExtract) 
     31        #the dataset is now initialised. now you can add features/defintions/arraydescriptors 
     32        #using the methods supplied. 
     33        #when finished building CSML objects call the getContents method to return the document.        
     34 
    735        '''containerContents contains the CSML Document (first item) and then any NetCDF files that are to be delivered with the document ''' 
    8         containerContents=[] 
    9         pass 
     36        self.containerContents=[] 
     37         
    1038     
    1139    def appendFileExtract(self, fileextract): 
     
    1745        ''' Append feature to FeatureCollection''' 
    1846        #append to FeatureCollection instance 
    19         pass 
     47        self.fm.append(feature) 
    2048     
    2149    def attachNetCDFFile(self, ncfile): 
     
    2351        #append NetCDF file object to containerContents 
    2452        #need to think about whether it is best to append the file object or just a path to the file 
    25         pass 
     53        self.containerContents.append(ncfile) 
    2654     
    2755    def getContents(self): 
    28         return containerContents 
     56        self.ds.arrayDescriptors=self.ad 
     57        self.ds.featureCollection=csml.parser.FeatureCollection(members=self.fm) 
     58        print self.fm 
     59        csmlout=self.ds.toXML() 
     60        #parse and pretty print the result 
     61        strCSML=csml.parser_extra.PrettyPrint(csmlout) 
     62        strCSML=csml.parser_extra.removeInlineNS(strCSML) 
     63        self.containerContents.append(strCSML) 
     64        return self.containerContents 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r1496 r1521  
    5353 
    5454 
    55 def subsetToGridSeries(self, timeSubset,  csmlpath=None, ncpath=None,**kwargs): 
     55def subsetToGridSeries(self, container, timeSubset,  csmlpath=None, ncpath=None,**kwargs): 
     56    #MUST be supplied with a CSMLContainer object to store the subsetted feature in 
     57     
    5658    if csmlpath is not None: 
    5759        pathToSubsetCSML = csmlpath 
     
    177179    rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=pathToSubsetNetCDF,variableName=self.id,arraySize=[arraySize]) 
    178180 
    179     #### write csml document #####  
    180     csmldoc=csml.csmllibs.csmldocument.CSMLDocument("mydoc", "mymetadata") 
    181     csmldoc.addGridSeriesFeature(domain,rangeSet,datasetID="A",featureID="B",description="C") 
    182     csmldoc=csmldoc.consolidate() 
    183     output=open(pathToSubsetCSML,'w') 
    184     output.write(csmldoc) 
    185     output.close() 
     181    csmlWrap=csml.csmllibs.csmlfeaturewrap.CSMLWrapper() 
     182    subsettedFeature=csmlWrap.createGridSeriesFeature(domain,rangeSet,datasetID="A",featureID="B",description="C") 
     183    container.appendFeature(subsettedFeature) 
    186184 
    187185    ### write netcdf using NCWriter class (wraps cdms) ### 
     
    209207    nc.addVariable(fulldata,self.id, axes,units='') #to do, units attribute for CF compliance 
    210208    nc.closeFinishedFile() 
     209    container.attachNetCDFFile(nc) 
    211210    return pathToSubsetCSML,pathToSubsetNetCDF, totalArraySize 
  • TI02-CSML/trunk/csml/csmllibs/__init__.py

    r1480 r1521  
    1010import csmlfeaturefilemap 
    1111import csmlfiles 
     12import csmlfeaturewrap 
    1213 
    13  
Note: See TracChangeset for help on using the changeset viewer.