pyoptics.fdtd.monitors

Monitors record data during a run, so the full time history never has to be stored.

  • Probe: time series of one component at a point (spectra, ring-downs).

  • Snapshots: decimated frames of a component for plots and animations, optionally cropped, subsampled, stored as float16, kept as a ring buffer (keep_last) or streamed to an HDF5 file.

  • DFTField: running discrete Fourier transform at a few wavelengths. The complex amplitudes follow the pyoptics convention (time dependence exp(-i omega t)): a field f(t) gives F = sum f(t) exp(+i omega t) dt, so a wave travelling towards +x has the phase exp(+ikx). For a continuous wave, Re{F exp(-i omega t)} animates the steady state over one period.

  • Flux: power through a line (2D) or a point (1D) per wavelength, from the DFT of E and H; ratios of two runs (with and without a structure) give reflectance and transmittance.

Monitor regions are given as ((xmin, xmax), (ymin, ymax)) (None for the whole domain); each component keeps the nodes that fall inside.

Classes

DFTField

Running DFT of field components at vacuum wavelengths.

DFTFieldData

Complex field amplitudes at some wavelengths: fields[component] has the shape (n_wavelengths, ...), coords[component] one array per axis.

Flux

Spectral power flux through a line (2D) or a point (1D).

Monitor

Base class: setup(sim) once, record(sim) after every step.

Probe

Time series of one field component at the node nearest to a point.

SnapshotStack

Frames of one component: times (n,), coords (one array per axis), frames (n, ...) and the component name.

Snapshots

Decimated frames of one field component.

class pyoptics.fdtd.monitors.Monitor[source]

Bases: object

Base class: setup(sim) once, record(sim) after every step.

class pyoptics.fdtd.monitors.Probe(position, component=None)[source]

Bases: Monitor

Time series of one field component at the node nearest to a point.

Attributes after a run: times, values (arrays).

spectrum(wavelengths)[source]

DFT of the recorded series at vacuum wavelengths (convention as DFTField).

class pyoptics.fdtd.monitors.SnapshotStack(times, coords, frames, component, mode='Ez')[source]

Bases: object

Frames of one component: times (n,), coords (one array per axis), frames (n, …) and the component name.

save(path)[source]

Save to .npz or (with h5py) .h5.

class pyoptics.fdtd.monitors.Snapshots(component=None, every=10, region=None, stride=1, dtype=<class 'numpy.float16'>, keep_last=None, start=0.0, path=None)[source]

Bases: Monitor

Decimated frames of one field component.

Parameters:
componentstr, optional

Default: Ez in the Ez mode, Hz in the Hz mode.

everyint

Record every every steps.

regiontuple, optional

Crop, ((xmin, xmax), (ymin, ymax)).

strideint

Spatial subsampling.

dtypenumpy dtype

Storage type of the frames; float16 halves the memory of float32 and is plenty for plots.

keep_lastint, optional

Keep only the last frames (ring buffer).

startnumber

Time at which recording starts.

pathstr, optional

Stream the frames to this HDF5 file (needs h5py) instead of keeping them in memory.

close()[source]

Close the HDF5 file of a streaming recorder.

stack()[source]

The recorded frames as a SnapshotStack (read back from the file when streaming).

class pyoptics.fdtd.monitors.DFTFieldData(wavelengths, fields, coords, mode='Ez')[source]

Bases: object

Complex field amplitudes at some wavelengths: fields[component] has the shape (n_wavelengths, …), coords[component] one array per axis.

class pyoptics.fdtd.monitors.DFTField(wavelengths, components=None, region=None, start=0.0, stride=1)[source]

Bases: Monitor

Running DFT of field components at vacuum wavelengths.

Parameters:
wavelengthsnumber or array
componentssequence of str, optional

Default: all components of the mode.

regiontuple, optional

((xmin, xmax), (ymin, ymax)); default: the whole grid.

startnumber

Time from which on to accumulate (e.g. after a CW source has reached the steady state).

strideint

Spatial subsampling.

field(component)[source]

Complex amplitudes (n_wavelengths, …) of a component.

data()[source]

The result as DFTFieldData (e.g. to save it).

steady_state(component)[source]

Complex amplitudes normalized to a continuous wave: for a CW run accumulated over whole periods, this is the phasor of the field (F*2/duration).

class pyoptics.fdtd.monitors.Flux(position, wavelengths, axis=0, extent=None)[source]

Bases: Monitor

Spectral power flux through a line (2D) or a point (1D).

The line is normal to axis at position, optionally limited to extent along the other axis; the flux counts positive along +axis. H is interpolated to the E nodes. flux() returns 1/2 Re(sum E H*) dA per wavelength (arbitrary units: divide by the flux of a reference run).

flux()[source]

Power flux per wavelength (n_wavelengths,).

fields()[source]

DFT amplitudes of E and H (interpolated) along the line.