def test_analyze(self): ws = resource_filename('tidegates.testing', 'analyze') testdir = 'tidegates.testing.analyze' test_dem = resource_filename(testdir, 'dem.tif') test_zones = resource_filename(testdir, 'zones.shp') test_wetlands = resource_filename(testdir, 'wetlands.shp') test_buidlings = resource_filename(testdir, 'buildings.shp') output = resource_filename(testdir, 'flooding.shp') topo_array, zones_array, template = tidegates.process_dem_and_zones( dem=test_dem, zones=test_zones, ID_column="GeoID", cleanup=True, verbose=False ) with utils.WorkSpace(ws), utils.OverwriteState(True): flood, wetland, building = self.tbx.analyze( topo_array=topo_array, zones_array=zones_array, template=template, elev=self.elev, slr=self.slr, surge=self.surge, num=None, flood_output=output, dem=test_dem, zones=test_zones, ID_column='GeoID', wetlands=test_wetlands, buildings=test_buidlings, ) nt.assert_true(isinstance(flood, arcpy.mapping.Layer)) nt.assert_equal(flood.dataSource, resource_filename(testdir, self.flood_output)) nt.assert_true(isinstance(wetland, arcpy.mapping.Layer)) nt.assert_true(isinstance(building, arcpy.mapping.Layer)) tgtest.assert_shapefiles_are_close( resource_filename(testdir, self.flood_output), resource_filename(testdir, self.known_flood_output) )
def test_analyze(self): ws = resource_filename('tidegates.testing', 'analyze') testdir = 'tidegates.testing.analyze' test_dem = resource_filename(testdir, 'dem.tif') test_zones = resource_filename(testdir, 'zones.shp') test_wetlands = resource_filename(testdir, 'wetlands.shp') test_buidlings = resource_filename(testdir, 'buildings.shp') output = resource_filename(testdir, 'flooding.shp') topo_array, zones_array, template = tidegates.process_dem_and_zones( dem=test_dem, zones=test_zones, ID_column="GeoID", cleanup=True, verbose=False) with utils.WorkSpace(ws), utils.OverwriteState(True): flood, wetland, building = self.tbx.analyze( topo_array=topo_array, zones_array=zones_array, template=template, elev=self.elev, slr=self.slr, surge=self.surge, num=None, flood_output=output, dem=test_dem, zones=test_zones, ID_column='GeoID', wetlands=test_wetlands, buildings=test_buidlings, ) nt.assert_true(isinstance(flood, arcpy.mapping.Layer)) nt.assert_equal(flood.dataSource, resource_filename(testdir, self.flood_output)) nt.assert_true(isinstance(wetland, arcpy.mapping.Layer)) nt.assert_true(isinstance(building, arcpy.mapping.Layer)) tgtest.assert_shapefiles_are_close( resource_filename(testdir, self.flood_output), resource_filename(testdir, self.known_flood_output))
def test_process_dem_and_zones(): known_topo = numpy.array([ [-999.0, 0.305, 0.610, 0.914, 1.219, 1.524, 1.829, 2.134,], [ 0.305, 0.610, 0.914, 1.219, 1.524, 1.829, 2.134, 2.438,], [ 0.610, 0.914, 1.219, 1.524, 1.829, 2.134, 2.438, 2.743,], [ 0.914, 1.219, 1.524, 1.829, 2.134, 2.438, 2.743, 3.048,], [ 1.219, 1.524, 1.829, 2.134, 2.438, 2.743, 3.048, 3.353,], [ 1.524, 1.829, 2.134, 2.438, 2.743, 3.048, 3.353, 3.658,], ]) known_zones = numpy.array([ [-999, 2, 2, 2, 2, 2, 2, -999], [-999, 2, 2, 2, -999, 2, 2, -999], [ 1, 1, 1, 1, -999, 2, 2, -999], [ 1, 1, 1, 1, -999, 2, 2, -999], [ 1, -999, 1, 1, 2, 2, 2, 2], [-999, -999, 1, 1, 2, 2, 2, 2] ]) known_cell_size = 8 known_X, known_Y = 4, 22 ws = resource_filename('tidegates.testing', 'process_dem_and_zones') with utils.WorkSpace(ws), utils.OverwriteState(True): ta, za, template = tidegates.process_dem_and_zones( dem='topo.tif', zones='zones.shp', ID_column='GeoID', cleanup=True, verbose=False ) nptest.assert_array_almost_equal(ta, known_topo, decimal=3) nptest.assert_array_almost_equal(za, known_zones, decimal=3) nt.assert_equal(template.meanCellWidth, known_cell_size) nt.assert_equal(template.meanCellHeight, known_cell_size) nt.assert_equal(template.extent.lowerLeft.X, known_X) nt.assert_equal(template.extent.lowerLeft.Y, known_Y)
def main_execute(self, **params): """ Performs the flood-impact analysis on multiple flood elevations. Parameters ---------- workspace : str The folder or geodatabase where the analysis will be executed. dem : str Filename of the digital elevation model (topography data) to be used in determinging the inundated areas. zones : str Name of zones of influence layer. ID_column : str Name of the field in ``zones`` that uniquely identifies each zone of influence. elevation : list, optional List of (custom) flood elevations to be analyzed. If this is not provided, *all* of the standard scenarios will be evaluated. flood_output : str Filename where the extent of flooding and damage will be saved. wetlands, buildings : str, optional Names of the wetland and building footprint layers. wetland_output, building_output : str, optional Filenames where the flooded wetlands and building footprints will be saved. Returns ------- None """ wetlands = params.get('wetlands', None) buildings = params.get('buildings', None) all_floods = [] all_wetlands = [] all_buildings = [] with utils.WorkSpace(params['workspace']), utils.OverwriteState(True): topo_array, zones_array, template = tidegates.process_dem_and_zones( dem=params['dem'], zones=params['zones'], ID_column=params['ID_column'] ) for num, scenario in enumerate(self.make_scenarios(**params)): fldlyr, wtlndlyr, blgdlyr = self.analyze( topo_array=topo_array, zones_array=zones_array, template=template, elev=scenario['elev'], surge=scenario['surge_name'], slr=scenario['slr'], num=num, **params ) all_floods.append(fldlyr.dataSource) if wetlands is not None: all_wetlands.append(wtlndlyr.dataSource) if buildings is not None: all_buildings.append(blgdlyr.dataSource) self.finish_results( params['flood_output'], all_floods, msg="Merging and cleaning up all flood results", verbose=True, asMessage=True, ) if wetlands is not None: wtld_output = params.get( 'wetland_output', utils.create_temp_filename(params['wetlands'], prefix='output_', filetype='shape') ) self.finish_results( wtld_output, all_wetlands, sourcename=params['wetlands'], msg="Merging and cleaning up all wetlands results", verbose=True, asMessage=True, ) if buildings is not None: bldg_output = params.get( 'building_output', utils.create_temp_filename(params['buildings'], prefix='output_', filetype='shape') ) self.finish_results( bldg_output, all_buildings, sourcename=params['buildings'], msg="Merging and cleaning up all buildings results", verbose=True, asMessage=True, )
def main_execute(self, **params): """ Performs the flood-impact analysis on multiple flood elevations. Parameters ---------- workspace : str The folder or geodatabase where the analysis will be executed. dem : str Filename of the digital elevation model (topography data) to be used in determinging the inundated areas. zones : str Name of zones of influence layer. ID_column : str Name of the field in ``zones`` that uniquely identifies each zone of influence. elevation : list, optional List of (custom) flood elevations to be analyzed. If this is not provided, *all* of the standard scenarios will be evaluated. flood_output : str Filename where the extent of flooding and damage will be saved. wetlands, buildings : str, optional Names of the wetland and building footprint layers. wetland_output, building_output : str, optional Filenames where the flooded wetlands and building footprints will be saved. Returns ------- None """ wetlands = params.get('wetlands', None) buildings = params.get('buildings', None) all_floods = [] all_wetlands = [] all_buildings = [] with utils.WorkSpace(params['workspace']), utils.OverwriteState(True): topo_array, zones_array, template = tidegates.process_dem_and_zones( dem=params['dem'], zones=params['zones'], ID_column=params['ID_column'] ) for scenario in self.make_scenarios(**params): fldlyr, wtlndlyr, blgdlyr = self.analyze( topo_array=topo_array, zones_array=zones_array, template=template, elev=scenario['elev'], surge=scenario['surge_name'], slr=scenario['slr'], **params ) all_floods.append(fldlyr.dataSource) if wetlands is not None: all_wetlands.append(wtlndlyr.dataSource) if buildings is not None: all_buildings.append(blgdlyr.dataSource) self.finish_results( params['flood_output'], all_floods, msg="Merging and cleaning up all flood results", verbose=True, asMessage=True, ) if wetlands is not None: wtld_output = params.get( 'wetland_output', utils.create_temp_filename(params['wetlands'], prefix='output_', filetype='shape') ) self.finish_results( wtld_output, all_wetlands, sourcename=params['wetlands'], msg="Merging and cleaning up all wetlands results", verbose=True, asMessage=True, ) if buildings is not None: bldg_output = params.get( 'building_output', utils.create_temp_filename(params['buildings'], prefix='output_', filetype='shape') ) self.finish_results( bldg_output, all_buildings, sourcename=params['buildings'], msg="Merging and cleaning up all buildings results", verbose=True, asMessage=True, )
def test_process_dem_and_zones(): known_topo = numpy.array([ [ -999.0, 0.305, 0.610, 0.914, 1.219, 1.524, 1.829, 2.134, ], [ 0.305, 0.610, 0.914, 1.219, 1.524, 1.829, 2.134, 2.438, ], [ 0.610, 0.914, 1.219, 1.524, 1.829, 2.134, 2.438, 2.743, ], [ 0.914, 1.219, 1.524, 1.829, 2.134, 2.438, 2.743, 3.048, ], [ 1.219, 1.524, 1.829, 2.134, 2.438, 2.743, 3.048, 3.353, ], [ 1.524, 1.829, 2.134, 2.438, 2.743, 3.048, 3.353, 3.658, ], ]) known_zones = numpy.array([[-999, 2, 2, 2, 2, 2, 2, -999], [-999, 2, 2, 2, -999, 2, 2, -999], [1, 1, 1, 1, -999, 2, 2, -999], [1, 1, 1, 1, -999, 2, 2, -999], [1, -999, 1, 1, 2, 2, 2, 2], [-999, -999, 1, 1, 2, 2, 2, 2]]) known_cell_size = 8 known_X, known_Y = 4, 22 ws = resource_filename('tidegates.testing', 'process_dem_and_zones') with utils.WorkSpace(ws), utils.OverwriteState(True): ta, za, template = tidegates.process_dem_and_zones(dem='topo.tif', zones='zones.shp', ID_column='GeoID', cleanup=True, verbose=False) nptest.assert_array_almost_equal(ta, known_topo, decimal=3) nptest.assert_array_almost_equal(za, known_zones, decimal=3) nt.assert_equal(template.meanCellWidth, known_cell_size) nt.assert_equal(template.meanCellHeight, known_cell_size) nt.assert_equal(template.extent.lowerLeft.X, known_X) nt.assert_equal(template.extent.lowerLeft.Y, known_Y)