Changeset 2206
- Timestamp:
- 26/02/07 14:03:46 (14 years ago)
- Location:
- TI02-CSML/trunk/csml
- Files:
-
- 1 deleted
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/API/__init__.py
r2159 r2206 51 51 52 52 ##GridSeriesFeature methods: 53 addMethods(csml.parser.GridSeriesFeature,[ops_GridFeature.testmethod,ops_GridSeriesFeature.getDomain,ops_GridSeriesFeature.subsetToGridSeries, ops_GridSeriesFeature.getUom ])53 addMethods(csml.parser.GridSeriesFeature,[ops_GridFeature.testmethod,ops_GridSeriesFeature.getDomain,ops_GridSeriesFeature.subsetToGridSeries, ops_GridSeriesFeature.getUom, ops_GridSeriesFeature._subsetGrid]) 54 54 55 55 ##TrajectoryFeature methods: -
TI02-CSML/trunk/csml/API/csmlutils.py
r2156 r2206 1 1 '''csml utils contains useful utility functions''' 2 2 import csml 3 3 4 4 def listify(item): … … 40 40 rtMessage="" 41 41 newValue=None 42 43 def __fixTimes(value, axisValues): 44 newValue = csml.csmllibs.csmltime.getTimeAsValue(value) 45 newAxisValues=[] 46 for ax in axisValues: 47 newAxisValues.append(csml.csmllibs.csmltime.getTimeAsValue(ax)) 48 return newValue, newAxisValues 42 49 43 50 if value in axisValues: 44 51 newValue=value 45 else: 52 else: 53 if str(value).find('T') != -1: 54 value, axisValues=__fixTimes(value,axisValues) 46 55 sortedAxis=[] 47 56 for i in axisValues: 48 57 sortedAxis.append(i) 49 sortedAxis.sort() 50 58 sortedAxis.sort() 51 59 if value<sortedAxis[0]: 52 60 newValue=sortedAxis[0] … … 61 69 nextone=current 62 70 current=tempc 63 64 71 if value>current and value<nextone: 65 72 lowergap=value-current … … 74 81 if newValue==None: 75 82 rtMessage="%s axis selected value '%s' nudged to nearest value in real axis '%s' ;" % (axisType, value, newValue) 76 print rtMessage 77 83 # print rtMessage 84 if type(newValue) is float: 85 if len(str(int(newValue))) ==14: # it's a time 86 print newValue 87 newValue=csml.csmllibs.csmltime.convertValueToCSML(newValue) 78 88 return (newValue) -
TI02-CSML/trunk/csml/API/genSubset.py
r2205 r2206 8 8 9 9 def checkNeighbours(domain, gridnames, **kwargs): 10 print domain11 10 #for any non-range requests, get nearest neighbour 12 11 #e.g if 'latitude': (11) requested, latitude=12 may be the nearest value … … 106 105 times=timeSelection 107 106 108 109 #times=timeSelection110 111 print times112 print len(times)113 107 if len(times)==0: 114 108 #no time specified, select all. … … 176 170 if filePos in filesFetched: 177 171 continue #already got data from this file, try next time 178 print selection179 172 data, fillvalue, axisorder, units=comp.getData(fileposition=filePos, **selection) 180 173 files.append(comp.fileList.fileNames.CONTENT[filePos]) #TODO, get the right file name … … 202 195 crs=cat.getCRS(feature.value.gridSeriesDomain.srsName) 203 196 timeName=crs.axes[crs.timeAxis] 204 #set the reference system for the time axis 197 #Find the original time name (timeAxis) for the file. 198 for gridOrd in feature.value.gridSeriesDomain.coordTransformTable.gridOrdinates: 199 if gridOrd.coordAxisLabel.CONTENT==timeName: 200 timeAxis = gridOrd.gridAxesSpanned.CONTENT #only works for regular grids atm 201 break 202 #set the reference system for the time axis 205 203 calunits, caltype=_setCalendar(feature, timeName) 206 204 207 205 #selection by time - get explcit time values, not just a range mint, maxt 206 208 207 try: 209 timeSelection=kwargs[time Name]208 timeSelection=kwargs[timeAxis] 210 209 except KeyError: 211 210 timeSelection=[] 211 212 212 times=_getTimes(timeSelection, timeName,domain) 213 213 214 214 215 return pathToSubsetNetCDF, kwargs, time Name, calunits, caltype, times215 return pathToSubsetNetCDF, kwargs, timeAxis,timeName, calunits, caltype, times -
TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py
r2205 r2206 44 44 uom =None 45 45 return uom 46 47 48 def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 49 46 47 def _subsetGrid(self, csmlpath=None, ncpath=None,**kwargs): 48 '''this takes a selection from a gridseries object (be it a profile, a grid, whatever, it is still just a selection''' 49 50 50 #set self.domain: 51 51 self.getDomain() … … 53 53 #if request doesn't match domain points find nearest neighbours 54 54 kwargs=csml.API.genSubset.checkNeighbours(self.domain, self.gridnames, **kwargs) 55 56 55 #get the CRS from a the catalogue 57 56 cat=csml.csmllibs.csmlcrs.CRSCatalogue() … … 59 58 60 59 #non-feature specific setup code, mainly handles the time dimension/calendar 61 pathToSubsetNetCDF, kwargs, time Name,calunits, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs)60 pathToSubsetNetCDF, kwargs, timeAxis, timeName,calunits, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 62 61 63 #Find the original time name (timeAxis) for the file.64 for gridOrd in self.value.gridSeriesDomain.coordTransformTable.gridOrdinates:65 if gridOrd.coordAxisLabel.CONTENT==timeName:66 timeAxis = gridOrd.gridAxesSpanned.CONTENT #only works for regular grids atm67 else:68 print 'crs not supported'69 70 62 ##Get names of variables in file and relate them to the subset selection 71 63 selection={} … … 76 68 allValues=tuple(self.domain[gridOrd.coordAxisLabel.CONTENT]) 77 69 strTimes, axisorder, units, fulldata, fillvalue =csml.API.genSubset.getTheData(self, selection, times, timeName) 70 return pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs 78 71 72 def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 73 #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 74 pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs) 79 75 80 76 #Okay, got the data now. Need to write CSML feature and NetCDF files. -
TI02-CSML/trunk/csml/csmllibs/csmltime.py
r2196 r2206 66 66 timeok = 1 67 67 return timeok 68 69 def getTimeAsValue(time): 70 year=int(time.split('-')[0]) 71 month=int(time.split('-')[1]) 72 day=int(time.split('-')[2].split('T')[0]) 73 hour=int(time.split('-')[2].split('T')[1].split(':')[0]) 74 minute=int(time.split('-')[2].split('T')[1].split(':')[1]) 75 second=float(time.split('-')[2].split('T')[1].split(':')[2]) 76 return (10000000000*year+100000000*month + (1000000 * day) + (10000*hour) + (100*minute) + second) 77 78 def convertValueToCSML(t): 79 #this may need to be more robust 80 csmlt='%s-%s-%sT%s:%s:%s.%s'%(int(t/10000000000),str(int(t/100000000))[-2:],str(int(t/1000000))[-2:] 81 ,str(int(t/10000))[-2:],str(int(t/100))[-2:],str(int(t))[-2:],0) 82 return csmlt 83 68 84 69 85 def getCDtime(time): -
TI02-CSML/trunk/csml/csmlprofilescan.py
r2191 r2206 195 195 196 196 if __name__=='__main__': 197 #print 'profiling..'197 print 'profiling..' 198 198 #profile.run('main()') 199 main() 200 201 202 203 204 205 206 207 208 209 210 211 212 213 199 profile.run('import csml') 200 subdir='/home/dom/Desktop/SVN/trunk/csml/chilbolton/' 201 f=[] 202 for item in os.listdir(subdir): 203 name=os.path.join(subdir,item) 204 if os.path.isfile(name): 205 if name[-3:]=='.nc': 206 f.append(name) 207 profile.run("csml.csmllibs.csmltime.getFileTimeList(f,'time')") 208 209 210 #main() 211 212 213 214 215 216 217 218 219 220 221 222 223 224 -
TI02-CSML/trunk/csml/csmlscan.py
r2191 r2206 194 194 195 195 196 if __name__=='__main__': 197 #print 'profiling..' 198 #profile.run('main()') 196 if __name__=='__main__': 199 197 main() 200 198 -
TI02-CSML/trunk/csml/testfiles/apicalls.py
r2205 r2206 38 38 #define a selection (based on the domain) 39 39 subsetDictionary={} 40 subsetDictionary['t']=('2794-12-1T0:0:0.0', '2813-12-1T0:0:0.0') 41 subsetDictionary['latitude']=(-90,90) 40 subsetDictionary['t']=('2794-12-1T0:0:0.0','2795-12-1T0:0:0.0') 41 #subsetDictionary['t']=() 42 subsetDictionary['latitude']=(-90,60) 42 43 subsetDictionary['longitude']=(-31.265,30.258) 43 44 #request subsetted data from features (can set paths here) and add to container
Note: See TracChangeset
for help on using the changeset viewer.