wolfhece.acceptability.func

Author: University of Liege, HECE, LEMA Date: 2024

Copyright (c) 2024 University of Liege. All rights reserved.

This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited.

Module Contents

wolfhece.acceptability.func.ENGINE = 'pyogrio'[source]
wolfhece.acceptability.func.EXTENT = '.gpkg'[source]
class wolfhece.acceptability.func.Modif_Type[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.acceptability.func.Modif_Type

Enum class for the type of modification

WALOUS = 'Walous layers changed to PICC buidings'[source]
POINT2POLY_EPURATION = 'Change BDREF based on AJOUT_PDET sent by Perrine (SPI)'[source]
POINT2POLY_PICC = 'Convert the points to polygons based on PICC'[source]
POINT2POLY_CAPAPICC = 'Convert the points to polygons based on PICC and CaPa'[source]
INHABITED = 'Select only inhabited buildings'[source]
ROAD = 'Create a buffer around the roads'[source]
COPY = 'Copy the data'[source]
class wolfhece.acceptability.func.Vulnerability_csv(file: pathlib.Path)[source]
get_layers() list[source]
get_vulnerability_level(layer: str) str[source]
get_vulnerability_code(layer: str) str[source]
wolfhece.acceptability.func.get_data_type(fname: pathlib.Path)[source]
wolfhece.acceptability.func.cleaning_directory(dir: pathlib.Path)[source]

Cleaning the directory

class wolfhece.acceptability.func.Accept_Manager(main_dir: str = 'Data', Study_area: str = 'Bassin_Vesdre.shp', scenario=None, Original_gdb: str = 'GT_Resilence_dataRisques202010.gdb', CaPa_Walloon: str = 'Cadastre_Walloon.gpkg', PICC_Walloon: str = 'PICC_vDIFF.gdb', CE_IGN_top10v: str = 'CE_IGN_TOP10V/CE_IGN_TOP10V.shp', EPU_Stations: str = 'AJOUT_PDET_EPU_DG03_STATIONS.shp', Ponderation_csv: str = 'Ponderation.csv', Vuln_csv: str = 'Vulnerability.csv', Intermediate_csv: str = 'Intermediate.csv')[source]

Structure to store the directories and names of the files.

In the main directory, the following directories are mandatory/created:
  • INPUT : filled by the user - contains the input data

  • TEMP : created by the script - contains the temporary data for the study area

  • OUTPUT: created by the script - contains the output data for each scenario of the study area

The INPUT directory contains the following subdirectories:
  • DATABASE: contains the data for the entire Walloon region
    • Cadastre_Walloon.gpkg: the Cadastre Walloon file

    • GT_Resilence_dataRisques202010.gdb: the original gdb file from SPW - GT Resilience

    • PICC-vDIFF.gdb: the PICC Walloon file

    • CE_IGN_TOP10V: the IGN top10v shapefile

  • EPU_STATIONS_NEW:
    • AJOUT_PDET_EPU_DG03_STATIONS.shp: the EPU stations shapefile

  • STUDY_AREA: contains the study area shapefiles - one for each study area - e.g. Bassin_Vesdre.shp

  • CSVs: contains the CSV files
    • Intermediate.csv: contains the matrices data for the acceptability computation

    # - Ponderation.csv: contains the ponderation data for the acceptability computation - Vulnerability.csv: contains the mapping between layers and vulnerability levels - a code value is also provided

  • WATER_DEPTH: contains the water depth data for each scenario
    • Study_area1:
      • Scenario1

      • Scenario2

      -… - ScenarioN

    • Study_area2:
      • Scenario1

      • Scenario2

      -… - ScenarioN

    -… - Study_areaN:

    • Scenario1

    • Scenario2

    -… - ScenarioN

The TEMP directory contains the following subdirectories:
  • DATABASES: contains the temporary data each study area
    • Study_area1:
      • database.gpkg: the clipped database

      • CaPa.gpkg: the clipped Cadastre Walloon file

      • PICC.gpkg: the clipped PICC Walloon file

      • CE_IGN_TOP10V.tiff: the IGN top10v raster file

      • Maske_River_extent.tiff: the river extent raster file from IGN

      • VULNERABILITY: the vulnerability data
        • RASTERS:
          • Code : one file for each layer

          • Vulne : one file for each layer

        • Scenario1:

property is_valid_inputs: bool[source]
property is_valid_study_area: bool[source]
property is_valid_vulnerability_csv: bool[source]
property is_valid_points_csv: bool[source]
property is_valid_ponderation_csv: bool[source]
create_paths()[source]

Create the paths for the directories and files

create_paths_scenario()[source]
check_files() str[source]

Check the files in the directories

change_studyarea(Study_area: str = None) None[source]
change_scenario(scenario: str) None[source]
get_files_in_rm_buildings() list[pathlib.Path][source]
get_files_in_rasters_vulne() list[pathlib.Path][source]
get_layers_in_gdb() list[str][source]
get_layer_types_in_gdb() list[str][source]
get_layers_in_clipgdb() list[str][source]
get_layers_in_wmodif() list[str][source]
get_layers_in_codevulne() list[str][source]
get_files_in_rasters_code() list[pathlib.Path][source]
get_q_files() list[pathlib.Path][source]
get_list_scenarios() list[str][source]
get_list_studyareas(with_suffix: bool = False) list[str][source]
get_sims_files_for_scenario() list[pathlib.Path][source]
get_sim_file_for_return_period(return_period: int) pathlib.Path[source]
get_types_in_file(file: str) list[str][source]

Get the types of the geometries in the Shape file

is_type_unique(file: str) bool[source]

Check if the file contains only one type of geometry

is_polygons(set2test: set) bool[source]

Check if the set contains only polygons

is_same_types(file: str) tuple[bool, str][source]

Check if the file contains only the same type of geometry

get_return_periods() list[int][source]

Get the return periods from the simulations

Return list[int]:

the sorted list of return periods

get_ponderations() pandas.DataFrame[source]

Get the ponderation data from available simulations

get_filepath_for_return_period(return_period: int) pathlib.Path[source]
change_dir() None[source]
restore_dir() None[source]
check_inputs() bool[source]

Check if the input directories exist.

Inputs can not be created automatically. The user must provide them.

check_temporary() bool[source]

Check if the temporary directories exist.

If not, create them.

check_outputs() bool[source]

Check if the output directories exist.

If not, create them.

check_before_database_creation() bool[source]

Check if the necessary files are present before the database creation

check_before_rasterize() bool[source]
check_before_vulnerability() bool[source]
check_vuln_code_sa() bool[source]
check_vuln_code_scenario() bool[source]
compare_original_clipped_layers() str[source]

Compare the original layers with the clipped ones

compare_clipped_raster_layers() str[source]

Compare the clipped layers with the rasterized ones

get_operand(file: str) Modif_Type[source]

Get the operand based on the layer name

check_origin_shape() list[str][source]
wolfhece.acceptability.func.clip_layer(layer: str, file_path: str, Study_Area: str, output_dir: str)[source]

Clip the input data based on the selected bassin and saves it in separate shape files.

As shape file doen not support DateTime, the columns with DateTime are converted to string.

Parameters:
  • layer – the layer name in the GDB file

  • file_path – the path to the GDB file

  • Study_Area – the path to the study area shapefile

  • output_dir – the path to the output directory

wolfhece.acceptability.func.data_modification(layer: str, manager: Accept_Manager, picc: geopandas.GeoDataFrame, capa: geopandas.GeoDataFrame)[source]

Apply the data modifications as described in the LEMA report

FIXME : Add more doc in this docstring

Parameters:
  • input_database – the path to the input database

  • layer – the layer name in the database

  • output_database – the path to the output database

  • picc – the PICC Walloon file – Preloaded

  • capa – the Cadastre Walloon file – Preloaded

wolfhece.acceptability.func.compute_vulnerability(manager: Accept_Manager)[source]

Compute the vulnerability for the Study Area

This function will not modify the data by the removed buildings/scenarios.

Parameters:

dirsnames – the Dirs_Names object from the calling function

wolfhece.acceptability.func.compute_code(manager: Accept_Manager)[source]

Compute the code for the Study Area

This function will not modify the data by the removed buildings/scenarios.

Parameters:

dirsnames – the Dirs_Names object from the calling function

wolfhece.acceptability.func.compute_vulnerability4scenario(manager: Accept_Manager)[source]

Compute the vulnerability for the scenario

This function will modify the data by the removed buildings/scenarios.

FIXME: It could be interseting to permit the user to provide tiff files for the removed buildings and other scenarios.

Parameters:

dirsnames – the Dirs_Names object from the calling function

wolfhece.acceptability.func.match_vulnerability2sim(inRas: pathlib.Path, outRas: pathlib.Path, MODREC: pathlib.Path)[source]

Clip the raster to the MODREC/simulation extent

Parameters:
  • inRas – the input raster file

  • outRas – the output raster file

  • MODREC – the MODREC/simulation extent file

wolfhece.acceptability.func.update_accept(accept, model_h, ij, bounds, loc_accept)[source]
wolfhece.acceptability.func.compute_acceptability(manager: Accept_Manager, model_h: numpy.ndarray, vulnerability: numpy.ndarray, interval: int, geo_projection: tuple, save_to_file: bool = True) numpy.ndarray[source]
Compute the local acceptability based on :
  • the vulnerability

  • the water depth

  • the matrices

Parameters:
  • manager – the Accept_Manager object from the calling function

  • model_h – the water depth matrix

  • vulnerability – the vulnerability matrix

  • interval – the return period

  • geo_projection – the geotransform and the projection - tuple extracted from another raster file

wolfhece.acceptability.func.shp_to_raster(vector_fn: str, raster_fn: str, pixel_size: float = 1.0, manager: Accept_Manager = None)[source]

Convert a vector layer to a raster tiff file.

The raster will contain only 2 values : 0 and 1

  • 1 : the inside of the vector layer

  • 0 : the rest == NoData/NullValue

Parameters:
  • vector_fn – the path to the vector file

  • raster_fn – the path to the raster file

  • pixel_size – the pixel size of the raster

wolfhece.acceptability.func.vector_to_raster(layer: str, manager: Accept_Manager, attribute: str, pixel_size: float, convert_to_sparse: bool = True)[source]

Convert a vector layer to a raster tiff file

FIXME: Test de vulerability value and return immedialty if it is 1 if attribute == “Vulne”

Parameters:
  • layer – the layer name in the GDB file

  • vector_input – the path to the vector file

  • extent – the path to the extent file

  • attribute – the attribute to rasterize

  • pixel_size – the pixel size of the raster

wolfhece.acceptability.func.convert_to_csr(i_indices, j_indices, num_rows)[source]