Skip to content

Add BlazedRulings, a triangular groove whose blaze and antiblaze facets have any angles - #301

Merged
roytsmart merged 2 commits into
mainfrom
feature/blazed-rulings
Dec 1, 2026
Merged

roytsmart merged 2 commits into
mainfrom
feature/blazed-rulings

Conversation

@roytsmart

@roytsmart roytsmart commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Adds optika.rulings.BlazedRulings(spacing, angle_blaze, angle_antiblaze, diffraction_order), a triangular groove whose blaze facet and antiblaze facet can each have any angle. Ruled gratings are specified this way, by a blaze angle and an antiblaze angle, and the existing profiles only cover the two ends: SawtoothRulings (a vertical antiblaze facet) and TriangularRulings (two equal facets).

Model

  • Parameters. The angles are measured from the surface at each point, so the facets follow its curvature. The depth and the width of each facet come from the local period of the rulings along the surface, so the facets keep their angles where the spacing varies. Where the ruling planes are not perpendicular to the surface, that period is longer than the distance between the planes. With d that period:

    • the depth is H = d sin θb sin θa / sin(θb + θa);
    • the fraction of the period covered by the blaze facet is f = sin θa cos θb / sin(θb + θa).
  • Efficiency. The scalar (Kirchhoff) integral over one period has a closed form, a sinc function from each facet:

    η_i = [f sinc(γ + i f) + (−1)^i (1 − f) sinc(γ − i (1 − f))]²

    Here γ = H |n₁ cos α − n₂ cos β| / λ is the same γ as in SawtoothRulings.

  • Limits. f = 1 gives SawtoothRulings exactly, and f = 1/2 gives TriangularRulings exactly.

  • Orientation. The blaze facets face the ruling vector, so positive angles blaze the negative orders, like SawtoothRulings with a positive depth. Negative angles mirror the groove and blaze the positive orders.

  • Checks. efficiency raises a ValueError unless both angles are in (0°, 90°], or both in [−90°, 0), and not both vertical. Plain numbers are taken as radians.

The docstring example plots the first-order efficiency of a 3° blaze for antiblaze angles from 90° down to 3°. Over that range the peak falls from 1.0 to 0.30 and moves to shorter wavelengths.

Tests

  • TestBlazedRulings runs the shared AbstractTestAbstractRulings suite, with one constant-spacing case and one variable-spacing case.
  • test_blazed_rulings_sawtooth: a 90° antiblaze matches SawtoothRulings with depth d tan θb, over orders −100 to 100, four wavelengths and three angles of incidence.
  • test_blazed_rulings_triangular: equal angles match TriangularRulings with depth (d/2) tan θ.
  • test_blazed_rulings_quadrature: the closed form matches a direct midpoint-rule integral of the phase screen, for a 1°/4° profile in orders −4 to 4, to 1e-7.
  • test_blazed_rulings_spacing_local: with a Polynomial1dRulingSpacing, the efficiency at each position matches rulings with that constant spacing.
  • test_blazed_rulings_period_tangential: with ruling planes tilted 30° from the surface normal, the efficiency matches rulings whose planes are perpendicular to the surface with the same period along it.
  • test_blazed_rulings_mirrored: negative angles, with the incident light and the order mirrored too, give the same efficiency.
  • test_blazed_rulings_radians: plain numbers match the same angles in degrees.
  • test_blazed_rulings_invalid: ten sets of angles that don't describe a groove raise a ValueError.
  • BlazedRulings is added to test_efficiency_reciprocal and test_efficiency_conserved (the sum over orders is 1).

All 227 rulings tests pass locally, and black and ruff are clean.

Overlap with #302

#302 fixes two bugs in the shared _gamma: it dropped the sign that decides which orders an asymmetric profile blazes in transmission, and it sent everything to order 0 when light arrived from the back of the surface. BlazedRulings inherits both until #302 merges. Whichever of the two merges second needs a rebase to:

🤖 Generated with Claude Code

https://claude.ai/code/session_01StcJvUf6xFg2ese9XDDhaB

…cets have any angles

The efficiency is the closed form of the scalar (Kirchhoff) integral over
one period, a sinc function from each facet. A vertical antiblaze facet
gives `SawtoothRulings`, and facets of the same angle give
`TriangularRulings`. The angles are measured from the surface at each
point, and the depth of the grooves follows the local spacing of the
rulings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StcJvUf6xFg2ese9XDDhaB
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7ab8db0) to head (13e673e).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #301    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          142       142            
  Lines        13864     14007   +143     
==========================================
+ Hits         13864     14007   +143     
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.

…e surface

- Raise a `ValueError` unless both facet angles are greater than 0 and at
  most 90 degrees, or both negative, and not both vertical. Angles outside
  that range gave efficiencies far above one, and two flat facets divided
  zero by zero.
- Accept angles as plain numbers in radians, which raised an
  `AttributeError`.
- Compute the depth of the grooves from their period along the surface,
  which is longer than the distance between the ruling planes where those
  planes are not perpendicular to the surface.
- Document which way the blaze facets face (toward the ruling vector, into
  the negative orders), and that negative angles mirror the groove to blaze
  the positive orders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StcJvUf6xFg2ese9XDDhaB
@roytsmart
roytsmart merged commit 873ee18 into main Dec 1, 2026
12 checks passed
@roytsmart
roytsmart deleted the feature/blazed-rulings branch December 1, 2026 22:36
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