tidy3d.TetrahedralGridDataset#
- class TetrahedralGridDataset[source]#
Bases:
UnstructuredGridDatasetDataset for storing tetrahedral grid data. Data values are associated with the nodes of the grid.
- Parameters:
points (PointDataArray) – Coordinates of points composing the unstructured grid.
values (Union[IndexedDataArray, IndexedVoltageDataArray, IndexedSurfaceFieldDataArray, IndexedSurfaceFieldTimeDataArray, IndexedFieldDataArray, IndexedFieldTimeDataArray, IndexedFreqDataArray, IndexedTimeDataArray, IndexedFieldVoltageDataArray, IndexedSurfaceFreqDataArray, IndexedSurfaceTimeDataArray, PointDataArray]) – Values stored at the grid points.
cells (CellDataArray) – Cells composing the unstructured grid specified as connections between grid points.
Note
To use full functionality of unstructured datasets one must install
vtkpackage (pip install tidy3d[vtk]orpip 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
pointsvaluescellsFundametal parameters to set up based on grid dimensionality
Methods
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:
- line_slice(axis, pos)[source]#
Slice data with a line and return the resulting xarray.DataArray.
- Parameters:
- Returns:
The resulting slice.
- Return type:
- 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:
- plot(x=None, y=None, z=None, **kwargs)[source]#
Plot a 2D slice of the tetrahedral grid data.
Exactly one of
x,y, orzmust be provided to select the slicing plane. The slice produces aTriangularGridDatasetwhose.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