Changeset 9244
- Timestamp:
- Jul 4, 2014, 3:12:11 PM (10 years ago)
- Location:
- trunk/anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/utilities/quantity_setting_functions.py
r9219 r9244 74 74 ################################################################################################### 75 75 76 def composite_quantity_setting_function( fun_poly_pairs, domain):76 def composite_quantity_setting_function(poly_fun_pairs, domain): 77 77 """ 78 78 Make a 'composite function' to set quantities -- applies different functions inside different polygon regions. 79 79 80 fun_poly_pairs = [ [f0, p0], [f1, p1], ...]80 poly_fun_pairs = [ [p0, f0], [p1, f1], ...] 81 81 where fi is a function, or a constant, or the name of a gdal-compatible rasterFile; 82 82 and pi is a polygon, or None, or 'All' (or it can be 'Extent' in the case that fi is a rasterFile name) … … 90 90 91 91 INPUT: 92 fun_poly_pairs = [ [f0, p0], [f1, p1], ...]92 poly_fun_pairs = [ [p0, f0], [p1, f1], ...] 93 93 94 94 where fi(x,y) are functions returning quantity values at … … 123 123 isSet=scipy.zeros(len(x)) # Record if each point has been set 124 124 quantityVal=x*0 # F value 125 lfp=len( fun_poly_pairs)125 lfp=len(poly_fun_pairs) 126 126 if(lfp<=0): 127 127 raise Exception, 'Must have at least 1 fun-poly-pair' … … 135 135 # Test that none of the pi polygons [except perhaps the last] is 'All' 136 136 for i in range(lfp-1): 137 if ( fun_poly_pairs[i][1]=='All'):138 # This is only ok if all the othe fun_poly_pairs are None139 remaining_ fun_poly_pairs_are_None=[ fun_poly_pairs[j][1] is None for j in range(i+1,lfp)]140 if(not all(remaining_ fun_poly_pairs_are_None)):137 if (poly_fun_pairs[i][0]=='All'): 138 # This is only ok if all the othe poly_fun_pairs are None 139 remaining_poly_fun_pairs_are_None=[ poly_fun_pairs[j][0] is None for j in range(i+1,lfp)] 140 if(not all(remaining_poly_fun_pairs_are_None)): 141 141 raise Exception, 'Can only have the last polygon = All' 142 142 143 143 # Apply the fi inside the pi 144 144 for i in range(lfp): 145 fi = fun_poly_pairs[i][0] # The function146 pi = fun_poly_pairs[i][1] # The polygon145 fi = poly_fun_pairs[i][1] # The function 146 pi = poly_fun_pairs[i][0] # The polygon 147 147 148 148 # Quick exit … … 246 246 for i in range(len(Pt_Pol_Data)): 247 247 qFunChanList.append([ 248 make_nearestNeighbour_quantity_function(Pt_Pol_Data[i][1], domain),249 Pt_Pol_Data[i][0]248 Pt_Pol_Data[i][0], 249 make_nearestNeighbour_quantity_function(Pt_Pol_Data[i][1], domain) 250 250 ]) 251 251 252 252 # 253 qFun=composite_quantity_setting_function(qFunChanList+[[ qFun1, 'All']], domain)253 qFun=composite_quantity_setting_function(qFunChanList+[['All', qFun1]], domain) 254 254 255 255 return qFun -
trunk/anuga_core/source/anuga/utilities/test_quantity_setting_functions.py
r9219 r9244 161 161 162 162 # This example uses a constant, and a raster, to set the quantity 163 F=qs.composite_quantity_setting_function([[ -1000., trenchPoly], ['PointData_ElevTest.tif', 'Extent']],\163 F=qs.composite_quantity_setting_function([[trenchPoly, -1000.], ['Extent', 'PointData_ElevTest.tif']],\ 164 164 domain) 165 165 … … 183 183 def f0(x,y): 184 184 return x/10. 185 F=qs.composite_quantity_setting_function([[ f0, trenchPoly], ['PointData_ElevTest.tif', 'Extent']],\185 F=qs.composite_quantity_setting_function([[trenchPoly, f0], ['Extent', 'PointData_ElevTest.tif']],\ 186 186 domain) 187 187 fitted=F(testPts_X,testPts_Y) … … 196 196 197 197 # This example uses 'All' as a polygon 198 F=qs.composite_quantity_setting_function([[ f0, 'All'], ['PointData_ElevTest.tif', None]],\198 F=qs.composite_quantity_setting_function([['All', f0 ], [None, 'PointData_ElevTest.tif']],\ 199 199 domain) 200 200 fitted=F(testPts_X,testPts_Y) … … 206 206 # This example should fail 207 207 try: 208 F=qs.composite_quantity_setting_function([[ f0, 'All'], ['PointData_ElevTest.tif', 'All']],\208 F=qs.composite_quantity_setting_function([['All', f0], ['All', 'PointData_ElevTest.tif']],\ 209 209 domain) 210 210 raise Exception, 'The last command should fail'
Note: See TracChangeset
for help on using the changeset viewer.