Added support for using the object surface as the field stop of a SequentialSystem#169
Added support for using the object surface as the field stop of a SequentialSystem#169jacobdparker wants to merge 1 commit into
SequentialSystem#169Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #169 +/- ##
==========================================
+ Coverage 99.34% 99.50% +0.15%
==========================================
Files 116 116
Lines 5974 6042 +68
==========================================
+ Hits 5935 6012 +77
+ Misses 39 30 -9
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:
|
9905960 to
901c539
Compare
d5a51da to
74c747b
Compare
| if material is not None and material.is_mirror: | ||
| return surface | ||
| sag = surface.sag | ||
| if sag is not None and not isinstance(sag, optika.sags.NoSag): |
There was a problem hiding this comment.
It's not enough for there to be a sag, the material must also have a different index of refraction
There was a problem hiding this comment.
You're right — thanks, this was a real bug in the helper's reasoning, not just the test.
I'd been treating the surface's own material as deciding whether it refracts, but the index step is what matters: in Surface.propagate_rays, n1 = rays.index_refraction (carried from upstream) and n2 = material.index_refraction(rays), and Snell's law only bends the ray when n2 != n1. So a curved surface has refractive power exactly when there's an index discontinuity across it — which depends on the previous surface's medium, not this one. The exit face of a glass element makes the point: it's a curved Vacuum-material surface (n2 = 1) that still refracts because the ray arrives with n1 = 1.5. So sag is not None is necessary but not sufficient.
One wrinkle: as far as I can tell no core material currently returns a transmitted index != 1 — Vacuum -> 1, and the mirrors/multilayers/filters all return rays.index_refraction (passthrough) — so n never leaves 1 for a transmitted ray and this branch never legitimately fires today. To make _anchor_surface correct in principle I'd thread the running index through the subsystem and treat a curved surface as powered iff n2 != n1 (which also needs a small refractive material to cover the branch — I'm adding a Sellmeier Glass material + a Cooke-triplet tutorial separately, which would give a real one).
Before I plumb that in: would you prefer the full n2 != n1 tracking now, or a lighter guard (drop the standalone sag heuristic and rely on mirror/rulings until there's an actual refractive material)? Happy to do either.
…uentialSystem Marking the object surface (with an angular, dimensionless aperture) as the field stop is the natural configuration for dispersive systems, where the sensor outline is not reachable at a single wavelength, but the stop root-finding problem was broken in three ways for this case: - The position-variable branch of `_calc_rayfunction_stops_only` called `sag()` with a 2-component vector, raising a TypeError before the solve even started. - The solved outputs were never broadcast over both stop axes, so the reductions in `field_min`/`field_max`/`pupil_min`/`pupil_max` raised an axis error. - The initial guess started every ray at the origin of the first stop with direction +z, which produces NaN residuals on the first iteration for surfaces far from that axis (e.g. the off-axis feed mirror of a Rowland-circle spectrograph) or on steep grazing-incidence flanks, and Newton's method cannot recover from NaN. The seed now aims each ray at its own target point on the last stop surface when no surface with optical power lies between the two stops (nearly exact), and otherwise at the center of the first powered surface. Adds a grazing-incidence spectrograph regression test whose source is the field stop, asserting that the recovered field equals the source's angular radius. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
74c747b to
9edd7b6
Compare
Second PR in the stop-solver stack — stacked on #168 (the diff shown here is relative to that branch).
Problem
Marking the object surface (with an angular, dimensionless aperture) as the field stop is the natural configuration for dispersive systems — at a single wavelength of a dispersed spectrum, most of the sensor outline is unreachable, so targeting the sensor wire is ill-posed. But this configuration was broken in three independent ways:
_calc_rayfunction_stops_onlycalledsag()with a 2-component vector →TypeErrorbefore the solve started.field_min/max/pupil_min/maxreductions.Changes
zfuncbuilds a proper 3-D vector before callingsag()._calc_rayfunction_stopsbroadcasts position and direction against each other before the stop-axis reductions._anchor_surfacehelper: the seed now aims each ray at its own target point on the last stop surface when no powered surface lies between the stops (nearly exact — the grazing solve converges in ~5 iterations), and otherwise at the center of the first powered surface.Tests
Adds
TestSequentialSystemGrazingSpectrograph: a grazing-incidence paraboloid + transmission-grating spectrograph whose source is the field stop, asserting the recovered field equals the source's angular radius (0.25°) to 1e-6 deg. Also verified against the FURSTSpectrographmodel from Kankelborg-Group/furst-optics#25, which recoversfield_max= ±0.26656° (the sunpy solar angular radius).🤖 Generated with Claude Code