Changeset 839


Ignore:
Timestamp:
26/04/06 16:43:02 (13 years ago)
Author:
domlowe
Message:

basic getData method working for NetCDF/PP/NasaAmes

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

Legend:

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

    r835 r839  
    44from  Parser import * 
    55import nappy 
    6 from cdms import Cdunif 
     6import cdms 
    77import parser_extra 
    88from xml.dom.minidom import parseString 
    99import elementtree.ElementTree as etree 
     10 
     11#import the DataInterface module from the Scanner, assumes it is in a sibling directory to the one containing csmlio.py 
     12#TODO - how best to organise modules... 
     13import os 
     14currentPath=os.getcwd() 
     15parentPath=os.sep.join(currentPath.split(os.sep)[:-1]) 
     16parserPath=parentPath + '/Scanner/csmllibs' 
     17sys.path.append(parserPath) #append the parser path to sys.path 
     18try: 
     19    import csmldataiface 
     20except: 
     21    print 'Could not import CSML Data Interface module. Make sure the Parser code is in ../newparser directory on the same level as ../Scanner directory.' 
     22    sys.exit() 
    1023 
    1124 
     
    102115    def getFileExtractList(self): 
    103116        fileExtractList=[] 
     117        print dir(self.dataset) 
    104118        for arrayDescriptor in self.dataset.arrayDescriptors: 
    105119            fileExtractList.append(arrayDescriptor.id) 
     
    107121     
    108122    def getData(self, fileExtractID): 
    109         #getData, given the gml:id of a file extract, calls the appropriate library to read the data 
     123        #getData, given the gml:id of a file extract, returns the (full) data for that extract 
    110124        self.__setArrayDescriptor(fileExtractID) 
    111125        file = self.currentArrayDescriptor.fileName 
    112         if isinstance(self.currentArrayDescriptor, NetCDFExtract): 
    113             pass 
    114         if isinstance(self.currentArrayDescriptor, NASAAmesExtract): 
    115             pass 
    116         if isinstance(self.currentArrayDescriptor, GRIBExtract): 
    117             pass 
    118         #if isinstance(self.currentArrayDescriptor, PPExtract): 
    119            # pass 
    120         #if isinstance(self.currentArrayDescriptor, QXFExtract): 
    121            # pass         
    122         return file         
     126        print self.currentArrayDescriptor.arraySize 
     127        variable = self.currentArrayDescriptor.variableName 
     128        DI = csmldataiface.DataInterface() 
     129        DI=DI.getUnknownInterfaceType(file)         
     130        DI.openFile(file) 
     131        DI.setAxis(variable) 
     132        fulldata = DI.getDataForAxis() 
     133        return fulldata 
  • TI02-CSML/trunk/newparser/ioDemo.py

    r835 r839  
    1212 
    1313#parse in CSML document: 
    14 csml.parse('example.xml') 
     14#csml.parse('example.xml') 
     15csml.parse('gridseriestest.xml') 
    1516 
    1617#return CSML document as string: 
     
    3536 
    3637#get gml description (long name) of feature 
    37 fdesc= csml.getFeatureDescription('feat04') 
    38 print fdesc 
     38#fdesc= csml.getFeatureDescription('feat04') 
     39#print fdesc 
    3940 
    4041#get list of file extracts by gml:id 
     
    4748#currently returns a list, but may need to consider masked arrays 
    4849#dataArray = csml.getData(fileExtractID) 
    49 dataArray = csml.getData('feat04times') 
     50#dataArray = csml.getData('feat04times') 
     51dataArray = csml.getData('2__ncextract_latitude') 
    5052print dataArray 
    5153 
  • TI02-CSML/trunk/newparser/parser_extra.py

    r836 r839  
    88import Parser 
    99import sys 
     10import elementtree.ElementTree as etree 
    1011 
    1112 
     
    1314def removeInlineNS(csmlstring): 
    1415        #  removeInlineNS: function removes "inline" namespaces and declares them as part of the Dataset element. 
     16        #TODO: This whole thing is hardcoded and needs reviewing. 
    1517         
    16  
     18        #first need to update the ElementTree namespace map: 
     19        etree._namespace_map.update({ 
     20        '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'}) 
     21     
     22        # This is used when parsing a csml document# 
    1723        #remove all 
    1824        csmlstring=csmlstring.replace(' xmlns:csml="http://ndg.nerc.ac.uk/csml"','') 
     
    2127        csmlstring=csmlstring.replace('xsi:schemaLocation="http://ndg.nerc.ac.uk/csml/XMLSchemas/CSMLAppSchema.xsd"','') 
    2228        csmlstring=csmlstring.replace('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','') 
    23          
    24         
     29 
    2530        #remove cmsl: prefixes 
    2631        csmlstring=csmlstring.replace('<csml:','<') 
     
    2934        csmlstring=csmlstring.replace('xmlns:gml="http://www.opengis.net/gml">', 'xmlns:gml="http://www.opengis.net/gml" xmlns:om="http://www.opengis.net/om" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://ndg.nerc.ac.uk/csml/XMLSchemas/CSMLAppSchema.xsd">') 
    3035         
     36        #this is used when creating a new csml document 
     37        csmlstring=csmlstring.replace('ns0', 'gml') 
     38        csmlstring=csmlstring.replace('xmlns:ns1', 'xmlns:xlink') 
     39        csmlstring=csmlstring.replace('ns1:href', 'xlink:href') 
     40        csmlstring=csmlstring.replace('ns1:', '')  #the rest of the ns1s are CSML namespaces... due to the way it has been parsed.         
    3141        return csmlstring 
    3242 
Note: See TracChangeset for help on using the changeset viewer.