Changeset 2304 for TI02-CSML/trunk
- Timestamp:
- 21/03/07 11:44:38 (14 years ago)
- Location:
- TI02-CSML/trunk/csml
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/API/__init__.py
r2294 r2304 51 51 52 52 ##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 ])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,ops_GridSeriesFeature.subsetToPointSeries]) 54 54 55 55 ##TrajectoryFeature methods: -
TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py
r2294 r2304 195 195 subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToProfile(csmlpath=csmlpath, ncpath=ncpath, **kwargs) 196 196 return subsettedFeature, pathToSubsetNetCDF 197 198 def 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 25 25 valList.append(val) 26 26 self.domain[name]=valList 27 27 28 #handle other axes , eg pressure levels, but ignore location 28 29 #TODO should use lonAxis at latAxis from CRS rather than latitude, longitude. … … 35 36 valList=[] 36 37 for val in vals.split(): 37 valList.append( val)38 valList.append(float(val)) 38 39 self.domain[name]=valList 39 40 return self.domain … … 68 69 69 70 def 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 138 def subsetToPointSeries(self, csmlpath=None, ncpath=None,**kwargs): 70 139 #perform the subset 71 140 pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs) … … 123 192 print 'NetCDF file written to %s'%pathToSubsetNetCDF 124 193 return subsettedFeature, pathToSubsetNetCDF 194 -
TI02-CSML/trunk/csml/csmllibs/csmldataiface.py
r2290 r2304 432 432 print kwargs 433 433 434 435 434 #takes keyword args defining subset eg 436 435 #subset=getSubsetOfDataForVar(latitude=(0.,10.0), longitude=(90, 100.0)) -
TI02-CSML/trunk/csml/csmllibs/netCDFWriter.py
r2290 r2304 53 53 54 54 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. 57 56 axesdone=[] 58 57 … … 88 87 89 88 if kwargs is not None: 89 print 'handling extra' 90 90 for kw in kwargs: 91 91 lon,lat=None,None 92 92 if kw=='longitude': 93 93 lon=1 94 name='longitude'95 94 elif kw == 'latitude': 96 95 lat=1 97 name = 'latitude'96 name = kw 98 97 for ax in enumerate(axisorder): 99 98 if ax[1]==name: … … 101 100 vals=(kwargs[kw],) 102 101 self.addAxis(name,vals,isLon=lon,isLat=lat,units=unitlist[position]) 102 axesdone.append(name) 103 104 print 'Axesdone:' 105 print axesdone 106 103 107 self.addVariable(fulldata,varid, axisorder, fillvalue, units=unitlist[-1] ) #to do, units attribute for CF compliance 104 108
Note: See TracChangeset
for help on using the changeset viewer.