Repository navigation
Spread the Huygens PSF into the diffraction orders of filter meshes - #299
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
force-pushed
the
feature/mesh-diffraction
branch
from
November 23, 2026 16:26
298ec5f to
e95150e
Compare
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 = √efficiencyof each period. The fractions sum toefficiency. 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:mesh=Falseleaves the meshes out. With the default, the sensor positions must be a regular grid, which is checked before the diffraction integral, and aValueErrorsays to passmesh=Falseotherwise.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
Tests
test_efficiency_order: the orders sum toefficiency, the zeroth order carriesefficiency², 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°: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 withmesh=False.test_wavefield_mesh_skipped:wavefield()andpsf(mesh=False)do not trace the orders.-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:
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