コード例 #1
0
ファイル: gdal.py プロジェクト: mhearne-usgs/grid
def _resample_test():
    try:
        print 'Test resampling data without padding...'
        data,geodict = Grid2D._createSampleData(9,7)
        gdalgrid = GDALGrid(data,geodict)
        gdalgrid.save('test.bil')
        
        newdict = {'xmin':3.0,'xmax':4.0,'ymin':3.0,'ymax':4.0,'xdim':1.0,'ydim':1.0}
        newdict = Grid2D.fillGeoDict(newdict)
        gdalgrid3 = GDALGrid.load('test.bil',samplegeodict=newdict,resample=True)
        output = np.array([[34,35],
                           [41,42]])
        np.testing.assert_almost_equal(gdalgrid3._data,output)
        print 'Passed resampling data without padding...'
        
        print 'Test resampling data with padding...'
        data,geodict = Grid2D._createSampleData(4,4)
        gdalgrid = GDALGrid(data,geodict)
        gdalgrid.save('test.bil')
        newdict = {'xmin':0.0,'xmax':4.0,'ymin':0.0,'ymax':4.0,'xdim':1.0,'ydim':1.0}
        newdict = Grid2D.fillGeoDict(newdict)
        gdalgrid3 = GDALGrid.load('test.bil',samplegeodict=newdict,resample=True,doPadding=True)
        output = np.array([[np.nan,np.nan,np.nan,np.nan,np.nan],
                           [np.nan,2.5,3.5,4.5,np.nan],
                           [np.nan,6.5,7.5,8.5,np.nan],
                           [np.nan,10.5,11.5,12.5,np.nan],
                           [np.nan,np.nan,np.nan,np.nan,np.nan]])
        np.testing.assert_almost_equal(gdalgrid3._data,output)
        print 'Passed resampling data with padding...'
    except AssertionError,error:
        print 'Failed resample test:\n %s' % error
コード例 #2
0
ファイル: gdal.py プロジェクト: mhearne-usgs/grid
def _subset_test():
    try:
        print 'Testing subsetting of non-square grid...'
        data,geodict = Grid2D._createSampleData(6,4)
        gdalgrid = GDALGrid(data,geodict)
        gdalgrid.save('test.bil')
        newdict = {'xmin':1.5,'xmax':2.5,'ymin':1.5,'ymax':3.5,'xdim':1.0,'ydim':1.0}
        gdalgrid3 = GDALGrid.load('test.bil',samplegeodict=newdict)
        output = np.array([[9,10],
                           [13,14],
                           [17,18]])
        np.testing.assert_almost_equal(gdalgrid3._data,output)
        print 'Passed subsetting of non-square grid.'
        
    except AssertionError,error:
        print 'Failed subset test:\n %s' % error
コード例 #3
0
ファイル: gdal.py プロジェクト: mhearne-usgs/grid
def _pad_test():
    try:
        print 'Test padding data with null values...'
        data,geodict = Grid2D._createSampleData(4,4)
        gdalgrid = GDALGrid(data,geodict)
        gdalgrid.save('test.bil')

        newdict = {'xmin':-0.5,'xmax':4.5,'ymin':-0.5,'ymax':4.5,'xdim':1.0,'ydim':1.0}
        gdalgrid2 = GDALGrid.load('test.bil',samplegeodict=newdict,doPadding=True)
        output = np.array([[np.nan,np.nan,np.nan,np.nan,np.nan,np.nan],
                           [np.nan,0.0,1.0,2.0,3.0,np.nan],
                           [np.nan,4.0,5.0,6.0,7.0,np.nan],
                           [np.nan,8.0,9.0,10.0,11.0,np.nan],
                           [np.nan,12.0,13.0,14.0,15.0,np.nan],
                           [np.nan,np.nan,np.nan,np.nan,np.nan,np.nan]])
        np.testing.assert_almost_equal(gdalgrid2._data,output)
        print 'Passed padding data null values.'
    except AssertionError,error:
        print 'Failed padding test:\n %s' % error