wolfhece.wolf_array._selection_data

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

wolfhece.wolf_array._selection_data.ALL_SELECTED = 'all'[source]
class wolfhece.wolf_array._selection_data.StorageMode(*args, **kwds)[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.wolf_array._selection_data.StorageMode

Storage mode for selections in WolfArray

LIST = 0[source]
ARRAY = 1[source]
class wolfhece.wolf_array._selection_data.SelectionData(parent: wolfhece.wolf_array._base.WolfArrayModel, threshold_array_mode: int = 100000)[source]

User-selected data in a WolfArray

Contains two storage elements :
  • myselection

  • selections( dict): Stored selection(s) to be used, for example, in a spatial interpolation operation.

    These selections are only lost in the event of a general reset.

The selected nodes are stored using their “world” spatial coordinates so that they can be easily transferred to other objects.

The “myselection” can be stored in two modes :
  • LIST: ‘all’ or list of (x, y) coordinates or tuple of (‘all’, np.ndarray) for all nodes and excluded nodes

  • ARRAY: np.ndarray of selected nodes (boolean array) with shape (nbx, nby) where nbx and nby are the number of nodes in the x and y directions respectively.

The boolean array is True if the node is selected, False if not selected.

The selection can be converted from one mode to another automatically based on the number of nodes in the array. If the number of nodes exceeds a threshold (default is 100,000), the selection is stored as an ARRAY. Otherwise, it is stored as a LIST.

The selection can be forced to a specific storage mode using the force_storage_mode method.

_myselection: list[tuple[float, float]] | str | tuple[str, numpy.ndarray][source]
selections: dict[str:dict['select':list[tuple[float, float]], 'idgllist':int, 'color':list[float]]][source]
parent: wolfhece.wolf_array._base.WolfArrayModel[source]
wx_exists[source]
_boolarray: numpy.ndarray | None = None[source]
_storage_mode[source]
update_plot_selection = False[source]
hideselection = False[source]
numlist_select = 0[source]
threshold_array_mode = 100000[source]
_auto_storage_mode()[source]

Choose the storage mode based on the number of nodes in the array

_convert_to_storage_mode(new_mode: StorageMode)[source]

Convert the selection to the new storage mode.

Parameters:

new_mode – The new storage mode to convert to (StorageMode.LIST or StorageMode.ARRAY).

force_storage_mode(new_mode: StorageMode)[source]

Force the storage mode to the new mode.

Parameters:

new_mode – The new storage mode to force (StorageMode.LIST or StorageMode.ARRAY).

property myselection: list[tuple[float, float]] | str[source]

Current selection of nodes.

Returns:

  • ‘all’ if all nodes are selected

  • list of (x, y) coordinates if specific nodes are selected

property _myselection_as_array: numpy.ndarray[source]

Current selection of nodes as a numpy array.

Returns:

  • np.ndarray of shape (nbx, nby) where nbx and nby are the number of nodes in the x and y directions respectively.

  • True if the node is selected, False if not selected.

property myselection_npargwhere: numpy.ndarray[source]

Current selection of nodes as a numpy array using np.argwhere

is_all_selected() bool[source]

Check if all nodes are selected.

Returns:

True if all nodes are selected, False otherwise

set_selection_from_list_xy(xylist: list[tuple[float, float]])[source]

Set the current selection from a list of (x, y) coordinates.

Alias for myselection setter to set a list of (x, y) coordinates. This will convert the list to the appropriate storage mode if necessary.

property dx: float[source]

Resolution in x

property dy: float[source]

Resolution in y

property nb: int[source]

Number of selected nodes.

unmask_selection(resetplot: bool = True)[source]

Unmask selection

reset()[source]

Reset the selection

reset_all()[source]

Reset the selection

get_string(which: str = None, all_memories: bool = False) str[source]

Get string of the current selection or of a stored one.

Parameters:
  • which – id/key of the selection to get the string for. If None, get the current selection.

  • all_memories – If True, include all stored selections in the output string.

Returns:

String representation of the selection.

get_script(which: int = None) str[source]

Get script of the current selection or of a stored one.

Parameters:

which – id/key of the selection to get the script for. If None, get the current selection.

Returns:

Script representation of the selection.

copy_to_clipboard(which: int = None, typestr: Literal['string', 'script'] = 'string')[source]

Copy current selection to clipboard.

– ONLY WORKS WITH wxPython –

Parameters:
  • which – id/key of the selection to copy. If None, copy the current selection.

  • typestr – Type of data to copy to clipboard - ‘string’ for string representation, ‘script’ for script representation.

reselect_from_memory(idx: list[str] = None)[source]

Reselect a stored selection

Parameters:

idx – id/key of the selection to reselect. If None, show a dialog to choose from available selections.

move_selectionto(idx: str, color: list[float], resetplot: bool = True)[source]

Transfer current selection to dictionary

Parameters:
  • idx – id/key of the selection

  • color – color of the selection - list of 4 integers between 0 and 255

  • resetplot – if True, reset the plot after moving the selection

plot_selection()[source]

Plot current selection and stored selections

_plot_selection(curlist: list[float], color: list[float], loclist: int = 0)[source]

Plot a selection

Parameters:
  • curlist – list of selected nodes – list of tuples (x,y)

  • color – color of the selection - list of 3 floats between 0 and 1

  • loclist – index of OpenGL list

add_node_to_selection(x: float, y: float, verif: bool = True)[source]

Add one coordinate to the selection

Parameters:
  • x – x coordinate - float

  • y – y coordinate - float

  • verif – if True, the coordinates are checked to avoid duplicates

add_nodes_to_selection(xy: list[float] | numpy.ndarray, verif: bool = True)[source]

Add multiple coordinates to the selection.

Parameters:
  • xy – list of coordinates or numpy array of shape (nb_nodes, 2) where nb_nodes is the number of nodes or a numpy array of shape (nbx, nby) where nbx and nby are the number of nodes in the x and y directions respectively. If a numpy array of shape (nbx, nby) is provided, it is assumed to be a boolean array where True indicates a selected node.

  • verif – if True, the coordinates are checked to avoid duplicates

_add_node_to_selectionij(i: int, j: int, verif=True)[source]

Add one ij coordinate to the selection.

Parameters:
  • i – i coordinate

  • j – j coordinate

  • verif – if True, the coordinates are checked to avoid duplicates

_add_nodes_to_selectionij(ij: list[tuple[float, float]], verif: bool = True)[source]

Add multiple ij coordinates to the selection

Parameters:
  • ij – list of ij coordinates

  • verif – if True, the coordinates are checked to avoid duplicates

_add_nodes_to_selection_np(ij: numpy.ndarray, verif: bool = True)[source]

Add multiple coordinates to the selection from a numpy array

Parameters:
  • ij – numpy array of coordinates - same shape as the parent array (nbx, nby) or (nb_nodes, 2)

  • verif – if True, the coordinates are checked to avoid duplicates

select_insidepoly(myvect: wolfhece.PyVertexvectors.vector)[source]

Select nodes inside a polygon.

Parameters:

myvect – vector defining the polygon

select_underpoly(myvect: wolfhece.PyVertexvectors.vector)[source]

Select nodes along a polyline

Parameters:

myvect – vector defining the polyline

dilate_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None)[source]

Extend the selection.

Parameters:
  • nb_iterations – Number of iterations to dilate the selection

  • use_mask – If True, use the mask of the parent array to limit the dilation

  • structure – Structuring element for dilation, default is a cross shape (nodes directly adjacent in the x or y direction)

erode_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None)[source]

Reduce the selection.

Parameters:
  • nb_iterations – Number of iterations to erode the selection

  • use_mask – If True, use the mask of the parent array to limit the erosion

  • structure – Structuring element for erosion, default is a cross shape (nodes directly adjacent in the x or y direction)

dilate_contour_selection(nbiter: int = 1, use_mask: bool = True, structure: numpy.ndarray = np.ones((3, 3)))[source]

Dilate the contour of the selection.

Parameters:
  • nbiter – Number of iterations to dilate the selection

  • use_mask – If True, use the mask of the parent array to limit the dilation

  • structure – Structuring element for dilation, default is a 3x3 square

erode_contour_selection()[source]

Erode the contour of the selection.

Parameters:
  • nbiter – Number of iterations to erode the selection

  • use_mask – If True, use the mask of the parent array to limit the erosion

  • structure – Structuring element for erosion, default is a 3x3 square

save_selection(filename: str = None)[source]

Save the selection to a file.

Parameters:

filename – Name of the file to save the selection to. If None, a dialog will be shown to choose the file.

load_selection(filename: str = None)[source]

Load a selection from a file.

Parameters:

filename – Name of the file to load the selection from. If None, a dialog will be shown to choose the file.

update_nb_nodes_selection(autostoragemode: bool = True) tuple[int, float, float, float, float][source]

Update the number of selected nodes.

Parameters:

autostoragemode – If True, automatically switch to ARRAY mode if the number of selected nodes exceeds the threshold.

Returns:

Tuple containing the number of selected nodes, and the bounds of the selection (xmin, xmax, ymin, ymax).

condition_select(cond: str | int, condval, condval2=0, usemask: bool = False)[source]

Select nodes based on a condition.

Parameters:
  • cond – condition to apply (0: ‘<’, 1: ‘<=’, 2: ‘==’, 3: ‘>=’, 4: ‘>’, 5: ‘NaN’, 6: ‘>=<=’, 7: ‘><’, 8: ‘<>’)

  • condval – value to compare with

  • condval2 – second value to compare with (for ranges)

  • usemask – whether to use the mask or not

treat_select(op: int, cond: int, opval, condval)[source]

Apply an operation on the selected nodes based on a condition.

Parameters:
  • op – operation to apply (0: ‘+’, 1: ‘-’, 2: ‘*’, 3: ‘/’, 4: ‘replace’)

  • cond – condition to apply (0: ‘<’, 1: ‘<=’, 2: ‘==’, 3: ‘>=’, 4: ‘>’, 5: ‘NaN’)

  • opval – value to apply the operation with

  • condval – value to compare with

refresh_parantarray()[source]

Refresh the parent array after a selection

mask_condition(op: int, cond: int, opval, condval)[source]

Mask nodes based on a condition.

Parameters:
  • op – operation to apply (0: ‘+’, 1: ‘-’, 2: ‘*’, 3: ‘/’, 4: ‘replace’)

  • cond – condition to apply (0: ‘<’, 1: ‘<=’, 2: ‘==’, 3: ‘>=’, 4: ‘>’, 5: ‘NaN’)

  • opval – value to apply the operation with

  • condval – value to compare with

get_values_sel() numpy.ndarray[source]

Get the values of the selected nodes.

Returns:

numpy array of values of the selected nodes, or -99999 if all nodes are selected.

_get_header() wolfhece.wolf_array._header_wolf.header_wolf | None[source]

Header corresponding to the selection

get_newarray() wolfhece.wolf_array._base.WolfArrayModel[source]

Create a new array from the selection.

Returns:

a new WolfArray object containing the selected nodes, or None if the selection is empty. Null values are set to -99999.

If all nodes are selected, returns a WolfArray molded from the parent.

select_all()[source]

Select all nodes.

It will set the selection to ALL_SELECTED, which is a special value indicating that all nodes are selected.

interp2Dpolygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all')[source]

Interpolation sous tous les polygones d’une zone cf parent.interp2Dpolygon

Useful for WX GUI, where the method is chosen by the user. From script, you can call this method directly from the parent array with the desired method and keep parameters.

interp2Dpolygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all')[source]

Interpolation sous un polygone cf parent.interp2Dpolygon

Useful for WX GUI, where the method is chosen by the user. From script, you can call this method directly from the parent array with the desired method and keep parameters.

interp2Dpolylines(working_zone: wolfhece.PyVertexvectors.zone, resetplot: bool = True)[source]

Interpolation sous toutes les polylignes de la zone cf parent.interp2Dpolyline

Useful for WX GUI, where the method is chosen by the user. From script, you can call this method directly from the parent array with the desired method and keep parameters.

interp2Dpolyline(working_vector: wolfhece.PyVertexvectors.vector, resetplot: bool = True)[source]

Interpolation sous la polyligne active cf parent.interp2Dpolyline

Useful for WX GUI, where the method is chosen by the user. From script, you can call this method directly from the parent array with the desired method and keep parameters.

copy(source: SelectionData)[source]

Copy the selection data from another SelectionData object.

Parameters:

source – another SelectionData object to copy from.

volumesurface(show=True)[source]

Evaluation of stage-storage-surface relation from “volume_estimation” routine of the WolfArray.

If the selection is empty, it will use the whole array. If the selection is ALL_SELECTED, it will use the whole array. If the selection is not empty, it will use the selected nodes only – see “get_newarray” routine.

If the parent array is linked to a MapViewer, it will apply the same operation to all linked active arrays.

Parameters:

show – if True, the figure will be shown.

class wolfhece.wolf_array._selection_data.SelectionDataMB(parent: wolfhece.wolf_array._mb.WolfArrayMB)[source]

Bases: SelectionData

Inheritance diagram of wolfhece.wolf_array._selection_data.SelectionDataMB

Extension of SelectionData to manage multiple blocks.

All routines are not implemented yet, as they depend on the specificities of the blocks.

For the rest, it is mainly a simple wrapper around the SelectionData of each block.

parent: wolfhece.wolf_array._mb.WolfArrayMB[source]
property nb[source]

Number of selected nodes.

unmask_selection()[source]

Unmask selection

reset()[source]

Reset the selection

select_all()[source]

Select all nodes.

It will set the selection to ALL_SELECTED, which is a special value indicating that all nodes are selected.

reset_all()[source]

Reset the selection

get_string(which: str = None) str[source]

Get string of the current selection or of a stored one.

Parameters:
  • which – id/key of the selection to get the string for. If None, get the current selection.

  • all_memories – If True, include all stored selections in the output string.

Returns:

String representation of the selection.

save_selection(filename: str = None, which: str = None)[source]

Save the selection to a file.

Parameters:

filename – Name of the file to save the selection to. If None, a dialog will be shown to choose the file.

load_selection(filename: str = None, which: str = None)[source]

Load a selection from a file.

Parameters:

filename – Name of the file to load the selection from. If None, a dialog will be shown to choose the file.

get_script(which: int = None) str[source]

Get script of the current selection or of a stored one.

Parameters:

which – id/key of the selection to get the script for. If None, get the current selection.

Returns:

Script representation of the selection.

get_newarray()[source]

Create a new array from the selection.

Returns:

a new WolfArray object containing the selected nodes, or None if the selection is empty. Null values are set to -99999.

If all nodes are selected, returns a WolfArray molded from the parent.

add_node_to_selection(x: float, y: float, verif: bool = True)[source]

Add a node to the selection

add_nodes_to_selection(xy: list[float] | numpy.ndarray, verif: bool = True)[source]

Add nodes to the selection

select_insidepoly(myvect: wolfhece.PyVertexvectors.vector)[source]

Select nodes inside a polygon.

Parameters:

myvect – vector defining the polygon

select_underpoly(myvect: wolfhece.PyVertexvectors.vector)[source]

Select nodes along a polyline

Parameters:

myvect – vector defining the polyline

dilate_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None)[source]

Extend the selection

erode_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None)[source]

Reduce the selection

update_nb_nodes_selection()[source]

Update the number of nodes selected

condition_select(cond, condval, condval2=0, usemask=False)[source]

Select nodes based on a condition.

Parameters:
  • cond – condition to apply (0: ‘<’, 1: ‘<=’, 2: ‘==’, 3: ‘>=’, 4: ‘>’, 5: ‘NaN’, 6: ‘>=<=’, 7: ‘><’, 8: ‘<>’)

  • condval – value to compare with

  • condval2 – second value to compare with (for ranges)

  • usemask – whether to use the mask or not

treat_select(op, cond, opval, condval)[source]

Apply an operation on the selected nodes based on a condition.

Parameters:
  • op – operation to apply (0: ‘+’, 1: ‘-’, 2: ‘*’, 3: ‘/’, 4: ‘replace’)

  • cond – condition to apply (0: ‘<’, 1: ‘<=’, 2: ‘==’, 3: ‘>=’, 4: ‘>’, 5: ‘NaN’)

  • opval – value to apply the operation with

  • condval – value to compare with

mask_condition(op, cond, opval, condval)[source]

Mask nodes based on a condition.

Parameters:
  • op – operation to apply (0: ‘+’, 1: ‘-’, 2: ‘*’, 3: ‘/’, 4: ‘replace’)

  • cond – condition to apply (0: ‘<’, 1: ‘<=’, 2: ‘==’, 3: ‘>=’, 4: ‘>’, 5: ‘NaN’)

  • opval – value to apply the operation with

  • condval – value to compare with

plot_selection()[source]

Plot current selection and stored selections

move_selectionto(idx: str, color: list[float])[source]

Transfer current selection to dictionary

Parameters:
  • idx – id/key of the selection

  • color – color of the selection - list of 4 integers between 0 and 255

  • resetplot – if True, reset the plot after moving the selection

copy_to_clipboard(which: int = None, typestr: Literal['string', 'script'] = 'string')[source]

Copy current selection to clipboard.

– ONLY WORKS WITH wxPython –

Parameters:
  • which – id/key of the selection to copy. If None, copy the current selection.

  • typestr – Type of data to copy to clipboard - ‘string’ for string representation, ‘script’ for script representation.

interp2Dpolygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all')[source]

Interpolation sous tous les polygones d’une zone cf parent.interp2Dpolygon

interp2Dpolygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all')[source]

Interpolation sous un polygone cf parent.interp2Dpolygon

interp2Dpolylines(working_zone: wolfhece.PyVertexvectors.zone, resetplot: bool = True)[source]

Interpolation sous toutes les polylignes de la zone cf parent.interp2Dpolyline

interp2Dpolyline(working_vector: wolfhece.PyVertexvectors.vector, resetplot: bool = True)[source]

Interpolation sous la polyligne active cf parent.interp2Dpolyline

volumesurface(show=True)[source]

Evaluation of stage-storage-surface relation