Ignore:
Timestamp:
Feb 18, 2015, 10:20:22 AM (10 years ago)
Author:
davies
Message:

Bugfix in new nan_interpolation_region functionality of composite_quantity_setting_functions

Location:
trunk/anuga_core/anuga/utilities
Files:
2 edited

Legend:

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

    r9672 r9679  
    263263    from anuga.geometry.polygon import inside_polygon
    264264
     265
    265266    # Check that clip_range has the right form
    266267    if clip_range is not None:
     
    494495                        points_to_reinterpolate = numpy.hstack(
    495496                            [points_to_reinterpolate,
    496                              points_in_nan_pi])
     497                             possible_points_to_reint[points_in_nan_pi]])
     498
    497499
    498500            if verbose:
  • trunk/anuga_core/anuga/utilities/tests/test_quantity_setting_functions.py

    r9513 r9679  
    304304        # value it would have had anyway
    305305        testPts_X = numpy.array([50.,50.00, 50., 50., 97., 51., 3.])
    306         testPts_Y = numpy.array([1.,    2., 3. , 4  , 20., 30., 60.])
     306        testPts_Y = numpy.array([1.,    2., 3. , 4  , 20., 50., 60.])
     307        fitted = F(testPts_X,testPts_Y)
     308       
     309        # We should have no nan values
     310        assert(sum(fitted!=fitted) == 0)
     311
     312        # Now the fitted value in the trench should be determined by f0 because
     313        # the re-interpolation of nan values was designed to ensure it
     314        assert(numpy.allclose(fitted[0],50./10.))
     315
     316        ###########################################################################
     317        # This example features a function with some nan return values, and uses
     318        # the nan_interpolation_region_polygon to try to fix it
     319
     320        # Make a polygon-point pair which we use to set elevation in a 'channel'
     321        innerTrenchPoly = [[minX+45., minY+45.], [minX+45., minY+55.],
     322            [minX+55., minY+55.], [minX+55., minY+45.]]
     323
     324        def f_nan(x,y):
     325            output = x*0 + numpy.nan
     326            return(output)
     327
     328        F = qs.composite_quantity_setting_function(
     329            [[innerTrenchPoly, f_nan], [trenchPoly, f0], ['Extent', 'PointData_ElevTest.tif']],
     330            domain,
     331            nan_treatment = 'fall_through',
     332            nan_interpolation_region_polygon = [trenchPoly],
     333            default_k_nearest_neighbours = 3,
     334            default_raster_interpolation = 'bilinear',
     335            verbose=False)
     336
     337        # Points where we test the function. We deliberately use many points with x=50,
     338        # which happens to ensure that the nan value is replaced with the same
     339        # value it would have had anyway
     340        testPts_X = numpy.array([50.,50.00, 50., 50., 97., 51., 3.])
     341        testPts_Y = numpy.array([1.,    2., 3. , 4  , 20., 50., 60.])
    307342        fitted = F(testPts_X,testPts_Y)
    308343       
Note: See TracChangeset for help on using the changeset viewer.