MonitorPanel#

class lumopt2.utils.panels.MonitorPanel(title: str | None = None, monitor_name: str = '', result_name: str = '', wavelength: float | None = None, frequency: float | None = None, operation: Literal['real', 'imag', 'abs', 'abs^2', 'angle'] = 'abs', cmap: str | None = None, axes_kwargs: Dict[str, Any] | None = None, image_kwargs: Dict[str, Any] | None = None, line_kwargs: Dict[str, Any] | None = None)#

Live plot of an FDTD monitor result (field component, S-parameter, …).

Auto-detects the result dimensionality and renders a 2D image, a 1D line plot, or a single scalar marker. For 2D images the panel reuses the same matplotlib.image.AxesImage and colorbar across iterations so updates are cheap.

Attributes:
monitor_namestr

Name of the monitor in the FDTD project (e.g. 'optimization_dft', 'FDTD::ports::port_h_out').

result_namestr

Result field to fetch. Recognised forms:

  • 'Ex'/'Ey'/'Ez'/'Hx'/'Hy'/'Hz' - one Cartesian component of the E/H field (the panel fetches the full vector via getresult(mon, 'E') / getresult(mon, 'H') and slices along the last axis).

  • 'E'/'H' - the magnitude of the full field vector.

  • 'T'/'transmission' - the bulk power transmission, i.e. the integrated Poynting flux through the monitor surface (sums every guided mode plus any radiation that hits the monitor).

  • 'T_out' - the mode-projected outgoing transmission of a port monitor: the power coupled specifically into the configured port mode. This is the value that PortResults feeds into the FOM, so plotting 'T_out' on a port monitor tracks the FOM trace. Differs from 'T' whenever the field at the port is not purely the chosen mode. Internally fetched from getresult(port, 'expansion for port monitor'); paired with the panel’s default operation='abs' this matches PortResults exactly (which also takes np.abs to handle the signed value Lumerical reports for backward injection).

  • '<key>.<attr>' - explicit dotted form: fetch the dataset getresult(monitor, key) and pull out the attribute attr. When attr is a Cartesian component name and key is the matching parent vector (e.g. 'E.Ey'), the panel slices the vector to deliver the requested component. This form makes the lookup explicit when a result has many attributes, and avoids ambiguity in custom dataset returns (e.g. 'farfield.Ex' from a far-field monitor).

  • any other string - fetched verbatim with getresult.

wavelengthfloat, optional

Wavelength (m) at which to slice multi-spectral spatial data. Takes precedence over frequency when both are given. When both are None the panel picks the middle wavelength. Ignored for 1D spectral data (where wavelength becomes the x-axis) (default: None).

frequencyfloat, optional

Frequency (Hz) at which to slice multi-spectral spatial data. Converted internally to a wavelength via c0/f (default: None).

operation{‘real’, ‘imag’, ‘abs’, ‘abs^2’, ‘angle’}, optional

Operation applied to the (typically complex) raw data before plotting (default: 'abs').

titlestr, optional

Custom panel title. When None the title is auto-generated from monitor_name and result_name (default: None).

cmapstr, optional

Matplotlib colormap used for 2D image plots. When None (default), a sensible default is picked from operation: 'RdBu' for the signed 'real' / 'imag' operations, 'inferno' for the non-negative 'abs' / 'abs^2' operations, and 'twilight' for the cyclic 'angle' operation. Pass an explicit string to override the default.

axes_kwargsdict, optional

Pass-through dict applied verbatim to the panel’s matplotlib Axes after each render via ax.set(**axes_kwargs). Any keyword whose name matches an Axes.set_<name> setter is accepted – e.g. {'ylim': (0, 1)} to clamp a 1D transmission trace, {'yscale': 'log'} to switch to a logarithmic y-axis, or {'xlabel': 'Wavelength (nm)'} to override the default x-axis label. Applied after the panel’s auto-rescale so user values win over autoscale; matplotlib raises a clear AttributeError when a key does not resolve. No validation is performed on the contents (default: None).

image_kwargsdict, optional

Pass-through dict applied to the 2D image artist after each render via image.set(**image_kwargs). Useful for fixing the colorbar range ({'clim': (-1, 1)}) or overriding the colormap ({'cmap': 'viridis'}). The colorbar is refreshed automatically so any clim / cmap change takes effect immediately. Ignored when the current render is not a 2D image (line / scalar / error states) (default: None).

line_kwargsdict, optional

Pass-through dict applied to the 1D line artist after each render via line.set(**line_kwargs). Useful for setting line color/style/width ({'color': 'red', 'linewidth': 2}). Ignored when the current render is not a 1D line plot (default: None).

Methods

MonitorPanel.on_optimization_end(ax, fig, ...)

Optional hook called once when the optimization completes.

MonitorPanel.setup(ax, fig, project)

Set the panel title; actual plot artists are created lazily.

MonitorPanel.update(ax, fig, project, state)

Fetch the latest data from the FDTD session and refresh the panel.

Attributes