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

Inheritance diagram of wolfhece.MulticriteriAnalysis.Operator

Mathematical operators used in the module.

AVERAGE = 'average'[source]
BETWEEN = 'between'[source]
BETWEEN_STRICT = 'strictly between'[source]
EQUAL = 'equal'[source]
INFERIOR = 'inferior'[source]
INFERIOR_OR_EQUAL = 'inferior or equal'[source]
OUTSIDE = 'outside'[source]
OUTSIDE_STRICT = 'strictly outside'[source]
PERCENTAGE = 'percentage'[source]
PRODUCT = 'product'[source]
SUM = 'sum'[source]
SUPERIOR = 'superior'[source]
SUPERIOR_OR_EQUAL = 'superior or equal'[source]
THRESHOLD = 'threshold'[source]
WEIGHTED_SUM = 'weighted sum'[source]
class wolfhece.MulticriteriAnalysis.Format(*args, **kwds)[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.MulticriteriAnalysis.Format

Types of data formats used in the module.

FLOAT32[source]
FLOAT64[source]
INT32[source]
INT64[source]
class wolfhece.MulticriteriAnalysis.Status(*args, **kwds)[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.MulticriteriAnalysis.Status

Status of objects in the module

PROGRESS_BAR_DISABLE = False[source]
class wolfhece.MulticriteriAnalysis.Constant(*args, **kwds)[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.MulticriteriAnalysis.Constant

This class contains the constants used throughout the module.

EPSG = 31370[source]
ONE = 1[source]
ZERO = 0[source]
CONDITION = 'condition'[source]
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.

_variable: numpy.ma.MaskedArray = None[source]
_dtype[source]
property variable: numpy.ma.MaskedArray[source]

Return the variable.

Returns:

The variable as a numpy masked array.

property dtype: type[source]

Return the data type of the variable.

Returns:

The data type of the variable.

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).

_available_conditions[source]
_needs_tuple[source]
_criteria: dict[source]
property threshold: float[source]

Get the threshold of the criteria.

Returns:

The threshold as a float.

property condition: str[source]

Get the condition.

Returns:

The condition as a string.

property criteria: dict[source]

Return the criteria.

Returns:

The criteria as a dictionary.

_number_to_tuple(value: float | int) tuple[source]

Convert a number to a tuple of two elements.

Parameters:

value – The number to convert.

Returns:

A tuple with the number as both elements.

_tuple_to_number(value: tuple) float[source]

Convert a tuple of two elements to a number.

Parameters:

value – The tuple to convert.

Returns:

The first element of the tuple 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.

_variable = None[source]
property variable: Variable[source]

Get the variable.

Returns:

The variable as a Variable object.

_criteria = None[source]
property criteria: Criteria[source]

Get the criteria.

Returns:

The criteria as a Criteria object.

_score: numpy.ma.MaskedArray = None[source]
_dtype = None[source]
property dtype: type[source]

Get the data type of the score.

Returns:

The data type of the score.

property score: numpy.ma.MaskedArray[source]

Get the score.

Returns:

The score as a numpy masked array.

_compute_score()[source]

Compute the score based on the variable and criteria.

Returns:

The score as a numpy masked array.

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.

_scores: dict[str, Score] = None[source]
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.

get_score(name: str) Score[source]

Get a score by its name.

Parameters:

name – The name of the score to get.

Returns:

The Score object with the given name.

remove_score(name: str) None[source]

Remove a score by its name.

Parameters:

name – The name of the score to remove.

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.

_scores = None[source]
_int_type = None[source]
_float_type = None[source]
_weight = None[source]
property scores: Scores[source]

Get the Scores object.

Returns:

The Scores object.

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.

property weight: dict[source]

Get the weight dictionary.

Returns:

The weight dictionary.

_available_operations[source]
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.

percentage() numpy.ma.MaskedArray[source]

Calculate the percentage of each score in the Scores object.

Returns:

The percentage of each score as a numpy masked array.

apply_operation(operation: Literal[Operator, Operator, Operator, Operator, Operator]) numpy.ma.MaskedArray[source]

Select an operation to perform on the scores.

Parameters:

operation – The operation to perform.

Returns:

The result of the operation 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.

_operations = None[source]
_mold = None[source]
_method = None[source]
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 method: str[source]

Get the method used for the results.

Returns:

The method as a string.

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_numpy_array: numpy.ma.MaskedArray[source]
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:

WolfArray

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.

_name = None[source]
_array = None[source]
_condition = None[source]
_threshold = None[source]
_score = None[source]
property name: str[source]

Get the name of the input.

Returns:

The name of the input.

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.

property threshold: float | int[source]

Get the threshold of the input.

Returns:

The threshold as a float or an int.

property score: Score[source]

Get the score of the input.

Returns:

The score as a Score object.

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.

_inputs: list[Input] = None[source]
_method: str = None[source]
_dtype: type | str = None[source]
_mold: wolfhece.wolf_array.WolfArray = None[source]
_path: pathlib.Path | str = None[source]
_EPSG: int = 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 number_of_inputs: int[source]

Get the number of inputs.

Returns:

The number of inputs.

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.