wolfhece.wolf_array._selection_data =================================== .. py:module:: wolfhece.wolf_array._selection_data .. autoapi-nested-parse:: 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 --------------- .. py:data:: ALL_SELECTED :value: 'all' .. py:class:: StorageMode(*args, **kwds) Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: wolfhece.wolf_array._selection_data.StorageMode :parts: 1 :private-bases: Storage mode for selections in WolfArray .. py:attribute:: LIST :value: 0 .. py:attribute:: ARRAY :value: 1 .. py:class:: SelectionData(parent: wolfhece.wolf_array._base.WolfArrayModel, threshold_array_mode: int = 100000) 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. .. py:attribute:: _myselection :type: list[tuple[float, float]] | str | tuple[str, numpy.ndarray] .. py:attribute:: selections :type: dict[str:dict['select':list[tuple[float, float]], 'idgllist':int, 'color':list[float]]] .. py:attribute:: parent :type: wolfhece.wolf_array._base.WolfArrayModel .. py:attribute:: wx_exists .. py:attribute:: _boolarray :type: numpy.ndarray | None :value: None .. py:attribute:: _storage_mode .. py:attribute:: update_plot_selection :value: False .. py:attribute:: hideselection :value: False .. py:attribute:: numlist_select :value: 0 .. py:attribute:: threshold_array_mode :value: 100000 .. py:method:: _auto_storage_mode() Choose the storage mode based on the number of nodes in the array .. py:method:: _convert_to_storage_mode(new_mode: StorageMode) Convert the selection to the new storage mode. :param new_mode: The new storage mode to convert to (StorageMode.LIST or StorageMode.ARRAY). .. py:method:: force_storage_mode(new_mode: StorageMode) Force the storage mode to the new mode. :param new_mode: The new storage mode to force (StorageMode.LIST or StorageMode.ARRAY). .. py:property:: myselection :type: list[tuple[float, float]] | str Current selection of nodes. :returns: - 'all' if all nodes are selected - list of (x, y) coordinates if specific nodes are selected .. py:property:: _myselection_as_array :type: numpy.ndarray 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. .. py:property:: myselection_npargwhere :type: numpy.ndarray Current selection of nodes as a numpy array using np.argwhere .. py:method:: is_all_selected() -> bool Check if all nodes are selected. :return: True if all nodes are selected, False otherwise .. py:method:: set_selection_from_list_xy(xylist: list[tuple[float, float]]) 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. .. py:property:: dx :type: float Resolution in x .. py:property:: dy :type: float Resolution in y .. py:property:: nb :type: int Number of selected nodes. .. py:method:: unmask_selection(resetplot: bool = True) Unmask selection .. py:method:: reset() Reset the selection .. py:method:: reset_all() Reset the selection .. py:method:: get_string(which: str = None, all_memories: bool = False) -> str Get string of the current selection or of a stored one. :param which: id/key of the selection to get the string for. If None, get the current selection. :param all_memories: If True, include all stored selections in the output string. :return: String representation of the selection. .. py:method:: get_script(which: int = None) -> str Get script of the current selection or of a stored one. :param which: id/key of the selection to get the script for. If None, get the current selection. :return: Script representation of the selection. .. py:method:: copy_to_clipboard(which: int = None, typestr: Literal['string', 'script'] = 'string') Copy current selection to clipboard. -- ONLY WORKS WITH wxPython -- :param which: id/key of the selection to copy. If None, copy the current selection. :param typestr: Type of data to copy to clipboard - 'string' for string representation, 'script' for script representation. .. py:method:: reselect_from_memory(idx: list[str] = None) Reselect a stored selection :param idx: id/key of the selection to reselect. If None, show a dialog to choose from available selections. .. py:method:: move_selectionto(idx: str, color: list[float], resetplot: bool = True) Transfer current selection to dictionary :param idx: id/key of the selection :param color: color of the selection - list of 4 integers between 0 and 255 :param resetplot: if True, reset the plot after moving the selection .. py:method:: plot_selection() Plot current selection and stored selections .. py:method:: _plot_selection(curlist: list[float], color: list[float], loclist: int = 0) Plot a selection :param curlist: list of selected nodes -- list of tuples (x,y) :param color: color of the selection - list of 3 floats between 0 and 1 :param loclist: index of OpenGL list .. py:method:: add_node_to_selection(x: float, y: float, verif: bool = True) Add one coordinate to the selection :param x: x coordinate - float :param y: y coordinate - float :param verif: if True, the coordinates are checked to avoid duplicates .. py:method:: add_nodes_to_selection(xy: list[float] | numpy.ndarray, verif: bool = True) Add multiple coordinates to the selection. :param 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. :param verif: if True, the coordinates are checked to avoid duplicates .. py:method:: _add_node_to_selectionij(i: int, j: int, verif=True) Add one ij coordinate to the selection. :param i: i coordinate :param j: j coordinate :param verif: if True, the coordinates are checked to avoid duplicates .. py:method:: _add_nodes_to_selectionij(ij: list[tuple[float, float]], verif: bool = True) Add multiple ij coordinates to the selection :param ij: list of ij coordinates :param verif: if True, the coordinates are checked to avoid duplicates .. py:method:: _add_nodes_to_selection_np(ij: numpy.ndarray, verif: bool = True) Add multiple coordinates to the selection from a numpy array :param ij: numpy array of coordinates - same shape as the parent array (nbx, nby) or (nb_nodes, 2) :param verif: if True, the coordinates are checked to avoid duplicates .. py:method:: select_insidepoly(myvect: wolfhece.PyVertexvectors.vector) Select nodes inside a polygon. :param myvect: vector defining the polygon .. py:method:: select_underpoly(myvect: wolfhece.PyVertexvectors.vector) Select nodes along a polyline :param myvect: vector defining the polyline .. py:method:: dilate_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None) Extend the selection. :param nb_iterations: Number of iterations to dilate the selection :param use_mask: If True, use the mask of the parent array to limit the dilation :param structure: Structuring element for dilation, default is a cross shape (nodes directly adjacent in the x or y direction) .. py:method:: erode_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None) Reduce the selection. :param nb_iterations: Number of iterations to erode the selection :param use_mask: If True, use the mask of the parent array to limit the erosion :param structure: Structuring element for erosion, default is a cross shape (nodes directly adjacent in the x or y direction) .. py:method:: dilate_contour_selection(nbiter: int = 1, use_mask: bool = True, structure: numpy.ndarray = np.ones((3, 3))) Dilate the contour of the selection. :param nbiter: Number of iterations to dilate the selection :param use_mask: If True, use the mask of the parent array to limit the dilation :param structure: Structuring element for dilation, default is a 3x3 square .. py:method:: erode_contour_selection() Erode the contour of the selection. :param nbiter: Number of iterations to erode the selection :param use_mask: If True, use the mask of the parent array to limit the erosion :param structure: Structuring element for erosion, default is a 3x3 square .. py:method:: save_selection(filename: str = None) Save the selection to a file. :param filename: Name of the file to save the selection to. If None, a dialog will be shown to choose the file. .. py:method:: load_selection(filename: str = None) Load a selection from a file. :param filename: Name of the file to load the selection from. If None, a dialog will be shown to choose the file. .. py:method:: update_nb_nodes_selection(autostoragemode: bool = True) -> tuple[int, float, float, float, float] Update the number of selected nodes. :param autostoragemode: If True, automatically switch to ARRAY mode if the number of selected nodes exceeds the threshold. :return: Tuple containing the number of selected nodes, and the bounds of the selection (xmin, xmax, ymin, ymax). .. py:method:: condition_select(cond: str | int, condval, condval2=0, usemask: bool = False) Select nodes based on a condition. :param cond: condition to apply (0: '<', 1: '<=', 2: '==', 3: '>=', 4: '>', 5: 'NaN', 6: '>=<=', 7: '><', 8: '<>') :param condval: value to compare with :param condval2: second value to compare with (for ranges) :param usemask: whether to use the mask or not .. py:method:: treat_select(op: int, cond: int, opval, condval) Apply an operation on the selected nodes based on a condition. :param op: operation to apply (0: '+', 1: '-', 2: '*', 3: '/', 4: 'replace') :param cond: condition to apply (0: '<', 1: '<=', 2: '==', 3: '>=', 4: '>', 5: 'NaN') :param opval: value to apply the operation with :param condval: value to compare with .. py:method:: refresh_parantarray() Refresh the parent array after a selection .. py:method:: mask_condition(op: int, cond: int, opval, condval) Mask nodes based on a condition. :param op: operation to apply (0: '+', 1: '-', 2: '*', 3: '/', 4: 'replace') :param cond: condition to apply (0: '<', 1: '<=', 2: '==', 3: '>=', 4: '>', 5: 'NaN') :param opval: value to apply the operation with :param condval: value to compare with .. py:method:: get_values_sel() -> numpy.ndarray Get the values of the selected nodes. :return: numpy array of values of the selected nodes, or -99999 if all nodes are selected. .. py:method:: _get_header() -> wolfhece.wolf_array._header_wolf.header_wolf | None Header corresponding to the selection .. py:method:: get_newarray() -> wolfhece.wolf_array._base.WolfArrayModel Create a new array from the selection. :return: 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. .. py:method:: select_all() Select all nodes. It will set the selection to ALL_SELECTED, which is a special value indicating that all nodes are selected. .. py:method:: interp2Dpolygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all') 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. .. py:method:: interp2Dpolygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all') 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. .. py:method:: interp2Dpolylines(working_zone: wolfhece.PyVertexvectors.zone, resetplot: bool = True) 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. .. py:method:: interp2Dpolyline(working_vector: wolfhece.PyVertexvectors.vector, resetplot: bool = True) 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. .. py:method:: copy(source: SelectionData) Copy the selection data from another SelectionData object. :param source: another SelectionData object to copy from. .. py:method:: volumesurface(show=True) 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. :param show: if True, the figure will be shown. .. py:class:: SelectionDataMB(parent: wolfhece.wolf_array._mb.WolfArrayMB) Bases: :py:obj:`SelectionData` .. autoapi-inheritance-diagram:: wolfhece.wolf_array._selection_data.SelectionDataMB :parts: 1 :private-bases: 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. .. py:attribute:: parent :type: wolfhece.wolf_array._mb.WolfArrayMB .. py:property:: nb Number of selected nodes. .. py:method:: unmask_selection() Unmask selection .. py:method:: reset() Reset the selection .. py:method:: select_all() Select all nodes. It will set the selection to ALL_SELECTED, which is a special value indicating that all nodes are selected. .. py:method:: reset_all() Reset the selection .. py:method:: get_string(which: str = None) -> str Get string of the current selection or of a stored one. :param which: id/key of the selection to get the string for. If None, get the current selection. :param all_memories: If True, include all stored selections in the output string. :return: String representation of the selection. .. py:method:: save_selection(filename: str = None, which: str = None) Save the selection to a file. :param filename: Name of the file to save the selection to. If None, a dialog will be shown to choose the file. .. py:method:: load_selection(filename: str = None, which: str = None) Load a selection from a file. :param filename: Name of the file to load the selection from. If None, a dialog will be shown to choose the file. .. py:method:: get_script(which: int = None) -> str Get script of the current selection or of a stored one. :param which: id/key of the selection to get the script for. If None, get the current selection. :return: Script representation of the selection. .. py:method:: get_newarray() Create a new array from the selection. :return: 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. .. py:method:: add_node_to_selection(x: float, y: float, verif: bool = True) Add a node to the selection .. py:method:: add_nodes_to_selection(xy: list[float] | numpy.ndarray, verif: bool = True) Add nodes to the selection .. py:method:: select_insidepoly(myvect: wolfhece.PyVertexvectors.vector) Select nodes inside a polygon. :param myvect: vector defining the polygon .. py:method:: select_underpoly(myvect: wolfhece.PyVertexvectors.vector) Select nodes along a polyline :param myvect: vector defining the polyline .. py:method:: dilate_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None) Extend the selection .. py:method:: erode_selection(nb_iterations: int, use_mask: bool = True, structure: numpy.ndarray = None) Reduce the selection .. py:method:: update_nb_nodes_selection() Update the number of nodes selected .. py:method:: condition_select(cond, condval, condval2=0, usemask=False) Select nodes based on a condition. :param cond: condition to apply (0: '<', 1: '<=', 2: '==', 3: '>=', 4: '>', 5: 'NaN', 6: '>=<=', 7: '><', 8: '<>') :param condval: value to compare with :param condval2: second value to compare with (for ranges) :param usemask: whether to use the mask or not .. py:method:: treat_select(op, cond, opval, condval) Apply an operation on the selected nodes based on a condition. :param op: operation to apply (0: '+', 1: '-', 2: '*', 3: '/', 4: 'replace') :param cond: condition to apply (0: '<', 1: '<=', 2: '==', 3: '>=', 4: '>', 5: 'NaN') :param opval: value to apply the operation with :param condval: value to compare with .. py:method:: mask_condition(op, cond, opval, condval) Mask nodes based on a condition. :param op: operation to apply (0: '+', 1: '-', 2: '*', 3: '/', 4: 'replace') :param cond: condition to apply (0: '<', 1: '<=', 2: '==', 3: '>=', 4: '>', 5: 'NaN') :param opval: value to apply the operation with :param condval: value to compare with .. py:method:: plot_selection() Plot current selection and stored selections .. py:method:: move_selectionto(idx: str, color: list[float]) Transfer current selection to dictionary :param idx: id/key of the selection :param color: color of the selection - list of 4 integers between 0 and 255 :param resetplot: if True, reset the plot after moving the selection .. py:method:: copy_to_clipboard(which: int = None, typestr: Literal['string', 'script'] = 'string') Copy current selection to clipboard. -- ONLY WORKS WITH wxPython -- :param which: id/key of the selection to copy. If None, copy the current selection. :param typestr: Type of data to copy to clipboard - 'string' for string representation, 'script' for script representation. .. py:method:: interp2Dpolygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all') Interpolation sous tous les polygones d'une zone cf parent.interp2Dpolygon .. py:method:: interp2Dpolygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal['nearest', 'linear', 'cubic'] = None, resetplot: bool = True, keep: Literal['all', 'below', 'above'] = 'all') Interpolation sous un polygone cf parent.interp2Dpolygon .. py:method:: interp2Dpolylines(working_zone: wolfhece.PyVertexvectors.zone, resetplot: bool = True) Interpolation sous toutes les polylignes de la zone cf parent.interp2Dpolyline .. py:method:: interp2Dpolyline(working_vector: wolfhece.PyVertexvectors.vector, resetplot: bool = True) Interpolation sous la polyligne active cf parent.interp2Dpolyline .. py:method:: volumesurface(show=True) Evaluation of stage-storage-surface relation