tidy3d.components.data.sim_data.SimulationData#
- class SimulationData[source]#
Bases:
AbstractYeeGridSimulationDataStores data from a collection of
Monitorobjects in aSimulation.- 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().simulation (Simulation) β Original
Simulationassociated with the data.data (Tuple[Annotated[Union[tidy3d.components.data.monitor_data.FieldData, tidy3d.components.data.monitor_data.FieldTimeData, tidy3d.components.data.monitor_data.PermittivityData, tidy3d.components.data.monitor_data.ModeSolverData, tidy3d.components.data.monitor_data.ModeData, tidy3d.components.data.monitor_data.FluxData, tidy3d.components.data.monitor_data.FluxTimeData, tidy3d.components.data.monitor_data.AuxFieldTimeData, tidy3d.components.data.monitor_data.FieldProjectionKSpaceData, tidy3d.components.data.monitor_data.FieldProjectionCartesianData, tidy3d.components.data.monitor_data.FieldProjectionAngleData, tidy3d.components.data.monitor_data.DiffractionData, tidy3d.components.data.monitor_data.DirectivityData], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})], ...]) β List of
MonitorDatainstances associated with the monitors of the originalSimulation.log (Optional[str] = None) β A string containing the log information from the simulation run.
diverged (bool = False) β A boolean flag denoting whether the simulation run diverged.
Notes
The
SimulationDataobjects store a copy of the originalSimulation:, so it can be recovered if theSimulationDatais loaded in a new session and theSimulationis no longer in memory.More importantly, the
SimulationDatacontains 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.Examples
Standalone example:
>>> import tidy3d as td >>> num_modes = 5 >>> x = [-1,1,3] >>> y = [-2,0,2,4] >>> z = [-3,-1,1,3,5] >>> f = [2e14, 3e14] >>> coords = dict(x=x[:-1], y=y[:-1], z=z[:-1], f=f) >>> grid = td.Grid(boundaries=td.Coords(x=x, y=y, z=z)) >>> scalar_field = td.ScalarFieldDataArray((1+1j) * np.random.random((2,3,4,2)), coords=coords) >>> field_monitor = td.FieldMonitor( ... size=(2,4,6), ... freqs=[2e14, 3e14], ... name='field', ... fields=['Ex'], ... colocate=True, ... ) >>> sim = td.Simulation( ... size=(2, 4, 6), ... grid_spec=td.GridSpec(wavelength=1.0), ... monitors=[field_monitor], ... run_time=2e-12, ... sources=[ ... td.UniformCurrentSource( ... size=(0, 0, 0), ... center=(0, 0.5, 0), ... polarization="Hx", ... source_time=td.GaussianPulse( ... freq0=2e14, ... fwidth=4e13, ... ), ... ) ... ], ... ) >>> field_data = td.FieldData(monitor=field_monitor, Ex=scalar_field, grid_expanded=grid) >>> sim_data = td.SimulationData(simulation=sim, data=(field_data,))
To save and load the
SimulationDataobject.sim_data.to_file(fname='path/to/file.hdf5') # Save a SimulationData object to a HDF5 file sim_data = SimulationData.from_file(fname='path/to/file.hdf5') # Load a SimulationData object from a HDF5 file.
See also
- Notebooks:
Quickstart: Usage in a basic simulation flow.
Attributes
Returns a TimeDataArray of field decay values over time steps.
Returns value of the field decay at the final time step.
logCustom logger to avoid the complexities of the logging module
Methods
renormalize(normalize_index)Return a copy of the
SimulationDatawith a different source used for the normalization.source_spectrum(source_index)Get a spectrum normalization function for a given source index.
to_mat_file(fname,Β **kwargs)Output the
SimulationDataobject as.matMATLAB file.Inherited Common Usage
- simulation#
- data#
- diverged#
- property field_decay#
Returns a TimeDataArray of field decay values over time steps.
- property final_decay_value#
Returns value of the field decay at the final time step.
- source_spectrum(source_index)[source]#
Get a spectrum normalization function for a given source index.
- renormalize(normalize_index)[source]#
Return a copy of the
SimulationDatawith a different source used for the normalization.
- to_mat_file(fname, **kwargs)[source]#
Output the
SimulationDataobject as.matMATLAB file.- Parameters:
fname (str) β Full path to the output file. Should include
.matfile extension.**kwargs (dict, optional) β Extra arguments to
scipy.io.savemat: seescipydocumentation for more detail.
Example
>>> simData.to_mat_file('/path/to/file/data.mat')
- __hash__()#
Hash method.
- log#
- attrs#