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 an attr obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a TypeError if attrs contain objects that can not be serialized. One can check if attrs are serializable by calling obj.json().

  • simulation (AbstractSimulation) – Original AbstractSimulation associated with the data.

  • data (Tuple[AbstractMonitorData, ...]) – List of AbstractMonitorData instances associated with the monitors of the original AbstractSimulation.

  • log (Optional[str] = None) – A string containing the log information from the simulation run.

Notes

The SimulationData objects store a copy of the original Simulation:, so it can be recovered if the SimulationData is loaded in a new session and the Simulation is no longer in memory.

More importantly, the SimulationData contains a reference to the data for each of the monitors within the original Simulation. This data can be accessed directly using the name given to the monitors initially.

Attributes

data

log

Custom logger to avoid the complexities of the logging module

attrs

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_scalar_array(field_data, axis, position)

Plot the field data for a monitor with simulation plot overlaid.

Inherited Common Usage

load_field_monitor(monitor_name)[source]#

Load monitor and raise exception if not a field monitor.

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") 
static apply_phase(data, phase=0.0)[source]#

Apply a phase to xarray data.

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, or ModeSolverData 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) or mode_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, or z).

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.