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, - attrsare mutable. For example, the following is allowed for setting an- attr- obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a- TypeErrorif- attrscontain objects that can not be serialized. One can check if- attrsare serializable by calling- obj.json().
- points (PointDataArray) – Coordinates of points composing the unstructured grid. 
- values (Union[IndexedDataArray, IndexedVoltageDataArray]) – 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]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 - Methods - does_cover(bounds)- Check whether data fully covers specified by - boundsspatial region.- 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 - axisand- center.- 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 by- bounds.- Inherited Common Usage - 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)[source]#
- Reflect unstructured data across the plane define by parameters - axisand- center. By default the original data is preserved, setting- reflection_onlyto- Truewill 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(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 - TriangularGridDatasetthat 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:
 
 - 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.- 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. 
 - 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