QPMS
Electromagnetic multiple scattering library and toolkit.
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
qpms.fieldplots Namespace Reference

Data Structures

class  Geometry
 

Functions

 find_field_blocks (f)
 
 read_mode_fields (blk)
 
 rect_grid (points, comps)
 
 disk_images (positions, lattice, half, radius)
 
 math_irrep_label (name)
 
 norm_log (values, valid_mask)
 
 norm_sym (values, valid_mask)
 
 _masked (data, mask)
 
 _mode_title (label, quantity, omega, resid, zero=False)
 
 _setup_ax (ax, xs, ys, geom)
 
 fig_intensity (xs, ys, I, mask, geom, title, dpi=180)
 
 _draw_inplane (ax, xs, ys, V, mask, norm)
 
 _add_streamlines (ax, xs, ys, V, mask)
 
 fig_inplane (xs, ys, V, mask, geom, norm, title, stream=True, dpi=180)
 
 fig_scalar (xs, ys, S, mask, geom, norm, title, dpi=180)
 
 save_figure (fig, stem, dpi=180)
 
 render_mode_static (xs, ys, E, mask, geom, outstem, label, omega, resid, skip_zero, dpi)
 
 render_mode_animated (xs, ys, E, mask, geom, outstem, label, omega, resid, skip_zero, frames, fps, dpi)
 
 process_container (cpath, opts)
 
 main (argv=None, default_radius=None)
 

Variables

 EH = eV / hbar
 
int RESID_MAX = 1e-2
 
int ZERO_REL = 1e-12
 

Detailed Description

Renderer for the eigenmode field maps stored by qpms-sim.

The resonances experiments accept a ``fields:`` option asking qpms-sim
to evaluate the scattered electric field of every found eigenpair on a
square grid in a z = const plane (usually the horizontal mirror plane
z = 0), stored in the ``fields`` group of the resonance blocks
(datasets E, omegas, points, residuals; cf. results_hdf5.h). This
module is the COMMON plotter for such maps, usable from any example or
analysis script:

    python3 -m qpms.fieldplots CONTAINER.qpms.h5 [more.h5 ...] [--animate]

For every selected container, resonance block and accepted eigenmode it
renders the in-plane field maps. The disk (particle) areas — ALL the
lattice images inside the window, positions and lattice basis read from
the container — are masked out and shaded: the scattered-field VSWF
expansion is valid in the background medium only, inside the particles
it diverges and the plotted values there are meaningless. The primitive
unit cell is drawn as a dashed parallelogram when the system is
periodic.

Static mode (default), five plots per mode:

  * ``_abs2``  |E|^2, log colour scale (sequential viridis);
  * ``_reexy`` Re(E_xy), background |Re(E_xy)| + Re(E_xy) streamlines
    (sequential viridis; the streamlines show the direction, normalised
    to unit vectors — the streamline pattern is invariant under the
    pointwise rescaling, only the direction matters here);
  * ``_imexy`` Im(E_xy), the same as _reexy;
  * ``_reez``  Re(E_z), diverging RdBu_r on a symmetric scale;
  * ``_imez``  Im(E_z), the same as _reez.

  For in-plane-polarised modes E_z is identically zero in the z = 0
  plane (and for out-of-plane modes so is E_xy), so one pair of panels
  is trivially empty for the plane-symmetric examples; ``--skip-zero``
  drops such panels.

Animation mode (``--animate``), three plots per mode: the phase-
independent |E|^2 map as above plus two animated GIFs following the
physical time evolution. qpms uses the e^{-i omega t} time convention,
so the field at the time phase phi = omega t is Re(P e^{-i phi}) where
P is the stored complex-amplitude quantity (the in-plane vector E_xy,
resp. the scalar E_z); phi sweeps [0, 2 pi) in equidistant steps
(``--frames``, rendered at ``--fps``). The colour scale is fixed over
the frames (computed from |P|), each GIF frame shows the momentary
field magnitude |Re(P e^{-i phi})| as the colour background with the
momentary direction as streamlines (E_xy), resp. the signed scalar
Re(E_z e^{-i phi}) (E_z).

The irrep labels are typeset through qpms.pretty_irrep_name (mathtext),
e.g. the plain label "A2''" renders as A_2''.

The particle radius for the disk mask is taken from ``--radius``
(nanometres; the shape parameters are not recorded in the container).
Requires matplotlib, h5py (and pillow for the GIFs); uses the Agg
backend.

Function Documentation

◆ _add_streamlines()

qpms.fieldplots._add_streamlines (   ax,
  xs,
  ys,
  V,
  mask 
)
protected
Streamlines of the real in-plane field V (ny, nx, 2). The field
is unit-normalised — the streamline pattern is invariant under the
pointwise positive rescaling, and the uniform speed spreads the
lines evenly over the window instead of bundling them at the
hotspots. The particle interiors (mask) and the field nulls become
NaN, terminating the streamlines there.

◆ _draw_inplane()

qpms.fieldplots._draw_inplane (   ax,
  xs,
  ys,
  V,
  mask,
  norm 
)
protected
The in-plane vector-field panel: |V| colour background (viridis,
the given norm) and the direction streamlines (unit-normalised
field, masked and zero regions skipped). Returns the pcolormesh.

◆ disk_images()

qpms.fieldplots.disk_images (   positions,
  lattice,
  half,
  radius 
)
All the lattice images of the particles intersecting the square
window [-half, half]^2 with the radius margin. Returns (n, 2);
works for the finite systems too (no lattice tiling then).

◆ fig_inplane()

qpms.fieldplots.fig_inplane (   xs,
  ys,
  V,
  mask,
  geom,
  norm,
  title,
  stream = True,
  dpi = 180 
)
Static in-plane vector panel: |V| background + direction.

◆ fig_intensity()

qpms.fieldplots.fig_intensity (   xs,
  ys,
  I,
  mask,
  geom,
  title,
  dpi = 180 
)
|E|^2 magnitude map, log colour scale.

◆ fig_scalar()

qpms.fieldplots.fig_scalar (   xs,
  ys,
  S,
  mask,
  geom,
  norm,
  title,
  dpi = 180 
)
Signed scalar panel with the diverging colormap.

◆ find_field_blocks()

qpms.fieldplots.find_field_blocks (   f)
All the resonance block groups with a 'fields' section of an open
container. Returns (experiment or None, irrep label, block group)
triples; both the named (resonances/<experiment>/<irrep>) and the
legacy nameless (resonances/<irrep>) layouts are recognised.

◆ math_irrep_label()

qpms.fieldplots.math_irrep_label (   name)
Matplotlib-ready pretty irrep label: wrapped in $...$ whenever
the string (prettified via qpms.pretty_irrep_name) consists solely
of the mathtext-safe characters (letters, digits, primes, subscripts
and the Greek k-symbols); anything else is returned verbatim.

◆ norm_log()

qpms.fieldplots.norm_log (   values,
  valid_mask 
)
Percentile-clipped log colour norm for magnitude maps; returns
None (no clipping) when the data carries no signal.

◆ norm_sym()

qpms.fieldplots.norm_sym (   values,
  valid_mask 
)
Symmetric-around-zero colour norm for the signed maps; the scale
is set by the 99.5th percentile of the magnitude.

◆ process_container()

qpms.fieldplots.process_container (   cpath,
  opts 
)
Render the field maps of one container; returns the number of
the produced plots.

◆ read_mode_fields()

qpms.fieldplots.read_mode_fields (   blk)
The stored field-map data of one block: (E, omegas, points,
residuals) with E (nmodes, npoints, 3) complex, points (npoints, 3)
in metres, residuals NaN-padded.

◆ rect_grid()

qpms.fieldplots.rect_grid (   points,
  comps 
)
Scatter the point-sampled field comps onto the rectangular grid
defined by the stored points. comps has the leading axis npoints
(arbitrary trailing axes; pass the transposed (npoints, nmodes, 3)
container array E). Returns (xs, ys, grids) with grids of shape
(ny, nx, ...) complex; the point ordering is irrelevant. Raises
ValueError for a non-rectangular grid.

◆ render_mode_animated()

qpms.fieldplots.render_mode_animated (   xs,
  ys,
  E,
  mask,
  geom,
  outstem,
  label,
  omega,
  resid,
  skip_zero,
  frames,
  fps,
  dpi 
)
The three plots of one eigenmode in the animation mode: the
static |E|^2 map plus the E_xy and E_z phase-sweep GIFs. The phase
phi = omega t runs over [0, 2 pi); the plotted quantity is
Re(P e^{-i phi}) (the qpms time convention is e^{-i omega t}).

◆ render_mode_static()

qpms.fieldplots.render_mode_static (   xs,
  ys,
  E,
  mask,
  geom,
  outstem,
  label,
  omega,
  resid,
  skip_zero,
  dpi 
)
The five static plots of one eigenmode; returns the file stems
written (each in pdf + png).