cherab.imas.ggd.UnstructGrid2D

class cherab.imas.ggd.UnstructGrid2D(vertices: ArrayLike, cells: NDArray[integer[Any]] | Sequence[Sequence[SupportsIndex] | NDArray[integer[Any]]], valid_data_mask: NDArray[bool] | Sequence[bool] | None = None, name: str = 'Cells', coordinate_system: 'cylindrical' | 'cartesian' = 'cylindrical')Source

Bases: GGDGrid

Unstructured 2D grid object.

The grid cells are polygons. Vertices may be shared with neighbouring cells.

To use Raysect’s KDtree accelerator, each polygonal cell is triangulated.

Parameters:
vertices: ArrayLike

Array-like of shape (N, 2) containing coordinates of the polygon vertices.

cells: NDArray[integer[Any]] | Sequence[Sequence[SupportsIndex] | NDArray[integer[Any]]]

An (N, 4) integer array or a list/tuple of 1-D integer index arrays containing the vertex indices in clockwise or counterclockwise order for each polygonal cell (the starting vertex must not be included twice).

valid_data_mask: NDArray[bool] | Sequence[bool] | None = None

Boolean mask over the source face/data entries. Its number of True values must equal the number of cells retained by this grid. Data passed to plotting/interpolation may therefore be either source-sized or already compacted to the valid cells.

name: str = 'Cells'

Name of the grid, by default 'Cells'.

coordinate_system: 'cylindrical' | 'cartesian' = 'cylindrical'

Coordinate system of the grid, by default 'cylindrical'.

Methods

interpolator(grid_data[, fill_value, ...])

Return an UnstructGridFunction2D interpolator instance for the data defined on this grid.

plot_mesh([data, ax])

Plot the polygonal mesh grid geometry to a matplotlib figure.

plot_triangle_mesh([data, ax])

Plot the triangle mesh grid geometry to a matplotlib figure.

subset(indices[, name, valid_data_mask])

Create a subset UnstructGrid2D from this instance.

vector_interpolator(grid_vectors[, ...])

Return an UnstructGridVectorFunction2D interpolator instance for the vector data defined on this grid.

Attributes

cell_area

Cell areas as (num_cell,) array.

cell_centre

Coordinate of cell centres as (num_cell, dimension) array.

cell_to_triangle_map

Array of shape (K, 2) mapping every grid cell index to triangle IDs.

cell_volume

Cell volume as (num_cell,) array.

cells

List of K polygonal cells as 1-D integer index arrays.

coordinate_system

Coordinate system.

dimension

Grid dimension.

mesh_extent

Extent of the mesh.

name

Grid name.

num_cell

Number of grid cells.

triangle_to_cell_map

Array of shape (M,) mapping every triangle index to a grid cell ID.

triangles

Mesh triangles as (M, 3) array.

valid_data_mask

Boolean mask over source data entries retained by this grid.

vertices

Mesh vertex coordinates as (N, 2) array.

property vertices : NDArray[float64]Source

Mesh vertex coordinates as (N, 2) array.

property cells : tuple[NDArray[int64], ...]Source

List of K polygonal cells as 1-D integer index arrays.

property triangles : NDArray[int32]Source

Mesh triangles as (M, 3) array.

property triangle_to_cell_map : NDArray[int32]Source

Array of shape (M,) mapping every triangle index to a grid cell ID.

property cell_to_triangle_map : NDArray[int32]Source

Array of shape (K, 2) mapping every grid cell index to triangle IDs.

The first column is the index of the first triangle forming the cell. The second column is the number of triangles forming the cell.

>>> itri, ntri = mesh.cell_to_triangle_map[icell]
>>> tri_cell = mesh.triangles[itri : itri + ntri]
property valid_data_mask : NDArray[bool]Source

Boolean mask over source data entries retained by this grid.

subset(indices: Sequence[SupportsIndex] | NDArray[integer[Any]], name: str | None = None, *, valid_data_mask: NDArray[bool] | Sequence[bool] | None = None) UnstructGrid2DSource

Create a subset UnstructGrid2D from this instance.

Parameters:
indices: Sequence[SupportsIndex] | NDArray[integer[Any]]

Indices of the cells of the original grid in the subset.

valid_data_mask: NDArray[bool] | Sequence[bool] | None = None

Boolean array indicating which cells in the subset have valid data.

name: str | None = None

Name of the grid subset. Default is instance.name + " subset".

Returns:

UnstructGrid2D – Subset instance.

Raises:

ValueError – If the validity mask is not one-dimensional or does not select exactly one valid entry per subset cell.

interpolator(grid_data: NDArray[floating[Any]] | Sequence[float], fill_value: float = 0, *, interpolator_cache: 'none' | 'memory' | 'disk' = 'memory', interpolator_cache_dir: str | Path | None = None, interpolator_cache_namespace: str = 'ggd') UnstructGridFunction2DSource

Return an UnstructGridFunction2D interpolator instance for the data defined on this grid.

On the second and subsequent calls, the interpolator is created as an instance of the previously created interpolator sharing the same KDtree structure.

Parameters:
grid_data: NDArray[floating[Any]] | Sequence[float]

Array containing data in the grid cells.

fill_value: float = 0

Value returned outside the grid, by default 0.0.

interpolator_cache: 'none' | 'memory' | 'disk' = 'memory'

Cache mode for the interpolator, by default "memory". The cache mode is described in the InterpolatorCacheMode type alias.

interpolator_cache_dir: str | Path | None = None

Directory used when interpolator_cache="disk", by default None (uses the system cache directory, e.g., ~/.cache/cherab/imas/interpolators).

interpolator_cache_namespace: str = 'ggd'

Namespace prefix to avoid cache-key collisions, by default "ggd".

Returns:

UnstructGridFunction2D – Interpolator instance.

vector_interpolator(grid_vectors: NDArray[float64], fill_vector: Vector3D = Vector3D(0.0, 0.0, 0.0), *, interpolator_cache: 'none' | 'memory' | 'disk' = 'memory', interpolator_cache_dir: str | Path | None = None, interpolator_cache_namespace: str = 'ggd') UnstructGridVectorFunction2DSource

Return an UnstructGridVectorFunction2D interpolator instance for the vector data defined on this grid.

On the second and subsequent calls, the interpolator is created as an instance of the previously created interpolator sharing the same KDtree structure.

Parameters:
grid_vectors: NDArray[float64]

(3, K) Array containing 3D vectors in the grid cells.

fill_vector: Vector3D = Vector3D(0.0, 0.0, 0.0)

3D vector returned outside the grid, by default Vector3D(0, 0, 0).

interpolator_cache: 'none' | 'memory' | 'disk' = 'memory'

Cache mode for the interpolator, by default "memory". The cache mode is described in the InterpolatorCacheMode type alias.

interpolator_cache_dir: str | Path | None = None

Directory used when interpolator_cache="disk", by default None (uses the system cache directory, e.g., ~/.cache/cherab/imas/interpolators).

interpolator_cache_namespace: str = 'ggd'

Namespace prefix to avoid cache-key collisions, by default "ggd".

Returns:

UnstructGridVectorFunction2D – Interpolator instance.

plot_triangle_mesh(data: NDArray[floating[Any]] | Sequence[float] | None = None, ax: Axes | None = None, **grid_styles) AxesSource

Plot the triangle mesh grid geometry to a matplotlib figure.

Parameters:
data: NDArray[floating[Any]] | Sequence[float] | None = None

Data array defined on the polygonal mesh.

ax: Axes | None = None

Matplotlib axes to plot on. If None, a new figure and axes are created.

**grid_styles

Styles for the grid lines and faces, by default {"facecolor": "none", "edgecolor": "b", "linewidth": 0.25}.

Returns:

Axes – The matplotlib axes with the plotted mesh.

property cell_area : NDArray[float64]Source

Cell areas as (num_cell,) array.

property cell_centre : NDArray[float64]Source

Coordinate of cell centres as (num_cell, dimension) array.

property cell_volume : NDArray[float64]Source

Cell volume as (num_cell,) array.

property coordinate_system : strSource

Coordinate system.

property dimension : intSource

Grid dimension.

property mesh_extent : dict[str, float]Source

Extent of the mesh.

A dictionary with xmin, xmax, ymin and ymax, … keys.

property name : strSource

Grid name.

property num_cell : intSource

Number of grid cells.

plot_mesh(data: NDArray[floating[Any]] | Sequence[float] | None = None, ax: Axes | None = None, **grid_styles) AxesSource

Plot the polygonal mesh grid geometry to a matplotlib figure.

Parameters:
data: NDArray[floating[Any]] | Sequence[float] | None = None

Data array defined on the polygonal mesh.

ax: Axes | None = None

Matplotlib axes to plot on. If None, a new figure and axes are created.

**grid_styles

Styles for the grid lines and faces, by default {"facecolor": "none", "edgecolor": "b", "linewidth": 0.25}. If data is provided, the styles are not applied to the grid lines and faces to allow the data colormap to be visible.

Returns:

Axes – The matplotlib axes with the plotted mesh.