geo3d.geometry.voxel¶
Classes¶
Class for defining a Voxel object. |
|
Class for defining a 2D grid of voxels. |
Module Contents¶
- class geo3d.geometry.voxel.Voxel(coordinates: tuple[int, int], state: int = 0, value: float = np.nan)¶
Class for defining a Voxel object.
- Attrs:
STATE_LABELS (dict): A dictionary defining the possible states of a voxel.
- STATE_LABELS¶
- _coordinates¶
- _state = 0¶
- _value¶
- property coordinates: tuple[int, int]¶
Returns the coordinates of the voxel.
- Returns:
The coordinates of the voxel.
- Return type:
tuple
- property state: int¶
Returns the state of the voxel.
- Returns:
The state of the voxel.
- Return type:
int
- property value: float¶
Returns the value of the voxel.
- Returns:
The numeric value of the voxel. np.nan if empty.
- Return type:
float
- __repr__() str¶
Special method to represent a Voxel object.
- Returns:
The representation of the Voxel object.
- Return type:
str
- class geo3d.geometry.voxel.VoxelGrid2D(x0: float, y0: float, nx: int, ny: int, size: int)¶
Class for defining a 2D grid of voxels.
In analogy with images, a grid is composed of multiple channels. Ech channel has a name and a particular agencement of its voxels and their values.
- x0¶
- y0¶
- nx¶
- ny¶
- size¶
- grid_base¶
- channel_dict¶
- get_channel(name: str) numpy.typing.NDArray¶
Get a particular channel from the grid.
- Parameters:
name (str) – the channel name.
- Returns:
The channel grid as an array of Voxels.
- Return type:
np.ndarray
- property shape: tuple[int, int]¶
Returns the grid shape.
- Returns:
(nx, ny)
- Return type:
tuple
- voxels(attr: str, channel_name: str) numpy.typing.NDArray[numpy.floating]¶
Get an array of voxels from a grid channel.
- Parameters:
attr – The voxel’s attribute to extract (‘state’ or ‘value’).
channel_name (str) – Name of the channel.
- Returns:
A 2D-array of voxels.
- Return type:
np.ndarray
- neighbors(coordinate: tuple[int, int]) List[tuple[int, int]]¶
Get the 8 neighbors of a voxel in a grid.
- Parameters:
coordinate (tuple) – The coordinates of the voxel.
- Returns:
The list of the neighbors of the voxel.
- Return type:
List
- fill(coordinate: tuple[int, int], channel_name: str) None¶
Fill a voxel.
- Parameters:
coordinate (tuple) – The coordinate of the voxel to fill.
channel_name (str) – name of the channel to fill.
- occupancy(coordinate: tuple[int, int], channel_name: str) float¶
Compute the occupancy of a voxel.
Each voxel in the grid has 8 neighbors (expect those at the bordure). The occupancy is defined by the number of neighbors of a voxel that have a ‘fill’ state. An occupancy of 3 means that for a given voxel, there is exactly 3 neighbors having the ‘fill’ state.
- Parameters:
coordinate (tuple) – The coordinate of the voxel.
channel_name (str) – name of the channel to fill.
- Returns:
The occupancy value.
- Return type:
int
- occupancy_condition(coordinate: tuple[int, int], channel_name: str, threshold: int = 3) bool¶
Get a boolean status of the occupancy of a voxel.
The voxel is filled only if its occupancy is lower than a threhsold.
- Parameters:
coordinate (tuple) – The coordinate of the voxel.
threshold (int) – The threshold on occupancy. Defaults to 3.
channel_name (str) – name of the grid to fill.
- Returns:
True if the occupancy is lower than the threshold
- Return type:
bool
- fill_elements(n: int, channel_name: str) int¶
Fill in elements in empty voxels.
- Parameters:
n (int) – The number of voxels to fill.
channel_name (str) – name of the channel to fill.
- Returns:
The number of voxels that were filled.
- Return type:
int
- enlarge(extra_rows: int) None¶
Enlarge the grid by adding extra rows at the top of the grid.
- Parameters:
extra_rows (int) – The number of rows to add.
- interpolate_values(channel_name: str) None¶
Interpolate the values of the voxels of a channel.
- Parameters:
channel_name (str) – name of the channel.
- add_channel(name: str, grid_array: numpy.ndarray, metadata: dict) None¶
Add a channel tp the grid.
- Parameters:
name (str) – The name of the channel. Must be unique in the channels dictionary.
grid_array (np.ndarray) – The 2D array of values.
metadata (dict) – A dictionary of metadata having the keys ‘classes’, ‘func_agg’, and ‘dimension’.
- plot(channel_name: str, kind: str = 'state') None¶
Plot the voxels grid from a channel.
The plot of a grid is made by a scatter plot. 2 kinds are possible, ‘state’ to visualize the occupancy state of each voxel, or ‘value’ to visualize the numeric value of each voxel.
- Parameters:
channel_name (str) – The name of the channel.
kind (str, optional) – The kind of plot (‘state’ or ‘value’). Defaults to ‘state’.