wolfhece.wolf_array._mb ======================= .. py:module:: wolfhece.wolf_array._mb .. autoapi-nested-parse:: WolfArrayMB - GUI-enabled multi-block array class with OpenGL rendering and wxPython integration. Inherits all data operations from :class:`WolfArrayMBModel` and adds: - OpenGL rendering, palette/colormap management - Interactive wx dialogs - Matplotlib visualization (``imshow``, ``plot_matplotlib``) 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:class:: WolfArrayMB(fname=None, mold=None, masknull=True, crop=None, whichtype=WOLF_ARRAY_MB_SINGLE, preload=True, create=False, mapviewer=None, nullvalue=0.0, srcheader=None, idx: str = '') Bases: :py:obj:`wolfhece.wolf_array._mb_model.WolfArrayMBModel`, :py:obj:`wolfhece.wolf_array._base_gui.WolfArray` .. autoapi-inheritance-diagram:: wolfhece.wolf_array._mb.WolfArrayMB :parts: 1 :private-bases: GUI-enabled multi-block array class. Inherits data operations from :class:`WolfArrayMBModel` and GUI/rendering from :class:`WolfArray`. Blocks (:class:`WolfArray` instances) are stored in the :attr:`myblocks` dictionary, keyed by identifiers produced by :func:`getkeyblock`. :ivar myblocks: Dictionary mapping block keys to :class:`WolfArray` instances. .. py:attribute:: myblocks :type: dict[str, wolfhece.wolf_array._base_gui.WolfArray] .. py:attribute:: mngselection .. py:attribute:: _active_blocks :value: 0 .. py:method:: make_multiblocks(others: list, abs: bool = True, copy: bool = True) -> WolfArrayMB :classmethod: Merge several single-block arrays into a new GUI multi-block array. :param others: List of :class:`WolfArray` instances to merge. :param abs: If ``True``, use global (absolute) world coordinates. :param copy: If ``True``, copy data from each source array. :return: A new :class:`WolfArrayMB` containing all blocks. .. py:method:: add_block(arr: wolfhece.wolf_array._base_gui.WolfArray, force_idx: bool = False, copyarray=False) Add a block to this multi-block array. After adding all blocks, call :meth:`set_header_from_added_blocks` to recompute the global header. :param arr: The block to add. :param force_idx: If ``True``, the block key is assigned automatically. :param copyarray: If ``True``, a deep copy of *arr* is stored. .. py:method:: add_ops_sel() Add operations and selection manager to all blocks. .. py:method:: extract_selection() Extract the current selection into a new multi-block array. Each block's :class:`SelectionData` produces a sub-array; the results are assembled into a new :class:`WolfArrayMB`. If a map viewer is attached, the extracted array is also registered in it. .. py:method:: contour(levels: Union[int, list[float]] = 10) -> wolfhece.PyVertexvectors.Zones Compute contour lines from this multi-block array. The array is first converted to a single-block :class:`WolfArray` before contouring. :param levels: Number of levels or explicit list of level values. :return: A :class:`Zones` object containing the contour polylines. .. py:method:: allocate_ressources() Allocate memory for every block defined in :attr:`head_blocks`. Creates :class:`WolfArray` (GUI-enabled) instances for each block header. .. py:method:: _make_result_array() Create an empty result array of the same type (GUI-enabled). :return: A new :class:`WolfArrayMB` with the same header. .. py:method:: as_WolfArray(abs: bool = True, forced_header: wolfhece.wolf_array._header_wolf.header_wolf = None) -> wolfhece.wolf_array._base_gui.WolfArray Convert to a single-block GUI-enabled :class:`WolfArray`. When blocks have different resolutions, coarser blocks are rebinned to match the finest resolution. :param abs: If ``True``, use absolute coordinates. :param forced_header: If provided, override the target header. :return: A new single-block :class:`WolfArray`. .. py:method:: read_data() Read binary block data from :attr:`filename`. Creates :class:`WolfArray` (GUI-enabled) instances for each block. .. py:method:: change_gui(newparentgui) Re-parent this array to a different :class:`WolfMapViewer`. If no viewer was previously attached, creates a new ``Ops_Array`` panel. Otherwise, migrates the existing one. :param newparentgui: Target :class:`WolfMapViewer` instance. :raises AssertionError: If *newparentgui* is not a :class:`WolfMapViewer`. .. py:method:: check_plot() Mark the array for plotting and load data if needed. Reads binary data from disk, applies the null-value mask, initialises the RGB buffer and updates the palette. .. py:method:: uncheck_plot(unload: bool = True, forceresetOGL: bool = False, askquestion: bool = True) Uncheck (hide) the array and optionally unload data. Optionally resets OpenGL display lists and frees block data. :param unload: If ``True``, unload block data from memory. :param forceresetOGL: If ``True``, force-reset OpenGL lists without asking. :param askquestion: If ``True``, prompt the user before resetting OpenGL lists. .. py:method:: mimic_plotdata() Propagate plot/plotting flags to every child block. .. py:method:: share_palette() Share this array's palette with all linked arrays. .. py:method:: link_palette() Assign this array's palette to every child block. .. py:method:: updatepalette(which: int = 0, onzoom: list[float] = []) Update the palette/colormap across all blocks. When :attr:`mypal.automatic` is ``True``, the palette range is recomputed from the data (optionally restricted to *onzoom*). :param which: Colormap index to use. :param onzoom: If not empty, ``[xmin, xmax, ymin, ymax]`` bounds restricting the data used for palette computation. .. py:method:: delete_lists() Delete OpenGL display lists for every block. .. py:method:: plot(sx=None, sy=None, xmin=None, ymin=None, xmax=None, ymax=None, size=None) Render all blocks via OpenGL. Also draws the current selection and any attached zones. :param sx: X scale factor. :param sy: Y scale factor. :param xmin: Viewport X minimum. :param ymin: Viewport Y minimum. :param xmax: Viewport X maximum. :param ymax: Viewport Y maximum. :param size: Unused, kept for API compatibility. .. py:method:: _fill_ogllist_for_one_grid_cell(curscale, loci, locj, force=False) Fill OpenGL display list for a single grid cell in every block. .. py:method:: imshow(figax: tuple[matplotlib.figure.Figure, matplotlib.axis.Axis] = None, cmap: matplotlib.colors.Colormap = None, step_ticks=100.0) -> tuple[matplotlib.figure.Figure, matplotlib.axis.Axis] Create a Matplotlib image from this multi-block array. Assembles all blocks into a single raster at the finest resolution, applies the palette (or a Matplotlib colormap), and renders with ``imshow``. :param figax: ``(fig, ax)`` to plot into. If ``None``, a new figure is created. :param cmap: Matplotlib :class:`~matplotlib.colors.Colormap`. If ``None``, the WOLF palette's RGBA output is used. :param step_ticks: Spacing between axis tick labels in world coordinate units. :return: ``(fig, ax)`` tuple. .. py:method:: plot_matplotlib(figax: tuple = None, getdata_im: bool = False, update_palette: bool = True, vmin: float = None, vmax: float = None, figsize: tuple = None, Walonmap: bool = False, cat: str = 'IMAGERIE/ORTHO_2022_ETE', first_mask_data: bool = True, with_legend: bool = False) Plot the multi-block array using Matplotlib. Converts to a single-block :class:`WolfArray` and delegates to its :meth:`~WolfArray.plot_matplotlib` method. .. rubric:: Notes - The null-value mask is applied before plotting. - If *Walonmap* is ``True``, a background map from the WalOnMap service is overlaid. - The aspect ratio is set to ``'equal'``. :param figax: ``(fig, ax)`` tuple. If ``None``, a new figure is created. :param getdata_im: If ``True``, also return the image object. :param update_palette: If ``True``, update the palette before plotting. :param vmin: Minimum value for colour scaling. :param vmax: Maximum value for colour scaling. :param figsize: Figure size in inches ``(width, height)``. :param Walonmap: If ``True``, overlay an orthophoto from WalOnMap. :param cat: WalOnMap orthophoto category (e.g. ``'IMAGERIE/ORTHO_2022_ETE'``). :param first_mask_data: If ``True``, apply the mask before plotting. :param with_legend: If ``True``, add a colour legend. :return: ``(fig, ax)`` or ``(fig, ax, im)`` if *getdata_im* is ``True``. :rtype: tuple