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.AxesImageand colorbar across iterations so updates are cheap.- Attributes:
- monitor_name
str Name of the monitor in the FDTD project (e.g.
'optimization_dft','FDTD::ports::port_h_out').- result_name
str 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 viagetresult(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 thatPortResultsfeeds 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 fromgetresult(port, 'expansion for port monitor'); paired with the panel’s defaultoperation='abs'this matchesPortResultsexactly (which also takesnp.absto handle the signed value Lumerical reports for backward injection).'<key>.<attr>'- explicit dotted form: fetch the datasetgetresult(monitor, key)and pull out the attributeattr. Whenattris a Cartesian component name andkeyis 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.
- wavelength
float,optional Wavelength (m) at which to slice multi-spectral spatial data. Takes precedence over
frequencywhen both are given. When both areNonethe panel picks the middle wavelength. Ignored for 1D spectral data (where wavelength becomes the x-axis) (default:None).- frequency
float,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').- title
str,optional Custom panel title. When
Nonethe title is auto-generated frommonitor_nameandresult_name(default:None).- cmap
str,optional Matplotlib colormap used for 2D image plots. When
None(default), a sensible default is picked fromoperation:'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_kwargs
dict,optional Pass-through dict applied verbatim to the panel’s matplotlib
Axesafter each render viaax.set(**axes_kwargs). Any keyword whose name matches anAxes.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 clearAttributeErrorwhen a key does not resolve. No validation is performed on the contents (default:None).- image_kwargs
dict,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 anyclim/cmapchange takes effect immediately. Ignored when the current render is not a 2D image (line / scalar / error states) (default:None).- line_kwargs
dict,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).
- monitor_name
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