tidy3d.components.data.sim_data.AbstractYeeGridSimulationData#
- class AbstractYeeGridSimulationData[source]#
Bases:
AbstractSimulationData
,ABC
Data from an
AbstractYeeGridSimulation
involving electromagnetic fields on a Yee 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()
.simulation (AbstractSimulation) โ Original
AbstractSimulation
associated with the data.data (Tuple[AbstractMonitorData, ...]) โ List of
AbstractMonitorData
instances associated with the monitors of the originalAbstractSimulation
.log (Optional[str] = None) โ A string containing the log information from the simulation run.
Notes
The
SimulationData
objects store a copy of the originalSimulation
:, so it can be recovered if theSimulationData
is loaded in a new session and theSimulation
is no longer in memory.More importantly, the
SimulationData
contains a reference to the data for each of the monitors within the originalSimulation
. This data can be accessed directly using the name given to the monitors initially.Attributes
Methods
apply_phase
(data[,ย phase])Apply a phase to xarray data.
at_boundaries
(field_monitor_name)Return xarray.Dataset representation of field monitor data colocated at Yee cell boundaries.
at_centers
(field_monitor_name)Return xarray.Dataset representation of field monitor data colocated at Yee cell centers.
get_intensity
(field_monitor_name)return xarray.DataArray of the intensity of a field monitor at Yee cell centers.
get_poynting_vector
(field_monitor_name)return
xarray.Dataset
of the Poynting vector at Yee cell centers.load_field_monitor
(monitor_name)Load monitor and raise exception if not a field monitor.
mnt_data_from_file
(fname,ย mnt_name,ย ...)Loads data for a specific monitor from a .hdf5 file with data for a
SimulationData
.plot_field
(field_monitor_name,ย field_name[,ย ...])Plot the field data for a monitor with simulation plot overlaid.
plot_field_monitor_data
(field_monitor_data,ย ...)Plot the field data for a monitor with simulation plot overlaid.
plot_scalar_array
(field_data,ย axis,ย position)Plot the field data for a monitor with simulation plot overlaid.
Inherited Common Usage
- at_centers(field_monitor_name)[source]#
Return xarray.Dataset representation of field monitor data colocated at Yee cell centers.
- Parameters:
field_monitor_name (str) โ Name of field monitor used in the original
Simulation
.- Returns:
Dataset containing all of the fields in the data interpolated to center locations on the Yee grid.
- Return type:
xarray.Dataset
- at_boundaries(field_monitor_name)[source]#
Return xarray.Dataset representation of field monitor data colocated at Yee cell boundaries.
- Parameters:
field_monitor_name (str) โ Name of field monitor used in the original
Simulation
.- Returns:
Dataset containing all of the fields in the data interpolated to boundary locations on the Yee grid.
- Return type:
xarray.Dataset
- get_poynting_vector(field_monitor_name)[source]#
return
xarray.Dataset
of the Poynting vector at Yee cell centers.Calculated values represent the instantaneous Poynting vector for time-domain fields and the complex vector for frequency-domain:
S = 1/2 E ร conj(H)
.Only the available components are returned, e.g., if the indicated monitor doesnโt include field component โExโ, then โSyโ and โSzโ will not be calculated.
- Parameters:
field_monitor_name (str) โ Name of field monitor used in the original
Simulation
.- Returns:
DataArray containing the Poynting vector calculated based on the field components colocated at the center locations of the Yee grid.
- Return type:
xarray.DataArray
- get_intensity(field_monitor_name)[source]#
return xarray.DataArray of the intensity of a field monitor at Yee cell centers.
- Parameters:
field_monitor_name (str) โ Name of field monitor used in the original
Simulation
.- Returns:
DataArray containing the electric intensity of the field-like monitor. Data is interpolated to the center locations on Yee grid.
- Return type:
xarray.DataArray
- classmethod mnt_data_from_file(fname, mnt_name, **parse_obj_kwargs)[source]#
Loads data for a specific monitor from a .hdf5 file with data for a
SimulationData
.- Parameters:
fname (str) โ Full path to an hdf5 file containing
SimulationData
data.mnt_name (str, optional) โ
.name
of the monitor to load the data from.**parse_obj_kwargs โ Keyword arguments passed to either pydanticโs
parse_obj
function when loading model.
- Returns:
Monitor data corresponding to the
mnt_name
type.- Return type:
MonitorData
Example
>>> field_data = your_simulation_data.from_file(fname='folder/data.hdf5', mnt_name="field")
- plot_field_monitor_data(field_monitor_data, field_name, val='real', scale='lin', eps_alpha=0.2, phase=0.0, robust=True, vmin=None, vmax=None, ax=None, **sel_kwargs)[source]#
Plot the field data for a monitor with simulation plot overlaid.
- Parameters:
field_monitor_data (AbstractFieldData) โ Field monitor data to plot.
field_name (str) โ Name of
field
component to plot (eg. โExโ). Also accepts'E'
and'H'
to plot the vector magnitudes of the electric and magnetic fields, and'S'
for the Poynting vector.val (Literal['real', 'imag', 'abs', 'abs^2', 'phase'] = 'real') โ Which part of the field to plot.
scale (Literal['lin', 'dB']) โ Plot in linear or logarithmic (dB) scale.
eps_alpha (float = 0.2) โ Opacity of the structure permittivity. Must be between 0 and 1 (inclusive).
phase (float = 0.0) โ Optional phase (radians) to apply to the fields. Only has an effect on frequency-domain fields.
robust (bool = True) โ If True and vmin or vmax are absent, uses the 2nd and 98th percentiles of the data to compute the color limits. This helps in visualizing the field patterns especially in the presence of a source.
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.ax (matplotlib.axes._subplots.Axes = None) โ matplotlib axes to plot on, if not specified, one is created.
sel_kwargs (keyword arguments used to perform
.sel()
selection in the monitor data.) โ These kwargs can select over the spatial dimensions (x
,y
,z
), frequency or time dimensions (f
,t
) ormode_index
, if applicable. For the plotting to work appropriately, the resulting data after selection must contain only two coordinates with len > 1. Furthermore, these should be spatial coordinates (x
,y
, orz
).
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes
- plot_field(field_monitor_name, field_name, val='real', scale='lin', eps_alpha=0.2, phase=0.0, robust=True, vmin=None, vmax=None, ax=None, **sel_kwargs)[source]#
Plot the field data for a monitor with simulation plot overlaid.
- Parameters:
field_monitor_name (str) โ Name of
FieldMonitor
,FieldTimeData
, orModeSolverData
to plot.field_name (str) โ Name of
field
component to plot (eg. โExโ). Also accepts'E'
and'H'
to plot the vector magnitudes of the electric and magnetic fields, and'S'
for the Poynting vector.val (Literal['real', 'imag', 'abs', 'abs^2', 'phase'] = 'real') โ Which part of the field to plot.
scale (Literal['lin', 'dB']) โ Plot in linear or logarithmic (dB) scale.
eps_alpha (float = 0.2) โ Opacity of the structure permittivity. Must be between 0 and 1 (inclusive).
phase (float = 0.0) โ Optional phase (radians) to apply to the fields. Only has an effect on frequency-domain fields.
robust (bool = True) โ If True and vmin or vmax are absent, uses the 2nd and 98th percentiles of the data to compute the color limits. This helps in visualizing the field patterns especially in the presence of a source.
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.ax (matplotlib.axes._subplots.Axes = None) โ matplotlib axes to plot on, if not specified, one is created.
sel_kwargs (keyword arguments used to perform
.sel()
selection in the monitor data.) โ These kwargs can select over the spatial dimensions (x
,y
,z
), frequency or time dimensions (f
,t
) ormode_index
, if applicable. For the plotting to work appropriately, the resulting data after selection must contain only two coordinates with len > 1. Furthermore, these should be spatial coordinates (x
,y
, orz
).
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes
- plot_scalar_array(field_data, axis, position, freq=None, eps_alpha=0.2, robust=True, vmin=None, vmax=None, cmap_type='divergent', ax=None)[source]#
Plot the field data for a monitor with simulation plot overlaid.
- Parameters:
field_data (xr.DataArray) โ DataArray with the field data to plot. Must be a scalar field.
axis (Axis) โ Axis normal to the plotting plane.
position (float) โ Position along the axis.
freq (float = None) โ Frequency at which the permittivity is evaluated at (if dispersive). By default, chooses permittivity as frequency goes to infinity.
eps_alpha (float = 0.2) โ Opacity of the structure permittivity. Must be between 0 and 1 (inclusive).
robust (bool = True) โ If True and vmin or vmax are absent, uses the 2nd and 98th percentiles of the data to compute the color limits. This helps in visualizing the field patterns especially in the presence of a source.
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.
cmap_type (Literal["divergent", "sequential", "cyclic"] = "divergent") โ Type of color map to use for plotting.
ax (matplotlib.axes._subplots.Axes = None) โ matplotlib axes to plot on, if not specified, one is created.
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes
- __hash__()#
Hash method.