Changeset 2598
- Timestamp:
- 18/06/07 14:07:51 (14 years ago)
- Location:
- TI02-CSML/trunk/csml/API
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/API/csmlutils.py
r2597 r2598 40 40 return kwargs 41 41 42 43 44 def nudgeSingleValuesToAxisValues(value, axisValues): 42 def nudgeSingleValuesToAxisValues(value, axisValues, minBound=None, maxBound=None): 45 43 """ 46 44 Takes a value and checks if it is in the axisValues array. If not, it nudges the 47 45 value to the nearest neighbour in axis. It returns the new value twice along 48 46 with a message describing the change. 47 48 minBound and maxBound added as options. 49 If a value is outside of minBound or maxBound it is nudged so that it is within. 50 51 TODO - rewrite this so it is legible! 52 49 53 """ 50 54 55 bounds=False 56 reverseBounds=False 57 58 #determine if bounds have been provided and if they are of the form (-30,30) or (330, 30) 59 if minBound!=None: 60 if maxBound!=None: 61 bounds =True 62 if minBound > maxBound: 63 reverseBounds = True 51 64 rtMessage="" 52 65 newValue=None 53 54 66 def __fixTimes(value, axisValues): 55 67 newValue = csml.csmllibs.csmltime.getTimeAsValue(value) … … 63 75 else: 64 76 if str(value).find('T') != -1: 77 minBound,minBound=None,None, 78 bounds,reverseBounds=False,False 65 79 value, axisValues=__fixTimes(value,axisValues) 66 sortedAxis=[] 67 for i in axisValues: 68 sortedAxis.append(i) 69 sortedAxis.sort() 80 sortedAxis=[] 81 if bounds == True: 82 if reverseBounds!=True: 83 for i in axisValues: 84 if i >= minBound: 85 if i <= maxBound: 86 sortedAxis.append(i) 87 88 else: 89 for i in axisValues: 90 if i >= minBound: 91 sortedAxis.append(i) 92 elif i >= maxBound: 93 sortedAxis.append(i) 94 else: 95 for i in axisValues: 96 sortedAxis.append(i) 97 sortedAxis.sort() 98 70 99 if value<sortedAxis[0]: 71 newValue=sortedAxis[0] 100 if sortedAxis[0] < maxBound: 101 newValue=sortedAxis[0] 102 else: 103 newValue=sortedAxis[-1] 72 104 elif value>sortedAxis[-1]: 73 105 newValue=sortedAxis[-1] 74 106 else: 75 107 for i in range(len(axisValues)): 76 108 if i<(len(axisValues)-1): … … 97 129 if len(str(int(newValue))) ==14: # it's a time 98 130 newValue=csml.csmllibs.csmltime.convertValueToCSML(newValue) 99 return (newValue) 131 return (newValue) 132 -
TI02-CSML/trunk/csml/API/genSubset.py
r2597 r2598 22 22 kwargs[key]=nearestNeighbour 23 23 else: 24 #handle ranges 25 tmpkey=[] 26 for val in kwargs[key]: 27 nearestNeighbour=csml.API.csmlutils.nudgeSingleValuesToAxisValues(val, domain[key]) 28 if nearestNeighbour is not None: 29 tmpkey.append(nearestNeighbour) 30 kwargs[key]=tuple(tmpkey) 24 ##handle ranges 25 #tmpkey=[] 26 ##this finds the nearest neighbour without overstepping 0 (for longitude) 27 #if kwargs[key][0] > kwargs[key][1]: 28 #nearestNeighbour=csml.API.csmlutils.nudgeSingleValuesToAxisValues(val, domain[key], minBound=kwargs[key][0], maxBound=0) 29 #if nearestNeighbour is not None: 30 #tmpkey.append(nearestNeighbour) 31 #nearestNeighbour=csml.API.csmlutils.nudgeSingleValuesToAxisValues(val, domain[key], minBound=0, maxBound=kwargs[key][1]) 32 #if nearestNeighbour is not None: 33 #tmpkey.append(nearestNeighbour) 34 35 #else: 36 tmpkey=[] 37 for val in kwargs[key]: 38 nearestNeighbour=csml.API.csmlutils.nudgeSingleValuesToAxisValues(val, domain[key], minBound=kwargs[key][0], maxBound=kwargs[key][1]) 39 if nearestNeighbour is not None: 40 tmpkey.append(nearestNeighbour) 41 kwargs[key]=tuple(tmpkey) 31 42 return kwargs 32 43
Note: See TracChangeset
for help on using the changeset viewer.