wolfhece.wolf_array
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.hillshade(array: numpy.ndarray, azimuth: float, angle_altitude: float) numpy.ndarray [source]
Create a hillshade array
- class wolfhece.wolf_array.Rebin_Ops[source]
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- wolfhece.wolf_array.getkeyblock(i, addone=True) str [source]
Name/Key of a block in the dictionnary of a WolfArrayMB instance
For Fortran compatibility, addone is True by default so first block is “block1” and not “block0”
- wolfhece.wolf_array.decodekeyblock(key, addone=True) int [source]
Decode key of a block in the dictionnary of a WolfArrayMB instance
For Fortran compatibility, addone is True by default so first block is “block1” and not “block0”
- class wolfhece.wolf_array.header_wolf[source]
Header of WolfArray
In case of a mutliblock, the header have informations about all the blocks in head_blocks dictionnary. Block keys are generated by “getkeyblock” function
- head_blocks: dict[str, header_wolf][source]
- set_origin(x: float, y: float, z: float)[source]
Set origin
- Parameters:
x – origin along X
y – origin along Y
z – origin along Z
- set_translation(tr_x: float, tr_y: float, tr_z: float)[source]
Set translation
- Parameters:
tr_x – translation along X
tr_y – translation along Y
tr_z – translation along Z
- get_bounds(abs=True)[source]
Return bounds in coordinates
- Parameters:
abs – if True, add translation to (x, y) (coordinate to global space)
- Returns:
tuple of two lists of two floats - ([xmin, xmax],[ymin, ymax])
- get_bounds_ij(abs=False)[source]
Return bounds in indices
Firstly, get_bounds is called to get bounds in coordinates and then get_ij_from_xy is called to get bounds in indices.
- Parameters:
abs – if True, add translation to (x, y) (coordinate to global space)
- get_ij_from_xy(x: float, y: float, z: float = 0.0, scale: float = 1.0, aswolf: bool = False, abs: bool = True, forcedims2: bool = False) tuple[numpy.int32, numpy.int32] | tuple[numpy.int32, numpy.int32, numpy.int32] [source]
Get indices from coordinates
- Parameters:
x – X coordinate
y – Y coordinate
z – Z coordinate (optional)
scale – scaling of the spatial resolution (dx,dy,[dz])
aswolf – if True, return if one-based (as Wolf VB6 or Fortran), otherwise 0-based (default Python standard)
abs – if True, remove translation from (x, y, [z]) (coordinate from global space)
forcedims2 – if True, force to return only 2 indices even if z is supplied
- get_ij_from_xy_array(xy: numpy.ndarray, scale: float = 1.0, aswolf: bool = False, abs: bool = True, forcedims2: bool = False) numpy.ndarray [source]
Get indices from coordinates
:param xy = numpy array containing (x, y, [z]) coordinates - shape (n, 2) or (n, 3) :param scale = scaling of the spatial resolution (dx,dy,[dz]) :param aswolf = if True, return if one-based (as Wolf VB6 or Fortran), otherwise 0-based (default Python standard) :param abs = if True, remove translation from (x, y, [z]) (coordinate from global space) :param forcedims2 = if True, force to return only 2 indices even if z is supplied
- Returns:
numpy array containing (i, j, [k]) indices - shape (n, 2) or (n, 3)
- get_xy_from_ij(i: int, j: int, k: int = 0, scale: float = 1.0, aswolf: bool = False, abs: bool = True) tuple[numpy.float64, numpy.float64] | tuple[numpy.float64, numpy.float64, numpy.float64] [source]
Get coordinates from indices
:param i = index along X coordinate :param j = index along Y coordinate :param k = index along Z coordinate (optional) :param scale = scaling of the spatial resolution (dx,dy,[dz]) :param aswolf = if True, input is one-based (as Wolf VB6 or Fortran), otherwise 0-based (default Python standard) :param abs = if True, add translation to results (x, y, [z]) (coordinate to global space)
- get_xy_from_ij_array(ij: numpy.ndarray, scale: float = 1.0, aswolf: bool = False, abs: bool = True) numpy.ndarray [source]
Converts array coordinates (numpy cells) to this array’s world coodinates.
:param ij = numpy array containing (i, j, [k]) indices - shape (n, 2) or (n, 3) :param scale = scaling of the spatial resolution (dx,dy,[dz]) :param aswolf = if True, input is one-based (as Wolf VB6 or Fortran), otherwise 0-based (default Python standard) :param abs = if True, add translation to results (x, y, [z]) (coordinate to global space)
..warning: ‘ij’ is not the result of np.where() but if you want to use np.where() you can use the following code:
` np.vstack((ij[0], ij[1])).T `
- ij2xy(i: int, j: int, k: int = 0, scale: float = 1.0, aswolf: bool = False, abs: bool = True) tuple[numpy.float64, numpy.float64] | tuple[numpy.float64, numpy.float64, numpy.float64] [source]
alias for get_xy_from_ij
- ij2xy_np(ij: numpy.ndarray, scale: float = 1.0, aswolf: bool = False, abs: bool = True) numpy.ndarray [source]
alias for get_xy_from_ij_array
- Parameters:
ij – numpy array containing (i, j, [k]) indices
scale – scaling of the spatial resolution (dx,dy,[dz])
aswolf – if True, input is one-based (as Wolf VB6 or Fortran), otherwise 0-based (default Python standard)
abs – if True, add translation to results (x, y, [z]) (coordinate to global space)
..warning: ‘ij’ is not the result of np.where() but if you want to use np.where() you can use the following code:
` np.vstack((ij[0], ij[1])).T `
- Returns:
numpy array containing (x, y, [z]) coordinates - shape (n, 2) or (n, 3)
- xy2ij(x: float, y: float, z: float = 0.0, scale: float = 1.0, aswolf: bool = False, abs: bool = True, forcedims2: bool = False) tuple[numpy.int32, numpy.int32] | tuple[numpy.int32, numpy.int32, numpy.int32] [source]
alias for get_ij_from_xy
- xy2ij_np(xy: numpy.ndarray, scale: float = 1.0, aswolf: bool = False, abs: bool = True) numpy.ndarray [source]
alias for get_ij_from_xy_array
- Parameters:
xy – numpy array containing (x, y, [z]) coordinates - shape (n, 2) or (n, 3)
scale – scaling of the spatial resolution (dx,dy,[dz])
aswolf – if True, return if one-based (as Wolf VB6 or Fortran), otherwise 0-based (default Python standard)
abs – if True, remove translation from (x, y, [z]) (coordinate from global space)
forcedims2 – if True, force to return only 2 indices even if z is supplied
:return : numpy array containing (i, j, [k]) indices - shape (n, 2) or (n, 3)
- xyz2ijk_np(xyz: numpy.ndarray, scale: float = 1.0, aswolf: bool = False, abs: bool = True) numpy.ndarray [source]
alias for get_xy_from_ij_array
- ijk2xyz_np(ijk: numpy.ndarray, scale: float = 1.0, aswolf: bool = False, abs: bool = True) numpy.ndarray [source]
alias for get_xy_from_ij_array
- find_intersection(other: header_wolf, ij: bool = False) tuple[list[float], list[float]] | tuple[list[list[float]], list[list[float]]] [source]
Find the intersection of two header
- Parameters:
other – other header
ij – if True, return indices instead of coordinates
- Returns:
None or tuple of two lists of two floats - ([xmin, xmax],[ymin, ymax]) or indices in each header (if ij=True) [[imin1, imax1], [jmin1, jmax1]], [[imin2, imax2], [jmin2, jmax2]]
- find_union(other: header_wolf | list[header_wolf]) tuple[list[float], list[float]] [source]
Find the union of two header
- Returns:
tuple of two lists of two floats - ([xmin, xmax],[ymin, ymax])
- read_txt_header(filename: str)[source]
Read informations from header .txt
- Parameters:
filename – path and filename of the basefile
If filename is a Path object, it is converted to a string If filename ends with ‘.tif’, nothing is done because infos are in the .tif file If filename ends with ‘.flt’, a .hdr file must be present and it will be read Otherwise, a filename.txt file must be present
- write_txt_header(filename: str, wolftype: int, forceupdate: bool = False)[source]
Writing the header to a text file
Nullvalue is not written
- Parameters:
filename – path and filename with ‘.txt’ extension, which will NOT be automatically added
wolftype – type of the WOLF_ARRAY_* array
forceupdate – if True, the file is rewritten even if it already exists
- is_like(other: header_wolf, check_mb: bool = False) bool [source]
Comparison of two headers
- Parameters:
other – other header to compare
check_mb – if True, the comparison is done on the blocks too
The nullvalue is not taken into account
- align2grid(x1: float, y1: float, eps: float = 0.0001) tuple[float, float] [source]
Align coordinates to nearest grid point where the grid is defined by the borders of the array.
- _rasterize_segment(x1: float, y1: float, x2: float, y2: float, xstart: float = None, ystart: float = None) list[list[float]] [source]
Rasterize a segment according to the grid where the grid is defined by the borders of the array.
- Parameters:
x1 – x coordinate of the first point
y1 – y coordinate of the first point
x2 – x coordinate of the second point
y2 – y coordinate of the second point
xstart – x coordinate of the starting point
ystart – y coordinate of the starting point
- Returns:
numpy array of the rasterized segment
- rasterize_vector(vector2raster: wolfhece.PyVertexvectors.vector, outformat: numpy.ndarray | wolfhece.PyVertexvectors.vector = vector) numpy.ndarray | wolfhece.PyVertexvectors.vector [source]
Rasterize a vector according to the grid
- Parameters:
vector2raster – vector to rasterize
outformat – output format (np.ndarray or vector)
- get_xy_infootprint_vect(myvect: wolfhece.PyVertexvectors.vector | shapely.geometry.Polygon, eps: float = 0.0) tuple[numpy.ndarray, numpy.ndarray] [source]
Return the coordinates of the cells in the footprint of a vector
- Parameters:
myvect – target vector
eps – epsilon to avoid rounding errors
- Returns:
tuple of two numpy arrays - (coordinates, indices)
- get_ij_infootprint_vect(myvect: wolfhece.PyVertexvectors.vector | shapely.geometry.Polygon, eps: float = 0.0) numpy.ndarray [source]
Return the indices of the cells in the footprint of a vector
- Parameters:
myvect – target vector
eps – epsilon to avoid rounding errors
- Returns:
numpy array of indices
- class wolfhece.wolf_array.NewArray(parent)[source]
Bases:
wx.Dialog
wx GUI interaction to create a new WolfArray
Once filled, user/__init__ must call “init_from_new”
- class wolfhece.wolf_array.CropDialog(parent)[source]
Bases:
wx.Dialog
wx GUI interaction to crop 2D array’s data
Used in “read_data” of a WolfArray
- class wolfhece.wolf_array.IntValidator[source]
Bases:
wx.Validator
Validates data as it is entered into the text controls.
- class wolfhece.wolf_array.Ops_Array(parentarray: WolfArray, mapviewer=None)[source]
Bases:
wx.Frame
Operations wx.Frame on WolfArray class
This class is used to perform operations on a WolfArray
Check if the vector manager is shared
- Unmaskall(event: wx.MouseEvent)[source]
Unmask all values in the current array @author Pierre Archambeau
- Unmasksel(event: wx.MouseEvent)[source]
Enlève le masque des éléments sélectionnés @author Pierre Archambeau
- interp2Dpolygons(event: wx.MouseEvent)[source]
Bouton d’interpolation sous tous les polygones d’une zone cf WolfArray.interp2Dpolygon
- interp2Dpolygon(event: wx.MouseEvent)[source]
Bouton d’interpolation sous un polygone cf WolfArray.interp2Dpolygon
- interp2Dpolylines(event: wx.MouseEvent)[source]
Bouton d’interpolation sous toutes les polylignes de la zone cf parent.interp2Dpolyline
- interp2Dpolyline(event: wx.MouseEvent)[source]
Bouton d’interpolation sous la polyligne active cf parent.interp2Dpolyline
- select_node_by_node()[source]
Select nodes by individual clicks
Set the right action in the mapviewer who will attend the clicks
- _select_vector_inside_manager(vect: wolfhece.PyVertexvectors.vector)[source]
Select nodes inside a vector or set action to add vertices to a vector by clicks
- _select_vector_under_manager(vect: wolfhece.PyVertexvectors.vector)[source]
Select nodes along a vector or set action to add vertices to a vector by clicks
- onshow(event: wx.MouseEvent)[source]
Show the window - set string with null value and update palette
- Active_vector(vect: wolfhece.PyVertexvectors.vector, copyall: bool = True)[source]
Set the active vector to vect and forward to mapviewer
- Active_zone(target_zone: wolfhece.PyVertexvectors.zone)[source]
Set the active zone to target_zone and forward to mapviewer
- class wolfhece.wolf_array.SelectionData(parent: WolfArray)[source]
User-selected data in a WolfArray
- Contains two storage elements :
myselection (list): Current selection which will be lost in the event of a reset
- 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.
- selections: dict[str:dict['select':list[tuple[float, float]], 'idgllist':int, 'color':list[float]]][source]
- set_selection_from_list_xy(xylist: list[tuple[float, float]])[source]
Set the current selection from a list of (x, y) coordinates
- get_string(which: str = None, all_memories: bool = False) str [source]
Get string of the current selection or of a stored one
- copy_to_clipboard(which: int = None, typestr: Literal[string, script] = 'string')[source]
Copy current selection to clipboard
- reselect_from_memory(idx: list[str] = None)[source]
Reselect a stored selection
- Parameters:
idx – id/key of the selection
- 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
- _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
y – y coordinate
verif – if True, the coordinates are checked to avoid duplicates
- add_nodes_to_selection(xy: list[float], verif: bool = True)[source]
Add multiple coordinates to the selection
- Parameters:
xy – list of coordinates
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
- select_insidepoly(myvect: wolfhece.PyVertexvectors.vector)[source]
Select nodes inside a polygon
- select_underpoly(myvect: wolfhece.PyVertexvectors.vector)[source]
Select nodes along a 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
- dilate_contour_selection(nbiter: int = 1, use_mask: bool = True, structure: numpy.ndarray = np.ones((3, 3)))[source]
Dilate the contour of the selection
- interp2Dpolygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal[nearest, linear, cubic] = None, resetplot: bool = True)[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)[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
- copy(source: SelectionData)[source]
- class wolfhece.wolf_array.SelectionDataMB(parent: WolfArrayMB)[source]
Bases:
SelectionData
Extension of SelectionData to manage multiple blocks
- select_insidepoly(myvect: wolfhece.PyVertexvectors.vector)[source]
Select nodes inside a polygon
- select_underpoly(myvect: wolfhece.PyVertexvectors.vector)[source]
Select nodes along a 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
- 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
- copy_to_clipboard(which: int = None, typestr: Literal[string, script] = 'string')[source]
Copy current selection to clipboard
- interp2Dpolygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal[nearest, linear, cubic] = None)[source]
Interpolation sous tous les polygones d’une zone cf parent.interp2Dpolygon
- interp2Dpolygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal[nearest, linear, cubic] = None)[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
- class wolfhece.wolf_array.WolfArray(fname: str = None, mold: WolfArray = None, masknull: bool = True, crop: list[list[float], list[float]] = None, whichtype=WOLF_ARRAY_FULL_SINGLE, preload: bool = True, create: bool = False, mapviewer=None, nullvalue: float = 0.0, srcheader: header_wolf = None, idx: str = '', plotted: bool = False, need_for_wx: bool = False, mask_source: numpy.ndarray = None, np_source: numpy.ndarray = None)[source]
Bases:
wolfhece.drawing_obj.Element_To_Draw
,header_wolf
Classe pour l’importation de WOLF arrays
simple précision, double précision, entier…
- property SelectionData: SelectionData[source]
Return the data of the selection
- property dtype[source]
Return the numpy dtype corresponding to the WOLF type
- Pay ettention to the difference between :
LOGICAL : Fortran and VB6
Bool : Python
In VB6, logical is stored as int16 In Fortran, there are Logical*1, Logical*2, Logical*4, Logical*8 In Python, bool is one byte In Numpy, np.bool_ is one byte
- property dtype_str[source]
Return the numpy dtype corresponding to the WOLF type, as a string
- Pay ettention to the difference between :
LOGICAL : Fortran and VB6
Bool : Python
In VB6, logical is stored as int16 In Fortran, there are Logical*1, Logical*2, Logical*4, Logical*8 In Python, bool is one byte In Numpy, np.bool_ is one byte
- linkedvec: wolfhece.PyVertexvectors.vector[source]
- crop_array(bbox: list[list[float], list[float]]) WolfArray [source]
Crop the data based on the bounding box
- loadnap_and_apply()[source]
Load a mask file (aka nap) and apply it to the array;
The mask values are set to the nullvalue.
The mask file must have the same name as the array file, with the extension .napbin. It is useful for 2D WOLF simulations.
Partage de la palette de couleurs entre matrices liées
- filter_inundation(epsilon: float = None, mask: numpy.ndarray = None)[source]
- Apply filter on array :
mask data below eps
mask data outisde linkedvec
- Parameters:
epsilon – value under which data are masked
mask – mask to apply if eps is None
If all params are None, the function will mask NaN values
- filter_independent_zones(n_largest: int = 1, reset_plot: bool = True)[source]
Filtre des zones indépendantes et conservation des n plus grandes
- filter_zone(set_null: bool = False, reset_plot: bool = True)[source]
Filtre des zones et conservation de celles pour lesquelles des mailles sont sélectionnées
- export_geotif(outdir='', extent='', EPSG: int = 31370)[source]
Export de la matrice au format Geotiff (Lambert 72 - EPSG:31370)
- Formats supportés :
Int32
Float32
Float64
- Parameters:
outdir – directory
extent – suffix to add to the filename before the extension ‘.tif’
EPSG – EPSG code, by default 31370 (Lambert 72)
- get_dxdy_min()[source]
Return the minimal size
Mainly useful in PyVertexVectors to get the minimal size of the cells and ensure compatibility with the 2D results (GPU and Multiblocks)
- get_dxdy_max()[source]
Return the maximal size
Mainly useful in PyVertexVectors to get the minimal size of the cells and ensure compatibility with the 2D results (GPU and Multiblocks)
- _import_npy(fn: str = '', crop: list[float] = None)[source]
Import a numpy file.
Must be called after the header is initialized, e.g. read_txt_header.
- Parameters:
fn – filename
crop – crop the data - [xmin, xmax, ymin, ymax]
- import_geotif(fn: str = '', which: int = None, crop: list[float] = None)[source]
Import de la matrice au format Geotiff
- Formats supportés :
Int32
Float32
Float64
- Parameters:
fn – filename
which – band to import
crop – crop the data - [xmin, xmax, ymin, ymax]
- add_ops_sel()[source]
Adding selection manager and operations array
Ops_Array (GUI) if mapviewer is not None
create SelectionData (Selection manager) if None
- change_gui(newparentgui)[source]
Move GUI to another instance
- Parameters:
newparentgui – WolfMapViewer instance
- compare_cloud(mycloud: wolfhece.PyVertex.cloud_vertices, delta: list[float] = [0.15, 0.5, 1.0])[source]
Graphique de comparaison des valeurs d’un nuage de points et des valeurs de la matrice sous les mêmes positions
- Parameters:
mycloud – cloud_vertices
delta – list of tolerance for the comparison
- compare_tri(mytri: wolfhece.PyVertexvectors.Triangulation)[source]
Graphique de comparaison des valeurs d’un nuage de points et des valeurs de la matrice sous les mêmes positions
- interpolate_on_polygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal[nearest, linear, cubic] = 'linear')[source]
Interpolation sous un polygone
- L’interpolation a lieu :
uniquement dans les mailles sélectionnées si elles existent
dans les mailles contenues dans le polygone sinon
On utilise ensuite “griddata” de Scipy pour interpoler les altitudes des mailles depuis les vertices 3D du polygone
- interpolate_on_polygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal[nearest, linear, cubic] = 'linear')[source]
Interpolation sous plusieurs polygones d’une même zone
- interpolate_on_polyline(working_vector: wolfhece.PyVertexvectors.vector, usemask=True)[source]
Interpolation sous une polyligne
- L’interpolation a lieu :
uniquement dans les mailles sélectionnées si elles existent
dans les mailles sous la polyligne sinon
On utilise ensuite “interpolate” de shapely pour interpoler les altitudes des mailles depuis les vertices 3D de la polyligne
- interpolate_on_polylines(working_zone: wolfhece.PyVertexvectors.zone, usemask=True)[source]
Interpolation sous toutes les polylignes d’une même zone
- interpolate_on_cloud(xy: numpy.ndarray, z: numpy.ndarray, method: Literal[linear, nearest, cubic] = 'linear')[source]
Interpolation sur un nuage de points.
- L’interpolation a lieu :
uniquement dans les mailles sélectionnées si elles existent
dans les mailles contenues dans le polygone convexe contenant les points sinon
Using griddata from Scipy.
- Parameters:
xy – numpy.array of vertices - shape (n,2)
z – numpy.array of values - shape (n,)
method – method for the interpolation – ‘nearest’, ‘linear’ or ‘cubic’
See : https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html
- interpolate_on_triangulation(coords, triangles, grid_x=None, grid_y=None, mask_tri=None, interp_method: Literal[matplotlib, scipy] = 'matplotlib')[source]
Interpolation sur une triangulation.
- L’interpolation a lieu :
uniquement dans les mailles sélectionnées si elles existent
dans les mailles contenues dans la triangulation sinon
Matplotlib is used by default, but Scipy(griddata) can be used as well. If Matplotlib crashes, try with Scipy. Matplotlib is more strict on the quality of the triangulation.
- Parameters:
coords – numpy.array of vertices - shape (n,3)
triangles – numpy.array of triangles - shape (m,3)
grid_x – numpy.array of x values where the interpolation will be done – if None, the grid is created from the array
grid_y – numpy.array of y values where the interpolation will be done – if None, the grid is created from the array
mask_tri – numpy.array of mask for the triangles
interp_method – method for the interpolation – ‘matplotlib’ or ‘scipy’
For matplotlib algo, see : https://matplotlib.org/stable/gallery/images_contours_and_fields/triinterp_demo.html For scipy algo, see : https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html
- import_from_gltf(fn: str = '', fnpos: str = '', interp_method: Literal[matplotlib, scipy] = 'matplotlib')[source]
Import from GLTF/GLB format
- Parameters:
fn – filename
fnpos – filename for the position’s information
interp_method – method for the interpolation – ‘matplotlib’ or ‘scipy’
- export_to_gltf(bounds: list[float] = None, fn: str = '')[source]
Export to GLTF/GLB format
- Parameters:
bounds – [[xmin,xmax],[ymin,ymax]]
fn – filename
- get_triangulation(bounds: list[float] = None)[source]
Traingulation of the array
- Parameters:
bounds – [[xmin,xmax],[ymin,ymax]]
- hillshade(azimuth: float, angle_altitude: float)[source]
Create a hillshade array – see “hillshade” function accelerated by JIT
- volume_estimation(axs: matplotlib.pyplot.Axes = None)[source]
Estimation of the volume of the selected zone
- paste_all(fromarray: WolfArray, mask_after: bool = True)[source]
Paste all the values from another WolfArray
- set_values_sel(xy: list[float], z: list[float], update: bool = True)[source]
Set values at the selected positions
- Parameters:
xy – [[x1,y1],[x2,y2],…]
z – [z1,z2,…]
update – update the plot
- init_from_header(myhead: header_wolf, dtype: numpy.dtype = None, force_type_from_header: bool = False)[source]
Initialize the array properties from a header_wolf object
- Parameters:
myhead – header_wolf object
dtype – numpy dtype
force_type_from_header – force the type from the header passed as argument
- copy_mask(source: WolfArray, forcenullvalue: bool = False, link: bool = True)[source]
Copy/Link the mask from another WolfArray
- Parameters:
source – WolfArray source
forcenullvalue – force nullvalue in the masked zone
link – link the mask if True (default), copy it otherwise
- mask_union(source: WolfArray, link: bool = True)[source]
Union of the mask with another WolfArray
- Parameters:
source – WolfArray source
link – link the mask if True (default), copy it otherwise
- mask_unions(sources: list[WolfArray], link: bool = True)[source]
Union of the mask with another WolfArrays
- Parameters:
source – list of WolfArray sourceq
link – link the mask if True (default), copy it otherwise
- copy_mask_log(mask: numpy.ndarray, link: bool = True)[source]
Copy the mask from a numpy array
- Parameters:
mask – numpy array
link – link the mask if True (default), copy it otherwise
- uncheck_plot(unload: bool = True, forceresetOGL: bool = False, askquestion: bool = True)[source]
Make sure the array is not plotted
- Parameters:
unload – unload the data if True (default), keep it otherwise
forceresetOGL – force the reset of the OpenGL lists
askquestion – ask the question if True and a wx App is running (default), don’t ask it otherwise
- get_header(abs: bool = True) header_wolf [source]
Return a header_wolf object - different from the self object header
- Parameters:
abs – if True (default), return an absolute header (shifted origin) and translation set to 0.
- set_header(header: header_wolf)[source]
Set the header from a header_wolf object
- concatenate(list_arr: list[WolfArray], nullvalue: float = 0.0)[source]
Concatenate the values from another WolfArrays into a new one
- Parameters:
list_arr – list of WolfArray objects
- Returns:
a new WolfArray
- Return_type:
WolfArray
- mask_outsidepoly(myvect: wolfhece.PyVertexvectors.vector, eps: float = 0.0, set_nullvalue: bool = True)[source]
Mask nodes outside a polygon and set values to nullvalue
- Parameters:
myvect – target vector in global coordinates
- mask_insidepoly(myvect: wolfhece.PyVertexvectors.vector, eps: float = 0.0, set_nullvalue: bool = True)[source]
Mask nodes inside a polygon and set values to nullvalue
- Parameters:
myvect – target vector in global coordinates
- get_xy_inside_polygon(myvect: wolfhece.PyVertexvectors.vector | shapely.geometry.Polygon, usemask: bool = True)[source]
Return the coordinates inside a polygon
- Parameters:
myvect – target vector
usemask – limit potential nodes to unmaksed nodes
- get_xy_inside_polygon_shapely(myvect: wolfhece.PyVertexvectors.vector | shapely.geometry.Polygon, usemask: bool = True)[source]
Return the coordinates inside a polygon
- Parameters:
myvect – target vector
usemask – limit potential nodes to unmaksed nodes
- get_xy_under_polyline(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True)[source]
Return the coordinates along a polyline
- Parameters:
myvect – target vector
usemask – limit potential nodes to unmaksed nodes
- get_ij_inside_polygon(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True, eps: float = 0.0)[source]
Return the indices inside a polygon
- Parameters:
myvect – target vector
usemask – limit potential nodes to unmaksed nodes
eps – epsilon for the intersection
- intersects_polygon(myvect: wolfhece.PyVertexvectors.vector | shapely.geometry.Polygon, usemask: bool = True)[source]
Return True if the array intersects the polygon
- Parameters:
myvect – target vector
usemask – limit potential nodes to unmaksed nodes
- intersects_polygon_shapely(myvect: wolfhece.PyVertexvectors.vector | shapely.geometry.Polygon, eps: float = 0.0, usemask: bool = True)[source]
Return True if the array intersects the polygon
- Parameters:
myvect – target vector
usemask – limit potential nodes to unmaksed nodes
- get_ij_under_polyline(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True)[source]
Return the indices along a polyline
- Parameters:
myvect – target vector
usedmask – limit potential nodes to unmaksed nodes
- get_values_insidepoly(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True, getxy: bool = False)[source]
Récupération des valeurs contenues dans un polygone
- Parameters:
usemask – (optional) restreint les éléments aux éléments non masqués de la matrice
getxy – (optional) retourne en plus les coordonnées des points
- get_values_underpoly(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True, getxy: bool = False)[source]
Récupération des valeurs contenues sous une polyligne
- Parameters:
usemask – (optional) restreint les éléments aux éléments non masqués de la matrice
getxy – (optional) retourne en plus les coordonnées des points
- get_all_values_insidepoly(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True, getxy: bool = False)[source]
Récupération de toutes les valeurs contenues dans un polygone
- Parameters:
usemask – (optional) restreint les éléments aux éléments non masqués de la matrice
getxy – (optional) retourne en plus les coordonnées des points
- ICI on retourne le résultat de get_values_insidepoly, car une seule matrice, mais une autre classe pourrait vouloir faure autre chose
C’est le cas notamment de Wolfresults_2D
- get_all_values_underpoly(myvect: wolfhece.PyVertexvectors.vector, usemask: bool = True, getxy: bool = False)[source]
Récupération de toutes les valeurs sous la polyligne
- Parameters:
usemask – (optional) restreint les éléments aux éléments non masqués de la matrice
getxy – (optional) retourne en plus les coordonnées des points
- ICI on retourne le résultat de get_values_underpoly, car une seule matrice, mais une autre classe pourrait vouloir faure autre chose
C’est le cas notamment de Wolfresults_2D
- write_all(newpath: str | pathlib.Path = None, EPSG: int = 31370)[source]
Ecriture de tous les fichiers d’un Wolf array
- Parameters:
newpath – new path and filename with extension – if None, use the current filename
EPSG – EPSG code for geotiff
- get_rebin_shape_size(factor: float) tuple[tuple[int, int], tuple[float, float]] [source]
Return the new shape after rebinning.
newdx = dx * factor newdy = dy * factor
The shape is adjusted to be a multiple of the factor.
- Parameters:
factor (float) – factor of resolution change – > 1.0 : decrease resolution, < 1.0 : increase resolution
- Returns:
new shape
- Return type:
Tuple[int, int], Tuple[float, float]
- get_rebin_header(factor: float) header_wolf [source]
Return a new header after rebinning.
- Parameters:
factor (float) – factor of resolution change – > 1.0 : decrease resolution, < 1.0 : increase resolution
- Returns:
new header
- Return type:
- rebin(factor: float, operation: Literal[mean, sum, min, max, median] = 'mean', operation_matrix: WolfArray = None) None [source]
Change resolution - in place.
If you want to keep current data, copy the WolfArray into a new variable -> newWA = Wolfarray(mold=curWA).
- Parameters:
factor (float) – factor of resolution change – > 1.0 : decrease resolution, < 1.0 : increase resolution
operation (str, Rebin_Ops) – operation to apply on the blocks (‘mean’, ‘sum’, ‘min’, ‘max’, ‘median’)
operation_matrix (WolfArray) – operation matrix to apply on the blocks – see the Enum “Rebin_Ops” for more infos. The matrix must have the same shape as the new array
- read_txt_header()[source]
Read header from txt file Supercharged by WolfArray to avoid explicit call to read_txt_header with parameters
- write_txt_header()[source]
Write header to txt file Supercharged by WolfArray to avoid explicit call to write_txt_header with parameters
- classmethod set_general_frame_from_xyz(fname: str, dx: float, dy: float, border_size: int = 5, delimiter: str = ',', fillin: bool = False)[source]
Lecture d’un fichier texte xyz et initialisation des données de base
- Parameters:
fname – nom du fichier xyz
dx – pas en x
dy – pas en y
border_size – nombre de mailles de bordure en plus de l’extension spatiale du fichier
- classmethod set_general_frame_from_xyz_dir(path: str, bounds: list, delimiter: str = ',', dxdy: tuple[float, float] = None, border_size: int = 5, fillin: bool = True)[source]
Lecture d’un dossier contenant des fichiers texte xyz, initialisation des données de base et chargement de la matrice Renvoie un WolfArray or False si le fichier n’est pas dans les limites
- Parameters:
path – chemin du dossier avec les fichier xyz
bounds – limites de l’extension spatiale
delimiter – délimiteur des fichiers xyz
border_size – nombre de mailles de bordure en plus de l’extension spatiale du fichier
- Dtype path:
str
- Dtype bounds:
list
- Dtype delimiter:
str
- Dtype border_size:
int
- meshgrid(mode: Literal[gc, borders] = 'gc')[source]
Création d’un maillage 2D
- Parameters:
mode – ‘gc’ pour les centres de mailles, ‘borders’ pour les bords de mailles
- crop_masked_at_edges()[source]
Crop the array to remove masked cells at the edges of the array :return: cropped array, WolfArray instance
- crop(i_start: int, j_start: int, nbx: int, nby: int, k_start: int = 1, nbz: int = 1)[source]
Crop the array
- Parameters:
i_start – start index in x
j_start – start index in y
nbx – number of cells in x
nby – number of cells in y
k_start – start index in z
nbz – number of cells in z
- Returns:
cropped array, WolfArray instance
- get_value(x: float, y: float, z: float = 0.0, nullvalue: float = -99999)[source]
Return the value at given coordinates
- Parameters:
x – x coordinate
y – y coordinate
z – z coordinate
nullvalue – value to return if the point is outside the array
- get_xlim(window_x: float, window_y: float)[source]
Return the limits in x for a given window size
- Parameters:
window_x – window size in x
window_y – window size in y
- get_ylim(window_x: float, window_y: float)[source]
Retrun the limits in y for a given window size
- Parameters:
window_x – window size in x
window_y – window size in y
- get_working_array(onzoom: list[float] = [])[source]
Return the part of the array in the zoom window
- Parameters:
onzoom – zoom window – [xmin, xmax, ymin, ymax]
- updatepalette(which: int = 0, onzoom=[])[source]
Update the palette/colormap
- Parameters:
which – which palette to update
onzoom – zoom window – [xmin, xmax, ymin, ymax]
- plot(sx: float = None, sy: float = None, xmin: float = None, ymin: float = None, xmax: float = None, ymax: float = None, size: float = None)[source]
Plot the array - OpenGL
- Parameters:
sx – scale along X
sy – scale along Y
xmin – Lower-Left coordinates in X
ymin – Lower-Left coordinates in Y
xmax – Upper-Right coordinates in X
ymax – Upper-Right coordinates in Y
size – size of the window (not used here but necessary for compatibility with Element_To_Draw)
- plot_matplotlib(figax: tuple = None, getdata_im: bool = False)[source]
Plot the array - Matplotlib version
Using imshow and RGB array
- suxsuy_contour(filename: str = '', abs: bool = False, one_vec_if_ml: bool = True) tuple[list[int, int], list[int, int], wolfhece.PyVertexvectors.vector | wolfhece.PyVertexvectors.zone, bool] [source]
The borders are computed on basis of the current mask
- Parameters:
filename – if provided, write ‘sux’, ‘sux’ and ‘xy’ files
abs – add translation coordinates (Global World Coordinates)
:return indicesX, indicesY, contourgen, interior
indicesX : list of coupled indices along X - vertical border - 1-based like Fortran indicesY : list of coupled indices along Y - horizontal border - 1-based like Fortran contourgen : external contour interior : if False, contour is unique ; if True, interior contours exist -> interior parts are merged
- 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] [source]
Create Matplotlib image from WolfArray
- set_array_from_numpy(array: numpy.ndarray, nullvalue: float = None)[source]
Set array from numpy array
- map_values(keys_vals: dict, default: float = None)[source]
Mapping array values to new values defined by a dictionnary.
First, check if all values are in keys_vals. If not, set to default. If default is None, set to nullvalue.
- Parameters:
keys_vals – dictionary of values to map
default – default value if key not found
- classmethod from_other_epsg_coo(input_raster_path: str, input_srs='EPSG:3812', output_srs='EPSG:31370', resampling_method=gdal.GRA_Bilinear, xRes: float = 0.5, yRes: float = 0.5)[source]
Reprojects and resamples a raster file from an other EPSG coordinates and return it as a WolfArray.
- Parameters:
input_raster_path (str) – The path to the input raster file.
input_srs (str) – The input spatial reference system (SRS) in the format ‘EPSG:XXXX’. Defaults to Lambert 2008 ‘EPSG:3812’.
output_srs (str) – The output spatial reference system (SRS) in the format ‘EPSG:XXXX’. Defaults to Belgian Lambert 72 ‘EPSG:31370’.
resampling_method – The resampling method to use. Defaults to gdal.GRA_Bilinear. Resampling method can be chosen among the gdal GRA_*
constants (gdal.GRA_Average; gdal.GRA_Bilinear; gdal.GRA_Cubic; gdal.GRA_CubicSpline; gdal.GRA_Lanczos; gdal.GRA_Mode; gdal.GRA_NearestNeighbour) :type resampling_method: int :param xRes: The desired output resolution in the x direction. Defaults to 0.5. :type xRes (float): float :param yRes: The desired output resolution in the y direction. Defaults to 0.5. :type yRes (float): float
- Raises:
AssertionError – If the input or output raster file is not a GeoTIFF file.
RuntimeError – If the input raster file cannot be opened.
PermissionError – If there is a permission error while trying to delete the output raster file.
Exception – If an unexpected error occurs while trying to delete the output raster file.
RuntimeError – If the reprojection fails for the input raster file.
- Returns:
WolfArray
- contour(levels: int | list[float] = 10) wolfhece.PyVertexvectors.Zones [source]
Compute contour lines
- class wolfhece.wolf_array.WolfArrayMB(fname=None, mold=None, masknull=True, crop=None, whichtype=WOLF_ARRAY_MB_SINGLE, preload=True, create=False, mapviewer=None, nullvalue=0, srcheader=None)[source]
Bases:
WolfArray
Matrice multiblocks
Les blocs (objets WolfArray) sont stockés dans un dictionnaire “myblocks”
- filter_zone(set_null: bool = False)[source]
Filtre des zones et conservation de celles pour lesquelles des mailles sont sélectionnées
- interpolate_on_polygon(working_vector: wolfhece.PyVertexvectors.vector, method: Literal[nearest, linear, cubic] = 'linear')[source]
Interpolation sous un polygone
- L’interpolation a lieu :
uniquement dans les mailles sélectionnées si elles existent
dans les mailles contenues dans le polygone sinon
On utilise ensuite “griddata” pour interpoler les altitudes des mailles depuis les vertices 3D du polygone
- interpolate_on_polygons(working_zone: wolfhece.PyVertexvectors.zone, method: Literal[nearest, linear, cubic] = 'linear')[source]
Interpolation sous plusieurs polygones d’une même zone
- interpolate_on_polyline(working_vector: wolfhece.PyVertexvectors.vector, usemask=True)[source]
Interpolation sous une polyligne
- L’interpolation a lieu :
uniquement dans les mailles sélectionnées si elles existent
dans les mailles sous la polyligne sinon
On utilise ensuite “interpolate” de shapely pour interpoler les altitudes des mailles depuis les vertices 3D de la polyligne
- interpolate_on_polylines(working_zone: wolfhece.PyVertexvectors.zone, usemask=True)[source]
Interpolation sous les polylignes d’une même zone
- add_block(arr: WolfArray, force_idx: bool = False, copyarray=False)[source]
Adds a properly configured block this multiblock.
- Parameters:
arr – The block to add.
force_idx – If True, the index/key will be set on arr. If False, the index/key must already be set on arr.
Partage de la palette de couleurs entre matrices liées
- copy_mask(source: WolfArrayMB, forcenullvalue: bool = False)[source]
Copy the mask of two arrays
- uncheck_plot(unload: bool = True, forceresetOGL: bool = False, askquestion: bool = True)[source]
Uncheck plot and apply to each block
- mask_union(source: WolfArrayMB)[source]
Union of the masks of two arrays
Applying for each block iteratively.
- get_ij_from_xy(x: float, y: float, z: float = 0.0, scale: float = 1.0, aswolf: bool = False, abs: bool = True, which_block: int = 1)[source]
alias for get_ij_from_xy for the block `which_block
- Parameters:
x – x coordinate
y – y coordinate
z – z coordinate
scale – scale factor
aswolf – if True, then the indices are 1-based like Fortran, otherwise 0-based like Python
abs – if True, then the translation is taken into account
which_block – block index 1-based
- get_values_as_wolf(i: int, j: int, which_block: int = 1)[source]
Return the value at indices (i,j) of the block `which_block.
- Parameters:
i – i index
j – j index
which_block – block index 1-based
- get_value(x: float, y: float, abs: bool = True)[source]
Read the value at world coordinate (x,y). if abs is given, then the translation is is taken into account.
If no block covers the coordinate, then np.NaN is returned If several blocks cover the given coordinate then the first match is returned (and thus, the others are ignored).
- Parameters:
x – x coordinate
y – y coordinate
abs – if True, then the translation is taken into account
- Returns:
the value at (x,y) or np.NaN if no block covers the coordinate
- get_xy_from_ij(i: int, j: int, which_block: int, aswolf: bool = False, abs: bool = True)[source]
Return the world coordinates (x,y) of the indices (i,j) of the block `which_block.
- Parameters:
i – i index – 1-based like Fortran or 0-based like Python, see ‘aswolf’ parameter
j – j index – 1-based like Fortran or 0-based like Python, see ‘aswolf’ parameter
which_block – block index 1-based
aswolf – if True, (i,j) are 1-based like Fortran, otherwise 0-based like Python
abs – if True, then the translation is taken into account
- get_blockij_from_xy(x: float, y: float, abs: bool = True)[source]
Return the block indices (i,j) of the block covering the world coordinate (x,y)
- Parameters:
x – x coordinate
y – y coordinate
abs – if True, then the translation is taken into account
- Returns:
the block indices (i,j,[k]) or (-1,-1,-1) if no block covers the coordinate
- updatepalette(which: int = 0, onzoom: list[float] = [])[source]
Update the palette/colormap of the array
- Parameters:
which – which colormap to use
onzoom – if not empty, then only the values within the zoom are used to update the palette – [xmin,xmax,ymin,ymax]
- plot(sx=None, sy=None, xmin=None, ymin=None, xmax=None, ymax=None, size=None)[source]
Plot the array
- 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] [source]
Create Matplotlib image from MultiBlock array
- as_WolfArray(abs: bool = True, forced_header: header_wolf = None) WolfArray [source]
Convert to WolfArray
Rebin blocks if necessary
- class wolfhece.wolf_array.WolfArrayMNAP(fname=None, mold=None, masknull=True, crop=None)[source]
Bases:
WolfArrayMB
Matrice MNAP d’une modélisation WOLF2D
Elle contient toutes les informations de maillage en Multi-blocks ainsi que les relations de voisinage de blocs.
Surcharge de WolfArrayMB avec modification des opérations de lecture/écriture car le fichier est au format TEXTE/ASCII et d’une structure spécifique.
- write_all()[source]
Ecriture de tous les fichiers d’un Wolf array
- Parameters:
newpath – new path and filename with extension – if None, use the current filename
EPSG – EPSG code for geotiff