tidy3d.TriangularGridDataset#
- class TriangularGridDataset[source]#
Bases:
UnstructuredGridDatasetDataset for storing triangular 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.
normal_axis (Literal[0, 1, 2]) – Orientation of the grid.
normal_pos (float) – Coordinate of the grid along the normal direction.
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
>>> tri_grid_points = PointDataArray( ... [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]], ... coords=dict(index=np.arange(4), axis=np.arange(2)), ... ) >>> >>> tri_grid_cells = CellDataArray( ... [[0, 1, 2], [1, 2, 3]], ... coords=dict(cell_index=np.arange(2), vertex_index=np.arange(3)), ... ) >>> >>> tri_grid_values = IndexedDataArray( ... [1.0, 2.0, 3.0, 4.0], coords=dict(index=np.arange(4)), ... ) >>> >>> tri_grid = TriangularGridDataset( ... normal_axis=1, ... normal_pos=0, ... points=tri_grid_points, ... cells=tri_grid_cells, ... values=tri_grid_values, ... )
Attributes
Grid bounds.
Fundamental parameters to set up based on grid dimensionality
pointsvaluescellsFundametal parameters to set up based on grid dimensionality
Methods
does_cover(bounds)Check whether data fully covers specified by
boundsspatial region.Get areas associated to each cell of the grid.
plane_slice(axis, pos)Slice data with a plane and return the resulting line as a DataArray.
plot([ax, field, grid, cbar, cmap, vmin, ...])Plot the data field and/or the unstructured grid.
reflect(axis, center[, reflection_only, ...])Reflect unstructured data across the plane define by parameters
axisandcenter.sel([x, y, z, method])Extract/interpolate data along one or more spatial or non-spatial directions.
sel_inside(bounds)Return a new
TriangularGridDatasetthat contains the minimal amount data necessary to cover a spatial region defined bybounds.- normal_axis#
- normal_pos#
Fundamental parameters to set up based on grid dimensionality
- property bounds#
Grid bounds.
- plane_slice(axis, pos)[source]#
Slice data with a plane and return the resulting line as a DataArray.
- 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:
- reflect(axis, center, reflection_only=False, symmetry=1.0)[source]#
Reflect unstructured data across the plane define by parameters
axisandcenter. By default the original data is preserved, settingreflection_onlytoTruewill produce only reflected data.- Parameters:
axis (Literal[0, 1, 2]) – Normal direction of the reflection plane.
center (float) – Location of the reflection plane along its normal direction.
reflection_only (bool = False) – Return only reflected data.
symmetry (float = 1.0) – Symmetry factor to apply to the data.
- Returns:
Data after reflextion is performed.
- Return type:
UnstructuredGridDataset
- 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. Parameter ‘method’ applies only to non-spatial dimensions.
- 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 (Literal[None, "nearest", "pad", "ffill", "backfill", "bfill"] = None) – Method to use in xarray sel() function.
**sel_kwargs (dict) – Keyword arguments to pass to the xarray sel() function.
- Returns:
Extracted data.
- Return type:
- sel_inside(bounds)[source]#
Return a new
TriangularGridDatasetthat contains the minimal amount data necessary to cover a spatial region defined bybounds.
- does_cover(bounds)[source]#
Check whether data fully covers specified by
boundsspatial region. If data contains only one point along a given direction, then it is assumed the data is constant along that direction and coverage is not checked.
- plot(ax=None, field=True, grid=True, cbar=True, cmap='viridis', vmin=None, vmax=None, shading='gouraud', cbar_kwargs=None, pcolor_kwargs=None)[source]#
Plot the data field and/or the unstructured grid.
- Parameters:
ax (matplotlib.axes._subplots.Axes = None) – matplotlib axes to plot on, if not specified, one is created.
field (bool = True) – Whether to plot the data field.
grid (bool = True) – Whether to plot the unstructured grid.
cbar (bool = True) – Display colorbar (only if
field == True).cmap (str = "viridis") – Color map to use for plotting.
vmin (float = None) – The lower bound of data range that the colormap covers. If
None, they are inferred from the data and other keyword arguments.vmax (float = None) – The upper bound of data range that the colormap covers. If
None, they are inferred from the data and other keyword arguments.shading (Literal["gourand", "flat"] = "gourand") – Type of shading to use when plotting the data field.
cbar_kwargs (Dict = {}) – Additional parameters passed to colorbar object.
pcolor_kwargs (Dict = {}) – Additional parameters passed to ax.tripcolor()
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes