Changeset 4033


Ignore:
Timestamp:
30/06/08 11:51:21 (11 years ago)
Author:
domlowe
Message:

Global attribtues now preserved except when they are data dependent CF attributes (which need recalculating). So far this is only implemented for gridseries to gridseries

Location:
TI02-CSML/trunk/csml
Files:
4 edited

Legend:

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

    r4030 r4033  
    265265        else: 
    266266            nc.addVariable(pv.data, pv.name, pv.axes.keys(),**pv.attributes) 
    267  
     267     
     268    if preservedData.globalAttributes !={}: 
     269        nc.addGlobalAttributes(preservedData.globalAttributes) 
    268270    nc.closeFinishedFile() 
    269271    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
  • TI02-CSML/trunk/csml/csmllibs/csmldataiface.py

    r4019 r4033  
    608608        return highlims 
    609609         
     610    def getGlobalAttributes(self): 
     611        '''return dictionary of 'global' attributes''' 
     612        atts= self.file.attributes.keys() 
     613        globalatts={} 
     614        for i in range(0,len(atts)): 
     615            globalatts[atts[i]]=self.file.attributes[atts[i]] 
     616        return globalatts 
     617         
    610618     
    611619class cdmlInterface(cdunifInterface): 
  • TI02-CSML/trunk/csml/csmllibs/csmlpreservation.py

    r4030 r4033  
    22 
    33''' csmlpreservation.py  - collection of classes used to preserve the content of the original data files - e.g. for preserving CF attributes that don't have a natural place in CSML''' 
     4 
     5 
     6#DATA_DEPENDENT_CF_ATTRIBUTES - CF global attributes that may not be consistent with subsetting data, and hence should not be preserved (although they may be recalculated later) 
     7DATA_DEPENDENT_CF_ATTRIBUTES=[ 
     8'geospatial_lat_min',  
     9'geospatial_lon_min',  
     10'geospatial_lat_max', 
     11'geospatial_lon_max', 
     12'geospatial_vertical_min', 
     13'geospatial_vertical_max', 
     14'time_coverage_start', 
     15'time_coverage_end', 
     16'time_coverage_duration'] 
     17 
    418 
    519class PreservedVariable(object): 
     
    2438        self.keyVariable=self._buildKeyVariable() 
    2539        self.projectionVariables=self._buildProjectionVariables() 
     40        self.globalAttributes=self._buildGlobalAttributes() 
    2641       
    2742    def _buildAttributeDict(self, attribs):       
     
    7893         
    7994         
    80          
     95    def _buildGlobalAttributes(self): 
     96         #need to get globalAttributes from data interface 
     97        globalatts={} 
     98        tempatts=self.di.getGlobalAttributes() 
     99        #only add attributes that aren't dependent on coverage domain 
     100        for key in tempatts.keys(): 
     101            if key not in DATA_DEPENDENT_CF_ATTRIBUTES: 
     102                globalatts[key]=tempatts[key] 
     103        return globalatts 
    81104         
    82105def getDomainSlice(subsettedDomain, originalDomain): 
  • TI02-CSML/trunk/csml/csmllibs/netCDFWriter.py

    r4019 r4033  
    1010        #initiates a new NetCDF file 
    1111        self.nc=cdms.open(fileName,'w') 
    12  
    13     def setGlobalAttributes(self, **kwargs): 
    14         #sets global attributes 
    15         pass 
    1612     
    1713    def addAxis(self,axisName, data,isLon=None,isLat=None,isTime=None,**kwargs): 
     
    5046                return axis 
    5147     
    52      
     48    def addGlobalAttributes(self, globalattDict): 
     49        ''' 'given a dictionary, add the key value pairs to the netcdf file as global attributes''' 
     50        for key in globalattDict.keys(): 
     51             setattr(self.nc, key, globalattDict[key]) 
    5352     
    5453    def addTimeVariable(self,timeval):   
Note: See TracChangeset for help on using the changeset viewer.