tidy3d.TriangularGridDataset#
- class TriangularGridDataset[source]#
Bases:
UnstructuredGridDataset
Dataset for storing triangular grid data. Data values are associated with the nodes of the grid.
- Parameters:
attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields,
attrs
are mutable. For example, the following is allowed for setting anattr
obj.attrs['foo'] = bar
. Also note that Tidy3D` will raise aTypeError
ifattrs
contain objects that can not be serialized. One can check ifattrs
are serializable by callingobj.json()
.points (PointDataArray) – Coordinates of points composing the unstructured grid.
values (IndexedDataArray) – 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
vtk
package (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
Methods
does_cover
(bounds)Check whether data fully covers specified by
bounds
spatial region.interp
(x, y, z[, fill_value, use_vtk, ...])Interpolate data at provided x, y, and z.
plane_slice
(axis, pos)Slice data with a plane and return the resulting line as a SpatialDataArray.
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
axis
andcenter
.sel
([x, y, z])Extract/interpolate data along one or more Cartesian directions.
sel_inside
(bounds)Return a new
TriangularGridDataset
that contains the minimal amount data necessary to cover a spatial region defined bybounds
.Inherited Common Usage
- normal_axis#
- normal_pos#
- property bounds#
Grid bounds.
- plane_slice(axis, pos)[source]#
Slice data with a plane and return the resulting line as a SpatialDataArray.
- 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:
- 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.
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes
- interp(x, y, z, fill_value=None, use_vtk=False, method='linear', ignore_normal_pos=True, max_samples_per_step=10000, max_cells_per_step=10000, rel_tol=1e-06)[source]#
Interpolate data at provided x, y, and z. Note that data is assumed to be invariant along the dataset’s normal direction.
- Parameters:
x (Union[float, ArrayLike]) – x-coordinates of sampling points.
y (Union[float, ArrayLike]) – y-coordinates of sampling points.
z (Union[float, ArrayLike]) – z-coordinates of sampling points.
fill_value (Union[float, Literal["extrapolate"]] = 0) – Value to use when filling points without interpolated values. If
"extrapolate"
then nearest values are used. Note: in a future version the default value will be changed to"extrapolate"
.use_vtk (bool = False) – Use vtk’s interpolation functionality or Tidy3D’s own implementation. Note: this option will be removed in a future version.
method (Literal["linear", "nearest"] = "linear") – Interpolation method to use.
ignore_normal_pos (bool = True) – (Depreciated) Assume data is invariant along the normal direction to the grid plane.
max_samples_per_step (int = 1e4) – Max number of points to interpolate at per iteration (used only if use_vtk=False). Using a higher number may speed up calculations but, at the same time, it increases RAM usage.
max_cells_per_step (int = 1e4) – Max number of cells to interpolate from per iteration (used only if use_vtk=False). Using a higher number may speed up calculations but, at the same time, it increases RAM usage.
rel_tol (float = 1e-6) – Relative tolerance when determining whether a point belongs to a cell.
- Returns:
Interpolated data.
- Return type:
- sel(x=None, y=None, z=None)[source]#
Extract/interpolate data along one or more Cartesian directions. At least of x, y, and z must be provided.
- 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.
- Returns:
Extracted data.
- Return type:
- reflect(axis, center, reflection_only=False)[source]#
Reflect unstructured data across the plane define by parameters
axis
andcenter
. By default the original data is preserved, settingreflection_only
toTrue
will produce only deflected 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.
- Returns:
Data after reflextion is performed.
- Return type:
UnstructuredGridDataset
- sel_inside(bounds)[source]#
Return a new
TriangularGridDataset
that contains the minimal amount data necessary to cover a spatial region defined bybounds
.- Parameters:
bounds (Tuple[float, float, float], Tuple[float, float float]) – Min and max bounds packaged as
(minx, miny, minz), (maxx, maxy, maxz)
.- Returns:
Extracted spatial data array.
- Return type:
- does_cover(bounds)[source]#
Check whether data fully covers specified by
bounds
spatial 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.- Parameters:
bounds (Tuple[float, float, float], Tuple[float, float float]) – Min and max bounds packaged as
(minx, miny, minz), (maxx, maxy, maxz)
.- Returns:
Full cover check outcome.
- Return type:
bool
- __hash__()#
Hash method.