pyoptics.fdtd.plot

Plots and animations of FDTD simulations (needs matplotlib).

  • plot_structure(): permittivity map with the PML, sources and monitors.

  • plot_field(): a component of the current fields, of a DFT monitor or of a snapshot, with the outlines of the structure on top.

  • animate(): a matplotlib animation of a SnapshotStack (time domain) or of a DFT field (the steady state Re{F exp(-i omega t)} over one period, which needs no stored frames at all). In notebooks, show it with IPython.display.HTML(anim.to_jshtml()) or as a GIF with gif(anim); save it with anim.save().

  • xt_diagram(): a 1D run as an image over x and t.

Real fields use a diverging colormap with symmetric limits, intensities inferno. The colours of sources and monitors are those of pyoptics.sketch. 2D arrays are indexed [ix, iy] and shown with x to the right.

Functions

animate

Animation of a SnapshotStack, or of a DFT field over one period.

gif

Render an animation to an animated GIF; returns an IPython Image (the notebook stores the GIF itself, typically much smaller than the frames of to_jshtml()).

plot_field

Plot a field component.

plot_structure

Refractive index map (2D, sqrt of the permittivity) or permittivity profile (1D) with PML, sources and monitors.

xt_diagram

A 1D SnapshotStack as an image over x (horizontal) and t (vertical): pulses show up as lines with slope 1/v, reflections as their mirror images.

pyoptics.fdtd.plot.plot_structure(sim, ax=None, component=None, cmap='Greys', show_pml=True, show_sources=True, show_monitors=True, colorbar=False)[source]

Refractive index map (2D, sqrt of the permittivity) or permittivity profile (1D) with PML, sources and monitors.

Sources are drawn in amber (points, lines, the TFSF box with an arrow for the direction), monitors in blue (flux lines dashed, DFT regions dotted, probes as crosses), the PML hatched (2D) or shaded (1D).

pyoptics.fdtd.plot.plot_field(data, component=None, ax=None, sim=None, part='real', wavelength_index=0, vmax=None, log=False, cmap=None, colorbar=True, title=None)[source]

Plot a field component.

Parameters:
dataSimulation, DFTField, DFTFieldData or SnapshotStack

A Simulation shows its current (real) fields, a DFT its complex amplitudes at wavelength_index, a SnapshotStack its last frame.

componentstr, optional
simSimulation, optional

Draw the outlines of its structure on top (used automatically if data is a Simulation).

part“real”, “imag”, “abs” or “intensity”
logbool

Logarithmic intensity in dB (part “abs” or “intensity”).

pyoptics.fdtd.plot.animate(data, component=None, sim=None, ax=None, frames=24, wavelength_index=0, interval=60, vmax=None, cmap='RdBu_r', title=True)[source]

Animation of a SnapshotStack, or of a DFT field over one period.

Parameters:
dataSnapshotStack, DFTField or DFTFieldData

A DFT field F is animated as Re{F exp(-i 2 pi k/frames)}, k = 0..frames - 1 (one period of the steady state).

simSimulation, optional

Draw the outlines of its structure on top.

framesint

Frames per period (DFT fields only).

vmaxnumber, optional

Colour limit; default: the maximum over all frames (snapshots: the 99.5 % percentile, so that the source does not saturate the scale).

Returns:
matplotlib.animation.FuncAnimation
pyoptics.fdtd.plot.gif(anim, fps=12, dpi=None)[source]

Render an animation to an animated GIF; returns an IPython Image (the notebook stores the GIF itself, typically much smaller than the frames of to_jshtml()).

pyoptics.fdtd.plot.xt_diagram(stack, ax=None, sim=None, vmax=None, cmap='RdBu_r', colorbar=True)[source]

A 1D SnapshotStack as an image over x (horizontal) and t (vertical): pulses show up as lines with slope 1/v, reflections as their mirror images.