pywatemsedem.io package

Submodules

pywatemsedem.io.folders module

class pywatemsedem.io.folders.CatchmentFolder(home_folder: Path, resolution: int)[source]

Bases: object

Data class for managing catchment folder structure.

This class defines and manages the folder structure for catchment data, including paths for vector and raster files.

Parameters:
  • home_folder (Path) – Root folder path for the catchment.

  • resolution (int) – Spatial resolution in meters, used to name the raster folder.

catchment_folder

Path to the ‘Data_Bekken’ subfolder.

Type:

Path

vct_folder

Path to the vector files folder (‘Shps’).

Type:

Path

rst_folder

Path to the raster files folder (‘Rst_{resolution}m’).

Type:

Path

check_catchment_folder(**options)[source]

Create ‘Data_bekken’ folder

check_home_folder(**options)[source]

Create home folder

check_rst_folder(**options)[source]

Create ‘Data_bekken’ folder

check_vct_folder(**options)[source]

Create home folder

create_all()[source]

Create all folders in the catchment folder structure.

home_folder: Path
resolution: int
class pywatemsedem.io.folders.ScenarioFolders(cfolder: CatchmentFolder, scenario_label: str, year: int)[source]

Bases: object

Class for keeping track of Scenario folder names

Parameters:
cfolder: CatchmentFolder
check_postprocessing(**options)[source]

Create ‘scenario_x/postprocess’ folder

check_scenario(**options)[source]

Create ‘scenario_x’ folder

check_wsinput(**options)[source]

Create ‘scenario_x/modelinput’ folder

check_wsoutput(**options)[source]

Create ‘scenario_x/modeloutput’ folder

check_years(**options)[source]

Create ‘scenario_x/year’ folder

create_all()[source]

Create all folders in the scenario folder structure.

scenario_label: str
year: int
pywatemsedem.io.folders.check_and_create_catchment_folder(home_folder, **options)[source]

Check and create home/catchment folder

Parameters:
pywatemsedem.io.folders.check_and_create_folder(folder, msg_subject='Folder', create=False, error_if_empty=False)[source]

Check and create pywatemsedem folder

Parameters:
  • folder (pathlib.Path) – Folder path of pywatemsedem folder

  • msg_subject (str) – Custom message used be to complete message

  • create (bool) – Indicate whether you want to create the folder

  • error_if_empty (bool) – See pywatemsedem.pywatemsedem.folders.error_if_folder_empty()

pywatemsedem.io.folders.check_and_create_home_folder(home_folder, **options)[source]

Check and create home folder

Parameters:
pywatemsedem.io.folders.check_and_create_postprocessing_folder(scenario_folder, **options)[source]

Check and create home/scenario_x/postprocessing folder

Parameters:
pywatemsedem.io.folders.check_and_create_rst_folder(catchment_folder, resolution, **options)[source]

Check and create home/catchment/vct folder

Parameters:
pywatemsedem.io.folders.check_and_create_scenario_folder(home_folder, scenario_label, **options)[source]

Check and create home/scenario_x folder

Parameters:
pywatemsedem.io.folders.check_and_create_vct_folder(catchment_folder, **options)[source]

Check and create home/catchment/vct folder

Parameters:
pywatemsedem.io.folders.check_and_create_vctyears_folder(vct_folder, year, **options)[source]

Check and create home/catchment/shps/year folder

Parameters:
pywatemsedem.io.folders.check_and_create_wsinput_folder(scenario_folder, **options)[source]

Check and create home/scenario_x/modelinput folder

Parameters:
pywatemsedem.io.folders.check_and_create_wsoutput_folder(scenario_folder, **options)[source]

Check and create home/scenario_x/modeloutput folder

Parameters:
pywatemsedem.io.folders.check_and_create_years_folder(scenario_folder, year, **options)[source]

Check and create home/scenario_x/year folder

Parameters:
pywatemsedem.io.folders.throw_error_if_folder_empty(folder, msg, error_if_empty)[source]

Check if pywatemsedem folder is empty

Parameters:

pywatemsedem.io.ini module

ini.py

This module contains the IniFile class, which is used to create the WaTEM/SEDEM ini-file, together with some useful functions to handle ini-files.

class pywatemsedem.io.ini.IniFile(inputfolder, outputfolder, choices)[source]

Bases: object

Create WaTEM/SEDEM ini-file

Parameters:

Examples

>>> choices = Choices(...)
>>> forced_routing = ...
>>> buffers = ...
>>> inifile = IniFile("modelinput","modeloutput",choices)
>>> inifile.add_model_information()
>>> inifile.add_working_directories()
>>> inifile.add_files()
>>> inifile.add_parameters()
>>> inifile.add_options()
>>> inifile.add_output()
>>> inifile.add_extensions(buffers, forced_routing, river_underground)
>>> inifile.write("modelinput/ini_file.ini")
add_clay_content_extension()[source]

Add clay content estimation extension to config file

add_cn_extension()[source]

Add CN-extension and its extension parameters/files to config file

add_dams_extensions()[source]

add dams extension to config file

add_ditches_extension()[source]

Add ditches extension to config file

add_extensions(buffers, forced_routing, river_underground)[source]

Add section parameters and parameters extensions to config file

Parameters:
  • buffers (pandas.DataFrame) –

    Holding buffer properties, with columns,

    • buffercap (float): Volume

    • hdam (float): Height dam

    • hknijp^ (float): Height opening

    • dknijp (float): Opening area

    • qcoef (float): Discharge coefficient

    • boverl (float): Width dam

    • eff (float): Trapping efficiency

    • BUF_EXID (float): Extension ID

    • BUF_ID (float): Buffer id

  • forced_routing (pandas.DataFrame) –

    Forced routing table with columns, see here

    • NR (int):

    • from col (int): source pixel column

    • from row (int): source pixel row

    • target col (int): target pixel column

    • target row (int): target pixel row

  • river_underground (pandas.DataFrame) –

    River underground routing table with columns, see here

    • NR (int):

    • from col (int): source pixel column

    • from row (int): source pixel row

    • target col (int): target pixel column

    • target row (int): target pixel row

add_files()[source]

Add all Files to config file

add_force_routing_extension(forced_routing, river_underground)[source]

Add force routing extension and force routing parameters to config file

Parameters:
  • forced_routing (pandas.DataFrame) –

    Forced routing table with columns, see here

    • NR (int):

    • from col (int): source pixel column

    • from row (int): source pixel row

    • target col (int): target pixel column

    • target row (int): target pixel row

  • river_underground (pandas.DataFrame) –

    River underground routing table with columns, see here

    • NR (int):

    • from col (int): source pixel column

    • from row (int): source pixel row

    • target col (int): target pixel column

    • target row (int): target pixel row

add_include_buffer_extension(buffers)[source]

Add buffer extension and buffer parameters to config file

Parameters:

buffers (pandas.DataFrame) –

Holding buffer properties, with columns,

  • buffercap (float): Volume

  • hdam (float): Height dam

  • hknijp^ (float): Height opening

  • dknijp (float): Opening area

  • qcoef (float): Discharge coefficient

  • boverl (float): Width dam

  • eff (float): Trapping efficiency

  • BUF_EXID (float): Extension ID

  • BUF_ID (float): Buffer id

add_ktc_and_calibration_extensions()[source]

Add create ktc map and calibration extensions and their extension parameters to config file

add_ktil_extension()[source]

Add create ktil map extension and its extension parameters to config file

add_manual_outlet_extension()[source]

Add manual outlet selection extension to config file

add_model_information()[source]

Add section model information to config file

add_options()[source]

Adds specified model options to the configuration.

add_output()[source]

Add outputs to config file

add_parameters()[source]

Add parameters to config file

add_river_routing_extension()[source]

Add river routing extension to config file and the needed files for this extension

add_river_segment_output_extension()[source]

Add output per river segment extension to config file

add_sections()[source]

Adding all watem-sedem sections to the config file

add_sewer_extension()[source]

Add sewer extension to config file

add_working_directories()[source]

Add section working directory to config file

write(ini)[source]

Write ini file to disk

pywatemsedem.io.ini.add_field(ini, section, key, value)[source]

Add one specific key in ini-file

Loads, writes value to key (in section) and closes file

Parameters:
  • ini (pathlib.Path) – File name

  • section (str) – Section name, i.e. Model information, Working directories, Files, User Choices, Output , Variables, Calibration, Buffer $id and Forced Routing $id.

  • key (str) – Key

  • value (str) – New value

pywatemsedem.io.ini.get_item_from_ini(ini, section, option, dtype)[source]

Gets an item from an option in a certain section of an ini-file

Parameters:
  • ini (pathlib.Path) – File path of the ini-file

  • section (str) – Name of the desired section

  • option (str) – Name of the desired option

  • dtype (dtype) – Type of parameter to be read (str, int, float or bool). If another string is given to this parameter, a TypeError is raised.

Returns:

Settings value of ini-file. If the option or section does not exist in the ini-file or the value of the section-option None is returned.

Return type:

str or int or float or bool or None

pywatemsedem.io.ini.get_options_from_ini(ini, section)[source]

Gets all options from a certain section of an ini-file

Parameters:
  • ini (pathlib.Path) – File path of the ini-file

  • section (str) – Name of the desired section

Returns:

list with all options present in the section of the ini-file

Return type:

list

pywatemsedem.io.ini.get_sections_from_ini(ini)[source]

Gets all sections from an ini-file

Parameters:

ini (pathlib.Path) – File path of the ini-file

Returns:

list with all sections present in the ini-file

Return type:

list

pywatemsedem.io.ini.modify_field(ini, section, key, value)[source]

Add one specific key in ini-file

Loads, writes value to key (in section) and closes file

Parameters:
  • ini (pathlib.Path) – File name

  • section (str) – Section name, i.e. Model information, Working directories, Files, User Choices, Output , Variables, Calibration, Buffer $id and Forced Routing $id.

  • key (str) – Key

  • new_value (str) – New value

  • ini_updated (pathlib.Path, default None) – New file to write to

pywatemsedem.io.ini.open_ini(ini)[source]

Open ini file.

Parameters:

ini (pathlib.Path or str)

Returns:

content

Return type:

list

pywatemsedem.io.modelinput module

class pywatemsedem.io.modelinput.Modelinput(ini, resolution, epsg, nodata)[source]

Bases: Factory

Raster class with model inputs as attributes.

Modelinput class serves the goal of automating the reading in, checking and visualisation of the input data of the WaTEM/SEDEM model.

mask

Catchment mask raster or polygon.

Type:

pathlib.Path or str

rivermask

River mask raster.

Type:

pathlib.Path or str

cfactor

C-factor raster.

Type:

pathlib.Path or str

buffers

Buffers raster.

Type:

pathlib.Path or str

dtm

Digital terrain model raster.

Type:

pathlib.Path or str

kfactor

K-factor raster.

Type:

pathlib.Path or str

ktc

kTC raster.

Type:

pathlib.Path or str

outlet

Outlet raster.

Type:

pathlib.Path or str

pfactor

P-factor raster.

Type:

pathlib.Path or str

compositelanduse

Composite landuse raster.

Type:

pathlib.Path or str

ptef

Parcel trapping efficiency raster.

Type:

pathlib.Path or str

riversegments

River segments raster.

Type:

pathlib.Path or str

riverrouting

River routing raster.

Type:

pathlib.Path or str

sewers

Sewers raster.

Type:

pathlib.Path or str

upstream_segments

Upstream segments table.

Type:

pathlib.Path or str

adjacent_segments

Adjacent segments table.

Type:

pathlib.Path or str

ktil

kTil raster.

Type:

pathlib.Path or str

tillagedirection

Tillage direction raster.

Type:

pathlib.Path or str

orientedroughness

Oriented roughness raster.

Type:

pathlib.Path or str

ditches

Ditches raster.

Type:

pathlib.Path or str

dams

Dams raster.

Type:

pathlib.Path or str

cn

Curve number raster.

Type:

pathlib.Path or str

rainfall

Rainfall table.

Type:

pathlib.Path or str

property adjacent_segments

Return the adjacent_segments table.

For documentation, see here

property buffers

Return the buffers raster.

For documentation, see here

property cfactor

Return the C-factor raster.

For documentation, see here

property cn

Return the CN raster.

For documentation, see here

property compositelanduse

Return the compositelanduse raster.

For documentation, see here

property dams

Return the dams raster.

For documentation, see here

property ditches

Return the ditches raster.

For documentation, see here

property dtm

Return the DTM raster.

For documentation, see here

property kfactor

Return the K-factor raster.

For documentation, see here

property ktc

Return the kTC raster.

For documentation, see here

property ktil

Return the ktil raster.

For documentation, see here

property mask

Return mask raster.

property orientedroughness

Return the orientedroughness raster.

For documentation, see here

property outlet

Return the outlet raster.

For documentation, see here

property pfactor

Return the P-factor raster.

For documentation, see here

property ptef

Return the PTEF raster.

For documentation, see here

property rainfall

Return the rainfall table.

For documentation, see here

property rivermask

Return the river mask raster. Not an actual input of the model, but a raster that can be derived from the river segments raster, useful for visualisation purposes.

property riverrouting

Return the riverrouting raster.

For documentation, see here

property riversegments

Return the riversegments raster.

For documentation, see here

property sewers

Return the sewers raster.

For documentation, see here

property tillagedirection

Return the tillagedirection raster.

For documentation, see here

property upstream_segments

Return the upstream_segments table.

For documentation, see here

pywatemsedem.io.modeloutput module

class pywatemsedem.io.modeloutput.Modeloutput(ini, resolution, epsg, nodata)[source]

Bases: Factory

Class with model outputs as attributes.

Modeloutput class serves the goal of automating the reading in, checking and visualisation of the output data of the WaTEM/SEDEM model.

aspect

Aspect raster.

Type:

pathlib.Path or str

routing

Routing table.

Type:

pathlib.Path or str

routing_missing

Routing missing table.

Type:

pathlib.Path or str

ls

LS-factor raster.

Type:

pathlib.Path or str

slope

Slope raster.

Type:

pathlib.Path or str

uparea

Upstream area raster.

Type:

pathlib.Path or str

total_sediment

Total sediment table.

Type:

pathlib.Path or str

total_sediment_segments

Total sediment per segment table.

Type:

pathlib.Path or str

cumulative_sediment_segments

Cumulative sediment per segment table.

Type:

pathlib.Path or str

sewer_in

Sewer in raster.

Type:

pathlib.Path or str

sedi_export

Sediment export raster.

Type:

pathlib.Path or str

sedi_in

Sediment in raster.

Type:

pathlib.Path or str

sedi_out

Sediment out raster.

Type:

pathlib.Path or str

sedtil_in

Tillage sediment in raster.

Type:

pathlib.Path or str

sedtil_out

Tillage sediment out raster.

Type:

pathlib.Path or str

cumulative

Cumulative sediment raster.

Type:

pathlib.Path or str

watereros_kg

Water erosion raster (kg).

Type:

pathlib.Path or str

watereros_mm

Water erosion raster (mm).

Type:

pathlib.Path or str

tileros_kg

Tillage erosion raster (kg).

Type:

pathlib.Path or str

tileros_mm

Tillage erosion raster (mm).

Type:

pathlib.Path or str

capacity

Capacity raster.

Type:

pathlib.Path or str

rusle

RUSLE raster.

Type:

pathlib.Path or str

property aspect

Return the aspect raster.

For documentation, see here

property capacity

Return the capacity raster.

For documentation, see here

property cumulative

Return the cumulative raster.

For documentation, see here

property cumulative_sediment_segments

Return the cumulative_sediment_segments table.

For documentation, see here. For explanation on column variables of dataframe: see pywatemsedem.io.modeloutput.load_cumulative_sediment_segments_file().

property ls

Return the LS raster.

For documentation, see here

make_routing_vector(modelinput, percentile=90, routing_missing=False)[source]

Converts pandas dataframe of routing or routing_missing to a geopandas dataframe

Parameters:
  • modelinput (Object) – instance of Modelinput class (see pywatemsedem/io/modelinput.py)

  • percentile (int, default = 90) – Only vectors belonging to sedi_outdata percentile and higher is kept

  • routing_missing (bool, default = False) – set to True to apply function to routing_missing instead of routing

Return type:

geopandas.GeoDataFrame

property routing

Return the routing table.

For documentation, see here

property routing_missing

Return the routing_missing table.

For documentation, see here

property rusle

Return the RUSLE raster.

For documentation, see here

property sedi_export

Return the sedi_export raster.

For documentation, see here

property sedi_in

Return the sedi_in raster.

For documentation, see here

property sedi_out

Return the sedi_out raster.

For documentation, see here

property sedtil_in

Return the sedtil_in raster.

For documentation, see here

property sedtil_out

Return the sedtil_out raster.

For documentation, see here

property sewer_in

Return the sewer_in raster.

For documentation, see here

property slope

Return the slope raster.

For documentation, see here

property tileros_kg

Return the tileros_kg raster.

For documentation, see here

property tileros_mm

Return the tileros_mm raster.

For documentation, see here

property total_sediment

Return the total_sediment table.

For documentation, see here. For explanation on column variables of dataframe: see pywatemsedem.io.modeloutput.load_total_sediment_file().

property total_sediment_segments

Return the total_sediment_segments table.

For documentation, see here. For explanation on column variables of dataframe: see pywatemsedem.io.modeloutput.load_total_sediment_segments_file().

property uparea

Return the uparea raster.

For documentation, see here

property watereros_kg

Return the watereros_kg raster.

For documentation, see here

property watereros_mm

Return the watereros_mm raster.

For documentation, see here

pywatemsedem.io.modeloutput.check_segment_edges(adj_edges, up_edges, arr)[source]

Check river segment their edges. All the segments present in adj_edges and up_edges must be present in the array from the segments raster.

Parameters:
Returns:

  • adj_edges (pandas.DataFrame) – Filtered

  • up_edges (pandas.DataFrame) – Filtered

  • filt (bool) – Flag indicating filtering of dataframes

pywatemsedem.io.modeloutput.compute_cumulative_loads_in_sinks(df_sedi_export, profile, threshold, delta=10, plot=False)[source]

Analyse cumulative sediment load by sorting sedi_export values from high to low

Parameters:
  • df_sedi_export (pandas.DataFrame) – Data Frame format of sedi_export raster (format: see pywatemsedem.pywatemsedem.utils.raster_array_to_pandas_dataframe())

  • profile (rasterio.profiles) – See rasterio.open()

  • threshold (int) – x percentage highest load that the user wants to analyse

  • delta (int) – Delta used to iterate percentage

  • plot (bool, default False) – True if you want a cumulative sedi_export plot

Returns:

  • df_sedi_export (pandas.DataFrame) – Data Frame format of sedi_export raster (format: see pywatemsedem.pywatemsedem.utils.raster_array_to_pandas_dataframe()) added with:

    • cum_perc (float): cumulative highest load

    • perc (float): percentage highest load

    • class (int): class as defined by delta_perc

  • percentage (str) – updated percentage

pywatemsedem.io.modeloutput.compute_efficiency_buffers(rst_buffer, rst_sedi_in, rst_sedi_out)[source]

Compute efficiency per buffer

This function calculates the incoming and outgoing sediment per buffer. The deposition is computed by substracting the outgoing from the ingoing sediment.

Parameters:
  • rst_buffer (str or pathlib.Path | str) – File path of buffer raster with buffer id’s

  • rst_sedi_in (str or ppathlib.Path | str) – File path of WaTEM/SEDEM sedi_in raster, incoming sediment per pixel

  • rst_sedi_out (str or pathlib.Path | str) – File path of WaTEM/SEDEM sedi_out raster, outgoing sediment per pixel

Returns:

df_output – Holding results of mass balance of buffers.

  • buf_id (float): id of the buffer (as in the buffer raster)

  • sedi_in (float): total incoming sediment in the buffer.

  • sedi_out (float): total outgoing sediment in the buffer.

  • buff_sed (float): amount sediment deposited in the buffer.

Return type:

pandas.DataFrame

pywatemsedem.io.modeloutput.condition_routing_dataframe_on_extent(df_routing, rstparams, extent)[source]

Clip routing_dataframe on defined extent

Parameters:
Returns:

df_routing – See pywatemsedem.io.modeloutput.open_txt_routing_file()

Return type:

pandas.DataFrame

pywatemsedem.io.modeloutput.create_deposition_raster(rst_watereros)[source]

Create deposition raster from watereros.

Extract positve values from Watereros raster and set negatives to 0

Parameters:

rst_watereros (str or pathlib.Path | str) – File path to WaTEM/SEDEM watereros raster.

Returns:

rst_deposition – File path to pywatemsedem erosion raster.

Return type:

pathlib.Path | str

pywatemsedem.io.modeloutput.create_erosion_raster(rst_watereros)[source]

Create erosion raster from watereros.

Extract negative values from Watereros raster and set positives to 0. Erosion values in this raster are positive (inverse of watereros)

Parameters:

rst_watereros (str or pathlib.Path | str) – File path to WaTEM/SEDEM watereros raster.

Returns:

rst_erosion – File path to pywatemsedem erosion raster.

Return type:

pathlib.Path | str

pywatemsedem.io.modeloutput.create_id_raster_for_highest_value_arr(arr, id_, profile, resmap)[source]

Create a raster with an id value assigned to the highest value in the raster”

Parameters:
  • arr (str or pathlib.Path | str) – with floats

  • id (int) – Sequential number of the catchment

  • profile (rasterio profile) – Rasterio profile of the sedout raster

  • resmap (str or pathlib.Path | str, optional) – Folder path to write results to

Returns:

  • rst_id (str) – File path of the raster with id for highest value in raster

  • val (float) – Maximum value in raster

pywatemsedem.io.modeloutput.define_subcatchments_saga(rst_in, txt_routing, resmap, rasterprop, tag='')[source]

Define subcatchment for several points defined with a unique id in the raster

Parameters:
  • rst_in – Raster with single-pixels for which subcatchment should be determined > 0: determine subcatchment = 0: don’t determine subcatchments

  • txt_routing_nonriver (str or pathlib.Path | str) – File path of the WaTEM/SEDEMrouting table

  • resmap (str or pathlib.Path | str) – Folder path where results should be saved

  • rasterprop (dict) – rasterio profile dictionary holding all metadata for geotiff rasters

  • tag (str or pathlib.Path | str) – File path of output shape and raster

  • catchment_name (str) – Name of catchment, default “”

  • scenario_label (str, default "") – Scenario number or letter.

Returns:

  • rst_subcatchments (str or pathlib.Path | str) – File path of raster with pixels beloging to a subcatchment having id equal to id sink in rst_in

  • vct_subcatchments (str or pathlib.Path | str:) – File path of shapefile with polygon being the subcatchment having an id equal to id sink in rst_in

pywatemsedem.io.modeloutput.get_prckrt_statistics(rst_prckrt, unit='ha', resolution=20)[source]

Get the statistics of the WaTEM/SEDEM perceelskaart

Load the WaTEM/SEDEM perceelskaart and compute for every unique id the area (ha or m2).

Parameters:
  • rst_prckrt (str or pathlib.Path | str) – File path ofWaTEM/SEDEM perceelskaart

  • unit (str) – The unit of the output, currently pixel, m2 and ha implemented

  • resolution (int) – Resolution of the rasters

Returns:

out

Area for each class, keys:

  • agriculture (float): area (ha/m2)

  • river (float): area (ha/m2)

  • infrastructure (float): area (ha/m2)

  • forest (float): area (ha/m2)

  • meadow (float): area (ha/m2)

  • open_water (float): area (ha/m2)

  • gras_strip (float): area (ha/m2)

Return type:

dict,

pywatemsedem.io.modeloutput.identify_individual_priority_catchments(arr_sedi_out, rst_profile, txt_routing_non_river, nmax, resmap=PosixPath('/home/runner/work/pywatemsedem/pywatemsedem'), epsg='')[source]

identify the individual priority catchments and add them to a raster and shapes dictionary

Parameters:
  • arr_sedi_out (numpy.ndarray) – numpy array format of sedout raster

  • rst_profile (rasterio profile) – rasterio profile of the sedout raster

  • txt_routing_nonriver (str or pathlib.Path | str) – File path of the WaTEM/SEDEM routing table

  • nmax (int) – maximum number of catchment

Returns:

subcatchmentpriority – catchment shapes with number of catchment

Return type:

geopandas.GeoDataFrame

pywatemsedem.io.modeloutput.identify_rank_sediment_loads(rst_sedi_export, threshold, rst_out, rst_endpoints=None)[source]

Identify the highest threshold percentage sediment loads.

This functions identifies the cumulative distribution of the sedi_export (and sewer_in, optional) raster:

  • (optional) map sewer_in raster to sedi_export raster

  • convert sedi_export raster to a list-format

  • sort from high to low

  • compute cumulative distribution

  • classify

Parameters:
Returns:

pywatemsedem.io.modeloutput.load_sediment_segments_file(txt_sediment_segments_file)[source]

Load the WaTEM/SEDEM total/cumulative sediment per segment file.

Parameters:

txt_sediment_segments_file (str or pathlib.Path) – Path to the text file containing sediment values for each segment.

Returns:

DataFrame containing the sediment data per segment. The table contains:

  • first column: segment identifiers (integer)

  • second column: sediment values associated with each segment (float)

Return type:

pandas.DataFrame

pywatemsedem.io.modeloutput.load_total_sediment_file(txt_total_sediment_file)[source]

Load the total sediment file of WaTEM/SEDEM written in WaTEM/SEDEM dict_output map

Parameters:

txt_total_sediment_file (str or pathlib.Path | str) – File Path of the sediment file

Returns:

dict_output – The dict_output sediment data dictionary contains the following data:

  • erosion (float): total amount of erosion (kg)

  • deposition (float): total amount of deposition (kg)

  • river (float): total amount of sediment run-off to the river (kg)

  • outside_domain (float): total amount of sediment run-off out of the catchment (kg)

  • buffers (float): total amount of sediment trapped in buffers (kg)

  • endpoints (float): total sewer of sediment trapped in sewers and ditches (kg)

Return type:

dict

pywatemsedem.io.modeloutput.make_routing_vct_saga(txt_routing, rst_prckrt, vct_out, rstparams, extent=None, tile_number=None)[source]

Generate a routing vct routing file (added with WaTEM/SEDEM landuse) based on the routing table extent and tilenumber are defined to make a routing file only for a certain extent

Parameters:
  • txt_routing (str or pathlib.Path | str) – File path of the WaTEM/SEDEM routing tabl

  • rst_prckrt (str) – name of WaTEM/SEDEM input ‘perceelskaart’

  • vct_out – name of the shape outputfile

  • rstparams (dict) – gdal dictionary holding all metadata for idrisi rasters

  • extent (list, default None) – list holding value of extent to consider, xmin,ymin,xmax,ymax

  • tile_number (int, optional, default None) – number of the tile, used to add to filename

Returns:

vct_out – The resulting vector file will contain following features:

  • col (int): source column number.

  • row (int): source row number.

  • targetcol (int): target column number.

  • targetcol (int): source column number.

  • part (float): fraction of source that flows to target (between 0 and 1).

  • distance (float): distance of routing (m)

  • landuSource (int): landuse code of source pixel

  • landuTarg (int): landuse code of target pixel

  • jump (int): yes (1) or no (0)

  • targetX (float): x coor value of target

  • targetY (float): y coor value of target

  • sourceX (float): x coor value of source

  • sourceY (float): y coor value of source

Return type:

str

pywatemsedem.io.modeloutput.map_rank_sediment_loads(rst_sedi_export, threshold, vct_out='rank.shp', rst_endpoints=None, unit='kg')[source]

Rank the sediment loads in sedi_export (and sewer_in) from high to low

This function uses the rank output raster/dataframe of pywatemsedem.io.modeloutput.identify_rank_sediment_loads() to map a vector point file with information on rank, sediment output.

For computation details, see pywatemsedem.io.modeloutput.identify_rank_sediment_loads()

Parameters:

Note

Only points are taken into account that account for x of the highest sediment loads. x is determined by threshold.

pywatemsedem.io.modeloutput.open_txt_routing_file(txt_routing)[source]

Open routing file with exceptions and separators as needed.

Parameters:

txt_routing (str or pathlib.Path) – File path of the WaTEM/SEDEM routing table.

Returns:

df_routing – The routing DataFrame contains the following columns:

  • col (int): source column in rasters

  • row (int): source row in rasters

  • target1col (int): first target column in rasters

  • target1row (int): first target row in rasters

  • part1 (float): Part that flows to target1

  • distance1 (float): Distance of 1st vector

  • target2col (int): second target column in rasters

  • target2row (int): second target row in rasters

  • part2 (float): Part that flows to target2

  • distance2 (float): Distance of 2nd vector

Return type:

pandas.DataFrame

pywatemsedem.io.modeloutput.prepare_make_routing_vct_saga(txt_routing, vct_out, separator, rstparams, extent, tile_number)[source]

Prepare the input files for make routing vct_saga If an extension is defined, then this function will clip the file to this rectangular geographical extent

Parameters:
  • txt_routing_nonriver (str or pathlib.Path | str) – File path of the WaTEM/SEDEM routing table.

  • vct_out (str) – Name of output shapefile for ‘run_saga_make_routing_shp_cmd’ function.

  • separator (str) – Current delimiter of txt_routing.

  • rstparams (dict) – gdal dictionary holding all metadata for idrisi rasters.

  • extent (list) – min and max of rectangular frame to clip df [xmin, xmax, ymin, ymax].

  • tile_number (int) – number of tile

Returns:

  • vct_temp (str) – The resulting vector file will contain following features:

    • col (int): source column number.

    • row (int): source row number.

    • targetcol (int): target column number.

    • targetcol (int): source column number.

    • part (float): fraction of source that flows to target (between 0 and 1).

    • distance (float): distance of routing (m)

    • landuSource (int): landuse code of source pixel

    • landuTarg (int): landuse code of target pixel

    • jump (int): yes (1) or no (0)

    • targetX (float): x coor value of target

    • targetY (float): y coor value of target

    • sourceX (float): x coor value of source

    • sourceY (float): y coor value of source

  • condition (boolean) – True if make_routing_shp has to be run

pywatemsedem.io.modeloutput.remove_river_routing(df_routing)[source]

Remove river routing from routing dataframe

Parameters:

df_routing (pandas.DataFrame) – Long format of routing table

Returns:

Long format of routing table, with river routing removed

Return type:

df_routing

pywatemsedem.io.modeloutput.run_saga_make_routing_shp_cmd(txt_routing, rst_prckrt, vct_out)[source]

Run the saga make routing shape command. This command makes from a pywatemsedem routing table and a pywatemsedem ‘perceelskaart’ a routing shapfile representation.

The resulting vector file will contain following features:

  • col (int): source column number.

  • row (int): source row number.

  • targetcol (int): target column number.

  • targetcol (int): source column number.

  • part (float): fraction of source that flows to target (between 0 and 1).

  • distance (float): distance of routing (m)

  • landuSource (int): landuse code of source pixel

  • landuTarg (int): landuse code of target pixel

  • jump (int): yes (1) or no (0)

  • targetX (float): x coor value of target

  • targetY (float): y coor value of target

  • sourceX (float): x coor value of source

  • sourceY (float): y coor value of source

Parameters:
  • txt_routing_nonriver (str or pathlib.Path | str) – File path of the WaTEM/SEDEM routing table

  • rst_prckrt (str) – File path of the WaTEM/SEDEM ‘perceelskaart’ raster

  • vct_out (str) – File path of the output file

pywatemsedem.io.modeloutput.verify_highest_load_with_threshold(df_sedi_export, threshold)[source]

Verify whether that the highest load is not accountable for more than 50 percent of all the load in a catchment. If this is true, adapt threshold.

Parameters:
Returns:

threshold_ – Adapted threshold (depending on if-else clause).

Return type:

float

pywatemsedem.io.plots module

pywatemsedem.io.plots.axes_creator(fig, ax)[source]

Creates fig and ax object if none ar given

Parameters:
Returns:

  • fig (matplotlib.figure.Figure)

  • ax (matplotlib.pyplot.axis)

pywatemsedem.io.plots.log_scale_enabler(arr, cnorm)[source]

Checks if log scale is supplied. If minimum is lower or equal to zero, changes lower bound to smallest value above zero.

Parameters:
Returns:

lower – lower value for colorscale

Return type:

float

pywatemsedem.io.plots.normalising_function(mini, Q25, Q50, Q75, maxi)[source]

Custom normalisation function for maptlotlib plotting

Parameters:
  • mini – minimum of the colorscale

  • Q25 – 25th percentile

  • Q50 – 50th percentile

  • Q75 – 75th percentile

  • maxi – maximum of the colorscale

Returns:

norm

Return type:

matplotlib.colors.Normalize

pywatemsedem.io.plots.plot_continuous_raster(fig, ax, arr, bounds, cmap='cividis', norm=None, colorbar=True, ticks=None, *args, **kwargs)[source]
Parameters:
Returns:

  • fig (matplotlib.figure.Figure)

  • ax (matplotlib.pyplot.axis)

pywatemsedem.io.plots.plot_cumulative_sedimentload(df, fname)[source]

Make a cumulative plot of the ordered sediment load values (high to low)

Parameters:
  • df (pandas.DataFrame) – Data with cumulative sediment load - value (float): sediment load value - cum_perc (float): cumulative percentage - rank (float): rank

  • fname (str or pathlib Path) – File path of output figure

pywatemsedem.io.plots.plot_discrete_raster(fig, ax, arr, bounds, labels, cmap='cividis', norm=None, *args, **kwargs)[source]
Parameters:
Returns:

  • fig (matplotlib.figure.Figure)

  • ax (matplotlib.pyplot.axis)

pywatemsedem.io.plots.plot_landuse(arr, nodata, *args, **kwargs)[source]

Plot landuse maps with standardized colors for the different classes

Parameters:
  • arr (numpy array) – the landuse raster

  • nodata (int) – the nodata value

pywatemsedem.io.plots.plot_output_raster(fig, ax, arr, mask, bounds, title='none', ticks=None, *args, **kwargs)[source]

Standard non-linear continuous raster plot for output raster

Parameters:
Returns:

  • fig (matplotlib.figure.Figure)

  • ax (matplotlib.pyplot.axis)

pywatemsedem.io.valid module

pywatemsedem.io.valid.valid_array_type(arr, required_type)[source]

Checks if arr is 1) a numpy.dtype 2) the desired numpy.dtype

Parameters:
Return type:

True

pywatemsedem.io.valid.valid_boundaries(arr, lower=None, upper=None, tolerance=None)[source]

Checks if values are within specified boundaries.

Parameters:
  • arr (numpy.ndarray) – Input array.

  • lower (int or float, default None) – Lower boundary.

  • upper (int or float, default None) – Upper boundary.

  • tolerance (float, default None) –

    Allowed tolerance outside the boundaries.

    Example: - upper=10, tolerance=0.5 -> values up to 10.5 allowed - lower=0, tolerance=0.5 -> values down to -0.5 allowed

Returns:

True if all values are within allowed boundaries.

Return type:

bool

pywatemsedem.io.valid.valid_nodata(arr, nodata_value=-9999)[source]

Checks if a nodata value is present in arr

Parameters:
  • arr (numpy.ndarray) – Input array

  • nodata_value (int, default -9999) – Value to be interpreted as no data present

Return type:

True

pywatemsedem.io.valid.valid_non_nan(arr)[source]

Checks if Nan are present in the array

Parameters:

arr (numpy.ndarray) – Input array

Return type:

True

pywatemsedem.io.valid.valid_values(arr, unique_values)[source]

Checks if values in an array are within the set of unique values

The input array can only have the input values defined in unique_values.

Parameters:
  • arr (numpy.ndarray) – Input array

  • unique_values (list) – Unique values that the raster can have

Return type:

True

Module contents