tidy3d.TetrahedralGridDataset#

class TetrahedralGridDataset[source]#

Bases: UnstructuredGridDataset

Dataset for storing tetrahedral grid data. Data values are associated with the nodes of the grid.

Parameters:

Note

To use full functionality of unstructured datasets one must install vtk package (pip install tidy3d[vtk] or pip install vtk). Otherwise the functionality of unstructured datasets is limited to creation, writing to/loading from a file, and arithmetic manipulations.

Example

>>> import numpy as np
>>> from tidy3d.components.data.data_array import PointDataArray, CellDataArray, IndexedDataArray
>>>
>>> tet_grid_points = PointDataArray(
...     [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]],
...     coords=dict(index=np.arange(4), axis=np.arange(3)),
... )
>>>
>>> tet_grid_cells = CellDataArray(
...     [[0, 1, 2, 3]],
...     coords=dict(cell_index=np.arange(1), vertex_index=np.arange(4)),
... )
>>>
>>> tet_grid_values = IndexedDataArray(
...     [1.0, 2.0, 3.0, 4.0], coords=dict(index=np.arange(4)),
... )
>>>
>>> tet_grid = TetrahedralGridDataset(
...     points=tet_grid_points,
...     cells=tet_grid_cells,
...     values=tet_grid_values,
... )

Attributes

points

values

cells

Fundametal parameters to set up based on grid dimensionality

Methods

get_cell_volumes()

Get the volumes associated to each cell in the grid

line_slice(axis, pos)

Slice data with a line and return the resulting xarray.DataArray.

plane_slice(axis, pos)

Slice data with a plane and return the resulting TriangularGridDataset.

plot([x, y, z])

Plot a 2D slice of the tetrahedral grid data.

sel([x, y, z, method])

Extract/interpolate data along one or more spatial or non-spatial directions.

plane_slice(axis, pos)[source]#

Slice data with a plane and return the resulting TriangularGridDataset.

Parameters:
  • axis (Axis) – The normal direction of the slicing plane.

  • pos (float) – Position of the slicing plane along its normal direction.

Returns:

The resulting slice.

Return type:

TriangularGridDataset

line_slice(axis, pos)[source]#

Slice data with a line and return the resulting xarray.DataArray.

Parameters:
  • axis (Axis) – The axis of the slicing line.

  • pos (Tuple[float, float, float]) – Position of the slicing line.

Returns:

The resulting slice.

Return type:

xarray.DataArray

sel(x=None, y=None, z=None, method=None, **sel_kwargs)[source]#

Extract/interpolate data along one or more spatial or non-spatial directions.

Must provide at least one argument among ‘x’, ‘y’, ‘z’ or non-spatial dimensions through additional arguments. Along spatial dimensions a suitable slicing of grid is applied (plane slice, line slice, or interpolation). Selection along non-spatial dimensions is forwarded to .sel() xarray function.

Parameters:
  • x (Union[float, ArrayLike] = None) – x-coordinate of the slice.

  • y (Union[float, ArrayLike] = None) – y-coordinate of the slice.

  • z (Union[float, ArrayLike] = None) – z-coordinate of the slice.

  • method (Optional[Literal["nearest", "pad", "ffill", "backfill", "bfill"]] = None) – Method to use for inexact matches (applies to non-spatial dimensions only).

  • **sel_kwargs (dict) – Keyword arguments to pass to the xarray sel() function.

Returns:

Extracted data.

Return type:

Union[TriangularGridDataset, xarray.DataArray]

plot(x=None, y=None, z=None, **kwargs)[source]#

Plot a 2D slice of the tetrahedral grid data.

Exactly one of x, y, or z must be provided to select the slicing plane. The slice produces a TriangularGridDataset whose .plot() method is then called with the remaining keyword arguments.

Parameters:
  • x (float = None) – Position of the slicing plane along the x-axis.

  • y (float = None) – Position of the slicing plane along the y-axis.

  • z (float = None) – Position of the slicing plane along the z-axis.

  • **kwargs (dict) – Keyword arguments forwarded to TriangularGridDataset.plot().

Returns:

The supplied or created matplotlib axes.

Return type:

matplotlib.axes._subplots.Axes

get_cell_volumes()[source]#

Get the volumes associated to each cell in the grid