wolfhece.pypolygons_scen

Author: HECE - University of Liege, Pierre Archambeau 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

class wolfhece.pypolygons_scen.ZipFileWrapper(file, mode='r', compression=ZIP_STORED, allowZip64=True, compresslevel=None, *, strict_timestamps=True)[source]

Bases: zipfile.ZipFile

Inheritance diagram of wolfhece.pypolygons_scen.ZipFileWrapper

Class with methods to open, read, write, close, list zip files.

z = ZipFile(file, mode=”r”, compression=ZIP_STORED, allowZip64=True,

compresslevel=None)

file: Either the path to the file, or a file-like object.

If it is a path, the file will be opened and closed by ZipFile.

mode: The mode can be either read ‘r’, write ‘w’, exclusive create ‘x’,

or append ‘a’.

compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),

ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).

allowZip64: if True ZipFile will create files with ZIP64 extensions when

needed, otherwise it will raise an exception when this would be necessary.

compresslevel: None (default for the given compression type) or an integer

specifying the level to pass to the compressor. When using ZIP_STORED or ZIP_LZMA this keyword has no effect. When using ZIP_DEFLATED integers 0 through 9 are accepted. When using ZIP_BZIP2 integers 1 through 9 are accepted.

open(name='data', mode='r', pwd=None, **kwargs)[source]

Return file-like object for ‘name’.

name is a string for the file name within the ZIP file, or a ZipInfo object.

mode should be ‘r’ to read a file already in the ZIP file, or ‘w’ to write to a file newly added to the archive.

pwd is the password to decrypt files (only used for reading).

When writing, if the file size is not known in advance but may exceed 2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large files. If the size is known in advance, it is best to pass a ZipInfo instance for name, with zinfo.file_size set.

read()[source]

Return file bytes for name.

class wolfhece.pypolygons_scen.Extracting_Zones(filename='', ox: float = 0, oy: float = 0, tx: float = 0, ty: float = 0, parent=None, is2D=True, idx: str = '', plotted: bool = True, mapviewer=None, need_for_wx: bool = False)[source]

Bases: wolfhece.PyVertexvectors.Zones

Inheritance diagram of wolfhece.pypolygons_scen.Extracting_Zones

Classe permettant de récupérer les valeurs à l’intérieur des polygones définis dans plusieurs zones.

Ces polygones ne sont pas nécessairement ordonnés ou relatifs au lit mineur.

cache_data(outputfile: str)[source]

Serialize the values in a file

load_data(inputfile: str)[source]

Deserialize the values from a file

_serialize_values(outputfile: str)[source]

Serialize the values in a file

_deserialize_values(inputfile: str)[source]

Deserialize the values from a file

find_values_inside_parts(linked_arrays)[source]

Récupère les valeurs à l’intérieur de la zone

Retour :
  • dictionnaire dont la clé est le nom (ou l’index) du polygone dans la zone –> parties centrale, amont ou aval

  • chaque entrée est un dictionnaire dont la clé ‘values’ contient un dictionnaire pour chaque matrice du projet

  • chaque élément de ce sous-dictionnaire est un tuple contenant toutes les valeurs utiles

* ATTENTION : si linked_arrays est un dictionnaire, alors un niveau supérieur est ajouté sur base des clés de ce dictionnaire, dans ce cas, self.linked est un dict et non une liste *

_get_heads(which_vec: str, which_group=None)[source]

Compute Head

get_values(which_vec: str, which_value: wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_pos | wolfhece.pybridges.stored_values_coords, which_group=None) dict[source]

Get values for a specific part

La donnée retournée est un dictionnaire –> dépend du typage de “self.linked” (cf “find_values_inside_parts)” pour plus d’infos)

Soit il n’y a qu’un projet à traiter –> le dictionnaire reprend les différentes valeurs pour chaque matrice/simulation du projet Soit il y a plusiuers projets à traiter –> le dictionnaire contient autant d’entrées que de projet et chaque sous-dictionnaire reprend les différentes valeurs pour chaque matrice/simulation du projet

get_values_op(which_vec: str, which_value: wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_pos | wolfhece.pybridges.stored_values_coords, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN) dict[source]
class wolfhece.pypolygons_scen.Polygons_Analyze(myfile='', ds: float = 5.0, ox: float = 0, oy: float = 0, tx: float = 0, ty: float = 0, parent=None, is2D=True, wx_exists: bool = False)[source]

Bases: wolfhece.PyVertexvectors.Zones

Inheritance diagram of wolfhece.pypolygons_scen.Polygons_Analyze

Classe permettant de récupérer les valeurs à l’intérieur des polygones définis dans la dernière zone d’une fichier .vecz.

Ce fichier est typiquement le résultat de la création de polygones sur base de parallèles via l’interface graphique.

Utile notamment dans l’analyse de modélisations 2D (CPU et/ou GPU).

cache_data(outputfile: str)[source]

Serialize the values in a json file – zipped

load_data(inputfile: str)[source]

Deserialize the values from a json file – zipped

_serialize_values(outputfile: str)[source]

Serialize the values in a file

_deserialize_values(inputfile: str)[source]

Deserialize the values from a file

compute_distance(poly: shapely.geometry.LineString | wolfhece.PyVertexvectors.vector)[source]

Compute the curvilinear distance along a support polyline

Parameters:

poly – vector or LineString Shapely object

find_values_inside_parts(linked_arrays: dict | list)[source]

Récupère les valeurs à l’intérieur des polygones - dernière zone du fichier

Stockage :
  • dictionnaire dont la clé est le nom (ou l’index) du polygone dans la zone

  • chaque entrée est un dictionnaire dont la clé ‘values’ contient un dictionnaire pour chaque matrice du projet

  • chaque élément de ce sous-dictionnaire est un tuple contenant toutes les valeurs utiles

* ATTENTION : si linked_arrays est un dictionnaire, alors un niveau supérieur est ajouté sur base des clés de ce dictionnaire, dans ce cas, self.linked est un dict et non une liste *

_get_river_heads(which_group=None)[source]

Compute Head

Parameters:

which_group – group to get

get_river_values(which_value: wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_pos | wolfhece.pybridges.stored_values_coords, which_group=None) dict[source]

Get values for the river polygons

La donnée retournée est un dictionnaire –> dépend du typage de “self.linked” (cf “find_values_inside_parts)” pour plus d’infos)

Soit il n’y a qu’un projet à traiter –> le dictionnaire contient une entrée pour chaque polygone et

les différentes valeurs pour chaque matrice/simulation du projet dans chaque polygone

Soit il y a plusiuers projets à traiter –> le dictionnaire contient autant d’entrées que de projet et

chaque sous-dictionnaire reprend les différentes valeurs comme ci-dessus

Parameters:
  • which_value – value to get

  • which_group – group to get

get_river_values_op(which_value: wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_pos | wolfhece.pybridges.stored_values_coords, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN) dict[source]

Get values for the river polygons with an operator

Parameters:
  • which_value – value to get

  • which_group – group to get

  • operator – MEDIAN, MIN, MAX, PERCENTILE95, PERCENTILE5, ALL

list_groups()[source]

List the groups of the river polygons

list_sims(which_group=None)[source]

List the sims for a specific group or for all the groups of the river polygons

get_s_values(which_value: wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_pos | wolfhece.pybridges.stored_values_coords = stored_values_unk.WATERLEVEL, which_group: str = None, which_sim: str = None, operator: wolfhece.pybridges.operators = operators.MEDIAN)[source]

Get the values of the river polygons for a specific simulation

Parameters:
  • which_value – value to get

  • which_group – group to get

  • which_sim – simulation to get

  • operator – operator to use

get_s_xy()[source]

Get the centroids of the river polygons

get_s_xy4sim(which_group: str, which_sim: str, operator: wolfhece.pybridges.operators = operators.MEDIAN)[source]

Get the position for a specific simulation

save_xy_s_tofile(outputfile: str)[source]

Save the centroids of the river polygons to a file

save_xy_s_tofile_4sim(outputfile: str, which_group: str, which_sim: str)[source]

Save the centroids of the river polygons to a file

export_as(outputfile: pathlib.Path, unks: list[wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_coords], which_group: str, which_sim: str, operator: wolfhece.pybridges.operators = operators.MEDIAN)[source]

Export the values of the river polygons to a file

Parameters:
  • outputfile – output file (supported formats: csv, xlsx)

  • unks – list of values to export

  • which_group – group to export

  • which_sim – simulation to export

  • operator – operator to use for values (coordinates will be exported as MEDIAN)

plot_unk(figax=None, which_value: wolfhece.pybridges.stored_values_unk | wolfhece.pybridges.stored_values_pos = stored_values_unk.WATERLEVEL, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN, options: dict = None, label=True, show=False)[source]

Plot the values of the river polygons

Parameters:
  • figax – tuple (fig, ax) for the plot

  • which_value – value to plot

  • which_group – group to plot

  • operator – operator to use

  • options – options for the plot

  • label – show the labels or not

  • show – show the plot or not

plot_waterline(figax=None, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN, show=False)[source]

Plot the waterline

Parameters:
  • figax – tuple (fig, ax) for the plot

  • which_group – group to plot

  • operator – operator to use

  • show – show the plot or not

plot_bedelevation(figax=None, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN, show=False)[source]

Plot the bed elevation

Parameters:
  • figax – tuple (fig, ax) for the plot

  • which_group – group to plot

  • operator – operator to use

  • show – show the plot or not

plot_stage(figax=None, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN, show=False)[source]

Plot the water stage /water level

Parameters:
  • figax – tuple (fig, ax) for the plot

  • which_group – group to plot

  • operator – operator to use

  • show – show the plot or not

plot_waterhead(figax=None, which_group=None, operator: wolfhece.pybridges.operators = operators.MEDIAN, show=False)[source]

Plot the water head

Parameters:
  • figax – tuple (fig, ax) for the plot

  • which_group – group to plot

  • operator – operator to use

  • show – show the plot or not