Changeset 9245
- Timestamp:
- Jul 4, 2014, 5:01:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/utilities/quantity_setting_functions.py
r9244 r9245 92 92 poly_fun_pairs = [ [p0, f0], [p1, f1], ...] 93 93 94 where fi(x,y) are functions returning quantity values at95 points, or constants in which case points in the polygon are set to that96 value, or (string) rasterFile names which can be passed to quantityRasterFun to make a function97 98 and pi are polygons where we want to use fi inside94 where fi(x,y) is a function returning quantity values at points, or any of the special cases below 95 SPECIAL fi CASES: 96 fi = a constant in which case points in the polygon are set to that value, 97 fi = a string rasterFile name which can be passed to quantityRasterFun to make a function, 98 fi = a numpy array with 3 columns (x,y,Value) in which case nearest-neighbour interpolation is used on the points 99 99 100 101 pi are polygons where we want to use fi inside 102 SPECIAL pi CASES: 100 103 If any pi = 'All', then we assume that ALL unset points are set 101 using the function. This CAN ONLY happen in the last [fi,pi] pair where pi is 102 not None (since fi will be applied to all remaining points -- so anything else is probably an input mistake) 103 104 using the function. This CAN ONLY happen in the last [fi,pi] pair where pi is 105 not None (since fi will be applied to all remaining points -- so anything else is probably an input mistake) 104 106 If any pi = None, then that [fi,pi] pair is skipped 105 106 if pi='Extent' and fi is the name of a raster file, then the 107 If pi = 'Extent' and fi is the name of a raster file, then the 107 108 extent of the raster file is used to define the polygon 108 109 … … 114 115 """ 115 116 import os 116 import scipy117 import numpy 117 118 from matplotlib import path 118 119 … … 121 122 This is the function we return 122 123 """ 123 isSet= scipy.zeros(len(x)) # Record if each point has been set124 isSet=numpy.zeros(len(x)) # Record if each point has been set 124 125 quantityVal=x*0 # F value 125 126 lfp=len(poly_fun_pairs) … … 131 132 xll=domain.geo_reference.xllcorner 132 133 yll=domain.geo_reference.yllcorner 133 xy_array_trans= scipy.vstack([x+xll,y+yll]).transpose()134 xy_array_trans=numpy.vstack([x+xll,y+yll]).transpose() 134 135 135 136 # Test that none of the pi polygons [except perhaps the last] is 'All' … … 159 160 import anuga.utilities.spatialInputUtil as su 160 161 newpi=su.getRasterExtent(fi,asPolygon=True) 161 pi_path=path.Path( scipy.array(newpi))162 pi_path=path.Path(numpy.array(newpi)) 162 163 else: 163 164 # Try matplotlib -- make the path a matplotlib path object 164 pi_path=path.Path( scipy.array(pi))165 pi_path=path.Path(numpy.array(pi)) 165 166 166 167 fInside=xy_array_trans[:,0]*0. … … 184 185 newfi = quantityRasterFun(domain, fi) 185 186 quantityVal[fInds] = newfi(x[fInds], y[fInds]) 187 elif(type(fi) is numpy.ndarray): 188 if fi.shape[1] is not 3: 189 raise Exception, 'Array should have 3 columns -- x,y,value' 190 newfi = make_nearestNeighbour_quantity_function(fi, domain) 191 quantityVal[fInds] = newfi(x[fInds], y[fInds]) 192 else: 193 msg='Cannot make function from type '+str(type(fi)) 194 raise Exception, msg 186 195 187 196 isSet[fInds]=1
Note: See TracChangeset
for help on using the changeset viewer.