Beispiel #1
0
    def testResultRastersProduced(self):
        with TempDir() as d:
            arcpy.ImportToolbox(config.pyt_file)
            arcpy.multiplescales_btm(self.in_raster,
                                     self.nbh_sizes, self.metrics, d)

            depth_stats = {
                'meandepth': -20.56248074571827,
                'stddevdepth': 0.2946229406453136,
                'vardepth': 0.1281792675921596
            }

            for (prefix, expected_value) in depth_stats.items():
                raster_path = os.path.join(
                    d, "{0}_{1:03d}.tif".format(prefix, 3))
                self.assertAlmostEqual(
                    su.raster_properties(raster_path, 'MEAN'), expected_value)

            vrm_raster = os.path.join(d, 'ruggedness_003.tif')
            self.assertAlmostEqual(
                su.raster_properties(vrm_raster, "MEAN"), 0.00062628513039036)
            self.assertAlmostEqual(
                su.raster_properties(vrm_raster, "STD"), 0.00087457748556755)

            rast_names = ['meandepth_003.tif', 'stddevdepth_003.tif',
                          'vardepth_003.tif', 'ruggedness_003.tif',
                          'meandepth_013.tif', 'stddevdepth_013.tif',
                          'vardepth_013.tif', 'ruggedness_013.tif']

            for each in rast_names:
                file_name = os.path.join(d, each)
                self.assertTrue(os.path.exists(file_name))
def main(bpi_raster=None, out_raster=None):
    try:
        # Get raster properties
        message = ("Calculating properties of the Bathymetric "
                   "Position Index (BPI) raster...")
        utils.msg(message)
        utils.msg("  input raster: {}\n   output: {}".format(
            bpi_raster, out_raster))
        # convert to a path
        desc = arcpy.Describe(bpi_raster)
        bpi_raster_path = desc.catalogPath

        bpi_mean = utils.raster_properties(bpi_raster_path, "MEAN")
        utils.msg("BPI raster mean: {}.".format(bpi_mean))
        bpi_std_dev = utils.raster_properties(bpi_raster_path, "STD")
        utils.msg("BPI raster standard deviation: {}.".format(bpi_std_dev))

        # Create the standardized Bathymetric Position Index (BPI) raster
        std_msg = "Standardizing the Bathymetric Position Index (BPI) raster..."
        utils.msg(std_msg)
        arcpy.env.rasterStatistics = "STATISTICS"
        outRaster = Int(Plus(Times(Divide(
            Minus(bpi_raster_path, bpi_mean), bpi_std_dev), 100), 0.5))
        out_raster = utils.validate_path(out_raster)
        outRaster.save(out_raster)

    except Exception as e:
        utils.msg(e, mtype='error')
Beispiel #3
0
def main(bpi_raster=None, out_raster=None):
    try:
        # Get raster properties
        message = ("Calculating properties of the Bathymetric "
                   "Position Index (BPI) raster...")
        utils.msg(message)
        utils.msg("  input raster: {}\n   output: {}".format(
            bpi_raster, out_raster))
        # convert to a path
        desc = arcpy.Describe(bpi_raster)
        bpi_raster_path = desc.catalogPath

        bpi_mean = utils.raster_properties(bpi_raster_path, "MEAN")
        utils.msg("BPI raster mean: {}.".format(bpi_mean))
        bpi_std_dev = utils.raster_properties(bpi_raster_path, "STD")
        utils.msg("BPI raster standard deviation: {}.".format(bpi_std_dev))

        # Create the standardized Bathymetric Position Index (BPI) raster
        std_msg = "Standardizing the Bathymetric Position Index (BPI) raster..."
        utils.msg(std_msg)
        arcpy.env.rasterStatistics = "STATISTICS"
        outRaster = Int(
            Plus(
                Times(Divide(Minus(bpi_raster_path, bpi_mean), bpi_std_dev),
                      100), 0.5))
        out_raster = utils.validate_path(out_raster)
        outRaster.save(out_raster)

    except Exception as e:
        utils.msg(e, mtype='error')
Beispiel #4
0
    def testStdRun(self):
        with TempDir() as d:
            in_raster = os.path.join(d, 'test_bpi.tif')
            std_raster = os.path.join(d, 'test_std_bpi.tif')

            # was encountering this: ERROR 000875: Output raster:
            # c:\Users\shau7031\AppData\Local\Temp\tmp8co8nk\FocalSt_bath1's
            # workspace is an invalid workspace. Force workspace to temp:
            arcpy.env.scratchWorkspace = d
            bpi.main(bathy=config.bathy_raster,
                     inner_radius=10,
                     outer_radius=30,
                     out_raster=in_raster,
                     bpi_type='broad')

            self.assertTrue(os.path.exists(in_raster))

            standardize_bpi_grids.main(bpi_raster=in_raster,
                                       out_raster=std_raster)
            self.assertTrue(os.path.exists(std_raster))

            self.assertAlmostEqual(su.raster_properties(std_raster, "MEAN"),
                                   0.671608391608)
            self.assertAlmostEqual(su.raster_properties(std_raster, "STD"),
                                   99.655593923183)
Beispiel #5
0
    def testRasterProperties(self):
        """ Test the raster properties with a US locale."""
        # force to the US locale for radix tests
        locale.setlocale(locale.LC_ALL, "english_us")
        mean = su.raster_properties(config.bathy_raster, 'MEAN')
        self.assertAlmostEqual(mean, self.mean)

        std = su.raster_properties(config.bathy_raster, 'STD')
        self.assertAlmostEqual(std, self.std)
Beispiel #6
0
    def testRasterProperties(self):
        """ Test the raster properties with a US locale."""
        # force to the US locale for radix tests
        locale.setlocale(locale.LC_ALL, "english_us")
        mean = su.raster_properties(config.bathy_raster, 'MEAN')
        self.assertAlmostEqual(mean, self.mean)

        std = su.raster_properties(config.bathy_raster, 'STD')
        self.assertAlmostEqual(std, self.std)
Beispiel #7
0
    def testRasterPropertiesAlternativeDecimalMark(self):
        """ Test a locale which uses "," as its decimal separator."""
        # Windows locales are different than the locale() equivs
        locale.setlocale(locale.LC_ALL, "german_germany")

        # Changing the Python locale doesn't change the ArcGIS locale, so these will fail.
        mean = su.raster_properties(config.bathy_raster, 'MEAN')
        self.assertNotAlmostEqual(mean, self.mean)

        std = su.raster_properties(config.bathy_raster, 'STD')
        self.assertNotAlmostEqual(std, self.std)
Beispiel #8
0
    def testRasterPropertiesAlternativeDecimalMark(self):
        """ Test a locale which uses "," as its decimal separator."""
        # Windows locales are different than the locale() equivs
        locale.setlocale(locale.LC_ALL, "german_germany")

        # Changing the Python locale doesn't change the ArcGIS locale,
        # so these will fail.
        mean = su.raster_properties(config.bathy_raster, 'MEAN')
        self.assertNotAlmostEqual(mean, self.mean)

        std = su.raster_properties(config.bathy_raster, 'STD')
        self.assertNotAlmostEqual(std, self.std)
Beispiel #9
0
    def testVrmRun(self):
        with TempDir() as d:
            neighborhood = 3  # 3x3 neighborhood
            vrm_raster = os.path.join(d, 'test_vrm.tif')

            arcpy.env.scratchWorkspace = d
            ruggedness.main(config.bathy_raster, neighborhood, vrm_raster)
            self.assertTrue(os.path.exists(vrm_raster))

            self.assertAlmostEqual(su.raster_properties(vrm_raster, "MEAN"),
                                   0.00062628513039036)
            self.assertAlmostEqual(su.raster_properties(vrm_raster, "STD"),
                                   0.00087457748556755)
Beispiel #10
0
    def testVrmRun(self):
        with TempDir() as d:
            neighborhood = 3    # 3x3 neighborhood
            vrm_raster = os.path.join(d, 'test_vrm.tif')

            arcpy.env.scratchWorkspace = d
            ruggedness.main(config.bathy_raster, neighborhood, vrm_raster)
            self.assertTrue(os.path.exists(vrm_raster))

            self.assertAlmostEqual(
                su.raster_properties(vrm_raster, "MEAN"), 0.00062628513039036)
            self.assertAlmostEqual(
                su.raster_properties(vrm_raster, "STD"), 0.00087457748556755)
Beispiel #11
0
    def testBpiRun(self):
        with TempDir() as d:
            raster_fn = 'test_run_bpi.tif'
            bpi_raster = os.path.join(d, raster_fn)
            bpi.main(bathy=config.bathy_raster, inner_radius=10,
                     outer_radius=30, out_raster=bpi_raster, bpi_type='broad')

            self.assertTrue(raster_fn in os.listdir(d))

            self.assertAlmostEqual(
                su.raster_properties(bpi_raster, "MEAN"), 0.295664335664)
            self.assertAlmostEqual(
                su.raster_properties(bpi_raster, "STD"), 1.65611606614)
Beispiel #12
0
    def testRasterPropertiesAlternativeDecimalMark(self):
        """ Test a locale which uses "," as its decimal separator."""
        # Windows locales are different than the locale() equivs
        locale.setlocale(locale.LC_ALL, "german_germany")

        # force reload utils after locale is set; otherwise it'll set it
        # internally.
        reload(su)

        mean = su.raster_properties(config.bathy_raster, 'MEAN')
        self.assertAlmostEqual(mean, self.mean)

        std = su.raster_properties(config.bathy_raster, 'STD')
        self.assertAlmostEqual(std, self.std)
Beispiel #13
0
    def testAspectRun(self):
        with TempDir() as d:
            aspect_sin_raster = os.path.join(d, 'test_aspect_sin.tif')
            aspect_cos_raster = os.path.join(d, 'test_aspect_cos.tif')
            arcpy.env.scratchWorkspace = d

            aspect.main(bathy=config.bathy_raster, out_sin_raster=aspect_sin_raster, \
                    out_cos_raster=aspect_cos_raster)

            self.assertTrue(os.path.exists(aspect_sin_raster))
            self.assertTrue(os.path.exists(aspect_cos_raster))

            self.assertAlmostEqual(su.raster_properties(aspect_sin_raster, "MEAN"), \
                -0.06153140691827335)
            self.assertAlmostEqual(su.raster_properties(aspect_cos_raster, "MEAN"), \
                0.02073092622177259) 
Beispiel #14
0
    def testDepthStatisticsRun(self):
        with TempDir() as d:
            neighborhood = 3    # 3x3 neighborhood
            arcpy.env.scratchWorkspace = d
            out_workspace = d
            stats = "'Mean Depth';Variance;"\
                    "'Standard Deviation';'Terrain Ruggedness (VRM)';"\
                    "'Interquartile Range';Kurtosis"

            depth_statistics.main(
                config.bathy_raster, neighborhood, out_workspace, stats)

            # mean of depth summary rasters
            mean_depths = {
                'mean': -20.56248074571827,
                'sdev': 0.2946229406453136,
                'var': 0.1281792675921596,
                'iqr': 0.45498055403516,
                'kurt': -0.90668194852357
            }

            for (prefix, expected_value) in mean_depths.items():
                raster_path = os.path.join(
                    d, "{0}_{1}_{2:03d}.tif".format(self.base,
                                                    prefix, neighborhood))
                self.assertTrue(os.path.exists(raster_path))
                self.assertAlmostEqual(
                    su.raster_properties(raster_path, 'MEAN'), expected_value)
Beispiel #15
0
    def testDepthStatisticsRun(self):
        with TempDir() as d:
            neighborhood = 3  # 3x3 neighborhood
            arcpy.env.scratchWorkspace = d
            out_workspace = d
            stats = "'Mean Depth';Variance;"\
                    "'Standard Deviation';'Terrain Ruggedness (VRM)';"\
                    "'Interquartile Range';Kurtosis"

            depth_statistics.main(config.bathy_raster, neighborhood,
                                  out_workspace, stats)

            # mean of depth summary rasters
            mean_depths = {
                'mean': -20.56248074571827,
                'sdev': 0.2946229406453136,
                'var': 0.1281792675921596,
                'iqr': 0.45498055403516,
                'kurt': -0.90668194852357
            }

            for (prefix, expected_value) in mean_depths.items():
                raster_path = os.path.join(
                    d, "{0}_{1}_{2:03d}.tif".format(self.base, prefix,
                                                    neighborhood))
                self.assertTrue(os.path.exists(raster_path))
                self.assertAlmostEqual(
                    su.raster_properties(raster_path, 'MEAN'), expected_value)
Beispiel #16
0
    def testBpiRun(self):
        with TempDir() as d:
            raster_fn = 'test_run_bpi.tif'
            bpi_raster = os.path.join(d, raster_fn)
            bpi.main(bathy=config.bathy_raster,
                     inner_radius=10,
                     outer_radius=30,
                     out_raster=bpi_raster,
                     bpi_type='broad')

            self.assertTrue(raster_fn in os.listdir(d))

            self.assertAlmostEqual(su.raster_properties(bpi_raster, "MEAN"),
                                   0.295664335664)
            self.assertAlmostEqual(su.raster_properties(bpi_raster, "STD"),
                                   1.65611606614)
Beispiel #17
0
    def testSlopeRun(self):
        with TempDir() as d:
            slope_raster = os.path.join(d, 'test_slope.tif')
            arcpy.env.scratchWorkspace = d
            slope.main(bathy=config.bathy_raster, out_raster=slope_raster)
            self.assertTrue(os.path.exists(slope_raster))

            self.assertAlmostEqual(
                su.raster_properties(slope_raster, "MEAN"), 3.802105241105673)
Beispiel #18
0
    def testSlopeRun(self):
        with TempDir() as d:
            slope_raster = os.path.join(d, 'test_slope.tif')
            arcpy.env.scratchWorkspace = d
            slope.main(bathy=config.bathy_raster, out_raster=slope_raster)
            self.assertTrue(os.path.exists(slope_raster))

            self.assertAlmostEqual(su.raster_properties(slope_raster, "MEAN"),
                                   3.802105241105673)
Beispiel #19
0
    def testAspectRun(self):
        with TempDir() as d:
            aspect_sin_raster = os.path.join(d, 'test_aspect_sin.tif')
            aspect_cos_raster = os.path.join(d, 'test_aspect_cos.tif')
            arcpy.env.scratchWorkspace = d

            aspect.main(bathy=config.bathy_raster,
                        out_sin_raster=aspect_sin_raster,
                        out_cos_raster=aspect_cos_raster)

            self.assertTrue(os.path.exists(aspect_sin_raster))
            self.assertTrue(os.path.exists(aspect_cos_raster))

            self.assertAlmostEqual(
                su.raster_properties(aspect_sin_raster, "MEAN"),
                -0.06153140691827335)
            self.assertAlmostEqual(
                su.raster_properties(aspect_cos_raster, "MEAN"),
                0.02073092622177259)
Beispiel #20
0
    def testRasterPropertiesAlternativeDecimalMark(self):
        """ Test a locale which uses "," as its decimal separator."""
        # Windows locales are different than the locale() equivs
        locale.setlocale(locale.LC_ALL, "german_germany")

        # force reload utils after locale is set; otherwise it'll set it
        # internally.
        try:
            reload(su)
        except NameError:
            # py3, assume 3.4+
            import importlib
            importlib.reload(su)

        mean = su.raster_properties(config.bathy_raster, 'MEAN')
        self.assertAlmostEqual(mean, self.mean)

        std = su.raster_properties(config.bathy_raster, 'STD')
        self.assertAlmostEqual(std, self.std)
Beispiel #21
0
    def testToolboxRunWithLayers(self):
        """ Test running the tool against the toolbox version
        using Layer files."""
        with TempDir() as d:

            broad_std_raster = os.path.join(d, 'test_broad_std_bpi.tif')
            fine_std_raster = os.path.join(d, 'test_fine_std_bpi.tif')

            arcpy.env.scratchWorkspace = d
            arcpy.ImportToolbox(config.pyt_file)

            (install_dir, arcgis_version, product) = su.arcgis_platform()

            if product == 'Desktop':
                mxd = arcpy.mapping.MapDocument(config.bpi_grids_mxd)
                df = arcpy.mapping.ListDataFrames(mxd)[0]
                layers = arcpy.mapping.ListLayers(df)
            else:
                aprx = arcpy.mp.ArcGISProject(config.bpi_grids_aprx)
                mdoc = aprx.listMaps()[0]
                layers = mdoc.listLayers()
            layer_names = [l.name for l in layers]

            broad_lyr = layers[layer_names.index('broad_bpi')]
            fine_lyr = layers[layer_names.index('fine_bpi')]

            arcpy.standardizebpi_btm(
                broad_lyr.dataSource, "0", "0", broad_std_raster,
                fine_lyr.dataSource, "0", "0", fine_std_raster)

            self.assertTrue(os.path.exists(broad_std_raster))
            self.assertTrue(os.path.exists(fine_std_raster))

            # Compare to known rasters
            self.assertAlmostEqual(
                su.raster_properties(broad_std_raster, "MEAN"),
                su.raster_properties(config.broad_std_raster, "MEAN"))
            self.assertAlmostEqual(
                su.raster_properties(broad_std_raster, "STD"),
                su.raster_properties(config.broad_std_raster, "STD"))

            self.assertAlmostEqual(
                su.raster_properties(fine_std_raster, "MEAN"),
                su.raster_properties(config.fine_std_raster, "MEAN"))
            self.assertAlmostEqual(
                su.raster_properties(fine_std_raster, "STD"),
                su.raster_properties(config.fine_std_raster, "STD"))

            if product == 'Desktop':
                del layers, df, mxd
            else:
                del layers, mdoc, aprx
Beispiel #22
0
    def testToolboxRunWithLayers(self):
        """ Test running the tool against the toolbox version
        using Layer files."""
        with TempDir() as d:

            broad_std_raster = os.path.join(d, 'test_broad_std_bpi.tif')
            fine_std_raster = os.path.join(d, 'test_fine_std_bpi.tif')

            arcpy.env.scratchWorkspace = d
            arcpy.ImportToolbox(config.pyt_file)

            (install_dir, arcgis_version, product) = su.arcgis_platform()

            if product == 'Desktop':
                mxd = arcpy.mapping.MapDocument(config.bpi_grids_mxd)
                df = arcpy.mapping.ListDataFrames(mxd)[0]
                layers = arcpy.mapping.ListLayers(df)
            else:
                aprx = arcpy.mp.ArcGISProject(config.bpi_grids_aprx)
                mdoc = aprx.listMaps()[0]
                layers = mdoc.listLayers()
            layer_names = [l.name for l in layers]

            broad_lyr = layers[layer_names.index('broad_bpi')]
            fine_lyr = layers[layer_names.index('fine_bpi')]

            arcpy.standardizebpi_btm(broad_lyr.dataSource, "0", "0",
                                     broad_std_raster, fine_lyr.dataSource,
                                     "0", "0", fine_std_raster)

            self.assertTrue(os.path.exists(broad_std_raster))
            self.assertTrue(os.path.exists(fine_std_raster))

            # Compare to known rasters
            self.assertAlmostEqual(
                su.raster_properties(broad_std_raster, "MEAN"),
                su.raster_properties(config.broad_std_raster, "MEAN"))
            self.assertAlmostEqual(
                su.raster_properties(broad_std_raster, "STD"),
                su.raster_properties(config.broad_std_raster, "STD"))

            self.assertAlmostEqual(
                su.raster_properties(fine_std_raster, "MEAN"),
                su.raster_properties(config.fine_std_raster, "MEAN"))
            self.assertAlmostEqual(
                su.raster_properties(fine_std_raster, "STD"),
                su.raster_properties(config.fine_std_raster, "STD"))

            if product == 'Desktop':
                del layers, df, mxd
            else:
                del layers, mdoc, aprx
Beispiel #23
0
    def testSaPaRun(self):
        with TempDir() as d:
            ratio_raster = os.path.join(d, 'test_sapa_ratio.tif')
            surf_raster = os.path.join(d, 'test_surface_area.tif')

            arcpy.env.scratchWorkspace = d
            surface_area_to_planar_area.main(config.bathy_raster,
                    ratio_raster, surf_raster)
            self.assertTrue(os.path.exists(ratio_raster))
            self.assertTrue(os.path.exists(surf_raster))

            self.assertAlmostEqual(su.raster_properties(ratio_raster, "MEAN"), \
               1.0042422342676)
            self.assertAlmostEqual(su.raster_properties(ratio_raster, "STD"), \
               0.0058175502835692)

            self.assertAlmostEqual(su.raster_properties(surf_raster, "MEAN"), \
                25.119343739217)
            self.assertAlmostEqual(su.raster_properties(surf_raster, "STD"), \
                0.14551573347447)
Beispiel #24
0
    def testSaPaRunNoCorrection(self):
        with TempDir() as d:
            ratio_raster = os.path.join(d, 'test_sapa_ratio.tif')
            surf_raster = os.path.join(d, 'test_surface_area.tif')

            arcpy.env.scratchWorkspace = d
            surface_area_to_planar_area.main(config.bathy_raster, ratio_raster,
                                             False, surf_raster)

            self.assertTrue(os.path.exists(ratio_raster))
            self.assertTrue(os.path.exists(surf_raster))

            self.assertAlmostEqual(su.raster_properties(ratio_raster, "MEAN"),
                                   1.0042422342676)
            self.assertAlmostEqual(su.raster_properties(ratio_raster, "STD"),
                                   0.0058175502835692)

            self.assertAlmostEqual(su.raster_properties(surf_raster, "MEAN"),
                                   25.119343091857)
            self.assertAlmostEqual(su.raster_properties(surf_raster, "STD"),
                                   0.14551573347447)
Beispiel #25
0
    def testSaPaRunCorrection(self):
        with TempDir() as d:
            ratio_raster = os.path.join(d, 'test_sapa_ratio.tif')
            surf_raster = os.path.join(d, 'test_surface_area.tif')

            arcpy.env.scratchWorkspace = d
            surface_area_to_planar_area.main(config.bathy_raster, ratio_raster,
                                             True, surf_raster)

            self.assertTrue(os.path.exists(ratio_raster))
            self.assertTrue(os.path.exists(surf_raster))

            self.assertAlmostEqual(su.raster_properties(ratio_raster, "MEAN"),
                                   1.000616701751028)
            self.assertAlmostEqual(su.raster_properties(ratio_raster, "STD"),
                                   0.0008445980914179108)

            self.assertAlmostEqual(su.raster_properties(surf_raster, "MEAN"),
                                   25.119343091857)
            self.assertAlmostEqual(su.raster_properties(surf_raster, "STD"),
                                   0.14551570953239)
Beispiel #26
0
    def testSaPaRunCorrection(self):
        with TempDir() as d:
            ratio_raster = os.path.join(d, 'test_sapa_ratio.tif')
            surf_raster = os.path.join(d, 'test_surface_area.tif')

            arcpy.env.scratchWorkspace = d
            surface_area_to_planar_area.main(
                config.bathy_raster, ratio_raster, True, surf_raster)

            self.assertTrue(os.path.exists(ratio_raster))
            self.assertTrue(os.path.exists(surf_raster))

            self.assertAlmostEqual(
                su.raster_properties(ratio_raster, "MEAN"), 1.000616701751028)
            self.assertAlmostEqual(
                su.raster_properties(ratio_raster, "STD"), 0.0008445980914179108)

            self.assertAlmostEqual(
                su.raster_properties(surf_raster, "MEAN"), 25.119343091857)
            self.assertAlmostEqual(
                su.raster_properties(surf_raster, "STD"), 0.14551570953239)
Beispiel #27
0
    def testStdRun(self):
        with TempDir() as d:
            in_raster = os.path.join(d, 'test_bpi.tif')
            std_raster = os.path.join(d, 'test_std_bpi.tif')

            # was encountering this: ERROR 000875: Output raster:
            # c:\Users\shau7031\AppData\Local\Temp\tmp8co8nk\FocalSt_bath1's
            # workspace is an invalid output workspace. Force the workspace to temp:
            arcpy.env.scratchWorkspace = d
            bpi.main(bathy=config.bathy_raster, inner_radius=10,
                outer_radius=30, out_raster=in_raster, bpi_type='broad')

            self.assertTrue(os.path.exists(in_raster))

            standardize_bpi_grids.main(bpi_raster=in_raster, out_raster=std_raster)
            self.assertTrue(os.path.exists(std_raster))

            self.assertAlmostEqual(
                    su.raster_properties(std_raster, "MEAN"), 0.671608391608)
            self.assertAlmostEqual(
                    su.raster_properties(std_raster, "STD"), 99.655593923183)
Beispiel #28
0
    def testResultRastersProduced(self):
        with TempDir() as d:
            arcpy.env.scratchWorkspace = d
            arcpy.ImportToolbox(config.pyt_file)
            arcpy.multiplescales_btm(self.in_raster, self.nbh_sizes,
                                     self.metrics, d)

            depth_stats = {
                'mean': -20.56248074571827,
                'sdev': 0.2946229406453136,
                'var': 0.1281792675921596,
                'iqr': 0.45498055403516,
                'kurt': -0.90668194852357
            }

            for (prefix, expected_value) in depth_stats.items():
                raster_path = os.path.join(
                    d, "bathy5m_clip_{0}_{1:03d}.tif".format(prefix, 3))
                self.assertAlmostEqual(
                    su.raster_properties(raster_path, 'MEAN'), expected_value)

            vrm_raster = os.path.join(d, 'bathy5m_clip_vrm_003.tif')
            self.assertAlmostEqual(su.raster_properties(vrm_raster, "MEAN"),
                                   0.00062628513039036)
            self.assertAlmostEqual(su.raster_properties(vrm_raster, "STD"),
                                   0.00087457748556755)

            rast_names = [
                'bathy5m_clip_mean_003.tif', 'bathy5m_clip_sdev_003.tif',
                'bathy5m_clip_var_003.tif', 'bathy5m_clip_vrm_003.tif',
                'bathy5m_clip_mean_013.tif', 'bathy5m_clip_sdev_013.tif',
                'bathy5m_clip_var_013.tif', 'bathy5m_clip_vrm_013.tif',
                'bathy5m_clip_iqr_003.tif', 'bathy5m_clip_kurt_003.tif',
                'bathy5m_clip_iqr_013.tif', 'bathy5m_clip_kurt_013.tif'
            ]

            for each in rast_names:
                file_name = os.path.join(d, each)
                self.assertTrue(os.path.exists(file_name))
Beispiel #29
0
    def testResultRastersProduced(self):
        with TempDir() as d:
            arcpy.env.scratchWorkspace = d
            arcpy.ImportToolbox(config.pyt_file)
            arcpy.multiplescales_btm(self.in_raster,
                                     self.nbh_sizes, self.metrics, d)

            depth_stats = {
                'mean': -20.56248074571827,
                'sdev': 0.2946229406453136,
                'var': 0.1281792675921596,
                'iqr': 0.45498055403516,
                'kurt': -0.90668194852357
            }

            for (prefix, expected_value) in depth_stats.items():
                raster_path = os.path.join(
                    d, "bathy5m_clip_{0}_{1:03d}.tif".format(prefix, 3))
                self.assertAlmostEqual(
                    su.raster_properties(raster_path, 'MEAN'), expected_value)

            vrm_raster = os.path.join(d, 'bathy5m_clip_vrm_003.tif')
            self.assertAlmostEqual(
                su.raster_properties(vrm_raster, "MEAN"), 0.00062628513039036)
            self.assertAlmostEqual(
                su.raster_properties(vrm_raster, "STD"), 0.00087457748556755)

            rast_names = ['bathy5m_clip_mean_003.tif', 'bathy5m_clip_sdev_003.tif',
                          'bathy5m_clip_var_003.tif', 'bathy5m_clip_vrm_003.tif',
                          'bathy5m_clip_mean_013.tif', 'bathy5m_clip_sdev_013.tif',
                          'bathy5m_clip_var_013.tif', 'bathy5m_clip_vrm_013.tif',
                          'bathy5m_clip_iqr_003.tif', 'bathy5m_clip_kurt_003.tif',
                          'bathy5m_clip_iqr_013.tif', 'bathy5m_clip_kurt_013.tif']

            for each in rast_names:
                file_name = os.path.join(d, each)
                self.assertTrue(os.path.exists(file_name))
Beispiel #30
0
 def testClassifyWithFgdbLocation(self):
     with TempDir() as d:
         fgdb_name = "classify.gdb"
         fgdb_workspace = os.path.join(d, fgdb_name)
         # create a temporary File Geodatabase location
         arcpy.CreateFileGDB_management(d, fgdb_name)
         self.assertTrue(os.path.exists(fgdb_workspace))
         # TODO: this currently hacks up the path to be a valid name, but should probably
         # instead throw an error and let the user correct the output name.
         classify_raster = os.path.join(fgdb_workspace, 'output_in_fgdb')
         classify.main(config.base_xml, config.broad_std_raster, config.fine_std_raster, \
                 config.slope_raster,  config.bathy_raster, classify_raster)
         # resulting 'fixed' name
         mean = su.raster_properties(classify_raster, "MEAN")
         self.assertAlmostEqual(mean, 5.78153846153846)
Beispiel #31
0
    def testSaPaRunWithFgdbLocation(self):
        with TempDir() as d:
            fgdb_name = "sapa.gdb"
            fgdb_workspace = os.path.join(d, fgdb_name)
            # create a temporary File Geodatabase location
            arcpy.CreateFileGDB_management(d, fgdb_name)
            self.assertTrue(os.path.exists(fgdb_workspace))

            ratio_raster = os.path.join(fgdb_workspace, 'test_sapa_ratio')
            surf_raster = os.path.join(fgdb_workspace, 'test_sapa_area')

            arcpy.env.scratchWorkspace = d
            surface_area_to_planar_area.main(
                config.bathy_raster, ratio_raster, False, surf_raster)

            self.assertAlmostEqual(
                su.raster_properties(ratio_raster, "MEAN"), 1.0042422342676)
            self.assertAlmostEqual(
                su.raster_properties(ratio_raster, "STD"), 0.0058175502835692)

            self.assertAlmostEqual(
                su.raster_properties(surf_raster, "MEAN"), 25.119343091857)
            self.assertAlmostEqual(
                su.raster_properties(surf_raster, "STD"), 0.14551573347447)
Beispiel #32
0
    def testSaPaRunWithFgdbLocation(self):
        with TempDir() as d:
            fgdb_name = "sapa.gdb"
            fgdb_workspace = os.path.join(d, fgdb_name)
            # create a temporary File Geodatabase location
            arcpy.CreateFileGDB_management(d, fgdb_name)
            self.assertTrue(os.path.exists(fgdb_workspace))

            ratio_raster = os.path.join(fgdb_workspace, 'test_sapa_ratio')
            surf_raster = os.path.join(fgdb_workspace, 'test_sapa_area')

            arcpy.env.scratchWorkspace = d
            surface_area_to_planar_area.main(config.bathy_raster, ratio_raster,
                                             False, surf_raster)

            self.assertAlmostEqual(su.raster_properties(ratio_raster, "MEAN"),
                                   1.0042422342676)
            self.assertAlmostEqual(su.raster_properties(ratio_raster, "STD"),
                                   0.0058175502835692)

            self.assertAlmostEqual(su.raster_properties(surf_raster, "MEAN"),
                                   25.119343091857)
            self.assertAlmostEqual(su.raster_properties(surf_raster, "STD"),
                                   0.14551573347447)
Beispiel #33
0
    def testModelExecuteWithExcel(self):
        with TempDir() as d:
            model_output = os.path.join(d, 'output_zones.tif')
            arcpy.env.scratchWorkspace = d

            btm_model.main(d, config.bathy_raster, self.broad_inner_rad, \
                    self.broad_outer_rad, self.fine_inner_rad, self.fine_outer_rad, \
                    config.base_excel, model_output)

            self.assertTrue(os.path.exists(model_output))

            self.excel_mean = su.raster_properties(model_output, "MEAN")
            self.assertAlmostEqual(self.excel_mean, self.true_mean)

            # count up the number of cells in the first class
            self.assertEqual(self.sumFirstClass(model_output), 88)
Beispiel #34
0
    def testModelExecuteWithXml(self):
        with TempDir() as d:
            model_output = os.path.join(d, 'output_zones.tif')
            arcpy.env.scratchWorkspace = d

            btm_model.main(d, config.bathy_raster, self.broad_inner_rad,
                           self.broad_outer_rad, self.fine_inner_rad,
                           self.fine_outer_rad, config.base_xml, model_output)

            self.assertTrue(os.path.exists(model_output))

            self.xml_mean = su.raster_properties(model_output, "MEAN")
            self.assertAlmostEqual(self.xml_mean, self.true_mean)

            # count up the number of cells in the first class
            self.assertEqual(self.sumFirstClass(model_output), 88)
Beispiel #35
0
 def testClassifyWithFgdbLocation(self):
     with TempDir() as d:
         fgdb_name = "classify.gdb"
         fgdb_workspace = os.path.join(d, fgdb_name)
         # create a temporary File Geodatabase location
         arcpy.CreateFileGDB_management(d, fgdb_name)
         self.assertTrue(os.path.exists(fgdb_workspace))
         # TODO: this currently hacks up the path to be a valid name,
         # but should probably instead throw an error and let the user
         # correct the output name.
         classify_raster = os.path.join(fgdb_workspace, 'output_in_fgdb')
         classify.main(config.base_xml, config.broad_std_raster,
                       config.fine_std_raster, config.slope_raster,
                       config.bathy_raster, classify_raster)
         # resulting 'fixed' name
         mean = su.raster_properties(classify_raster, "MEAN")
         self.assertAlmostEqual(mean, 5.78153846153846)
Beispiel #36
0
    def testModelExecuteWithCsvFromToolbox(self):
        with TempDir() as d:
            model_output = os.path.join(d, 'output_zones.tif')
            arcpy.env.scratchWorkspace = d

            arcpy.ImportToolbox(config.pyt_file)
            arcpy.runfullmodel_btm(d, config.bathy_raster,
                                   self.broad_inner_rad, self.broad_outer_rad,
                                   self.fine_inner_rad, self.fine_outer_rad,
                                   config.base_csv, model_output)

            self.assertTrue(os.path.exists(model_output))

            self.csv_mean = su.raster_properties(model_output, "MEAN")
            self.assertAlmostEqual(self.csv_mean, self.true_mean)

            # count up the number of cells in the first class
            self.assertEqual(self.sumFirstClass(model_output), 88)
Beispiel #37
0
    def testToolboxRunWithLayers(self):
        """ Test running the tool against the toolbox version
        using Layer files."""
        with TempDir() as d:

            broad_std_raster = os.path.join(d, 'test_broad_std_bpi.tif')
            fine_std_raster = os.path.join(d, 'test_fine_std_bpi.tif')

            arcpy.env.scratchWorkspace = d
            arcpy.ImportToolbox(config.pyt_file)

            mxd = arcpy.mapping.MapDocument(config.bpi_grids_mxd)
            df = arcpy.mapping.ListDataFrames(mxd)[0]
            layers = arcpy.mapping.ListLayers(df)
            layer_names = [l.name for l in layers]

            broad_lyr = layers[layer_names.index('broad_bpi')]
            fine_lyr = layers[layer_names.index('fine_bpi')]

            arcpy.standardizebpi_btm(
                broad_lyr.dataSource, "0", "0", broad_std_raster,
                fine_lyr.dataSource, "0", "0", fine_std_raster)

            self.assertTrue(os.path.exists(broad_std_raster))
            self.assertTrue(os.path.exists(fine_std_raster))

            # Compare to known rasters
            self.assertAlmostEqual(
                su.raster_properties(broad_std_raster, "MEAN"),
                su.raster_properties(config.broad_std_raster, "MEAN"))
            self.assertAlmostEqual(
                su.raster_properties(broad_std_raster, "STD"),
                su.raster_properties(config.broad_std_raster, "STD"))

            self.assertAlmostEqual(
                su.raster_properties(fine_std_raster, "MEAN"),
                su.raster_properties(config.fine_std_raster, "MEAN"))
            self.assertAlmostEqual(
                su.raster_properties(fine_std_raster, "STD"),
                su.raster_properties(config.fine_std_raster, "STD"))

            del layers, df, mxd
Beispiel #38
0
    def testModelExecuteWithExcel(self):
        with TempDir() as d:
            zones_output = os.path.join(d, 'output_zones.tif')
            arcpy.env.scratchWorkspace = d

            btm_model.main(d, config.bathy_raster, self.broad_inner_rad, \
                    self.broad_outer_rad, self.fine_inner_rad, self.fine_outer_rad, \
                    config.zones_excel, zones_output)

            self.assertTrue(os.path.exists(zones_output))
            arcpy.BuildRasterAttributeTable_management(zones_output)

            self.excel_mean = su.raster_properties(zones_output, "MEAN")
            self.excel_zones = zones_output
            # some asserts here for validation
            rat = self.extractRasterAttributeTable(self.excel_zones)
            for (value, count) in self.expected.items():
                self.assertEqual(count, rat[value])
Beispiel #39
0
    def testModelExecuteWithCsvFromToolbox(self):
        with TempDir() as d:
            model_output = os.path.join(d, 'output_zones.tif')
            arcpy.env.scratchWorkspace = d

            arcpy.ImportToolbox(config.pyt_file)
            arcpy.runfullmodel_btm(
                d, config.bathy_raster, self.broad_inner_rad,
                self.broad_outer_rad, self.fine_inner_rad, self.fine_outer_rad,
                config.base_csv, model_output)

            self.assertTrue(os.path.exists(model_output))

            self.csv_mean = su.raster_properties(model_output, "MEAN")
            self.assertAlmostEqual(self.csv_mean, self.true_mean)

            # count up the number of cells in the first class
            self.assertEqual(self.sumFirstClass(model_output), 88)
Beispiel #40
0
    def testDepthStatisticsOnlyDiffToMean(self):
        """test just difference to mean."""
        with TempDir() as d:
            neighborhood = 3  # 3x3 neighborhood
            arcpy.env.scratchWorkspace = d
            out_workspace = d
            stats = "'Difference to Mean'"

            depth_statistics.main(config.bathy_raster, neighborhood,
                                  out_workspace, stats)

            prefix = 'mean_diff'
            expected_value = -0.0055500285014563
            raster_path = os.path.join(
                d, "{0}_{1}_{2:03d}.tif".format(self.base, prefix,
                                                neighborhood))
            self.assertTrue(os.path.exists(raster_path))
            self.assertAlmostEqual(su.raster_properties(raster_path, 'MEAN'),
                                   expected_value)
Beispiel #41
0
    def testModelExecuteWithExcel(self):
        with TempDir() as d:
            zones_output = os.path.join(d, 'output_zones.tif')
            arcpy.env.scratchWorkspace = d

            btm_model.main(d, config.bathy_raster, self.broad_inner_rad,
                           self.broad_outer_rad, self.fine_inner_rad,
                           self.fine_outer_rad, config.zones_excel,
                           zones_output)

            self.assertTrue(os.path.exists(zones_output))
            arcpy.BuildRasterAttributeTable_management(zones_output)

            self.excel_mean = su.raster_properties(zones_output, "MEAN")
            self.excel_zones = zones_output
            # some asserts here for validation
            rat = self.extractRasterAttributeTable(self.excel_zones)
            for (value, count) in self.expected.items():
                self.assertEqual(count, rat[value])
Beispiel #42
0
    def testDepthStatisticsOnlyDiffToMean(self):
        """test just difference to mean."""
        with TempDir() as d:
            neighborhood = 3    # 3x3 neighborhood
            arcpy.env.scratchWorkspace = d
            out_workspace = d
            stats = "'Difference to Mean'"

            depth_statistics.main(
                config.bathy_raster, neighborhood, out_workspace, stats)

            prefix = 'mean_diff'
            expected_value = -0.0055500285014563
            raster_path = os.path.join(
                d, "{0}_{1}_{2:03d}.tif".format(self.base,
                                                    prefix, neighborhood))
            self.assertTrue(os.path.exists(raster_path))
            self.assertAlmostEqual(
                su.raster_properties(raster_path, 'MEAN'), expected_value)
Beispiel #43
0
    def testDepthStatisticsRun(self):
        with TempDir() as d:
            neighborhood = 3 # 3x3 neighborhood
            arcpy.env.scratchWorkspace = d
            out_workspace = d
            stats = "Mean Depth;Variance;Standard Deviation"
            depth_statistics.main(config.bathy_raster, neighborhood,
                    out_workspace, stats)

            # mean of depth summary rasters
            mean_depths = {
                'meandepth': -20.56248074571827,
                'stdevdepth': 0.2946229406453136,
                'vardepth': 0.1281792675921596}

            for (stat, mean_value) in mean_depths.items():
                raster = os.path.join(d, stat)
                self.assertTrue(os.path.exists(raster))
                self.assertAlmostEqual(su.raster_properties(raster, "MEAN"), \
                        mean_value)
Beispiel #44
0
    def testDepthStatisticsRun(self):
        with TempDir() as d:
            neighborhood = 3  # 3x3 neighborhood
            arcpy.env.scratchWorkspace = d
            out_workspace = d
            stats = "Mean Depth;Variance;Standard Deviation"
            depth_statistics.main(config.bathy_raster, neighborhood,
                                  out_workspace, stats)

            # mean of depth summary rasters
            mean_depths = {
                'meandepth': -20.56248074571827,
                'stdevdepth': 0.2946229406453136,
                'vardepth': 0.1281792675921596
            }

            for (stat, mean_value) in mean_depths.items():
                raster = os.path.join(d, stat)
                self.assertTrue(os.path.exists(raster))
                self.assertAlmostEqual(su.raster_properties(raster, "MEAN"),
                                       mean_value)