コード例 #1
0
def test_flood_area():
    topo = numpy.mgrid[:8, :8].sum(axis=0) * tidegates.METERS_PER_FOOT
    zones = numpy.array([
        [-1,  2,  2,  2,  2,  2,  2, -1,],
        [-1,  2,  2,  2, -1,  2,  2, -1,],
        [ 1,  1,  1,  1, -1,  2,  2, -1,],
        [ 1,  1,  1,  1, -1,  2,  2, -1,],
        [ 1, -1,  1,  1,  2,  2,  2,  2,],
        [-1, -1,  1,  1,  2,  2,  2,  2,],
        [-1, -1, -1, -1, -1, -1, -1, -1,],
        [-1, -1, -1, -1, -1, -1, -1, -1,]
    ])
    template = utils.RasterTemplate(8, 4, 6)
    ws = resource_filename('tidegates.testing', 'flood_area')
    filename = 'test_flood_area_output.shp'
    with utils.WorkSpace(ws), utils.OverwriteState(True):
        floods = tidegates.flood_area(
            topo_array=topo,
            zones_array=zones,
            template=template,
            ID_column='GeoID',
            elevation_feet=5,
            filename=filename,
            cleanup=True,
            verbose=False,
        )

    nt.assert_true(isinstance(floods, arcpy.mapping.Layer))
    tgtest.assert_shapefiles_are_close(
        resource_filename('tidegates.testing.flood_area', 'known_flood_area_output.shp'),
        resource_filename('tidegates.testing.flood_area', filename)
    )

    utils.cleanup_temp_results(floods)
コード例 #2
0
def test_flood_area():
    ws = resource_filename('tidegates.testing', 'flood_area')
    with utils.WorkSpace(ws), utils.OverwriteState(True):
        filename = 'test_flood_area_output.shp'
        floods = tidegates.flood_area(
            dem='test_dem.tif',
            zones='test_zones.shp',
            ID_column='GeoID',
            elevation_feet=7.8,
            filename=filename,
            cleanup=True,
            verbose=False,
        )

    nt.assert_true(isinstance(floods, arcpy.mapping.Layer))
    tgtest.assert_shapefiles_are_close(
        resource_filename('tidegates.testing.flood_area', 'known_flood_area_output.shp'),
        resource_filename('tidegates.testing.flood_area', filename)
    )

    utils.cleanup_temp_results(floods)
コード例 #3
0
ファイル: toolbox.py プロジェクト: Geosyntec/python-tidegates
    def analyze(self, topo_array, zones_array, template,
                elev=None, surge=None, slr=None, num=0, **params):
        """ Tool-agnostic helper function for :meth:`.main_execute`.

        Parameters
        ----------
        topo_array : numpy array
            Floating point array of the digital elevation model.
        zones_array : numpy array
            Categorical (integer) array of where each non-zero value
            delineates a tidegate's zone of influence.
        template : arcpy.Raster or tidegates.utils.RasterTemplate
            A raster or raster-like object that define the spatial
            extent of the analysis area. Required attributes are:
              - templatemeanCellWidth
              - templatemeanCellHeight
              - templateextent.lowerLeft
        elev : float, optional
            Custom elevation to be analyzed
        slr : float, optional
            Sea level rise associated with the standard scenario.
        surge : str, optional
            The name of the storm surge associated with the scenario
            (e.g., MHHW, 100yr).
        **params : keyword arguments
            Keyword arguments of analysis parameters generated by
            `self._get_parameter_values`

        Returns
        -------
        floods, flooded_wetlands, flooded_buildings : arcpy.mapping.Layers
            Layers (or None) of the floods and flood-impacted wetlands
            and buildings, respectively.

        """

        # prep input
        elev, title, floods_path = self._prep_flooder_input(
            flood_output=params['flood_output'],
            elev=elev,
            surge=surge,
            slr=slr,
            num=num,
        )

        # define the scenario in the message windows
        self._show_header(title)

        # run the scenario and add its info the output attribute table
        flooded_zones = tidegates.flood_area(
            topo_array=topo_array,
            zones_array=zones_array,
            template=template,
            ID_column=params['ID_column'],
            elevation_feet=elev,
            filename=floods_path,
            num=num,
            verbose=True,
            asMessage=True
        )
        self._add_scenario_columns(flooded_zones.dataSource, elev=elev, surge=surge, slr=slr)

        # setup temporary files for impacted wetlands and buildings
        wl_path = utils.create_temp_filename(floods_path, prefix="_wetlands_", filetype='shape', num=num)
        bldg_path = utils.create_temp_filename(floods_path, prefix="_buildings_", filetype='shape', num=num)

        # asses impacts due to flooding
        fldlyr, wtlndlyr, blgdlyr = tidegates.assess_impact(
            floods_path=floods_path,
            flood_idcol=params['ID_column'],
            wetlands_path=params.get('wetlands', None),
            wetlands_output=wl_path,
            buildings_path=params.get('buildings', None),
            buildings_output=bldg_path,
            cleanup=False,
            verbose=True,
            asMessage=True,
        )

        if wtlndlyr is not None:
            self._add_scenario_columns(wtlndlyr.dataSource, elev=elev, surge=surge, slr=slr)

        return fldlyr, wtlndlyr, blgdlyr
コード例 #4
0
    def analyze(self, topo_array, zones_array, template,
                elev=None, surge=None, slr=None, **params):
        """ Tool-agnostic helper function for :meth:`.main_execute`.

        Parameters
        ----------
        topo_array : numpy array
            Floating point array of the digital elevation model.
        zones_array : numpy array
            Categorical (integer) array of where each non-zero value
            delineates a tidegate's zone of influence.
        template : arcpy.Raster or tidegates.utils.RasterTemplate
            A raster or raster-like object that define the spatial
            extent of the analysis area. Required attributes are:
              - templatemeanCellWidth
              - templatemeanCellHeight
              - templateextent.lowerLeft
        elev : float, optional
            Custom elevation to be analyzed
        slr : float, optional
            Sea level rise associated with the standard scenario.
        surge : str, optional
            The name of the storm surge associated with the scenario
            (e.g., MHHW, 100yr).
        **params : keyword arguments
            Keyword arguments of analysis parameters generated by
            `self._get_parameter_values`

        Returns
        -------
        floods, flooded_wetlands, flooded_buildings : arcpy.mapping.Layers
            Layers (or None) of the floods and flood-impacted wetlands
            and buildings, respectively.

        """

        # prep input
        elev, title, floods_path = self._prep_flooder_input(
            flood_output=params['flood_output'],
            elev=elev,
            surge=surge,
            slr=slr,
        )

        # define the scenario in the message windows
        self._show_header(title)

        # run the scenario and add its info the output attribute table
        flooded_zones = tidegates.flood_area(
            topo_array=topo_array,
            zones_array=zones_array,
            template=template,
            ID_column=params['ID_column'],
            elevation_feet=elev,
            filename=floods_path,
            verbose=True,
            asMessage=True
        )
        self._add_scenario_columns(flooded_zones.dataSource, elev=elev, surge=surge, slr=slr)

        # setup temporary files for impacted wetlands and buildings
        wl_path = utils.create_temp_filename(floods_path, prefix="_wetlands_", filetype='shape')
        bldg_path = utils.create_temp_filename(floods_path, prefix="_buildings_", filetype='shape')

        # asses impacts due to flooding
        fldlyr, wtlndlyr, blgdlyr = tidegates.assess_impact(
            floods_path=floods_path,
            flood_idcol=params['ID_column'],
            wetlands_path=params.get('wetlands', None),
            wetlands_output=wl_path,
            buildings_path=params.get('buildings', None),
            buildings_output=bldg_path,
            cleanup=False,
            verbose=True,
            asMessage=True,
        )

        if wtlndlyr is not None:
            self._add_scenario_columns(wtlndlyr.dataSource, elev=elev, surge=surge, slr=slr)

        return fldlyr, wtlndlyr, blgdlyr
コード例 #5
0
def test_flood_area():
    topo = numpy.mgrid[:8, :8].sum(axis=0) * tidegates.METERS_PER_FOOT
    zones = numpy.array([[
        -1,
        2,
        2,
        2,
        2,
        2,
        2,
        -1,
    ], [
        -1,
        2,
        2,
        2,
        -1,
        2,
        2,
        -1,
    ], [
        1,
        1,
        1,
        1,
        -1,
        2,
        2,
        -1,
    ], [
        1,
        1,
        1,
        1,
        -1,
        2,
        2,
        -1,
    ], [
        1,
        -1,
        1,
        1,
        2,
        2,
        2,
        2,
    ], [
        -1,
        -1,
        1,
        1,
        2,
        2,
        2,
        2,
    ], [
        -1,
        -1,
        -1,
        -1,
        -1,
        -1,
        -1,
        -1,
    ], [
        -1,
        -1,
        -1,
        -1,
        -1,
        -1,
        -1,
        -1,
    ]])
    template = utils.RasterTemplate(8, 4, 6)
    ws = resource_filename('tidegates.testing', 'flood_area')
    filename = 'test_flood_area_output.shp'
    with utils.WorkSpace(ws), utils.OverwriteState(True):
        floods = tidegates.flood_area(
            topo_array=topo,
            zones_array=zones,
            template=template,
            ID_column='GeoID',
            elevation_feet=5,
            filename=filename,
            cleanup=True,
            verbose=False,
        )

    nt.assert_true(isinstance(floods, arcpy.mapping.Layer))
    tgtest.assert_shapefiles_are_close(
        resource_filename('tidegates.testing.flood_area',
                          'known_flood_area_output.shp'),
        resource_filename('tidegates.testing.flood_area', filename))

    utils.cleanup_temp_results(floods)
コード例 #6
0
    def analyze(self, elev=None, surge=None, slr=None, **params):
        """ Tool-agnostic helper function for :meth:`.main_execute`.

        Parameters
        ----------
        elev : float, optional
            Custom elevation to be analyzed
        slr : float, optional
            Sea level rise associated with the standard scenario.
        surge : str, optional
            The name of the storm surge associated with the scenario
            (e.g., MHHW, 100yr).
        **params : keyword arguments
            Keyword arguments of analysis parameters generated by
            `self._get_parameter_values`

        Returns
        -------
        floods, flooded_wetlands, flooded_buildings : arcpy.mapping.Layers
            Layers (or None) of the floods and flood-impacted wetlands
            and buildings, respectively.

        """

        # prep input
        elev, title, floods_path = self._prep_flooder_input(
            flood_output=params['flood_output'],
            elev=elev,
            surge=surge,
            slr=slr,
        )

        # define the scenario in the message windows
        self._show_header(title)

        # run the scenario and add its info the output attribute table
        flooded_zones = tidegates.flood_area(
            dem=params['dem'],
            zones=params['zones'],
            ID_column=params['ID_column'],
            elevation_feet=elev,
            filename=floods_path,
            verbose=True,
            asMessage=True
        )
        self._add_scenario_columns(flooded_zones.dataSource, elev=elev, surge=surge, slr=slr)

        # setup temporary files for impacted wetlands and buildings
        wl_path = utils.create_temp_filename(floods_path, prefix="_wetlands_", filetype='shape')
        bldg_path = utils.create_temp_filename(floods_path, prefix="_buildings_", filetype='shape')

        # asses impacts due to flooding
        fldlyr, wtlndlyr, blgdlyr = tidegates.assess_impact(
            floods_path=floods_path,
            flood_idcol=params['ID_column'],
            wetlands_path=params.get('wetlands', None),
            wetlands_output=wl_path,
            buildings_path=params.get('buildings', None),
            buildings_output=bldg_path,
            cleanup=False,
            verbose=True,
            asMessage=True,
        )

        if wtlndlyr is not None:
            self._add_scenario_columns(wtlndlyr.dataSource, elev=elev, surge=surge, slr=slr)

        return fldlyr, wtlndlyr, blgdlyr