Changeset 9244


Ignore:
Timestamp:
Jul 4, 2014, 3:12:11 PM (10 years ago)
Author:
davies
Message:

Changing interface to composite_quantity_setting_function for consistency with other functions

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  
    7474###################################################################################################
    7575
    76 def composite_quantity_setting_function(fun_poly_pairs, domain):
     76def composite_quantity_setting_function(poly_fun_pairs, domain):
    7777    """
    7878        Make a 'composite function' to set quantities -- applies different functions inside different polygon regions.
    7979             
    80         fun_poly_pairs = [ [f0, p0], [f1, p1], ...]
     80        poly_fun_pairs = [ [p0, f0], [p1, f1], ...]
    8181                    where fi is a function, or a constant, or the name of a gdal-compatible rasterFile;
    8282                    and pi is a polygon, or None, or 'All' (or it can be 'Extent' in the case that fi is a rasterFile name)
     
    9090
    9191        INPUT:
    92               fun_poly_pairs = [ [f0, p0], [f1, p1], ...]
     92              poly_fun_pairs = [ [p0, f0], [p1, f1], ...]
    9393
    9494                  where fi(x,y) are functions returning quantity values at
     
    123123        isSet=scipy.zeros(len(x)) # Record if each point has been set
    124124        quantityVal=x*0 # F value
    125         lfp=len(fun_poly_pairs)
     125        lfp=len(poly_fun_pairs)
    126126        if(lfp<=0):
    127127            raise Exception, 'Must have at least 1 fun-poly-pair'
     
    135135        # Test that none of the pi polygons [except perhaps the last] is 'All'
    136136        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 None
    139                 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)):
    141141                    raise Exception, 'Can only have the last polygon = All'
    142142
    143143        # Apply the fi inside the pi
    144144        for i in range(lfp):
    145             fi = fun_poly_pairs[i][0] # The function
    146             pi = fun_poly_pairs[i][1] # The polygon
     145            fi = poly_fun_pairs[i][1] # The function
     146            pi = poly_fun_pairs[i][0] # The polygon
    147147
    148148            # Quick exit
     
    246246    for i in range(len(Pt_Pol_Data)):
    247247        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)
    250250                              ])
    251251
    252252    #
    253     qFun=composite_quantity_setting_function(qFunChanList+[[qFun1, 'All']], domain)
     253    qFun=composite_quantity_setting_function(qFunChanList+[['All', qFun1]], domain)
    254254
    255255    return qFun
  • trunk/anuga_core/source/anuga/utilities/test_quantity_setting_functions.py

    r9219 r9244  
    161161 
    162162        # 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']],\
    164164                                                domain)
    165165
     
    183183        def f0(x,y):
    184184            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']],\
    186186                                                domain)
    187187        fitted=F(testPts_X,testPts_Y)
     
    196196
    197197        # 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']],\
    199199                                                domain)
    200200        fitted=F(testPts_X,testPts_Y)
     
    206206        # This example should fail
    207207        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']],\
    209209                                                    domain)
    210210            raise Exception, 'The last command should fail'
Note: See TracChangeset for help on using the changeset viewer.