wolfhece.MulticriteriAnalysis
This module contains the objects needed to perform a multi-criteria analysis for fish passage on spatially distributed hydrodynamic data.
The module tests are located in the folder: tests/test_MulticriteriAnalysis.py file, in HECEPython repository.
Authors: Utashi Ciraane, HECE, University of Liège, Belgium.
Module Contents
- class wolfhece.MulticriteriAnalysis.Operator(*args, **kwds)[source]
Bases:
enum.Enum
Mathematical operators used in the module.
- class wolfhece.MulticriteriAnalysis.Format(*args, **kwds)[source]
Bases:
enum.Enum
Types of data formats used in the module.
- class wolfhece.MulticriteriAnalysis.Status(*args, **kwds)[source]
Bases:
enum.Enum
Status of objects in the module
- class wolfhece.MulticriteriAnalysis.Constant(*args, **kwds)[source]
Bases:
enum.Enum
This class contains the constants used throughout the module.
- class wolfhece.MulticriteriAnalysis.Variable(variable: numpy.ma.MaskedArray | numpy.ndarray | wolfhece.wolf_array.WolfArray, dtype: numpy.dtype | str = Format.FLOAT32.value)[source]
This class is used to store variable (data: array) that will be used in the multi-criteria analysis.
- The types of variable allowed are:
np.ma.MaskedArray: A numpy masked array.
np.ndarray: A numpy array.
WolfArray: A WolfArray object from the wolfhece library.
- class wolfhece.MulticriteriAnalysis.Criteria(threshold: float | int | tuple, condition: Literal[Operator, Operator, Operator, Operator, Operator, Operator, Operator, Operator] = Operator.SUPERIOR_OR_EQUAL.value)[source]
This class is used to define a criteria included in the multi-criteria analysis
- It contains a threshold and a condition:.
superior,
inferior,
equal,
superior or equal,
inferior or equal,
between,
strictly between,
outside,
strictly outside.
The condition defines how the threshold is applied to select values in the variable true (1) or False (0).
- property threshold: float[source]
Get the threshold of the criteria.
- Returns:
The threshold as a float.
- class wolfhece.MulticriteriAnalysis.Score(variable: Variable, criteria: Criteria, dtype=Format.INT32.value)[source]
This class scores a Variable based on the given criteria (threshold & condition).
The score is a np.MaskedArray with the same shape as the given variable.
The score contains boolean values indicating whether the variable meets the criteria (1) or (0). If the variable is masked, the score is also masked.
Binary notation was selected to allow mathematical operations.
- class wolfhece.MulticriteriAnalysis.Scores(scores: dict[str, Score])[source]
This class is used to store multiple scores from different criteria as dictionary.
It contains a dictionary of scores, where the keys are the score names and the values are the Score objects.
- property scores: dict[str, Score][source]
Get the scores.
- Returns:
The scores as a dictionary of Score objects.
- property number: int[source]
Get the number of scores.
- Returns:
The number of scores in the dictionary.
- add_score(name: str, score: Score) None [source]
Add a score to the scores dictionary.
- Parameters:
name – The name of the score.
score – The Score object to add.
- class wolfhece.MulticriteriAnalysis.Operations(scores: Scores, int_type: str = Format.INT32.value, float_type: str = Format.FLOAT32.value, weight: dict = None)[source]
This class is used to perform mathematical operations on scores.
N.B.: if needed operations from other libraries can be added here. for instance pymcdm, scikit-mcda, etc.
- property int_type: str[source]
Get the integer data type used in the operations.
- Returns:
The integer data type as a string.
- property float_type: str[source]
Get the float data type used in the operations.
- Returns:
The float data type as a string.
- sum() numpy.ma.MaskedArray [source]
Sum all scores in the Scores object.
- Returns:
The sum of all scores as a numpy masked array.
- product() numpy.ma.MaskedArray [source]
Calculate the product of all scores in the Scores object.
- Returns:
The product of all scores as a numpy masked array.
- weighted_sum() numpy.ma.MaskedArray [source]
Calculate the weighted sum of all scores in the Scores object.
- Returns:
The weighted sum of all scores as a numpy masked array.
- average() numpy.ma.MaskedArray [source]
Calculate the average of all scores in the Scores object.
- Returns:
The average of all scores as a numpy masked array.
- class wolfhece.MulticriteriAnalysis.Results(operations: Operations, mold: wolfhece.wolf_array.WolfArray = None, method: Literal[Operator, Operator, Operator, Operator, Operator] = Operator.SUM.value)[source]
This class is used to collect results of the Operations module.
- It allows:
to define the mold (a WolfArray) which serve as the geo-spatial extent computed results,
to define the method used to compute scores,
to get and write the results.
- property operations: Operations[source]
Get the Operations object.
- Returns:
The Operations object.
- property mold: wolfhece.wolf_array.WolfArray[source]
Get the mold used for the results.
- Returns:
The mold as a WolfArray.
- property header: wolfhece.wolf_array.header_wolf[source]
Get the header of the mold.
- Returns:
The header of the mold as a header_wolf object.
- property as_WolfArray: wolfhece.wolf_array.WolfArray[source]
Get the results as a WolfArray.
- Returns:
The results as a WolfArray.
- create_header_wolf(origx: float = None, origy: float = None, origz: float = None, dx: float = None, dy: float = None, dz: float = None, nbx: int = None, nby: int = None, nbz: int = None)[source]
Create a header_wolf object. The header_wolf object is used to describe the spatial characteristics of the array.
- Parameters:
origx – The x-coordinate of the origin (in 2D - lower left corner),
defaults to None. :type origx: float, optional :param origy: The y-coordinate of the origin (in 2D - lower left corner), defaults to None. :type origy: float, optional :param origz: The z-coordinate of the origin, defaults to None. :type origz: float, optional :param dx: The x-spacing (discretization in the x direction), defaults to None. :type dx: float, optional :param dy: The y-spacing (discretization in the x direction), defaults to None. :type dy: float, optional :param dz: The z-spacing, defaults to None. :type dz: float, optional :param nbx: The number of columns, defaults to None. :type nbx: int, optional :param nby: The number of rows, defaults to None. :type nby: int, optional :param nbz: The number of layers, defaults to None. :type nbz: int, optional :return: A header_wolf object with the given parameters. :rtype: header_wolf
- create_WolfArray(dtype=None) wolfhece.wolf_array.WolfArray [source]
Create an empty WolfArray with the given name, and header.
- Parameters:
dtype (Union[type, str]) – The data type of the WolfArray, defaults to np.float32.
- Returns:
An empty WolfArray with the given name and header.
- Return type:
- as_results(results: numpy.ma.MaskedArray, EPSG: int = 31370, dtype: type | str = None, write_to: pathlib.Path | str = None) wolfhece.wolf_array.WolfArray [source]
Write the results to a WolfArray file.
- Parameters:
output_path – The path to write the results to.
name – The name of the results file.
header – The header for the WolfArray.
dtype – The data type of the WolfArray.
- class wolfhece.MulticriteriAnalysis.Input(name: str, array: numpy.ma.MaskedArray | numpy.ndarray | wolfhece.wolf_array.WolfArray, condition: Literal[Operator, Operator, Operator, Operator, Operator] = Operator.SUPERIOR_OR_EQUAL.value, threshold: float | int = 0.0)[source]
This class stores the inputs of the MultiCriteriaAnalysis.
Also, it ensures that the inputs are valid and consistent to feed the MulticriteriAnalysis tool.
- property array: numpy.ma.MaskedArray | numpy.ndarray | wolfhece.wolf_array.WolfArray[source]
Get the array of the input.
- Returns:
The array as a numpy masked array.
- property condition: Literal[Operator, Operator, Operator, Operator, Operator][source]
Get the condition of the input.
- Returns:
The condition as a string.
- class wolfhece.MulticriteriAnalysis.MulticriteriAnalysis(inputs: list[Input] | tuple[Input] | Input, method: Literal[Operator, Operator, Operator] = Operator.PERCENTAGE.value, dtype: type | str = Format.FLOAT32.value, mold: wolfhece.wolf_array.WolfArray = None, write_to: pathlib.Path | str = None, EPSG: int = None)[source]
This class performs a multi-criteria analysis based on a set of inputs (variables and criteria).
- The inputs are:
name: The name of the variable (observations).
array: The array (matrix) containing the variable (observations).
condition: The condition (criteria) used to distinguish between good and bad variables.
Basically, the condition is used to obtain a binary score (0 or 1) for each value in the array. - Threshold: The value(s) used as limits for the condition.
- _mold: wolfhece.wolf_array.WolfArray = None[source]
- property inputs: list[Input][source]
Get the inputs of the MultiCriteriaAnalysis.
- Returns:
The inputs as a list of Input objects.
- property method: Literal[Operator, Operator, Operator][source]
Get the method used for the MultiCriteriaAnalysis.
- Returns:
The method as a string.
- property dtype: type | str[source]
Get the data type used for the MultiCriteriaAnalysis.
- Returns:
The data type as a string or a numpy dtype.
- property mold: wolfhece.wolf_array.WolfArray[source]
Get the mold used for the MultiCriteriaAnalysis.
- Returns:
The mold as a WolfArray.
- property path: pathlib.Path | str[source]
Get the path where the results will be written.
- Returns:
The path as a string or a Path object.
- property EPSG: int[source]
Get the EPSG code for the results.
- Returns:
The EPSG code as an integer.
- property scores: Scores[source]
Get the scores for each input.
- Returns:
The scores as a Scores object.
- property operations: Operations[source]
Get the operations to be performed on the scores.
- Returns:
The Operations object.
- property results: wolfhece.wolf_array.WolfArray[source]
Perform the MultiCriteria Analysis on the inputs.
- Returns:
The results of the analysis as a Results object.
- write_result() wolfhece.wolf_array.WolfArray [source]
Write the results to a WolfArray file.
- Returns:
The results as a WolfArray.