src.flood_model.flooded_buildings

Functions

store_flooded_buildings_in_database(→ None)

Appends the details of which buildings are flooded for a given flood_model_id to the database

find_flooded_buildings(→ pandas.DataFrame)

Creates a building DataFrame with attribute "is_flooded",

categorise_buildings_as_flooded(→ geopandas.GeoDataFrame)

Identifies all buildings in building_polygons that intersect with areas in flooded_polygons.

retrieve_building_outlines(→ geopandas.GeoDataFrame)

Retrieve building outlines for an area of interest from the database

polygonize_flooded_area(→ geopandas.GeoDataFrame)

Takes a flood depth raster and applies depth thresholding on it so that only areas

Module Contents

src.flood_model.flooded_buildings.store_flooded_buildings_in_database(engine: sqlalchemy.engine.Engine, buildings: pandas.DataFrame, flood_model_id: int) None

Appends the details of which buildings are flooded for a given flood_model_id to the database

Parameters:
  • engine (Engine) – The sqlalchemy database connection engine

  • buildings (pd.DataFrame) – DataFrame containing a mapping of building_ids to their flood status for the current model run

  • flood_model_id (float) – The id of the current flood model run, to associate with the building flood data.

Returns:

This function does not return anything

Return type:

None

src.flood_model.flooded_buildings.find_flooded_buildings(engine: sqlalchemy.engine.Engine, area_of_interest: geopandas.GeoDataFrame, flood_model_output_path: pathlib.Path, flood_depth_threshold: float) pandas.DataFrame

Creates a building DataFrame with attribute “is_flooded”, depending on if the area for each building is flooded to a depth greater than or equal to flood_depth_threshold. the index, building_outline_id, matches building_outline_id from nz_building_outline table.

Parameters:
  • engine (Engine) – The sqlalchemy database connection engine

  • area_of_interest (gpd.GeoDataFrame) – A GeoDataFrame with a polygon specifying the area to get buildings for.

  • flood_model_output_path (pathlib.Path) – Path to the flood model output file to be read.

  • flood_depth_threshold (float) – The minimum depth required to designate a pixel in the raster as flooded.

Returns:

A pd.DataFrame specifying if each building is flooded or not.

Return type:

pd.DataFrame

src.flood_model.flooded_buildings.categorise_buildings_as_flooded(building_polygons: geopandas.GeoDataFrame, flood_polygons: geopandas.GeoDataFrame) geopandas.GeoDataFrame

Identifies all buildings in building_polygons that intersect with areas in flooded_polygons.

Parameters:
  • building_polygons (gpd.GeoDataFrame) – A GeoDataFrame with each polygon representing a building outline

  • flood_polygons (gpd.GeoDataFrame) – A GeoDataFrame with each polygon representing a flooded area

Returns:

A copy of building_polygons with an additional boolean attribute “is_flooded”

Return type:

gpd.GeoDataFrame

src.flood_model.flooded_buildings.retrieve_building_outlines(engine: sqlalchemy.engine.Engine, area_of_interest: geopandas.GeoDataFrame) geopandas.GeoDataFrame

Retrieve building outlines for an area of interest from the database

Parameters:
  • engine (Engine) – The sqlalchemy database connection engine

  • area_of_interest (gpd.GeoDataFrame) – A GeoDataFrame polygon specifying the area of interest to retrieve buildings in.

Returns:

A GeoDataFrame containing all of the building outlines in the area

Return type:

gpd.GeoDataFrame

src.flood_model.flooded_buildings.polygonize_flooded_area(flood_raster: xarray.DataArray, flood_depth_threshold: float) geopandas.GeoDataFrame

Takes a flood depth raster and applies depth thresholding on it so that only areas flooded deeper than or equal to flood_depth_threshold are represented. Returns the data in a collection of polygons

Parameters:
  • flood_raster (xarray.DataArray) – Raster with each pixel representing flood depth at the point

  • flood_depth_threshold (float) – The minimum depth specified to consider a pixel in the raster flooded

Returns:

A GeoDataFrame containing polygons of the flooded areas

Return type:

gpd.GeoDataFrame