Changeset 9303


Ignore:
Timestamp:
Aug 14, 2014, 10:33:25 AM (11 years ago)
Author:
davies
Message:

Fixing up recent plot_utils improvements

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

Legend:

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

    r9300 r9303  
    975975        # Combined nearest neighbours and inverse-distance interpolation
    976976        index_qFun=scipy.spatial.cKDTree(swwXY)
    977         NNInfo=index_qFun.query(gridXY_array,k=3)
     977        NNInfo=index_qFun.query(gridXY_array,k=k_nearest_neighbours)
    978978        # Weights for interpolation
    979979        nn_wts=1./(NNInfo[0]+1.0e-100)
    980980        nn_inds=NNInfo[1]
    981981        def myInterpFun(quantity):
    982             denom=nn_wts[:,0]+nn_wts[:,1]+nn_wts[:,2]
    983             num = quantity[nn_inds[:,0]]*nn_wts[:,0]+\
    984                   quantity[nn_inds[:,1]]*nn_wts[:,1]+\
    985                   quantity[nn_inds[:,2]]*nn_wts[:,2]
     982            denom=0.
     983            num=0.
     984            for i in range(k_nearest_neighbours):
     985                denom+=nn_wts[:,i]
     986                num+= quantity[nn_inds[:,i]]*nn_wts[:,i]
    986987            return (num/denom)
    987988
  • trunk/anuga_core/source/anuga/utilities/test_plot_utils.py

    r9212 r9303  
    397397        # Delete tif made with Make_Geotif
    398398        os.remove('PointData_TestData.tif')
     399
     400    def test_Make_Geotif_with_knn(self):
     401        # VERY BASIC TEST using knn+inverse distance interpolation to make the grid
     402        #
     403        # Simply create some data and grid it
     404        #
     405        # If nothing fails, that's good
     406        #
     407        # Pick a domain that makes sense in EPSG:32756
     408        x=np.linspace(307000., 308000., 100)     
     409        y=np.linspace(6193000., 6194000., 100)
     410        myCellSize=5.0
     411        xG,yG=np.meshgrid(x, y)
     412        xG=xG.flatten()
     413        yG=yG.flatten()
     414        # Surface is z=x+y
     415        fakeZ=xG-min(xG)+yG -min(yG)
     416        dataToGrid=np.vstack([xG,yG,fakeZ]).transpose()
     417        util.Make_Geotif(dataToGrid, output_quantities=['TestData'],
     418                         EPSG_CODE=32756, output_dir='.', CellSize=myCellSize,
     419                         k_nearest_neighbours=4)
     420
     421       
     422        # Use gdal to check that at least the data extent is ok
     423        import gdal
     424        raster=gdal.Open('PointData_TestData.tif')
     425        rasterGeoTrans=raster.GetGeoTransform()
     426        assert(np.allclose(x.min()-myCellSize/2.0, rasterGeoTrans[0]))
     427        assert(np.allclose(y.max()+myCellSize/2.0, rasterGeoTrans[3]))
     428        #release data file
     429        raster = None
     430        # Delete tif made with Make_Geotif
     431        os.remove('PointData_TestData.tif')
    399432       
    400433
Note: See TracChangeset for help on using the changeset viewer.