Ignore:
Timestamp:
10/06/08 16:23:57 (12 years ago)
Author:
domlowe
Message:

added code to assist in preservation of CF (and other) attributes. Not completely working atm

File:
1 edited

Legend:

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

    r3704 r4017  
    3131    except: 
    3232        return None 
    33      
     33 
     34def _preserveAttributes(self): 
     35    '''  attempts to preserve information from the original file if information exist, such as CF attributes, projection info etc 
     36    returns?? tbd'''     
     37    filename = self.value.rangeSet.valueArray.valueComponent.insertedExtract.components.fileList.fileNames.CONTENT.split(' ')[0] 
     38    di = csml.csmllibs.csmldataiface.DataInterface() 
     39    di = di.getUnknownInterfaceType(filename) 
     40    di.openFile(filename) 
     41    preservedData=csml.csmllibs.csmlpreservation.PreservedData(self.name.CONTENT, di) 
     42    return preservedData 
    3443     
    3544def getDomain(self): 
     
    217226    subsettedFeature=csmlWrap.createGridSeriesFeature(value=cvg,parameter=param,featureID=csml.csmllibs.csmlextra.getRandomID(),name=self.name,description=self.description) 
    218227  
     228    #Attempt to preserve any attributes from original data 
     229    preservedData=self._preserveAttributes() 
     230     
     231  
    219232    ### write netcdf using NCWriter class (wraps cdms) ### 
    220233    nc=csml.csmllibs.netCDFWriter.NCwriter(pathToSubsetNetCDF) 
     
    225238    stdname=param.getStandardName() 
    226239    nc.genWriteVar(self.name.CONTENT,ords, times, caltype, axislist, units, stdname, fulldata, fillvalue) 
     240     
     241    #now add the data we preserved earlier: 
     242    for pv in preservedData.projectionVariables: 
     243        for pvaxis in pv.axes: 
     244            nc.addAxis(pvaxis,pv.axes[pvaxis], pv.attributes) #of form: nc.addAxis(axisname, data)  
     245        nc.addVariable(pv.data, pv.name, pv.axes.keys(), -9999) #TODO get fill value, get missing attributes 
     246     
    227247    nc.closeFinishedFile() 
    228248    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
Note: See TracChangeset for help on using the changeset viewer.