tidy3d.Coords#
- class Coords[source]#
Bases:
Tidy3dBaseModelHolds data about a set of x,y,z positions on a 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 anattrobj.attrs['foo'] = bar. Also note that Tidy3D will raise aTypeErrorifattrscontain objects that can not be serialized. One can check ifattrsare serializable by callingobj.json().x (ArrayLike[dtype=float, ndim=1]) – 1-dimensional array of x coordinates.
y (ArrayLike[dtype=float, ndim=1]) – 1-dimensional array of y coordinates.
z (ArrayLike[dtype=float, ndim=1]) – 1-dimensional array of z coordinates.
Example
>>> x = np.linspace(-1, 1, 10) >>> y = np.linspace(-1, 1, 11) >>> z = np.linspace(-1, 1, 12) >>> coords = Coords(x=x, y=y, z=z)
Attributes
Returns an N-dimensional grid where N is the number of coordinate arrays that have more than one element.
Returns the sizes of the cells in each coordinate array as a dictionary.
Return a dict of the three Coord1D objects as numpy arrays.
Return a list of the three Coord1D objects as numpy arrays.
Methods
get_bounding_indices(coordinate, side[, buffer])Find the bounding indices up to a buffer corresponding to the supplied coordinate.
get_bounding_values(coordinate, side[, buffer])Find the bounding values corresponding to the supplied coordinate.
spatial_interp(array, interp_method[, ...])Similar to
xarrray.DataArray.interpwith 2 enhancements:Inherited Common Usage
- x#
- y#
- z#
- property to_dict#
Return a dict of the three Coord1D objects as numpy arrays.
- property to_list#
Return a list of the three Coord1D objects as numpy arrays.
- property cell_sizes#
Returns the sizes of the cells in each coordinate array as a dictionary.
- property cell_size_meshgrid#
Returns an N-dimensional grid where N is the number of coordinate arrays that have more than one element. Each grid element corresponds to the size of the mesh cell in N-dimensions and 1 for N=0.
- get_bounding_indices(coordinate, side, buffer=0)[source]#
Find the bounding indices up to a buffer corresponding to the supplied coordinate. For x, y, z values supplied in coordinate, look for index into the x, y, and z coordinate arrays such that the value at that index bounds the supplied coordinate entry on either the ‘right’ or ‘left’ side specified by the side parameter. An optional buffer of number of indices can be specified with the default 0. All indices are bound by 0 and the length of each coordinate array so that they can be directly used to index into the coordinate arrays without going out of bounds.
- get_bounding_values(coordinate, side, buffer=0)[source]#
Find the bounding values corresponding to the supplied coordinate. The bounding values extract the values out of the coordinate arrays for the indices found in get_bounding_indices.
- spatial_interp(array, interp_method, fill_value='extrapolate')[source]#
Similar to
xarrray.DataArray.interpwith 2 enhancements:1) (if input data is an
xarrray.DataArray) Check if the coordinate of the supplied data are in monotonically increasing order. If they are, apply the fasterassume_sorted=True.Data is assumed invariant along zero-size dimensions (if any).
- Parameters:
array (Union[) –
SpatialDataArray,ScalarFieldDataArray,TriangularGridDataset,TetrahedralGridDataset,] – Supplied scalar dataset
interp_method (
InterpMethod) – Interpolation method.fill_value (Union[Literal['extrapolate'], float] = "extrapolate") – Value used to fill in for points outside the data range. If set to ‘extrapolate’, values will be extrapolated into those regions using the “nearest” method.
- Returns:
The interpolated spatial dataset.
- Return type:
Union[
SpatialDataArray,ScalarFieldDataArray]
Note
This method is called from a
Coordsinstance with the array to be interpolated as an argument, not the other way around.
- __hash__()#
Hash method.