microlocal

microlocal.py — Unified microlocal analysis toolkit for 1D and 2D problems

Overview

The microlocal module provides a high‑level interface for studying the propagation of singularities and constructing semiclassical approximations for linear partial differential equations. It builds upon the dedicated wkb (WKB approximations) and caustics (catastrophe classification and ray caustic detection) modules, adding dimension‑agnostic functions for the core concepts of microlocal analysis:

  • Characteristic variety Char(P) = {(x,ξ) : p(x,ξ)=0} – the set of phase‑space points where the principal symbol vanishes, indicating where singularities can propagate.

  • Bicharacteristic flow – Hamilton’s equations for the principal symbol, whose integral curves (bicharacteristics) govern the propagation of wave‑front sets.

  • Wavefront set WF(u) – a refinement of the singular support that also records the directions (frequencies) in which the singularity occurs. The module visualises how an initial wavefront set evolves under the flow.

  • Wavefront-set animation – animate_wavefront_set animates WF(u) while one initial coordinate (x, y, ξ or η) sweeps a range: each frame is the propagated wavefront set of a family of seeds (point source, grid with a phase, rectangle, curve, …), shown in 2D projections or in a 3D view of the 4D phase space. See Animating the wavefront set below.

  • WKB approximation (re‑exported from wkb) – asymptotic solutions of the form u ≈ A e^{iS/ε}.

  • Caustics and Maslov index – detection of caustics (where rays focus) and computation of the associated Maslov phase shifts, crucial for correct semiclassical quantisation.

  • Bohr–Sommerfeld quantisation (1D) – semiclassical energy levels for bound states.

  • Operator visualisation and interactive analysis – a comprehensive suite for plotting symbol amplitude, phase, micro‑support, characteristic gradients, and launching interactive ipywidgets dashboards.

  • Matrix-valued symbols and pseudospectra – extraction of characteristic branches via eigenvalue computation for matrix operators, and visualisation of ε‑pseudospectra.

  • PDE solution rendering – rendering and animation tools for scalar, matrix, and wave equation fields in 1D and 2D space-time.

All functions automatically detect the spatial dimension (1 or 2) from the input data, making the module usable for both one‑dimensional and two‑dimensional problems without changing the calling syntax.

Mathematical background

In microlocal analysis, a linear partial differential operator P is studied via its principal symbol p(x,ξ), a function on the cotangent bundle T*ℝⁿ. The characteristic variety is the zero set of p. Singularities of a distribution u satisfying P u ≈ 0 are confined to the characteristic variety and propagate along bicharacteristics – integral curves of the Hamiltonian vector field

X_p = ( ∂p/∂ξ , –∂p/∂x ).

The wavefront set WF(u) is a closed conic subset of T*ℝⁿ {0} that records both the location x and the direction ξ of the singularity. If (x₀,ξ₀) ∉ WF(u), then u is smooth in a neighbourhood of x₀ in the direction ξ₀. The fundamental theorem of microlocal analysis states that WF(Pu) ⊆ WF(u) and that WF(u) WF(Pu) is contained in the characteristic variety and is invariant under the bicharacteristic flow.

The WKB method seeks solutions of the form u(x) = e^{iS(x)/ε} (a₀(x) + ε a₁(x) + …). The phase S satisfies the eikonal equation p(x,∇S)=0, and the amplitudes a_k satisfy transport equations along bicharacteristics. This construction breaks down at caustics, where rays focus; the Maslov index μ (a signed count of caustic crossings) provides a phase correction e^{iμπ/2} that restores uniformity.

The module integrates these concepts into a coherent toolkit, allowing the user to:

  • Symbolically compute the characteristic variety.

  • Numerically integrate bicharacteristics with symplectic integrators.

  • Visualise the evolution of wavefront sets, including 2D and 3D singularity animations and animated families of wavefront sets (animate_wavefront_set).

  • Obtain semiclassical spectra via Bohr–Sommerfeld quantisation (1D).

  • Detect caustics and compute the Maslov index (using the caustics module).

  • Interactively explore symbol properties such as amplitude, phase, and micro-support.

  • Analyse matrix-valued symbols by computing their characteristic branches.

  • Plot ε-pseudospectra and overlay complex eigenvalues.

  • Render scalar, matrix, and wave PDE solutions in space-time.

Animating the wavefront set

animate_wavefront_set(symbol, tspan, …) is the animated counterpart of plot_wavefront_set. Each frame shows the wavefront set obtained by propagating a family of seed singularities along the bicharacteristics over tspan; the animation variable is the initial coordinate that is given a range (exactly one of x_range, y_range, xi_range, eta_range), the others being fixed by x0, y0, xi0, eta0.

Seed families (2D; in 1D the seeds are a fan of frequencies at the point x0), selected by seed_family:

  • 'circle' (default) – point source: a small circle of seeds with outward covectors, as in visualize_wavefront_set.

  • 'fiber' – all directions of the covector at one point, run in both time directions. Modulo ξ → -ξ this is a Möbius strip, best seen in 3D with the sign-invariant coordinates 'u' = ξ²-η² and 'v' = 2ξη.

  • 'grid' – seeds on a rectangular grid (corner_ul, corner_lr, step) with a constant covector or the covector ∇S(x, y) of a phase function phase, i.e. the initial Lagrangian manifold of a WKB or plane wave.

  • 'rectangle' – wavefront set of the indicator of a rectangle: edge conormals plus a fan of directions at each corner.

  • 'curve' – conormal bundle of a parametrised curve (x(s), y(s)): a name from the catalogue WAVEFRONT_CURVES (20 curves: ellipse, parabola, astroid, cardioid, lemniscate, spirals, …), two sympy expressions or two callables. With covector_angle the covector direction is prescribed instead of the normal, which makes ‘circle’ and ‘fiber’ special cases of ‘curve’.

Views. All the projections of plot_wavefront_set are available (including 'full' with the four 2D slices of the 4D phase space), plus projection='3d': three coordinates coords3d as axes (position, frequency, time, or the invariants 'u', 'v') and a fourth quantity color_by as colour, so that all four dimensions of T*ℝ² are visible. The camera is controlled by view, rotate and ortho. Axis limits are fixed over the whole animation (pad, xlim, ylim, zlim, or fixed_limits=False to re-fit each frame).

Performance. All the rays of all the frames are integrated at once with a vectorised version of the fixed-step symplectic scheme of bicharacteristic_flow (fast=True, the default), which is orders of magnitude faster than ray-by-ray integration.

The function returns a matplotlib.animation.FuncAnimation; use HTML(anim.to_jshtml()) in a notebook or save_path to write a file.

Examples:

# Point source whose position moves vertically, 4 slices of phase space
anim = animate_wavefront_set(p, tspan=(0, 4), x0=1, xi0=1, eta0=1,
                             y_range=(-5, 5), seeds=100, projection='full')

# Plane-wave grid with a focusing phase, in 3D (x, y, t) with eta as colour
anim = animate_wavefront_set(p, tspan=(0, 1), seed_family='grid',
                             corner_ul=(-1, 1), corner_lr=(1, -1), step=0.125,
                             phase=-(x**2 + y**2)/4, y_range=(-2, 2),
                             projection='3d', coords3d=('x', 'y', 't'),
                             color_by='eta', ortho=True)

# Conormals of an astroid, then of a user-defined curve
anim = animate_wavefront_set(p, tspan=(0, 2), seed_family='curve',
                             curve='astroid', seeds=120, xi0=1, eta0=0,
                             x_range=(-1, 1))

References

microlocal.WAVEFRONT_CURVES: Dict[str, Dict[str, Any]] = {'archimedes_spiral': {'curve': (s*cos(s), s*sin(s)), 'note': 'Open spiral with evenly spaced turns; the curvature decays outward.', 'range': (0.0, 12.566370614359172)}, 'astroid': {'curve': (cos(s)**3, sin(s)**3), 'note': 'Four cusps (velocity vanishes there); strongly non-convex between them.', 'range': (0.0, 6.283185307179586)}, 'cardioid': {'curve': ((cos(s) + 1)*cos(s), (cos(s) + 1)*sin(s)), 'note': 'One cusp; the curvature is large near it.', 'range': (0.0, 6.283185307179586)}, 'circle': {'curve': (cos(s), sin(s)), 'note': 'Smooth, closed, constant curvature: the conormal rays focus at the centre (a point caustic).', 'range': (0.0, 6.283185307179586)}, 'cubic': {'curve': (s, s**3), 'note': 'Flat inflection at the origin (zero curvature there).', 'range': (-1.2, 1.2)}, 'cusp': {'curve': (s**2, s**3), 'note': 'Semicubical parabola: a cusp at s=0 where the velocity vanishes (that seed is skipped).', 'range': (-1.2, 1.2)}, 'cycloid': {'curve': (s - sin(s), 1 - cos(s)), 'note': 'Arches meeting in cusps at s = 2πk (velocity vanishes there).', 'range': (0.0, 12.566370614359172)}, 'deltoid': {'curve': (2*cos(s) + cos(2*s), 2*sin(s) - sin(2*s)), 'note': 'Three cusps (hypocycloid).', 'range': (0.0, 6.283185307179586)}, 'ellipse': {'curve': (2*cos(s), sin(s)), 'note': 'Closed, curvature varies: inward conormal rays envelope the evolute (a caustic with 4 cusps).', 'range': (0.0, 6.283185307179586)}, 'hyperbola': {'curve': (cosh(s), sinh(s)), 'note': 'One branch of x² - y² = 1; open curve with curvature decaying at infinity.', 'range': (-1.5, 1.5)}, 'lemniscate': {'curve': (cos(s)/(sin(s)**2 + 1), sin(s)*cos(s)/(sin(s)**2 + 1)), 'note': 'Figure eight: a transversal self-crossing at the origin, where two branches of WF meet.', 'range': (0.0, 6.283185307179586)}, 'limacon_loop': {'curve': ((2*cos(s) + 1)*cos(s), (2*cos(s) + 1)*sin(s)), 'note': 'Limaçon with an inner loop: one self-crossing, the loop has opposite orientation.', 'range': (0.0, 6.283185307179586)}, 'line': {'curve': (s, 0), 'note': 'Zero curvature: a plane wave, the conormals are parallel and no caustic ever forms.', 'range': (-3.0, 3.0)}, 'lissajous_3_2': {'curve': (sin(3*s), sin(2*s)), 'note': 'Lissajous 3:2: several transversal self-crossings, a "braid" in the conormal bundle.', 'range': (0.0, 6.283185307179586)}, 'log_spiral': {'curve': (exp(0.15*s)*cos(s), exp(0.15*s)*sin(s)), 'note': 'Self-similar spiral: the conormal rays make a constant angle with the radius.', 'range': (0.0, 12.566370614359172)}, 'nephroid': {'curve': (3*cos(s) - cos(3*s), 3*sin(s) - sin(3*s)), 'note': 'Two cusps; also the caustic of light rays in a circular cup.', 'range': (0.0, 6.283185307179586)}, 'parabola': {'curve': (s, s**2), 'note': 'Open curve: inward conormal rays envelope the evolute (a semicubical parabola).', 'range': (-2.0, 2.0)}, 'rose3': {'curve': (cos(s)*cos(3*s), sin(s)*cos(3*s)), 'note': 'Three-petal rose: passes through the origin three times with different tangents.', 'range': (0.0, 3.141592653589793)}, 'sine': {'curve': (s, sin(s)), 'note': 'Inflection points: the curvature changes sign, so rays switch between converging and diverging.', 'range': (-6.283185307179586, 6.283185307179586)}, 'trefoil': {'curve': (sin(s) + 2*sin(2*s), cos(s) - 2*cos(2*s)), 'note': 'Planar projection of the trefoil knot: three lobes and three crossings.', 'range': (0.0, 6.283185307179586)}}

Ready-made curves for animate_wavefront_set(..., seed_family='curve', curve=<name>).

Each entry has 'curve' (a pair of sympy expressions in a parameter s), 'range' (the default parameter interval) and 'note' (why the curve is interesting for wavefront-set propagation). Names: circle, ellipse, parabola, hyperbola, line, sine, cubic, cusp, astroid, cardioid, nephroid, deltoid, limacon_loop, lemniscate, lissajous_3_2, trefoil, archimedes_spiral, log_spiral, cycloid, rose3.

microlocal.animate_operator_singularity(op: Any, xi0: float = 5.0, eta0: float = 0.0, x0: float = 0.0, y0: float = 0.0, tmax: float = 4.0, n_frames: int = 100, projection: str | None = None) → FuncAnimation[source]

Animate the propagation of a singularity under the Hamiltonian flow. Thin delegate to the module-level animate_singularity engine (previously ~130 lines of duplicated Hamiltonian/ODE setup here, plus a near-identical copy further down the module).

microlocal.animate_scalar_1d(t: ndarray, U: ndarray, x: ndarray, quantity: Literal['real', 'imag', 'abs'] = 'real', interval: int = 40, save_path: str | None = None) → FuncAnimation[source]

Animate a scalar 1D solution as a line plot evolving in time.

Parameters:
  • t (ndarray, shape (n_times,)) – Time samples.

  • U (ndarray, shape (n_times, Nx)) – Solution values u(x, t) sampled on the grid.

  • x (ndarray, shape (Nx,)) – Spatial grid.

  • quantity ({'real', 'imag', 'abs'}, default='real') – Which part of U to plot; also sets the fixed y-axis limits from the min/max of that quantity over the whole trajectory.

  • interval (int, default=40) – Delay between animation frames, in milliseconds.

  • save_path (str, optional) – If given, the animation is saved to this path via anim.save.

Returns:

The animation object (figure is not shown automatically).

Return type:

matplotlib.animation.FuncAnimation

microlocal.animate_singularity(s_expr: Expr, vars_x: Sequence[Symbol], x0: float | Sequence[float] = 0.0, xi0: float | Sequence[float] = 5.0, tmax: float = 4.0, n_frames: int = 100, projection: Literal['phase', 'position', 'frequency'] | None = None, branches: Literal['all'] | int | Sequence[int] = 'all', labels: List[str] | None = None, interval: int = 50, contours: bool = True, solution: Any | None = None, quantity: str = 'abs', save_path: str | None = None) → FuncAnimation[source]

Animate the propagation of singularities along bicharacteristic trajectories, projected onto a 2D phase-space plane.

Internally calls integrate_singularity to obtain the trajectories, then draws a growing dashed trail plus a moving point per branch via the shared _trail_animation helper.

Parameters:
  • s_expr (sympy.Expr) – Principal symbol used to build the Hamiltonian(s).

  • vars_x (list of sympy.Symbol) – Spatial variables.

  • x0 (float or array_like, default=0.0) – Initial spatial position(s).

  • xi0 (float or array_like, default=5.0) – Initial frequency (momentum) component(s).

  • tmax (float, default=4.0) – Final integration time.

  • n_frames (int, default=100) – Number of time samples used for the trajectory and the animation.

  • projection ({'phase', 'position', 'frequency'} or None, default=None) – Which plane to draw. In 1D, defaults to ‘phase’ (x vs xi); in 2D, defaults to ‘position’ (x vs y) and (‘frequency’/’phase’ are not selectable in 2D – the projection is always (x, y)).

  • branches ('all', int, or list of int, default='all') – Which characteristic branches to animate.

  • labels (list of str, optional) – Currently unused (reserved for per-branch legend labels).

  • interval (int, default=50) – Delay between animation frames, in milliseconds.

  • contours (bool, default=True) – Currently unused (reserved for background contour overlays).

  • solution (optional) – Currently unused (reserved for overlaying a PDE solution field).

  • quantity (str, default='abs') – Currently unused (reserved alongside solution).

  • save_path (str, optional) – If given, the animation is saved to this path via anim.save.

Returns:

The animation object.

Return type:

matplotlib.animation.FuncAnimation

Raises:

ValueError – If projection is not one of the supported values for a 1D symbol.

microlocal.animate_singularity_3d(s_expr: Expr, vars_x: Sequence[Symbol], x0: float | Sequence[float] = 0.0, xi0: float | Sequence[float] = 5.0, tmax: float = 4.0, n_frames: int = 100, projection: Any | None = None, branches: Literal['all'] | int | Sequence[int] = 'all', labels: List[str] | None = None, interval: int = 50, save_path: str | None = None) → FuncAnimation[source]

Animate bicharacteristic trajectories in a 3D matplotlib plot.

Internally calls integrate_singularity to obtain the trajectories, then draws a growing dashed trail plus a moving point per branch via the shared _trail_animation helper. In 1D, the third axis is time t; in 2D (or higher), the first three phase-space coordinates (x, y, …) are used directly.

Parameters:
  • s_expr (sympy.Expr) – Principal symbol used to build the Hamiltonian(s).

  • vars_x (list of sympy.Symbol) – Spatial variables.

  • x0 (float or array_like, default=0.0) – Initial spatial position(s).

  • xi0 (float or array_like, default=5.0) – Initial frequency (momentum) component(s).

  • tmax (float, default=4.0) – Final integration time.

  • n_frames (int, default=100) – Number of time samples used for the trajectory and the animation.

  • projection (optional) – Currently unused for the 3D case (reserved for API parity with animate_singularity); the axes are always chosen as described above.

  • branches ('all', int, or list of int, default='all') – Which characteristic branches to animate.

  • labels (list of str, optional) – Currently unused (reserved for per-branch legend labels).

  • interval (int, default=50) – Delay between animation frames, in milliseconds.

  • save_path (str, optional) – If given, the animation is saved to this path via anim.save.

Returns:

The animation object.

Return type:

matplotlib.animation.FuncAnimation

microlocal.animate_wavefront_set(symbol: Expr, tspan: Tuple[float, float], x0: float | None = None, y0: float | None = None, xi0: float | None = None, eta0: float | None = None, x_range: Tuple[float, float] | None = None, y_range: Tuple[float, float] | None = None, xi_range: Tuple[float, float] | None = None, eta_range: Tuple[float, float] | None = None, seeds: int = 100, radius: float = 0.15, spread: float = 2.0, seed_family: Literal['circle', 'fiber', 'grid', 'rectangle', 'curve'] = 'circle', half_turn: bool = True, corner_ul: Tuple[float, float] | None = None, corner_lr: Tuple[float, float] | None = None, step: float | Tuple[float, float] = 0.5, phase: Expr | None = None, both_normals: bool = True, fan: int = 9, curve: Tuple[Any, Any] | None = None, curve_range: Tuple[float, float] | None = None, covector_angle: Any | None = None, closed: bool | None = None, two_sided: bool | None = None, n_frames: int = 40, dim: int | None = None, projection: str = 'cotangent', n_steps: int = 500, cmap: str = 'plasma', show_flow: bool = True, show_endpoints: bool = True, pad: float = 0.25, xlim: Tuple[float, float] | Sequence[Tuple[float, float] | None] | None = None, ylim: Tuple[float, float] | Sequence[Tuple[float, float] | None] | None = None, figsize: Tuple[float, float] | None = None, equal_aspect: bool | None = None, fixed_limits: bool = True, fast: bool = True, scheme: str = 'auto', max_points: int = 1000, energy: float | None = None, coords3d: Sequence[str] | None = None, color_by: str | None = None, zlim: Tuple[float, float] | None = None, view: Tuple[float, float] = (25.0, -60.0), rotate: float = 0.0, ortho: bool = False, title: str | None = None, ax: Axes | Sequence[Axes] | None = None, interval: int = 80, save_path: str | None = None) → FuncAnimation[source]

Animate the wavefront set WF(u) while one initial coordinate varies.

Each frame is the picture visualize_wavefront_set / interactive_symbol_analysis would give for one value of the animated variable: a family of seeds seed singularities is propagated along the bicharacteristics over tspan and drawn (strips, initial points in green, end points in red). The animated variable is the coordinate that has a range; it sweeps this range over n_frames frames while the other coordinates stay fixed.

The seed family is the default one of visualize_wavefront_set:

  • 2D: a point-source circle of radius radius around (x0, y0), with outward covectors of norm |(ξ0, η0)|. Varying x or y moves the circle; varying ξ or η changes the norm of the covectors.

  • 1D: a fan of seeds frequencies ξ ∈ [ξ0 - spread, ξ0 + spread] at the point x0. Varying x moves the fan, varying ξ shifts it.

Möbius strip: the covector (ξ, η) and its opposite -(ξ, η) define the same line, and since p is even they give the same geometric ray run in opposite directions: (ξ0, η0) at time t is the same point as -(ξ0, η0) at time -t. Taking the whole fiber over a point (directions modulo π, times in [-T, T]) therefore gives a strip whose two edges are glued with a flip of t, i.e. a Möbius strip. To see it, plot quantities that are invariant under (ξ, η) -> -(ξ, η) in projection=’3d’, e.g. coords3d=(‘u’, ‘v’, ‘y’) with the doubled-angle frequencies u = ξ² - η², v = 2ξη.

Parameters:
  • symbol (sympy expression) – Principal symbol p(x, ξ) in 1D or p(x, y, ξ, η) in 2D.

  • tspan (tuple) – (t_start, t_end) for bicharacteristic integration.

  • x0 (float, optional) – Fixed values of the coordinates (defaults 0, 0, 1, 0, as in visualize_wavefront_set). The one that has a range is ignored.

  • y0 (float, optional) – Fixed values of the coordinates (defaults 0, 0, 1, 0, as in visualize_wavefront_set). The one that has a range is ignored.

  • xi0 (float, optional) – Fixed values of the coordinates (defaults 0, 0, 1, 0, as in visualize_wavefront_set). The one that has a range is ignored.

  • eta0 (float, optional) – Fixed values of the coordinates (defaults 0, 0, 1, 0, as in visualize_wavefront_set). The one that has a range is ignored.

  • x_range (tuple (lo, hi)) – Range of the animated variable. Give exactly one (y and eta only in 2D).

  • y_range (tuple (lo, hi)) – Range of the animated variable. Give exactly one (y and eta only in 2D).

  • xi_range (tuple (lo, hi)) – Range of the animated variable. Give exactly one (y and eta only in 2D).

  • eta_range (tuple (lo, hi)) – Range of the animated variable. Give exactly one (y and eta only in 2D).

  • seeds (int, default=100) – Number of rays in each frame.

  • radius (float, default=0.15) – 2D: radius of the circle of seed points.

  • spread (float, default=2.0) – 1D: half-width of the fan of frequencies.

  • seed_family ({'circle', 'fiber', 'grid', 'rectangle', 'curve'}, default='circle') – 2D only. ‘circle’: the point-source circle described above. ‘fiber’: all seeds sit at the single point (x0, y0) and only the direction of the covector varies, over a half turn (see half_turn) with norm |(ξ0, η0)|; every ray is integrated in both time directions (the seed is at t = 0). Modulo the identification (ξ, η) ~ -(ξ, η) of a covector with its opposite, this is a Möbius strip (see the notes below). radius is ignored. If tspan[0] >= 0 the flow is run over (-tspan[1], tspan[1]); otherwise over tspan. ‘grid’: one seed at every node of a rectangular grid (see corner_ul, corner_lr, step), all with the same covector (ξ0, η0), or with the covector ∇S(x, y) if a phase function phase = S(x, y) is given (the initial Lagrangian manifold of a WKB / plane wave). ‘rectangle’: the wavefront set of the indicator of the rectangle: seeds along the four edges (spaced by step) with the unit conormals times |(ξ0, η0)|, plus a fan of fan directions at each corner. For both, seeds is ignored, and (x0, y0) is an offset that shifts the whole rectangle (default 0, 0), so x_range / y_range slide it; with ‘rectangle’ xi_range / eta_range change the covector norm, with ‘grid’ they change the constant covector (not allowed together with phase). With many rays use show_flow=False and a 3D view. ‘curve’: the conormal bundle of a parametrised curve (x(s), y(s)), s ∈ curve_range: seeds points along the curve, each with the unit conormal (y’(s), -x’(s))/|γ'(s)| times |(ξ0, η0)| (the right-hand normal, outward for a curve run counter-clockwise), plus the opposite conormal if both_normals. This is the wavefront set of a distribution singular along the curve (a line, circle, ellipse, parabola …). (x0, y0) shifts the curve and xi_range / eta_range change the covector norm, as for ‘rectangle’. Points where γ’(s) = 0 are skipped; corners of piecewise curves are not filled in (use ‘rectangle’ for that).

  • corner_ul (tuple (x, y)) – ‘grid’ / ‘rectangle’: upper-left and lower-right corners.

  • corner_lr (tuple (x, y)) – ‘grid’ / ‘rectangle’: upper-left and lower-right corners.

  • step (float or tuple (dx, dy), default=0.5) – ‘grid’ / ‘rectangle’: spacing along the x and y axes (the spacing is adjusted slightly so that the far edge is hit exactly).

  • phase (sympy expression in x, y, optional) – ‘grid’ only: phase function S(x, y); the covector at each node is (∂S/∂x, ∂S/∂y) evaluated at the (shifted) node.

  • curve (str or tuple (x(s), y(s)), optional) – ‘curve’ only: the name of a ready-made curve (a key of WAVEFRONT_CURVES, e.g. ‘astroid’), or two sympy expressions in one common parameter symbol (e.g. (2*cos(s), sin(s)); constants are allowed for one component), or two vectorised callables f(s) -> ndarray.

  • curve_range (tuple (s0, s1), optional) – ‘curve’ only: parameter interval (default: the catalogue range for a named curve, else (0, 2π)).

  • covector_angle (expression in s or callable, optional) – ‘curve’ only: direction φ(s) of the covector (cos φ, sin φ), instead of the normal to the curve. The curve may then be a single point, e.g. curve=(0, 0), covector_angle=s. This is how ‘circle’ (normal of a circle) and ‘fiber’ (constant position, rotating covector) are special cases of ‘curve’.

  • two_sided (bool, optional) – Integrate every ray in both time directions (seed at t = 0), as ‘fiber’ does. Default: True for ‘fiber’, else False.

  • closed (bool, optional) – ‘curve’ only: if True the end point s1 is not repeated. Default: detected automatically (curve(s0) == curve(s1)).

  • both_normals (bool, default=True) – ‘rectangle’ and ‘curve’: also seed the opposite conormals (WF is symmetric under ξ -> -ξ for a real distribution).

  • fan (int, default=9) – ‘rectangle’ only: number of directions in the fan at each corner (from one conormal to the other, and its opposite fan if both_normals).

  • half_turn (bool, default=True) – ‘fiber’ only: directions φ ∈ [0, π] (True) or [0, 2π] (False, which covers the Möbius strip twice). Both end points are included, so the initial curve closes up in sign-invariant coordinates such as (‘u’, ‘v’); in (ξ, η) itself a half turn is only an arc (use half_turn=False for the full circle there).

  • n_frames (int, default=40) – Number of values of the animated variable (one frame each).

  • dim (int, optional) – 1 or 2. Inferred from the arguments (y0, eta0, y_range or eta_range present -> 2D), else from the symbols of symbol.

  • projection – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • n_steps – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • cmap – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • show_flow – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • show_endpoints – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • title – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • ax – As in plot_wavefront_set (all projections, including ‘full’ in 2D); colour encodes the index of the ray. Additionally projection=’3d’ draws the rays in a 3D plot (see coords3d).

  • pad (float, default=0.25) – Margin around the rays on each side, as a fraction of the data extent (computed over all frames). Increase it for a wider view.

  • xlim (tuple (lo, hi), optional) – Explicit axis limits, overriding pad. For a single panel give a tuple; for projection=’full’ (2D) give a list of 4 tuples (or None entries) in the panel order position, frequency, (x, ξ), (y, η). Limits stay fixed during the whole animation.

  • ylim (tuple (lo, hi), optional) – Explicit axis limits, overriding pad. For a single panel give a tuple; for projection=’full’ (2D) give a list of 4 tuples (or None entries) in the panel order position, frequency, (x, ξ), (y, η). Limits stay fixed during the whole animation.

  • figsize (tuple (width, height) in inches, optional) – Size of the figure created here (ignored if ax is given). Default (12, 10) for projection=’full’ and (8, 6) otherwise.

  • equal_aspect (bool, optional) – True: equal scaling on both axes of every panel. False: every panel fills its cell. Default (None): equal scaling only for the position panel (x, y).

  • fixed_limits (bool, default=True) – True: the axis limits cover all frames and never change. False: the limits are re-fitted to the current frame (ignored for the axes with explicit xlim/ylim).

  • energy (float, optional) – 2D only. Put every seed on the energy shell p(x, y, ξ, η) = energy: the direction of its covector is kept (circle: outward, curve: conormal, grid: constant covector or ∇S, …) and its norm is solved for. This replaces the choice of |(ξ0, η0)|, which is then ignored, and gives the picture of the singularities of a solution of (P - E)u = 0. The norm is the smallest positive root of p(x, y, κu) = E along each direction u, which assumes that p increases with κ (as for kinetic + potential energy). Seeds in the classically forbidden region (no root) are dropped with a warning, and an error is raised if a frame has no seed left. With energy, xi_range / eta_range cannot be the animation variable, except for seed_family=’grid’ (where they change the direction of the covector).

  • fast (bool, default=True) – True: integrate all the rays of all the frames at once with NumPy (orders of magnitude faster than ray by ray). False: call bicharacteristic_flow ray by ray (slow reference path, always symplectic Euler).

  • scheme ({'auto', 'euler', 'verlet'}, default='auto') – Integration scheme of the fast path. ‘euler’: fixed-step symplectic Euler (first order, as bicharacteristic_flow). ‘verlet’: velocity Verlet (second order, symplectic, time-reversible), valid for separable symbols p = T(ξ, η) + V(x, y) such as kinetic + potential energy. ‘auto’ uses ‘verlet’ when the symbol is separable and ‘euler’ otherwise. Use scheme=’euler’ to compare with fast=False.

  • max_points (int, default=1000) – Maximum number of points stored (and drawn) per ray; the integration still uses all n_steps steps, so a large n_steps improves the accuracy without increasing the memory.

  • coords3d (tuple of 3 names, optional) – projection=’3d’ only: which three coordinates are the axes, among ‘x’, ‘y’, ‘xi’, ‘eta’ (2D) or ‘x’, ‘xi’ (1D), ‘t’ (time) and the derived quantities ‘kappa’ = |(ξ, η)| (covector norm; |ξ| in 1D) and, in 2D only, ‘phi’ = arg(ξ + iη) (covector angle, made continuous along each ray and equal to a value in [-π, π) at the seed; where the covector vanishes, e.g. at the turning points of bound radial rays, the covector reverses and ‘phi’ jumps by π, which is left as it is) and the sign-invariant frequencies ‘u’ = ξ²-η², ‘v’ = 2ξη. For example coords3d=('x', 'y', 'phi') draws the total space of the cotangent bundle as the base plane plus a circle fiber. Default (‘x’, ‘y’, ‘xi’) in 2D and (‘x’, ‘xi’, ‘t’) in 1D.

  • color_by (str, optional) – projection=’3d’ only: quantity mapped to colour – a coordinate name, ‘t’ or ‘index’ (ray index). Default: the 4th phase-space coordinate not used by the axes (e.g. ‘eta’), so that all four dimensions of T*ℝ² are visible; ‘kappa’ if ‘phi’ is one of the axes; ‘index’ in 1D.

  • zlim (tuple (lo, hi), optional) – projection=’3d’ only: explicit z limits (xlim and ylim give the x and y limits, each a plain tuple).

  • view (tuple (elevation, azimuth), default (25, -60)) – projection=’3d’ only: camera angles in degrees.

  • rotate (float, default=0.0) – projection=’3d’ only: degrees the camera turns around the z axis at each frame (e.g. 3.0 for a slowly turning view).

  • ortho (bool, default=False) – projection=’3d’ only: use an orthographic camera instead of the default perspective one, so that parallel lines stay parallel (planes such as t = 0 then look flat from any angle).

  • interval (int, default=80) – Delay between frames, in milliseconds.

  • save_path (str, optional) – If given, the animation is saved to this path via anim.save.

Returns:

  • matplotlib.animation.FuncAnimation – The animation object (anim._fig is the figure). The figure is closed if created here; use HTML(anim.to_jshtml()) in a notebook.

  • Special cases (the older families written as curves; radius, x0, y0 …

  • as above):: – # seed_family=’circle’ curve=(radius*cos(s), radius*sin(s)), both_normals=False # seed_family=’fiber’ (half_turn=True) curve=(0, 0), covector_angle=s, curve_range=(0, np.pi), both_normals=False, two_sided=True

Examples

anim = animate_wavefront_set(p, tspan=(0, 4), x0=1, xi0=1, eta0=1,
                             y_range=(-5, 5), seeds=100,
                             projection='position')

# 3D view of the 4D phase space: axes (x, y, ξ), colour = η
anim = animate_wavefront_set(p, tspan=(0, 4), x0=1, xi0=1, eta0=1,
                             y_range=(-5, 5), seeds=100,
                             projection='3d', rotate=2.0)

# wavefront set of an ellipse: conormals along the curve
anim = animate_wavefront_set(p, tspan=(0, 2), seed_family='curve',
                             curve=(2*cos(s), sin(s)), seeds=60,
                             xi0=1, eta0=0, x_range=(-1, 1))

# Möbius strip: whole fiber over a point, both time directions
anim = animate_wavefront_set(p, tspan=(0, 3), x0=0, xi0=1, eta0=0,
                             y_range=(0.2, 1.0), seeds=120,
                             seed_family='fiber', projection='3d',
                             coords3d=('u', 'v', 'y'))

# 1D
anim = animate_wavefront_set(p, tspan=(0, 4), x0=1, xi_range=(-2, 2),
                             seeds=40)
microlocal.bicharacteristic_flow(symbol: Expr, z0: Sequence[float], tspan: Tuple[float, float], dim: int | None = None, method: Literal['rk45', 'symplectic', 'verlet', 'hamiltonian'] = 'symplectic', n_steps: int = 1000) → Dict[str, ndarray][source]

Integrate the bicharacteristic flow on the cotangent bundle.

Hamilton’s equations: ẋ = ∂p/∂ξ, ξ̇ = -∂p/∂x (1D) or ẋ = ∂p/∂ξ, ẏ = ∂p/∂η, ξ̇ = -∂p/∂x, η̇ = -∂p/∂y (2D)

Parameters:
  • symbol (sympy expression) – Principal symbol.

  • z0 (tuple) – Initial condition on T*M. For 1D: (x₀, ξ₀); for 2D: (x₀, y₀, ξ₀, η₀).

  • tspan (tuple) – (t_start, t_end).

  • dim (int, optional) – Dimension. If None, inferred from length of z0.

  • method (str) – Integration method: ‘rk45’, ‘symplectic’, or ‘verlet’ (2D only).

  • n_steps (int) – Number of time steps.

Returns:

Trajectory data with keys ‘t’, ‘x’, ‘xi’ (1D) and also ‘y’,’eta’ (2D), plus ‘symbol_value’.

Return type:

dict

microlocal.bohr_sommerfeld_quantization(H: Expr, n_max: int = 10, x_range: Tuple[float, float] = (-10, 10), hbar: float = 1.0, E_range: Tuple[float, float] = (1e-06, 50.0)) → Dict[str, Any][source]

Compute Bohr-Sommerfeld quantization for 1D bound states.

Solves (1/(2π)) ∮ p dx = ℏ(n + α) with α = 1/2 (Maslov index).

Parameters:
  • H (sympy.Expr) – Hamiltonian H(x,p) as a symbolic expression.

  • n_max (int, optional) – Maximum quantum number to compute. Default is 10.

  • x_range (tuple of float, optional) – Spatial range for finding turning points. Default is (-10, 10).

  • hbar (float, optional) – Reduced Planck constant. Default is 1.0.

  • E_range (tuple of float, optional) – Energy range to scan for quantized levels. Default is (1e-6, 50.0).

Returns:

A dictionary containing: - ‘n’ : numpy.ndarray (Quantum numbers) - ‘E_n’ : numpy.ndarray (Quantized energy levels) - ‘actions’ : numpy.ndarray (Corresponding classical actions) - ‘hbar’ : float (The reduced Planck constant used) - ‘alpha’ : float (The Maslov index correction used, 0.5)

Return type:

dict

microlocal.characteristic_hamiltonians(s_expr: Expr | MatrixBase, vars_x: Sequence[Symbol], vars_xi: Sequence[Symbol] | None = None) → Tuple[List[Expr], List[Symbol], List[Symbol]][source]

Extract the characteristic Hamiltonian functions H(x, ξ) from a (possibly matrix-valued) operator symbol.

For a scalar symbol p(x, ξ), the single Hamiltonian is

H(x, ξ) = Re(p(x, ξ))

For a matrix symbol P(x, ξ), the eigenvalues λ_k(x, ξ) are computed symbolically and each branch yields

H_k(x, ξ) = Re(λ_k(x, ξ))

These Hamiltonians generate the bicharacteristic (ray) flow via Hamilton’s equations:

ẋ = ∂H/∂ξ, ξ̇ = −∂H/∂x

Parameters:
  • s_expr (sympy.Expr or sympy.Matrix) – Operator symbol (scalar or matrix-valued).

  • vars_x (list of sympy.Symbol) – Spatial variables.

  • vars_xi (list of sympy.Symbol, optional) – Frequency variables. If None, they are inferred from the free symbols of s_expr that are not in vars_x, and ordered canonically via _order_freq_vars.

Returns:

  • H_list (list of sympy.Expr) – One Hamiltonian per characteristic branch (eigenvalue).

  • xs (list of sympy.Symbol) – Canonical spatial symbols (real=True) used in H_list.

  • xis (list of sympy.Symbol) – Canonical frequency symbols (real=True) used in H_list.

Notes

The classical Hamiltonian governing bicharacteristic flow is the (real part of the) principal symbol itself. A previous version of this function erroneously computed Re(i * p), which vanishes identically for any real-valued symbol and therefore produced trivial (stationary) trajectories in the flow visualization.

The substitution to fresh canonical symbols ensures consistent differentiation even if the input expression uses symbols with different assumptions.

microlocal.characteristic_variety(symbol: Expr, dim: int | None = None, tol: float = 1e-08) → Dict[str, Any][source]

Compute the characteristic variety of a pseudo-differential operator.

Char(P) = { (x,ξ) in T*ℝ : p(x,ξ)=0 } (1D) or Char(P) = { (x,y,ξ,η) in T*ℝ² : p(x,y,ξ,η)=0 } (2D)

Parameters:
  • symbol (sympy expression) – Principal symbol p.

  • dim (int, optional) – Dimension (1 or 2). If None, inferred from symbol.

  • tol (float) – Tolerance for zero detection (unused, kept for compatibility).

Returns:

A dictionary containing the following keys:

  • ’implicit’sympy expression

    The symbol expression.

  • ’equation’sympy Eq

    The equation symbol = 0.

  • ’explicit’list or None

    List of explicit solutions ξ(x) (1D only), or None if no explicit solution exists.

  • ’function’callable

    A callable that evaluates the symbol.

Return type:

dict

microlocal.compute_caustics_2d(p: Expr, initial_curve: Dict[str, Sequence[float]], tmax: float, n_rays: int | None = None, **kwargs: Any) → List[Any][source]

Compute caustics for a 2D Hamiltonian given an initial curve.

Parameters:
  • p (sympy expression) – Hamiltonian symbol p(x, y, xi, eta).

  • initial_curve (dict) – Must contain keys ‘x’, ‘y’, ‘xi’, ‘eta’ with array values of equal length.

  • tmax (float) – Maximum integration time.

  • n_rays (int, optional) – Number of rays to use. If None, use all points in the initial curve.

  • **kwargs (additional arguments passed to bicharacteristic_flow) – (e.g., method=’symplectic’, n_steps=200).

Returns:

Each event contains position, time, momentum, Arnold type, etc.

Return type:

list of CausticEvent

microlocal.compute_maslov_index(traj: Dict[str, ndarray]) → int[source]

Compute the Maslov index for a single trajectory.

Parameters:

traj (dict) – Returned by bicharacteristic_flow. Must contain J11..J22 components.

Returns:

Maslov index (number of sign changes of det(J) or caustic crossings).

Return type:

int

microlocal.find_caustics_1d(symbol: Expr, x_range: Tuple[float, float], xi_range: Tuple[float, float], resolution: int = 100) → Dict[str, ndarray | float][source]

Find caustics (envelope of bicharacteristics) in 1D.

Uses a simplified condition: identifies regions where d²p/dξ² ≈ 0, which correspond to turning points in frequency.

Parameters:
  • symbol (sympy.Expr) – The 1D principal symbol p(x, ξ).

  • x_range (tuple of float) – The (min, max) range for the spatial variable x.

  • xi_range (tuple of float) – The (min, max) range for the frequency variable ξ.

  • resolution (int, optional) – Number of grid points per axis for the evaluation mesh. Default is 100.

Returns:

A dictionary containing: - ‘x_grid’ : numpy.ndarray (2D meshgrid of x coordinates) - ‘xi_grid’ : numpy.ndarray (2D meshgrid of ξ coordinates) - ‘caustic_indicator’ : numpy.ndarray (Absolute value of d²p/dξ²) - ‘threshold’ : float (10th percentile of the indicator, useful for masking)

Return type:

dict

microlocal.group_velocity_field(op: Any, xlim: Tuple[float, float] = (-2, 2), klim: Tuple[float, float] = (-10, 10), density: int = 30) → None[source]

Plot the group velocity field ∇_ξ p(x, ξ) for 1D pseudo-differential operators.

The group velocity represents the speed at which waves of different frequencies propagate in a dispersive medium. It is defined as the gradient of the symbol p(x, ξ) with respect to the frequency variable ξ.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • xlim (tuple of float) – Spatial domain limits (x-axis).

  • klim (tuple of float) – Frequency domain limits (ξ-axis).

  • density (int) – Number of grid points per axis used for visualization.

Raises:

NotImplementedError – If called on a 2D operator, since this visualization is only implemented for 1D.

Notes

  • This method visualizes the vector field (∂p/∂ξ) in phase space.

  • Used for analyzing wave propagation properties and dispersion relations.

  • Requires symbolic expression self.expr depending on x and ξ.

microlocal.integrate_singularity(s_expr: Expr | MatrixBase, vars_x: Sequence[Symbol], x0: float | Sequence[float] = 0.0, xi0: float | Sequence[float] = 5.0, tmax: float = 4.0, n_frames: int = 100, vars_xi: Sequence[Symbol] | None = None, branches: Literal['all'] | int | Sequence[int] = 'all', method: str = 'RK45', **ivp_kwargs: Any) → Tuple[List[Expr], List[Symbol], List[Symbol], ndarray, List[ndarray]][source]

Numerically integrate bicharacteristic (Hamiltonian ray) trajectories from an initial phase-space point (x₀, ξ₀).

For each characteristic branch H_k, Hamilton’s equations

ẋ = ∂H_k/∂ξ, ξ̇ = −∂H_k/∂x

are integrated using scipy.integrate.solve_ivp over [0, tmax].

Parameters:
  • s_expr (sympy.Expr or sympy.Matrix) – Operator symbol from which Hamiltonians are extracted.

  • vars_x (list of sympy.Symbol) – Spatial variables.

  • x0 (float or array_like, default 0.0) – Initial spatial position(s). Scalar for 1D, sequence for 2D.

  • xi0 (float or array_like, default 5.0) – Initial frequency (momentum) component(s).

  • tmax (float, default 4.0) – Final integration time.

  • n_frames (int, default 100) – Number of output time samples in [0, tmax].

  • vars_xi (list of sympy.Symbol, optional) – Explicit frequency variables (inferred if None).

  • branches ('all', int, or list of int, default 'all') – Which characteristic branches to integrate. ‘all’ integrates every branch; an int or list selects specific ones.

  • method (str, default 'RK45') – ODE solver method passed to solve_ivp.

  • **ivp_kwargs – Additional keyword arguments forwarded to solve_ivp (e.g. rtol, atol, max_step).

Returns:

  • H_list (list of sympy.Expr) – Hamiltonian expressions for the integrated branches.

  • xs (list of sympy.Symbol) – Canonical spatial symbols.

  • xis (list of sympy.Symbol) – Canonical frequency symbols.

  • t_eval (ndarray, shape (n_frames,)) – Time samples at which trajectories are recorded.

  • trajs (list of ndarray) – trajs[b] has shape (2·dim, n_frames): the first dim rows are position components, the last dim rows are momentum components.

Examples

>>> H, xs, xis, t, trajs = integrate_singularity(xi**2 + x**2, [x],
...                                              x0=0.0, xi0=3.0, tmax=6.0)
microlocal.interactive_symbol_analysis(pseudo_op: Any, xlim: Tuple[float, float] = (-2, 2), ylim: Tuple[float, float] = (-2, 2), xi_range: Tuple[float, float] = (0.1, 5), eta_range: Tuple[float, float] = (-5, 5), density: int = 50) → None[source]

Launch an interactive dashboard for symbol exploration using ipywidgets.

The dashboard combines a drop-down menu (the visualization mode) with sliders that set the base point of the exploration, (x₀[, y₀]) in position space and (ξ₀[, η₀]) in frequency space. The selected visualization is redrawn each time a widget changes. It works for operators in 1D and 2D and covers pointwise maps of the symbol (amplitude, phase, micro-support), characteristic-set diagnostics, vector fields (group velocity, Hamiltonian field) and the propagation of singularities (Hamiltonian flow and wavefront set).

Parameters:
  • pseudo_op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed interactively. Only its dimension (pseudo_op.dim, 1 or 2), its space variables and its symbol are used.

  • xlim (tuple of float, default=(-2, 2)) – Spatial domain limits along x and y (ylim is ignored in 1D). They define the evaluation grids and the ranges of the x₀ and y₀ sliders.

  • ylim (tuple of float, default=(-2, 2)) – Spatial domain limits along x and y (ylim is ignored in 1D). They define the evaluation grids and the ranges of the x₀ and y₀ sliders.

  • xi_range (tuple of float, default=(0.1, 5))

  • eta_range (tuple of float, default=(-5, 5)) – Frequency domain limits along ξ and η (eta_range is ignored in 1D). They define the evaluation grids and the ranges of the ξ₀ and η₀ sliders. In 1D, the width of xi_range is also used as the half-width of the fan of frequencies in the ‘Wavefront Set’ mode.

  • density (int, default=50) – Number of points per axis of the evaluation grids (resolution of the maps and vector fields). It is also the number of seeds (rays) of the ‘Wavefront Set’ mode. Large values make the dashboard slower.

Returns:

The dashboard (mode selector, sliders and output area) is displayed in the notebook; the figures are drawn in the output area and updated as the widgets change.

Return type:

None

Notes

  • Requires a Jupyter environment with ipywidgets. Each update closes all the open matplotlib figures (plt.close('all')) before redrawing.

  • Only 1D and 2D operators are supported.

  • Sliders (step 0.1): ξ₀ ranges over xi_range, η₀ over eta_range, x₀ over xlim and y₀ over ylim. Only the sliders needed by the selected mode are displayed; a hidden slider keeps its current value (initially ξ₀ = η₀ = 1 and x₀ = y₀ = 0).

Visualization modes in 1D (phase space (x, ξ)); sliders shown in brackets:

  • ‘Symbol Amplitude’ : |p(x,ξ)| as a color map

  • ‘Symbol Phase’ : arg p(x,ξ) (mod 2π, cyclic color map)

  • ‘Micro-Support (1/|p|)’ : 1/|p(x,ξ)|, large where the symbol is small

  • ‘Cotangent Fiber’ : p on the cotangent fiber above x₀

  • ‘Characteristic Set’ : approximate zero set {p ≈ 0}

  • ‘Characteristic Gradient’ : |∇p(x,ξ)|

  • ‘Group Velocity Field’ : ∂_ξ p(x,ξ) (1D only)

  • ‘Symplectic Vector Field’ : Hamiltonian vector field (∂_ξ p, -∂_x p)

  • ‘Hamiltonian Flow’ : trajectory from (x₀, ξ₀) with the vector field [ξ₀, x₀]

  • ‘Wavefront Set’ : propagation of a fan of seed frequencies at x₀ [ξ₀, x₀]

Visualization modes in 2D (phase space (x, y, ξ, η)):

  • ‘Symbol Amplitude’ : |p| over (x, y) at fixed frequency (ξ₀, η₀) [ξ₀, η₀]

  • ‘Symbol Phase’ : arg p over (x, y) at fixed frequency (ξ₀, η₀) [ξ₀, η₀]

  • ‘Micro-Support (1/|p|)’ : 1/|p| at fixed frequency (ξ₀, η₀) [ξ₀, η₀]

  • ‘Cotangent Fiber’ : p over the frequency plane (ξ, η) above (x₀, y₀) [x₀, y₀]

  • ‘Characteristic Set’ : approximate zero set {p ≈ 0} above (x₀, y₀) [x₀, y₀]

  • ‘Characteristic Gradient’ : |∇p| above (x₀, y₀) [x₀, y₀]

  • ‘Symplectic Vector Field’arrows (∂_ξ p, ∂_η p) over (x, y) at fixed frequency

    (ξ₀, η₀), colored by their norm [ξ₀, η₀]. This is the group velocity field, which is why there is no separate ‘Group Velocity Field’ mode in 2D.

  • ‘Hamiltonian Flow’ : trajectory from (x₀, y₀, ξ₀, η₀) [all four sliders]

  • ‘Wavefront Set’ : propagation of a point source at (x₀, y₀) [all four sliders]

‘Wavefront Set’ mode. The seeds are generated by visualize_wavefront_set and propagated along the bicharacteristics over t ∈ [0, 5] with 150 steps:

  • 1D: density seeds at the point x₀ with frequencies in [ξ₀ - w, ξ₀ + w], where w is the width of xi_range; the figure shows the cotangent projection.

  • 2D: density seeds on a circle of radius 0.15 around (x₀, y₀), with outward covectors of norm |(ξ₀, η₀)| (a point source); the figure shows the four 2D slices of phase space (position, frequency and the two cotangent slices).

For other settings (seed families, flow time, number of steps) or for animations, call visualize_wavefront_set, plot_wavefront_set or animate_wavefront_set directly.

See also

visualize_wavefront_set

Static wavefront-set plot with default seeds.

plot_wavefront_set

Wavefront-set plot for user-supplied seeds.

animate_wavefront_set

Animation of the wavefront set while an initial coordinate sweeps a range.

plot_hamiltonian_flow

Hamiltonian trajectories in phase space.

Examples

>>> x, y, xi, eta = sp.symbols('x y xi eta', real=True)
>>> symbol = (xi**2 + eta**2) / 2 - 1 / sp.sqrt(x**2 + y**2 + 0.01)
>>> op = PseudoDifferentialOperator(expr=symbol, vars_x=[x, y], mode='symbol')
>>> interactive_symbol_analysis(op, xlim=(-3, 3), ylim=(-3, 3),
...                             xi_range=(-3, 3), eta_range=(-3, 3), density=40)
microlocal.plot_bicharacteristics(symbol: Expr, initial_points: List[Sequence[float]], tspan: Tuple[float, float], dim: int | None = None, projection: Literal['position', 'frequency', 'mixed'] = 'position', **kwargs: Any) → None[source]

Plot bicharacteristic curves (Hamiltonian flow trajectories).

For 1D: plots trajectories in the (x,ξ) phase plane. For 2D: projection can be ‘position’ (x-y), ‘frequency’ (ξ-η), or ‘mixed’ (x-ξ).

Parameters:
  • symbol (sympy.Expr) – The principal symbol.

  • initial_points (list of tuple) – List of initial conditions for the flow.

  • tspan (tuple of float) – The (t_start, t_end) integration interval.

  • dim (int, optional) – Dimension (1 or 2). Inferred from initial_points if None.

  • projection (str, optional) – Projection plane for 2D plots. One of ‘position’, ‘frequency’, or ‘mixed’. Default is ‘position’.

  • **kwargs (dict) – Additional arguments passed to bicharacteristic_flow.

Returns:

Displays a matplotlib plot.

Return type:

None

microlocal.plot_characteristic_set(symbol: Expr, x_range: Tuple[float, float], xi_range: Tuple[float, float], dim: int | None = None, resolution: int = 200, **kwargs: Any) → None[source]

Plot the characteristic variety (zero set of the principal symbol).

For 1D: plots the contour p(x,ξ)=0 in the (x,ξ) phase plane. For 2D: plots a slice with fixed (ξ,η); you must provide xi0 and eta0 via kwargs.

Parameters:
  • symbol (sympy.Expr) – The principal symbol.

  • x_range (tuple of float) – Range for the first spatial variable (x).

  • xi_range (tuple of float) – Range for the second spatial variable (y) in 2D, or frequency (ξ) in 1D.

  • dim (int, optional) – Dimension (1 or 2). Inferred from symbol if None.

  • resolution (int, optional) – Grid resolution for plotting. Default is 200.

  • **kwargs (dict) – Additional arguments. For 2D, expects xi0 and eta0 (floats).

Returns:

Displays a matplotlib plot.

Return type:

None

microlocal.plot_hamiltonian_flow(op: Any, x0: float = 0.0, xi0: float = 5.0, y0: float = 0.0, eta0: float = 0.0, tmax: float = 1.0, n_steps: int = 100, show_field: bool = True) → None[source]

Integrate and plot the Hamiltonian trajectories of the symbol in phase space.

This method numerically integrates the Hamiltonian vector field derived from the operator’s symbol to visualize how singularities propagate under the flow. It supports both 1D and 2D problems.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • x0 (float) – Initial position and frequency (momentum) in 1D.

  • xi0 (float) – Initial position and frequency (momentum) in 1D.

  • y0 (float, optional) – Initial position and frequency in 2D; defaults to zero.

  • eta0 (float, optional) – Initial position and frequency in 2D; defaults to zero.

  • tmax (float) – Final integration time for the ODE solver.

  • n_steps (int) – Number of time steps used in the integration.

Notes

  • The Hamiltonian vector field is obtained from the symplectic flow of the symbol.

  • If the field is complex-valued, only its real part is used for integration.

  • In 1D, the trajectory is plotted in (x, ξ) phase space.

  • In 2D, the spatial trajectory (x(t), y(t)) is shown along with instantaneous momentum vectors (ξ(t), η(t)) using a quiver plot.

Raises:
  • NotImplementedError – If the spatial dimension is not 1D or 2D.

  • Displays –

  • -------- –

  • matplotlib plot – Phase space trajectory(ies) showing the evolution of position and momentum under the Hamiltonian dynamics.

microlocal.plot_matrix_1d(t: ndarray, U: ndarray, x: ndarray, labels: List[str] | None = None, quantity: Literal['real', 'imag', 'abs'] = 'real', save_path: str | None = None) → Figure[source]

Plot each component of a matrix-valued 1D solution as a stacked space-time heatmap.

Parameters:
  • t (ndarray, shape (n_times,)) – Time samples.

  • U (ndarray, shape (n_times, size, Nx)) – Diagonal (or otherwise reduced) matrix solution components, one row of panels per index k = 0, …, size-1.

  • x (ndarray, shape (Nx,)) – Spatial grid.

  • labels (list of str, optional) – One label per component; defaults to [“u_1”, …, “u_size”].

  • quantity ({'real', 'imag', 'abs'}, default='real') – Which part of U to plot.

  • save_path (str, optional) – If given, the figure is saved to this path (dpi=150) before closing.

Returns:

The completed figure (already closed via _finish_headless).

Return type:

matplotlib.figure.Figure

microlocal.plot_matrix_field_1d(t: ndarray, U: ndarray, x: ndarray, quantity: Literal['real', 'imag', 'abs'] = 'abs', component: Literal['trace', 'frobenius', 'diag'] | Tuple[int, int] = 'diag', labels: List[str] | None = None, save_path: str | None = None) → Figure[source]

Space-time heatmap(s) for a matrix-valued 1D solution.

Parameters:
  • t (ndarray, shape (n_times,)) – Time samples.

  • U (ndarray, shape (n_times, N, N, Nx)) – Matrix-valued solution field, as returned by solve_matrix_field / solve_sylvester_field in 1D.

  • x (ndarray, shape (Nx,)) – Spatial grid.

  • quantity ({'real', 'imag', 'abs'}, default='abs') – Which part of the (reduced) field to plot.

  • component ('diag' | 'trace' | 'frobenius' | (i, j), default='diag') – ‘diag’ – one panel per diagonal entry U_kk(x, t). ‘trace’ – single panel, sum_k U_kk(x, t). ‘frobenius’ – single panel, ||U(x, t)||_F. (i, j) – single panel, the (i, j) entry U_ij(x, t).

  • labels (list of str, optional) – Panel labels used when component=’diag’; defaults to [“U_11”, “U_22”, …].

  • save_path (str, optional) – If given, the figure is saved to this path (dpi=150) before closing.

Returns:

The completed figure (already closed via _finish_headless).

Return type:

matplotlib.figure.Figure

microlocal.plot_matrix_field_2d(t: ndarray, U: ndarray, x: ndarray, y: ndarray, times: Sequence[int] | None = None, quantity: Literal['real', 'imag', 'abs'] = 'abs', component: Literal['trace', 'frobenius'] | Tuple[int, int] = 'trace', save_path: str | None = None) → Figure[source]

Plot snapshot panels for a matrix-valued 2D solution field.

Parameters:
  • t (numpy.ndarray) – 1D array of time samples, shape (n_times,).

  • U (numpy.ndarray) – Matrix-valued solution field, shape (n_times, N, N, Nx, Ny).

  • x (numpy.ndarray) – 1D arrays of spatial grid coordinates.

  • y (numpy.ndarray) – 1D arrays of spatial grid coordinates.

  • times (array_like of int, optional) – Indices into t selecting which snapshots to plot. Defaults to 6 evenly spaced indices.

  • quantity ({'real', 'imag', 'abs'}, optional) – Which part of the reduced field to plot. Default is ‘abs’.

  • component ({'trace', 'frobenius'} or tuple of int, optional) – How to reduce the matrix field to a scalar field. ‘trace’ : sum of diagonal entries. ‘frobenius’ : Frobenius norm. (i, j) : specific matrix entry. Default is ‘trace’.

  • save_path (str, optional) – If provided, saves the figure to this path.

Returns:

The completed and closed figure object.

Return type:

matplotlib.figure.Figure

microlocal.plot_pseudospectrum(Lambda: ndarray, resolvent_norm: ndarray, sigma_min_grid: ndarray, epsilon_levels: Sequence[float], eigenvalues: ndarray | None) → None[source]

Plot pseudospectrum results.

Parameters:
  • Lambda (ndarray) – Complex λ grid

  • resolvent_norm (ndarray) – Resolvent norms

  • sigma_min_grid (ndarray) – Smallest singular values

  • epsilon_levels (list) – Contour levels

  • eigenvalues (ndarray or None) – Eigenvalues to overlay

microlocal.plot_scalar_1d(t: ndarray, U: ndarray, x: ndarray, title: str = 'u(x, t)', quantity: Literal['real', 'imag', 'abs'] = 'real', n_snapshots: int = 6, save_path: str | None = None) → Figure[source]

Plot a scalar 1D space-time solution as a combined heatmap and snapshot overlay.

Parameters:
  • t (ndarray, shape (n_times,)) – Time samples.

  • U (ndarray, shape (n_times, Nx)) – Solution values u(x, t) sampled on the grid.

  • x (ndarray, shape (Nx,)) – Spatial grid.

  • title (str, default="u(x, t)") – Base title used for the heatmap panel.

  • quantity ({'real', 'imag', 'abs'}, default='real') – Which part of U to plot.

  • n_snapshots (int, default=6) – Number of time slices drawn as line overlays in the second panel.

  • save_path (str, optional) – If given, the figure is saved to this path (dpi=150) before closing.

Returns:

The completed figure (already closed via _finish_headless, so it will not display inline; use save_path or re-show it explicitly).

Return type:

matplotlib.figure.Figure

microlocal.plot_scalar_2d(t: ndarray, U: ndarray, x: ndarray, y: ndarray, times: Sequence[int] | None = None, quantity: Literal['real', 'imag', 'abs'] = 'real', save_path: str | None = None) → Figure[source]

Plot a scalar 2D solution at selected time instants as a row of side-by-side pcolormesh panels.

Parameters:
  • t (ndarray, shape (n_times,)) – Time samples.

  • U (ndarray, shape (n_times, Nx, Ny)) – Solution values u(x, y, t) sampled on the grid.

  • x (ndarray) – Spatial grids along each axis.

  • y (ndarray) – Spatial grids along each axis.

  • times (array_like of int, optional) – Indices into t selecting which snapshots to plot. Defaults to 6 indices evenly spaced across the whole time range.

  • quantity ({'real', 'imag', 'abs'}, default='real') – Which part of U to plot.

  • save_path (str, optional) – If given, the figure is saved to this path (dpi=150) before closing.

Returns:

The completed figure (already closed via _finish_headless).

Return type:

matplotlib.figure.Figure

microlocal.plot_symplectic_vector_field(op: Any, xlim: Tuple[float, float] = (-2, 2), klim: Tuple[float, float] = (-5, 5), density: int = 30) → None[source]

Visualize the symplectic vector field (Hamiltonian vector field) associated with the operator’s symbol.

The plotted vector field corresponds to (∂_ξ p, -∂_x p), where p(x, ξ) is the principal symbol of the pseudo-differential operator. This field governs the bicharacteristic flow in phase space.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • xlim (tuple of float) – Range for spatial variable x, as (x_min, x_max).

  • klim (tuple of float) – Range for frequency variable ξ, as (ξ_min, ξ_max).

  • density (int) – Number of grid points per axis for the visualization grid.

Raises:

NotImplementedError – If called on a 2D operator (currently only 1D implementation available).

Notes

  • Only supports one-dimensional operators.

  • Uses symbolic differentiation to compute ∂_ξ p and ∂_x p.

  • Numerical evaluation is done via lambdify with NumPy backend.

  • Visualization uses matplotlib quiver plot to show vector directions.

microlocal.plot_wave_solution_1d(t: ndarray, U: ndarray, V: ndarray, x: ndarray, quantity: Literal['real', 'imag', 'abs'] = 'real', save_path: str | None = None) → Figure[source]

Plot side-by-side space-time heatmaps of displacement and velocity.

Intended for the output of solve_second_order (scalar, 1D case).

Parameters:
  • t (numpy.ndarray) – 1D array of time samples, shape (n_times,).

  • U (numpy.ndarray) – Displacement field u(x, t), shape (n_times, Nx).

  • V (numpy.ndarray) – Velocity field ∂_t u(x, t), shape (n_times, Nx).

  • x (numpy.ndarray) – 1D array of spatial grid coordinates, shape (Nx,).

  • quantity ({'real', 'imag', 'abs'}, optional) – Which part of the fields to plot. Default is ‘real’.

  • save_path (str, optional) – If provided, saves the figure to this path.

Returns:

The completed and closed figure object.

Return type:

matplotlib.figure.Figure

microlocal.plot_wavefront_set(symbol: Expr, initial_sing_support: List[Sequence[float]], tspan: Tuple[float, float], dim: int | None = None, projection: str = 'cotangent', n_steps: int = 500, cmap: str = 'plasma', show_flow: bool = True, show_endpoints: bool = True, title: str | None = None, ax: Axes | Sequence[Axes] | None = None) → Tuple[Figure, Axes | ndarray][source]

Plot the wavefront set WF(u) of a distribution u whose singularities propagate along bicharacteristics of the operator with symbol p.

The wavefront set is represented as a subset of the cotangent bundle T*ℝⁿ. Each initial point (x₀, ξ₀) seeds a bicharacteristic strip; the union of these strips in phase space approximates WF(u) at time tspan[1].

Parameters:
  • symbol (sympy expression) – Principal symbol p(x, ξ) in 1D or p(x, y, ξ, η) in 2D.

  • initial_sing_support (list of tuples) – Seed points on the wavefront set at t=0. 1D: list of (x₀, ξ₀) pairs. 2D: list of (x₀, y₀, ξ₀, η₀) quadruples.

  • tspan (tuple) – (t_start, t_end) for bicharacteristic integration.

  • dim (int, optional) – Dimension (1 or 2). Inferred from seed points if None.

  • projection (str) –

    Which subspace to visualise (dimension-dependent): - 1D:

    ’cotangent’ – (x, ξ) phase-space portrait [default] ‘position’ – x(t) projected onto ℝ (singular support)

    • 2D:

      ’cotangent’ – (x, ξ) slice (ignoring y, η) ‘position’ – (x, y) projection (singular support in ℝ²) ‘frequency’ – (ξ, η) projection (directions of non-smoothness) ‘full’ – 2×2 grid: position, frequency, (x,ξ), (y,η)

  • n_steps (int) – Number of integration steps per bicharacteristic.

  • cmap (str) – Matplotlib colormap used to colour individual bicharacteristics (colour encodes the index of the seed point, i.e. which part of the initial singular support it originated from).

  • show_flow (bool) – If True, draw the full bicharacteristic strip (trajectory in phase space). If False, only show the endpoint scatter.

  • show_endpoints (bool) – If True, mark the initial point (green •) and final point (red •) of each bicharacteristic.

  • title (str, optional) – Figure title. A sensible default is generated if None.

  • ax (matplotlib Axes or array of Axes, optional) – Axes to draw into. If None a new figure is created. For projection=’full’ (2D) pass an array of 4 Axes or leave None.

Returns:

  • fig (matplotlib Figure)

  • axes (Axes or array of Axes)

Examples

1D example – Schrödinger-type operator, horizontal line singularity:

x, xi = symbols('x xi', real=True)
p = xi**2 - (1 - x**2)           # simple potential well symbol
seeds = [(xi_val, float(xi_val)) for xi_val in np.linspace(-1, 1, 12)]
fig, ax = plot_wavefront_set(p, seeds, tspan=(0, 4), dim=1)
plt.show()

2D example – wave operator, outward circular wavefront:

x, y, xi, eta = symbols('x y xi eta', real=True)
p = xi**2 + eta**2 - 1
seeds = [(np.cos(t), np.sin(t), np.cos(t), np.sin(t))
         for t in np.linspace(0, 2*np.pi, 24, endpoint=False)]
fig, axes = plot_wavefront_set(p, seeds, tspan=(0, 2), dim=2,
                               projection='full')
plt.show()
microlocal.propagate_singularity(symbol: Expr, initial_sing_support: List[Sequence[float]], tspan: Tuple[float, float], dim: int | None = None, n_samples: int | None = None) → Dict[str, Any][source]

Propagate singular support along bicharacteristics.

Parameters:
  • symbol (sympy.Expr) – The principal symbol.

  • initial_sing_support (list of tuple) – List of initial phase-space points (x₀, ξ₀) for 1D or (x₀, y₀, ξ₀, η₀) for 2D.

  • tspan (tuple of float) – The (t_start, t_end) integration interval.

  • dim (int, optional) – Spatial dimension (1 or 2). Inferred from symbol if None.

  • n_samples (int, optional) – Currently unused. Kept for API compatibility.

Returns:

A dictionary containing: - ‘trajectories’ : list of dict (Bicharacteristic flow results) - ‘endpoints’ : list of tuple (Final phase-space coordinates) - ‘initial’ : list of tuple (The initial seed points provided)

Return type:

dict

microlocal.visualize_characteristic_gradient(op: Any, x_grid: ndarray, xi_grid: ndarray, y_grid: ndarray | None = None, eta_grid: ndarray | None = None, y0: float = 0.0, x0: float = 0.0) → None[source]

Visualize the norm of the gradient of the symbol in phase space.

This method computes the magnitude of the gradient |∇p| of a pseudo-differential symbol p(x, ξ) in 1D or p(x, y, ξ, η) in 2D. The resulting colormap reveals regions where the symbol varies rapidly or remains nearly stationary, which is particularly useful for analyzing characteristic sets.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • x_grid (numpy.ndarray) – 1D array of spatial coordinates for the x-direction.

  • xi_grid (numpy.ndarray) – 1D array of frequency coordinates (ξ).

  • y_grid (numpy.ndarray, optional) – 1D array of spatial coordinates for the y-direction (used in 2D mode). Default is None.

  • eta_grid (numpy.ndarray, optional) – 1D array of frequency coordinates (η) for the 2D case. Default is None.

  • x0 (float, optional) – Fixed x-coordinate for evaluating the symbol in 2D. Default is 0.0.

  • y0 (float, optional) – Fixed y-coordinate for evaluating the symbol in 2D. Default is 0.0.

Returns:

Displays a 2D colormap of |∇p| over the relevant phase-space domain.

Return type:

None

Notes

  • In 1D, the full gradient ∇p = (∂ₓp, ∂ξp) is computed over the (x, ξ) grid.

  • In 2D, the gradient ∇p = (∂ξp, ∂ηp) is computed at a fixed spatial point (x₀, y₀) over the (ξ, η) grid.

  • Numerical differentiation is performed using np.gradient.

  • High values of |∇p| indicate rapid variation of the symbol, while low values typically suggest characteristic regions.

microlocal.visualize_characteristic_set(op: Any, x_grid: ndarray, xi_grid: ndarray, y_grid: ndarray | None = None, eta_grid: ndarray | None = None, y0: float = 0.0, x0: float = 0.0, levels: Sequence[float] = [0.1]) → None[source]

Visualize the characteristic set of the pseudo-differential symbol, defined as the approximate zero set p(x, ξ) ≈ 0.

In microlocal analysis, the characteristic set is the locus of points in phase space (x, ξ) where the symbol p(x, ξ) vanishes, playing a key role in understanding propagation of singularities.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • x_grid (ndarray) – Spatial grid values (1D array) for plotting in 1D or evaluation point in 2D.

  • xi_grid (ndarray) – Frequency variable grid values (1D array) used to construct the frequency domain.

  • x0 (float, optional) – Fixed spatial coordinate in 2D case for evaluating the symbol at a specific x position.

  • y0 (float, optional) – Fixed spatial coordinate in 2D case for evaluating the symbol at a specific y position.

Notes

  • For 1D, this method plots the contour of |p(x, ξ)| = ε with ε = 1e-5 over the (x, ξ) plane.

  • For 2D, it evaluates the symbol at fixed (x₀, y₀) and plots the characteristic set in the (ξ, η) frequency plane.

  • This visualization helps identify directions of degeneracy or hypoellipticity of the operator.

Raises:
  • NotImplementedError – If called on a solver with dimensionality other than 1D or 2D.

  • Displays –

  • ------ –

  • A matplotlib contour plot showing either: –

    • The characteristic curve in the (x, ξ) phase plane (1D), - The characteristic surface slice in the (ξ, η) frequency plane at (x₀, y₀) (2D).

microlocal.visualize_fiber(op: Any, x_grid: ndarray, xi_grid: ndarray, x0: float = 0.0, y0: float = 0.0) → None[source]

Plot the cotangent fiber structure at a fixed spatial point (x₀[, y₀]).

This visualization shows how the symbol p(x, ξ) behaves on the cotangent fiber above a fixed spatial point. In microlocal analysis, this provides insight into the frequency content of the operator at that location.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • x_grid (ndarray) – Spatial grid values (1D) for evaluation in 1D case.

  • xi_grid (ndarray) – Frequency grid values (1D) for evaluation in both 1D and 2D cases.

  • x0 (float, optional) – Fixed x-coordinate of the base point in space (1D or 2D).

  • y0 (float, optional) – Fixed y-coordinate of the base point in space (2D only).

Notes

  • In 1D: Displays |p(x, ξ)| over the (x, ξ) phase plane near the fixed point.

  • In 2D: Fixes (x₀, y₀) and evaluates p(x₀, y₀, ξ, η), showing the fiber over that point.

  • The color map represents the magnitude of the symbol, highlighting regions where it vanishes or becomes singular.

Raises:

NotImplementedError – If called in 2D with missing or improperly formatted grids.

microlocal.visualize_micro_support(op: Any, xlim: Tuple[float, float] = (-2, 2), klim: Tuple[float, float] = (-10, 10), threshold: float = 0.001, density: int = 300, xi0: float = 0.0, eta0: float = 0.0) → None[source]

Visualize the micro-support of the operator by plotting the inverse of the symbol magnitude 1 / |p(x, ξ)|.

The micro-support provides insight into the singularities of a pseudo-differential operator in phase space (x, ξ). Regions where |p(x, ξ)| is small correspond to large values in 1/|p(x, ξ)|, highlighting areas of significant operator influence or singularity.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • xlim (tuple) – Spatial domain limits (x_min, x_max).

  • klim (tuple) – Frequency domain limits (ξ_min, ξ_max).

  • threshold (float) – Threshold below which |p(x, ξ)| is considered effectively zero; used for numerical stability.

  • density (int) – Number of grid points along each axis for visualization resolution.

Raises:

NotImplementedError – If called on a solver with dimension greater than 1 (only 1D visualization is supported).

Notes

  • This method evaluates the symbol p(x, ξ) over a grid and plots its reciprocal to emphasize regions where the symbol is near zero.

  • A small constant (1e-10) is added to the denominator to avoid division by zero.

  • The resulting plot helps identify characteristic sets.

microlocal.visualize_phase(op: Any, x_grid: ndarray, xi_grid: ndarray, y_grid: ndarray | None = None, eta_grid: ndarray | None = None, xi0: float = 0.0, eta0: float = 0.0) → None[source]

Plot the phase (argument) of the pseudodifferential operator’s symbol p(x, ξ) or p(x, y, ξ, η).

This visualization helps in understanding the oscillatory behavior and regularity properties of the operator in phase space. The phase is displayed modulo 2π using a cyclic colormap (‘twilight’) to emphasize its periodic nature.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • x_grid (ndarray) – 1D array of spatial coordinates (x).

  • xi_grid (ndarray) – 1D array of frequency coordinates (ξ).

  • y_grid (ndarray, optional) – 2D spatial grid for y-coordinate (in 2D problems). Default is None.

  • eta_grid (ndarray, optional) – 2D frequency grid for η (in 2D problems). Not used directly but kept for API consistency.

  • xi0 (float, optional) – Fixed value of ξ for slicing in 2D visualization. Default is 0.0.

  • eta0 (float, optional) – Fixed value of η for slicing in 2D visualization. Default is 0.0.

  • Notes

  • 1D (- In)

  • 2D (- In)

  • π. (- Uses plt.pcolormesh with 'twilight' colormap to represent angles from -π to)

  • Raises

  • NotImplementedError (-)

microlocal.visualize_symbol_amplitude(op: Any, x_grid: ndarray, xi_grid: ndarray, y_grid: ndarray | None = None, eta_grid: ndarray | None = None, xi0: float = 0.0, eta0: float = 0.0) → None[source]

Display the modulus |p(x, ξ)| or |p(x, y, ξ₀, η₀)| as a color map.

This method visualizes the amplitude of the pseudodifferential operator’s symbol in either 1D or 2D spatial configuration. In 2D, the frequency variables are fixed to specified values (ξ₀, η₀) for visualization purposes.

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator whose symbol is to be analyzed. Must expose attributes: dim, p_func, vars_x, symbol, and expr.

  • x_grid (ndarray) – Spatial grids over which to evaluate the symbol. y_grid is optional and used only in 2D.

  • y_grid (ndarray) – Spatial grids over which to evaluate the symbol. y_grid is optional and used only in 2D.

  • xi_grid (ndarray) – Frequency grids. In 2D, these define the domain over which the symbol is evaluated, but the visualization fixes ξ = ξ₀ and η = η₀.

  • eta_grid (ndarray) – Frequency grids. In 2D, these define the domain over which the symbol is evaluated, but the visualization fixes ξ = ξ₀ and η = η₀.

  • xi0 (float, optional) – Fixed frequency values for slicing in 2D visualization. Defaults to zero.

  • eta0 (float, optional) – Fixed frequency values for slicing in 2D visualization. Defaults to zero.

Notes

  • In 1D: Visualizes |p(x, ξ)| over the (x, ξ) grid.

  • In 2D: Visualizes |p(x, y, ξ₀, η₀)| at fixed frequencies ξ₀ and η₀.

  • The color intensity represents the magnitude of the symbol, highlighting regions where the symbol is large or small.

microlocal.visualize_wavefront_set(op: Any, seeds: List[Sequence[float]] | None = None, tspan: Tuple[float, float] = (0, 3.0), projection: str = 'cotangent', n_steps: int = 500, cmap: str = 'plasma', show_flow: bool = True, show_endpoints: bool = True, title: str | None = None, x0: float = 0.0, y0: float = 0.0, xi0: float = 1.0, eta0: float = 0.0, spread: float = 2.0, n_seeds: int = 25, radius: float = 0.15) → Tuple[Figure, Axes | ndarray][source]

Visualize the wavefront set WF(u) obtained by propagating seed singularities along the bicharacteristics of the operator’s symbol.

If seeds is not given, a default fan/point-source is built from (x0, y0) and (xi0, eta0).

Parameters:
  • op (PseudoDifferentialOperator) – The pseudo-differential operator.

  • seeds (list of tuple, optional) – Seed points for the wavefront set. If None, auto-generated.

  • tspan (tuple of float, optional) – Integration time interval (t_start, t_end). Default is (0, 3.0).

  • projection (str, optional) – Subspace to visualize. 1D: ‘cotangent’, ‘position’. 2D: ‘cotangent’, ‘position’, ‘frequency’, ‘mixed_x’, ‘mixed_y’, ‘full’.

  • n_steps (int, optional) – Number of integration steps per bicharacteristic. Default is 500.

  • cmap (str, optional) – Matplotlib colormap. Default is ‘plasma’.

  • show_flow (bool, optional) – Whether to draw the full bicharacteristic strip. Default is True.

  • show_endpoints (bool, optional) – Whether to mark initial and final points. Default is True.

  • title (str, optional) – Figure title.

  • x0 (float, optional) – Base spatial coordinates for auto-generated seeds.

  • y0 (float, optional) – Base spatial coordinates for auto-generated seeds.

  • xi0 (float, optional) – Base frequency coordinates for auto-generated seeds.

  • eta0 (float, optional) – Base frequency coordinates for auto-generated seeds.

  • spread (float, optional) – Frequency spread for 1D auto-generated seeds.

  • n_seeds (int, optional) – Number of seed points to generate if seeds is None.

  • radius (float, optional) – Radius for 2D point-source auto-generated seeds.

Returns:

  • fig (matplotlib.figure.Figure) – The generated figure.

  • axes (matplotlib.axes.Axes or ndarray of Axes) – The axes object(s).