- Timestamp:
- 13/02/07 13:29:33 (14 years ago)
- Location:
- TI02-CSML/trunk/csml
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/API/csmlutils.py
r2149 r2155 28 28 kwargs[key]=(kwargs[key][0],kwargs[key][1]+360) 29 29 return kwargs 30 31 32 33 def nudgeSingleValuesToAxisValues(value, axisValues): 34 """ 35 Takes a value and checks if it is in the axisValues array. If not, it nudges the 36 value to the nearest neighbour in axis. It returns the new value twice along 37 with a message describing the change. 38 """ 39 #import cdms 40 rtMessage="" 41 newValue=None 42 43 if value in axisValues: 44 newValue=value 45 else: 46 sortedAxis=[] 47 for i in axisValues: 48 sortedAxis.append(i) 49 sortedAxis.sort() 50 51 if value<sortedAxis[0]: 52 newValue=sortedAxis[0] 53 elif value>sortedAxis[-1]: 54 newValue=sortedAxis[-1] 55 else: 56 for i in range(len(axisValues)): 57 if i<(len(axisValues)-1): 58 (current, nextone)=(axisValues[i], axisValues[i+1]) 59 if current>nextone: 60 tempc=nextone 61 nextone=current 62 current=tempc 63 64 if value>current and value<nextone: 65 lowergap=value-current 66 uppergap=nextone-value 67 if uppergap==lowergap: 68 newValue=nextone 69 elif uppergap>lowergap: 70 newValue=current 71 elif uppergap<lowergap: 72 newValue=nextone 73 break 74 if newValue==None: 75 rtMessage="%s axis selected value '%s' nudged to nearest value in real axis '%s' ;" % (axisType, value, newValue) 76 print rtMessage 77 78 return (newValue) -
TI02-CSML/trunk/csml/API/genSubset.py
r2149 r2155 4 4 import csml 5 5 import csmlutils 6 6 import sys 7 8 def checkNeighbours(domain, **kwargs): 9 #for any non-range requests, get nearest neighbour 10 #e.g if 'latitude': (11) requested, latitude=12 may be the nearest value 11 for key in kwargs: 12 #handle single values 13 if type(kwargs[key]) is not tuple: 14 nearestNeighbour=csml.API.csmlutils.nudgeSingleValuesToAxisValues(kwargs[key],domain[key]) 15 if nearestNeighbour is not None: 16 kwargs[key]=nearestNeighbour 17 else: 18 #handle ranges 19 tmpkey=[] 20 for val in kwargs[key]: 21 nearestNeighbour=csml.API.csmlutils.nudgeSingleValuesToAxisValues(val, domain[key]) 22 if nearestNeighbour is not None: 23 tmpkey.append(nearestNeighbour) 24 kwargs[key]=tuple(tmpkey) 25 return kwargs 7 26 8 27 def subsetDomain(timeaxis,times, domain,**kwargs): … … 15 34 totalArraySize=1 16 35 for key in domain.keys(): 36 print key 17 37 straxisValues='' 18 38 if key in kwargs: … … 21 41 arraySize=len(strTimes.split()) 22 42 elif type(kwargs[key]) is not tuple: 23 #only one value not a range .43 #only one value not a range 24 44 straxisValues=str(kwargs[key]) 25 45 elif kwargs[key][0] < kwargs[key][1]: -
TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py
r2144 r2155 34 34 return self.domain 35 35 36 36 37 37 38 def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 39 38 40 #set self.domain: 39 self.getDomain() 41 self.getDomain() 42 43 #if request doesn't match domain points find nearest neighbours 44 kwargs=csml.API.genSubset.checkNeighbours(self.domain, **kwargs) 40 45 41 46 #get the CRS from a the catalogue -
TI02-CSML/trunk/csml/DDC/obs/clim10subset.py
r2149 r2155 39 39 subsetDictionary={} 40 40 subsetDictionary['time']=('1985-1-15T0:0:0.0') 41 subsetDictionary['latitude']=( 88.75)42 subsetDictionary['longitude']=( 4.25)41 subsetDictionary['latitude']=(12,88.85) 42 subsetDictionary['longitude']=(53.66, 55) 43 43 #request subsetted data from features (can set paths here) and add to container 44 44 #subset a feature
Note: See TracChangeset
for help on using the changeset viewer.