Changeset 2304 for TI02-CSML/trunk/csml


Ignore:
Timestamp:
21/03/07 11:44:38 (13 years ago)
Author:
domlowe
Message:

subsettign gridseries to pointseries code

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

Legend:

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

    r2294 r2304  
    5151 
    5252##GridSeriesFeature methods: 
    53 addMethods(csml.parser.GridSeriesFeature,[ops_GridFeature.testmethod,ops_GridSeriesFeature.getDomain,ops_GridSeriesFeature.subsetToGridSeries, ops_GridSeriesFeature.getUom, ops_GridSeriesFeature._subsetGrid,ops_GridSeriesFeature.subsetToProfileSeries, ops_GridSeriesFeature.subsetToProfile]) 
     53addMethods(csml.parser.GridSeriesFeature,[ops_GridFeature.testmethod,ops_GridSeriesFeature.getDomain,ops_GridSeriesFeature.subsetToGridSeries, ops_GridSeriesFeature.getUom, ops_GridSeriesFeature._subsetGrid,ops_GridSeriesFeature.subsetToProfileSeries, ops_GridSeriesFeature.subsetToProfile,ops_GridSeriesFeature.subsetToPointSeries]) 
    5454 
    5555##TrajectoryFeature methods: 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2294 r2304  
    195195    subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToProfile(csmlpath=csmlpath, ncpath=ncpath, **kwargs)     
    196196    return subsettedFeature, pathToSubsetNetCDF 
     197 
     198def subsetToPointSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     199    #Two step process - subset GridSeries to ProfileSeries, then ProfileSeries to PointSeries 
     200    profileSeries, pSfile=self.subsetToProfileSeries(csmlpath=csmlpath, ncpath=ncpath, **kwargs)    
     201    del kwargs['latitude']    #TODO - need to remove excess kwargs based on the domain of the temporary profileSeries feature 
     202    del kwargs['longitude'] 
     203    subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToProfile(csmlpath=csmlpath, ncpath=ncpath, **kwargs)     
     204    return subsettedFeature, pathToSubsetNetCDF 
  • TI02-CSML/trunk/csml/API/ops_ProfileSeriesFeature.py

    r2290 r2304  
    2525                    valList.append(val) 
    2626                self.domain[name]=valList 
     27 
    2728        #handle other axes , eg pressure levels, but ignore location 
    2829        #TODO should use lonAxis at latAxis from CRS rather than latitude, longitude. 
     
    3536                    valList=[] 
    3637                    for val in vals.split():   
    37                         valList.append(val) 
     38                        valList.append(float(val)) 
    3839                    self.domain[name]=valList 
    3940    return self.domain 
     
    6869             
    6970def subsetToProfile(self, csmlpath=None, ncpath=None,**kwargs): 
     71    #perform the subset  
     72    pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs)  
     73     
     74    (time, lat, lon)=(crs.axes[crs.timeAxis],crs.axes[crs.latAxis], crs.axes[crs.lonAxis]) 
     75     
     76    for axis in axisorder: 
     77        if axis not in [time, lat, lon]: 
     78            #this should be the 'profile' axis 
     79            if len(self.domain[axis]) ==1: 
     80                prof=self.domain[axis][0] 
     81            else: 
     82                prof=self.domain[axis] 
     83            
     84            profName=axis 
     85     
     86     
     87    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
     88    #Writing out the CSML feature 
     89    # define domain/coverage  to use in 'value' attribute    
     90     
     91    newdomain=csml.parser.csString(prof) 
     92     
     93    rangeSet=csml.parser.RangeSet() 
     94    #rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     95     
     96    #gridseries coverage 
     97    cvg=csml.parser.ProfileSeriesCoverage() 
     98    cvg.rangeSet=rangeSet 
     99    cvg.profileSeriesDomain=newdomain     
     100     
     101    #parameter, as before subsetting. 
     102    param = self.parameter 
     103         
     104    #create 'location' attribute: 
     105    loc=self.location  #locataion attribute of profile is same as that of parent profileseries 
     106     
     107    #create 'time' attribute 
     108    tName=crs.axes[crs.timeAxis] 
     109    try: 
     110        t=kwargs[tName] 
     111    except: 
     112        t=csml.parser.csString('unknown') 
     113                
     114    #create a stand alone profile feature containing this coverage 
     115    csmlWrap=csml.csmllibs.csmlfeaturewrap.CSMLWrapper() 
     116    subsettedFeature=csmlWrap.createProfileFeature(value=cvg,parameter=param,location=loc, time=t, featureID=self.id,description=self.description) 
     117  
     118    ### write netcdf using NCWriter class (wraps cdms) ###  
     119    nc=csml.csmllibs.netCDFWriter.NCwriter(pathToSubsetNetCDF) 
     120    axislist=[] 
     121    for a in axisorder: 
     122        if self.gridnames.has_key(a): 
     123            axislist.append(self.gridnames[a]) 
     124        else: 
     125            axislist.append(a) 
     126    ords=None   
     127    #need to pass in all dimensions except time as the kwargs.. 
     128    otherdims={} 
     129    otherdims[profName]=prof 
     130    otherdims['latitude']=float(loc.CONTENT.split()[0]) 
     131    otherdims['longitude']=float(loc.CONTENT.split()[1]) 
     132    nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue, **otherdims) 
     133    nc.closeFinishedFile() 
     134    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
     135    return subsettedFeature, pathToSubsetNetCDF 
     136 
     137 
     138def subsetToPointSeries(self, csmlpath=None, ncpath=None,**kwargs): 
    70139    #perform the subset  
    71140    pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs)  
     
    123192    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
    124193    return subsettedFeature, pathToSubsetNetCDF 
     194 
  • TI02-CSML/trunk/csml/csmllibs/csmldataiface.py

    r2290 r2304  
    432432        print kwargs 
    433433         
    434          
    435434        #takes keyword args defining subset eg 
    436435        #subset=getSubsetOfDataForVar(latitude=(0.,10.0), longitude=(90, 100.0)) 
  • TI02-CSML/trunk/csml/csmllibs/netCDFWriter.py

    r2290 r2304  
    5353 
    5454    def genWriteVar(self,varid, ordinates, times, calunits, caltype, axisorder, unitlist, fulldata, fillvalue, **kwargs): 
    55         #**kwargs may contain additional axes not contained in a GridCoordinatesTable - e.g latitude, longitude may be stored in other attribute not in the rectified grid. 
    56          
     55        #**kwargs may contain additional axes not contained in a GridCoordinatesTable - e.g latitude, longitude may be stored in other attribute not in the rectified grid.      
    5756        axesdone=[] 
    5857         
     
    8887         
    8988        if kwargs is not None: 
     89            print 'handling extra'           
    9090            for kw in kwargs: 
    9191                lon,lat=None,None 
    9292                if kw=='longitude': 
    9393                    lon=1 
    94                     name='longitude' 
    9594                elif kw == 'latitude': 
    9695                    lat=1 
    97                     name = 'latitude' 
     96                name = kw 
    9897                for ax in enumerate(axisorder): 
    9998                    if ax[1]==name: 
     
    101100                vals=(kwargs[kw],) 
    102101                self.addAxis(name,vals,isLon=lon,isLat=lat,units=unitlist[position]) 
     102                axesdone.append(name) 
     103             
     104        print 'Axesdone:' 
     105        print axesdone 
     106                 
    103107        self.addVariable(fulldata,varid, axisorder, fillvalue, units=unitlist[-1] ) #to do, units attribute for CF compliance 
    104108         
Note: See TracChangeset for help on using the changeset viewer.