tidy3d.TriangularGridDataset#

class TriangularGridDataset[source]#

Bases: UnstructuredGridDataset

Dataset for storing triangular 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

>>> 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

bounds

Grid bounds.

normal_axis

normal_pos

Fundamental parameters to set up based on grid dimensionality

points

values

cells

Fundametal parameters to set up based on grid dimensionality

Methods

does_cover(bounds)

Check whether data fully covers specified by bounds spatial region.

get_cell_volumes()

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 axis and center.

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

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

sel_inside(bounds)

Return a new TriangularGridDataset that contains the minimal amount data necessary to cover a spatial region defined by bounds.

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:

xarray.DataArray

reflect(axis, center, reflection_only=False, symmetry=1.0)[source]#

Reflect unstructured data across the plane define by parameters axis and center. By default the original data is preserved, setting reflection_only to True will 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:

xarray.DataArray

sel_inside(bounds)[source]#

Return a new TriangularGridDataset that contains the minimal amount data necessary to cover a spatial region defined by bounds.

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:

TriangularGridDataset

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

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

get_cell_volumes()[source]#

Get areas associated to each cell of the grid.