Changeset 4030


Ignore:
Timestamp:
27/06/08 10:19:12 (11 years ago)
Author:
domlowe
Message:

added code to preserve CF projection variables and subset them accordingly

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

Legend:

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

    r4019 r4030  
    252252     
    253253    #now add any other data we preserved earlier, e.g. projection variables: 
     254    #TODO: this should be a separate method 
     255    sliceinfo=csml.csmllibs.csmlpreservation.getDomainSlice(domainSubset, self.domain) 
    254256    for pv in preservedData.projectionVariables: 
     257        pvslice=[] 
    255258        for pvaxis in pv.axes: 
    256             nc.addAxis(pvaxis,pv.axes[pvaxis], pv.attributes) #of form: nc.addAxis(axisname, data)  
    257         print pv.data 
    258         #TODO slice the extra variables 
    259         #nc.addVariable(pv.data, pv.name, pv.axes.keys(),**pv.attributes)    
     259            nc.addAxis(pvaxis,pv.axes[pvaxis][sliceinfo[pvaxis][0]:sliceinfo[pvaxis][1]], pv.attributes) #of form: nc.addAxis(axisname, data)  
     260            pvslice.append(tuple([sliceinfo[pvaxis][0],sliceinfo[pvaxis][1]])) 
     261 
     262        #add the sliced (or not) variables. 
     263        if len(pvslice) > 0: 
     264            nc.addVariable(pv.data(*pvslice), pv.name, pv.axes.keys(),**pv.attributes) 
     265        else: 
     266            nc.addVariable(pv.data, pv.name, pv.axes.keys(),**pv.attributes) 
     267 
    260268    nc.closeFinishedFile() 
    261269    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
  • TI02-CSML/trunk/csml/csmllibs/csmlpreservation.py

    r4019 r4030  
    8080         
    8181         
     82def getDomainSlice(subsettedDomain, originalDomain): 
     83    ''' Utility function to convert the subsettedDomain to a set of slice tuples based on its position within the original domain. This information is needed to retrospectively subset the additional projection variables''' 
     84    sliceinfo={}    
     85    try: 
     86        for key in subsettedDomain: 
     87            firstvalue=eval(subsettedDomain[key].split(',')[0]) 
     88            lastvalue=eval(subsettedDomain[key].split(',')[-1:][0]) 
     89            vals= originalDomain[key].tolist() 
     90            sliceinfo[key]=(vals.index(firstvalue), vals.index(lastvalue)) 
     91    except: 
     92            pass # skip key 
     93    return sliceinfo 
    8294         
    8395         
    8496         
    85          
Note: See TracChangeset for help on using the changeset viewer.