Changeset 9245


Ignore:
Timestamp:
Jul 4, 2014, 5:01:13 PM (10 years ago)
Author:
davies
Message:

composite_quantity_setting_function can now use a 3 column array to make an input function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/utilities/quantity_setting_functions.py

    r9244 r9245  
    9292              poly_fun_pairs = [ [p0, f0], [p1, f1], ...]
    9393
    94                   where fi(x,y) are functions returning quantity values at
    95                   points, or constants in which case points in the polygon are set to that
    96                   value, or (string) rasterFile names which can be passed to quantityRasterFun to make a function
    97 
    98                   and pi are polygons where we want to use fi inside
     94                  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
    9999               
     100
     101                  pi are polygons where we want to use fi inside
     102                  SPECIAL pi CASES:
    100103                  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)
    104106                  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
    107108                    extent of the raster file is used to define the polygon
    108109
     
    114115    """
    115116    import os
    116     import scipy
     117    import numpy
    117118    from matplotlib import path
    118119
     
    121122            This is the function we return
    122123        """
    123         isSet=scipy.zeros(len(x)) # Record if each point has been set
     124        isSet=numpy.zeros(len(x)) # Record if each point has been set
    124125        quantityVal=x*0 # F value
    125126        lfp=len(poly_fun_pairs)
     
    131132        xll=domain.geo_reference.xllcorner
    132133        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()
    134135
    135136        # Test that none of the pi polygons [except perhaps the last] is 'All'
     
    159160                    import anuga.utilities.spatialInputUtil as su
    160161                    newpi=su.getRasterExtent(fi,asPolygon=True)
    161                     pi_path=path.Path(scipy.array(newpi))
     162                    pi_path=path.Path(numpy.array(newpi))
    162163                else:
    163164                    # 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))
    165166
    166167                fInside=xy_array_trans[:,0]*0.
     
    184185                    newfi = quantityRasterFun(domain, fi)
    185186                    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
    186195               
    187196                isSet[fInds]=1
Note: See TracChangeset for help on using the changeset viewer.