Skip to content

Spread the Huygens PSF into the diffraction orders of filter meshes - #299

Merged
roytsmart merged 3 commits into
mainfrom
feature/mesh-diffraction
Nov 23, 2026
Merged

roytsmart merged 3 commits into
mainfrom
feature/mesh-diffraction

Conversation

@roytsmart

@roytsmart roytsmart commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

The Huygens PSF treated the mesh which supports a thin-film filter as a uniform transmission. A mesh is a crossed transmission grating: it diffracts the light into orders which land on the sensor as copies of the image, λz/d apart along each axis of the mesh, where d is its period and z its distance from the image. On ESIS, the filters are Al on a 70 lpi Ni mesh with 82% open area, 202 mm in front of the detector. At O V (63 nm) the orders land 35 µm apart, and 18% of the light which passes the filter leaves the zeroth order.

What changes

  • AbstractMesh.efficiency_order(order) gives the fraction of the incident light in the order (m, n), c_m² c_n², where c_m = sin(πma)/(πm) for a square mesh open over a = √efficiency of each period. The fractions sum to efficiency. The wires run along the x and y axes of the surface the mesh supports, so the transformation of the surface (its roll) orients the mesh.
  • SequentialSystem.psf() now includes the meshes of all thin-film filters by default:
    • It deflects the rays leaving each filter into the first order along each axis of its mesh, and traces them to the sensor to find where the orders land. This covers the roll of the mesh, the tilt of the sensor and any optics between the filter and the sensor.
    • It adds copies of the PSF shifted there, weighted by the fraction of the light each order carries. The shifts are applied in the Fourier domain, as a product of one sum over the orders along each axis of the mesh, since their weights are separable, on a grid zero-padded so that the orders summed which miss the grid land on the padding. Beyond 1024 orders along an axis, which happens only when the orders land much closer together than the width of the grid, the sum is over all of them in closed form, from the autocorrelation of a square wave.
    • The PSF is cut off at the edge of the sensor after the mesh, so the light the mesh diffracts across the edge lands on the sensor.
    • mesh=False leaves the meshes out. With the default, the sensor positions must be a regular grid, which is checked before the diffraction integral, and a ValueError says to pass mesh=False otherwise.
  • wavefield() leaves the meshes out, as before, without tracing their orders, and its docstring now says so.

Why the orders add incoherently

How the orders interfere depends on where the wires cross the beam. On ESIS the beam is about 1.8 mm wide on the filter, about five periods of the mesh, and it slides through one period every ~29 pixels of motion of the image. Averaged over the position of the wires, the cross terms between different orders vanish, so the average PSF is the sum of shifted copies of the PSF without the mesh, weighted by c_m² c_n². This is exact within the Fresnel approximation, and it is the PSF that an extended source sees.

Approximations

  • The mesh is a square grid of thin, opaque wires of equal width.
  • Each order is a copy of the PSF of the zeroth order, so how the aberrations change with the small deflection of the order is left out, and the orders are not vignetted by the apertures after the filter. On ESIS the filter is the last surface before the detector.
  • Orders shifted by the width of the grid or more miss it and count as light off the grid. The light of the PSF which lands off the grid is not diffracted back onto it.
  • The grid must resolve the PSF, which must be nearly zero at its edges, or the shifted copies ring and the result can be slightly negative.

Tests

  • test_efficiency_order: the orders sum to efficiency, the zeroth order carries efficiency², and the orders are symmetric and separable.
  • test_psf_mesh, on an f/25 parabola with a filter 50 mm before focus, rolled by 30°:
    • the first orders land λz/d from the image, along the rolled axes of the mesh, to within 1e-3;
    • the PSF equals the sum of mesh-free PSFs evaluated by the diffraction integral at the shifted positions, to within 1e-4 of the peak (measured 1.7e-5).
  • test_psf_mesh_registration, a brute-force check of the physics: a converging beam through a sampled mesh, averaged over 25 positions of the wires, matches the shifted copies to within 2e-3 of the peak (measured 8.8e-4, from sampling the wires on a 20 µm grid). A uniform transmission is off by 0.56 of the peak.
  • test_psf_mesh_sensor_edge: with the edge of the sensor 1.25 µm from the image, the PSF is the PSF far from the edge, cut off at the edge, to within 1e-4 of the peak (measured 1.3e-5, the same as without the mesh).
  • test_psf_mesh_near_sensor: behind a filter 0.2 mm before focus, the orders land 20 nm apart, thousands of them on the grid, and change the PSF by at most 2% of the peak (measured 1.1%) in 0.6 s.
  • test_diffract_mesh: the orders summed one at a time and in closed form match copies of a Gaussian shifted one order at a time, to 3e-16 and 6.5e-5 of the peak.
  • test_diffract_mesh_degenerate, test_diffract_mesh_nan: shifts which do not span the plane and an opaque mesh leave the PSF unchanged, and a NaN stays where it is.
  • test_psf_mesh_irregular: an irregular grid or a line raises with the default, before the diffraction integral, and works with mesh=False.
  • test_wavefield_mesh_skipped: wavefield() and psf(mesh=False) do not trace the orders.
  • Full suite: 28,604 passed under -n 4, and the 484 DXF tests passed serially. Black and ruff are clean.

Effect on ESIS

The ESIS model clocks the filter mesh 45° to the pixels with the roll of the filter. With the mesh included, the MTF of the O V channel at its resolution requirement (0.484 cycles/arcsec), along / across the dispersion, becomes:

without the mesh with the mesh
design, center 0.744 / 0.752 0.597 / 0.604
design, corner 0.731 / 0.731 0.587 / 0.586
as built, center 0.568 / 0.523 0.456 / 0.420
as built, corner 0.535 / 0.506 0.429 / 0.406

Every value drops by a factor of 0.80. That is the mesh's own transfer function at 45°: the shift across one cycle at that frequency falls between the wire width and the open width along both axes of the mesh, where each axis passes 1 − wire/open = 0.896 of the contrast. Higher up, the MTF recovers in narrow peaks at the frequencies where the copies line up again, one period of the mesh apart along both of its axes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1f48441) to head (3d27630).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #299    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          142       142            
  Lines        13517     13864   +347     
==========================================
+ Hits         13517     13864   +347     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roytsmart
roytsmart changed the base branch from feature/psf-radiometry to main November 23, 2026 16:21
The mesh which supports a thin-film filter is a crossed transmission
grating, which diffracts the light into orders that land on the sensor
as copies of the image, lambda z / d apart along each axis of the mesh.
How the orders interfere depends on where the wires cross the beam,
which is not known and changes across the field, but averaged over the
position of the wires the cross terms between orders vanish and the
orders add incoherently.

- `AbstractMesh.efficiency_order()` gives the fraction of the incident
  light in each order (m, n), c_m^2 c_n^2 with c_m = sin(pi m a) / (pi m)
  for a square mesh open over a = sqrt(efficiency) of each period. The
  wires run along the x and y axes of the surface, so its transformation
  orients the mesh.
- `SequentialSystem.psf()` deflects the rays leaving each thin-film
  filter into the first order along each axis of its mesh, traces them
  to the sensor to find where the orders land, and adds copies of the
  PSF shifted there in the Fourier domain, weighted by the fraction of
  the light each order carries. `mesh=False` leaves this out.
- `wavefield()` leaves the meshes out, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP
@roytsmart
roytsmart force-pushed the feature/mesh-diffraction branch from 298ec5f to e95150e Compare November 23, 2026 16:26
roytsmart and others added 2 commits November 23, 2026 11:00
…ction

From the review of this pull request:

- Cut the point-spread function off at the edge of the sensor after
  spreading it into the orders of the mesh, so the light diffracted across
  the edge lands on the sensor. `_wavefield()` no longer zeroes the flux
  outside the aperture of the sensor; `psf()` does, after the mesh.
- Sum the orders along each axis of the mesh separately, since their
  weights are separable, on a grid padded so that the orders summed which
  miss it land on the padding. The cost grows with the number of orders
  along an axis rather than with its square: the PSF behind a filter
  0.2 mm before focus takes 0.6 s instead of more than three minutes.
  Beyond 1024 orders along an axis, the sum is over all of them, in closed
  form, from the autocorrelation of a square wave.
- Leave the PSF unchanged when the shifts do not span the plane, as for a
  filter on the sensor, which scaled it by the efficiency of the mesh, and
  for an opaque mesh, which made it NaN.
- Leave the positions where the PSF is not finite out of the FFT, which
  spread a NaN across the grid.
- Check that the sensor positions are a regular grid before the
  diffraction integral rather than after, and say that at least two are
  needed along each axis.
- Trace the orders only for `psf()` with the mesh, not for `wavefield()`
  or `psf(mesh=False)`, and reuse the rays traced to the sensor rather
  than trace them again.
- Document that the orders are not vignetted by the apertures after the
  filter, that each is a copy of the PSF of the zeroth order, and that the
  grid must resolve the PSF, or the shifted copies ring.
- Write `_coefficient()` with `optika.rulings._rulings._sinc()`.

Tests: the PSF near the edge of the sensor is the PSF far from it, cut off
at the edge, to 1.3e-5 of the peak; behind a filter 0.2 mm before focus
the orders, 20 nm apart, change the PSF by at most 1.1% of the peak; the
orders summed one at a time and in closed form match shifted Gaussians to
3e-16 and 6.5e-5 of the peak; zero shifts and an opaque mesh leave the PSF
unchanged; a NaN stays where it is; an irregular grid or a line raises
before the diffraction integral; `wavefield()` does not trace the orders.
`test_psf_mesh` checks only the orders which land on the grid, which cuts
it from 29 s to 10 s, and the symmetry of the orders is checked to a
tolerance rather than exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP
The helpers which failed if `_wavefield()` or `_mesh_diffraction()` was
called were never called when the tests pass, so their bodies were never
covered. Replace them with mocks which raise if called, and assert that
they were not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP
@roytsmart
roytsmart merged commit 7ab8db0 into main Nov 23, 2026
12 checks passed
@roytsmart
roytsmart deleted the feature/mesh-diffraction branch November 23, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant