def test_getValue( self ):
        """ Import DEM of CalPoly campus and test getValue method on upper left coords"""

        print "\nTest geotiff fields - getValue on CalPoly DEM\n"
        dem = getTestField()
        ulCoords = ( 711743.5, 3910110.5 ) #Coordinates are UTM Zone 10N
        #test getValue for upper left coords
        ulVal = dem.getValue( ulCoords )
        self.assertTrue( float_eq( ulVal, 117.36 ) )
    def test_getValue(self):
        """ Import DEM of CalPoly campus and test getValue method on upper left coords"""

        print "\nTest geotiff fields - getValue on CalPoly DEM\n"
        dem = getTestField()
        ulCoords = (711743.5, 3910110.5)  #Coordinates are UTM Zone 10N
        #test getValue for upper left coords
        ulVal = dem.getValue(ulCoords)
        self.assertTrue(float_eq(ulVal, 117.36))
Ejemplo n.º 3
0
 def test_normalised(self):
     
     r = RandNum(30)
     
     self.assertTrue(float_eq(r.nextNormalised(), 0.9520773088355697, 1e-5))
     self.assertTrue(float_eq(r.nextNormalised(), 0.3554310356575498, 1e-5))
     self.assertTrue(float_eq(r.nextNormalised(), 0.5447605464767113, 1e-5))
     self.assertTrue(float_eq(r.nextNormalised(), 0.608028552878688, 1e-5))
     self.assertTrue(float_eq(r.nextNormalised(), 0.625237893953786, 1e-5))
     self.assertTrue(float_eq(r.nextNormalised(), 0.8725258894812211, 1e-5))
    def test_local( self ):
        """
        Import DEM of CalPoly campus and test Map Albegra local function.

        Tested is a simple unary local operation, in which the value at each location is divided by 2 (lquot).
        """

        print "\nTest Map Algebra local function\n"
        dem = getTestField()
        newGtiffPath = os.path.join("tmp","testLocal.tif")
        ulCoords =( 711743.5, 3910110.5 )
        def localFunc( x ):
            return x/2
        dem.local( newGtiffPath, localFunc )
        testDem = GeoTiffField( newGtiffPath )
        oldVal = dem.getValue( ulCoords )
        testVal = testDem.getValue( ulCoords )
        self.assertTrue( float_eq( oldVal, testVal*2 ) )
    def test_focal( self ):
        """
        Import DEM of CalPoly campus and test Map Albegra focal function.

        Tested is a simple unary focal operation with a 3x3 square neighborhood and a mean focal function (fmean).

        """
        print "Test Map Algebra focal function"
        dem = getTestField()
        newGtiffPath = os.path.join("tmp","testFocal.tif")
        dem.focal( newGtiffPath, squareMean3 )
        testCoords = ( 711750.8, 3910105.1 )
        offset = getGtiffOffset ( dem.gField, testCoords )
        array = gdal.Open( os.path.join("..","..","data","fields","testField.tif") ).ReadAsArray()
        testNeighArray = squareMean3( array, offset )
        testNeighArray = np.round(testNeighArray, 3)
        testDem = GeoTiffField( newGtiffPath )
        testVal = testDem.getValue( testCoords )
        self.assertTrue( float_eq( testVal, testNeighArray ) ) #Confirm new value is mean of focal window
    def test_local(self):
        """
        Import DEM of CalPoly campus and test Map Albegra local function.

        Tested is a simple unary local operation, in which the value at each location is divided by 2 (lquot).
        """

        print "\nTest Map Algebra local function\n"
        dem = getTestField()
        newGtiffPath = os.path.join("tmp", "testLocal.tif")
        ulCoords = (711743.5, 3910110.5)

        def localFunc(x):
            return x / 2

        dem.local(newGtiffPath, localFunc)
        testDem = GeoTiffField(newGtiffPath)
        oldVal = dem.getValue(ulCoords)
        testVal = testDem.getValue(ulCoords)
        self.assertTrue(float_eq(oldVal, testVal * 2))
    def test_focal(self):
        """
        Import DEM of CalPoly campus and test Map Albegra focal function.

        Tested is a simple unary focal operation with a 3x3 square neighborhood and a mean focal function (fmean).

        """
        print "Test Map Algebra focal function"
        dem = getTestField()
        newGtiffPath = os.path.join("tmp", "testFocal.tif")
        dem.focal(newGtiffPath, squareMean3)
        testCoords = (711750.8, 3910105.1)
        offset = getGtiffOffset(dem.gField, testCoords)
        array = gdal.Open(
            os.path.join("..", "..", "data", "fields",
                         "testField.tif")).ReadAsArray()
        testNeighArray = squareMean3(array, offset)
        testNeighArray = np.round(testNeighArray, 3)
        testDem = GeoTiffField(newGtiffPath)
        testVal = testDem.getValue(testCoords)
        self.assertTrue(float_eq(
            testVal,
            testNeighArray))  #Confirm new value is mean of focal window