Changeset 1608


Ignore:
Timestamp:
19/10/06 12:40:50 (13 years ago)
Author:
domlowe
Message:

ongoing changes to csml2moles.py - convenient time to commit

Location:
TI02-CSML/trunk/csml2MolesStuff
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml2MolesStuff/csml2moles.py

    r1607 r1608  
    66import elementtree.ElementTree as etree 
    77import datetime 
     8import molesWriter 
    89#this is a fix to the  ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc. 
    910etree._namespace_map.update({ 
    1011        'http://www.opengis.net/om': 'om',  'http://www.opengis.net/gml': 'gml','http://ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'}) 
    1112 
    12       
     13 
    1314def _strToDate(ymd): 
    1415    '''given a string in form '2006-01-01' returns a datetime object''' 
    1516    return datetime.date(*map(int, ymd.split('-'))) 
    1617 
    17 def _getEnvelopefromFile(f): 
    18     '''parses a file and gets the bounding box from the feature collection''' 
     18def _getEnvelopefromDataset(ds): 
     19    '''gets the bounding box from the feature collection''' 
     20    envelope= ds.featureCollection.boundedBy 
     21    return envelope 
     22 
     23def _parsefile(f): 
    1924    tree = cElementTree.ElementTree(file=f) 
    2025    dataset = csml.parser.Dataset() 
    2126    dataset.fromXML(tree.getroot()) 
    22     envelope= dataset.featureCollection.boundedBy 
    23     return envelope 
     27    return dataset 
     28     
    2429 
    2530class EnvelopeAggregator(object): 
     
    7883        self.envelope.timePosition2=str(self.t2) 
    7984        return self.envelope 
    80     
    8185 
    82  
     86    #new process: 
    8387def main(args=None): 
    8488    '''Get command line arguments, should be paths to csml files 
     
    8993        sys.argv =args 
    9094    csmlfilelist= sys.argv[1:] 
    91     #use the first file to set up the aggregator: 
    92     env=_getEnvelopefromFile(csmlfilelist[0]) 
     95 
     96    #set up coverage envelope aggragator with envelope from first file: 
     97    dataset=_parsefile(csmlfilelist[0]) 
     98    env=_getEnvelopefromDataset(dataset) 
    9399    aggregator=EnvelopeAggregator(env) 
    94     #then aggregate across the rest of the files in the list 
    95     csmlfilelist=csmlfilelist[1:] 
     100  
     101    #for each file: 
    96102    for f in csmlfilelist: 
    97         aggregator.compareEnvelope(_getEnvelopefromFile(f)) 
     103        #parse file: 
     104        dataset=_parsefile(f) 
     105        #compare envelope: 
     106        aggregator.compareEnvelope(_getEnvelopefromDataset(dataset)) 
     107        #get other things: 
     108         
     109    #get aggregated envelope: 
    98110    finalEnvelope=aggregator.getAggregatedEnvelope() 
    99     #test output - need to decide what we want to do with the aggregated envelope:  
    100     #options include; Create an empty moles record, write to a text file, add to an existing moles record..? 
     111    #get other aggregations: 
     112     
     113    #write MOLES skeleton document: 
    101114    print finalEnvelope.lowerCorner.vals 
    102115    print finalEnvelope.upperCorner.vals 
  • TI02-CSML/trunk/csml2MolesStuff/molesWriter.py

    r1606 r1608  
    6363 
    6464    def _createClasses(self): 
    65         self.dataModelID=self._create_a_class('dataModelID', molesElement,) 
    66         self.dgDataGranule=self._create_a_class('dgDataGranule', molesElement) 
    67         self.dgDataEntity=self._create_a_class('dgDataGranule', molesElement) 
    68         self.dgMetadataRecord=self._create_a_class('dgMetadataRecord', molesElement) 
    69         self.dgMetadataID=self._create_a_class('dgMetadataID', molesElement) 
     65        #if you want more classes just add their names to this list 
     66        classList=[\ 
     67        'dataModelID', \ 
     68        'dgDataGranule', \ 
     69        'dgDataEntity', \ 
     70        'dgMetadataRecord', \ 
     71        'dgMetadataID', \ 
     72        ] 
     73 
     74        for className in classList: 
     75            newClass=self._create_a_class(className, molesElement) 
     76            setattr(self,className,newClass) 
    7077 
    7178def main(): 
     
    7481    M._createClasses() 
    7582     
    76     #create your moles doc by setting attributes. 
     83    '''create your moles doc by setting attributes of "M.className" 
     84    the classNames used must be declared in molesWriter.MolesDoc.classList''' 
    7785    dgMID=M.dgMetadataID(schemeIdentifier='NDG-B0', repositoryIdentifier='badc.nerc.ac.uk', localIdentifier='COAPEC_HadCM3_500Yr') 
    7886    dmID= M.dataModelID(schemeIdentifier='NDG-A0', repositoryIdentifier='badc.nerc.ac.uk', localIdentifier='COAPEC_500YrRun_wholerun_annual_atmos') 
Note: See TracChangeset for help on using the changeset viewer.