physicaloptix 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/CHANGELOG.md +15 -0
  2. physicaloptix-2.2.0/NOTICE +90 -0
  3. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/PKG-INFO +2 -1
  4. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/_version.py +2 -2
  5. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/instruments/__init__.py +3 -0
  6. physicaloptix-2.2.0/src/physicaloptix/instruments/_proper_beam.py +304 -0
  7. physicaloptix-2.2.0/src/physicaloptix/instruments/_proper_ops.py +194 -0
  8. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/instruments/roman.py +40 -8
  9. physicaloptix-2.2.0/src/physicaloptix/instruments/roman_full.py +363 -0
  10. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/.gitignore +0 -0
  11. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/.pre-commit-config.yaml +0 -0
  12. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/.readthedocs.yaml +0 -0
  13. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/.zenodo.json +0 -0
  14. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/CITATION.cff +0 -0
  15. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/LICENSE +0 -0
  16. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/README.md +0 -0
  17. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/pyproject.toml +0 -0
  18. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/__init__.py +0 -0
  19. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/apertures.py +0 -0
  20. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/coatings.py +0 -0
  21. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/core/__init__.py +0 -0
  22. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/core/field.py +0 -0
  23. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/core/grid.py +0 -0
  24. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/data/eac1_ci_train.yaml +0 -0
  25. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/data/eac1_primary.yaml +0 -0
  26. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/detector.py +0 -0
  27. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/diagnostics.py +0 -0
  28. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/diff.py +0 -0
  29. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/__init__.py +0 -0
  30. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/base.py +0 -0
  31. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/basis.py +0 -0
  32. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/dispersive.py +0 -0
  33. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/modes.py +0 -0
  34. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/phase_screen.py +0 -0
  35. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/vortex.py +0 -0
  36. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/elements/zernike_wfs.py +0 -0
  37. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/ifs.py +0 -0
  38. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/instruments/nircam.py +0 -0
  39. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/interop.py +0 -0
  40. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/linearize.py +0 -0
  41. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/multichannel.py +0 -0
  42. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/path.py +0 -0
  43. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/robustness.py +0 -0
  44. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/sources.py +0 -0
  45. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/speckle.py +0 -0
  46. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/stats.py +0 -0
  47. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/system.py +0 -0
  48. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/trains.py +0 -0
  49. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/transforms/__init__.py +0 -0
  50. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/transforms/cmft.py +0 -0
  51. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/transforms/fraunhofer.py +0 -0
  52. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/transforms/fresnel.py +0 -0
  53. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/__init__.py +0 -0
  54. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/_legacy.py +0 -0
  55. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/_prepare.py +0 -0
  56. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/_require.py +0 -0
  57. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/boiling.py +0 -0
  58. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/columns.py +0 -0
  59. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/fields.py +0 -0
  60. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/modes.py +0 -0
  61. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/profiles.py +0 -0
  62. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/speckle.py +0 -0
  63. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/viz/train.py +0 -0
  64. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/src/physicaloptix/yip.py +0 -0
  65. {physicaloptix-2.1.0 → physicaloptix-2.2.0}/tools/check_internal_refs.py +0 -0
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.0](https://github.com/CoreySpohn/physicaloptix/compare/v2.1.0...v2.2.0) (2026-09-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * **roman:** add flight DM wavefront terms to the compact model and document the full train ([d5eb0bc](https://github.com/CoreySpohn/physicaloptix/commit/d5eb0bcd41f8482afd7a4d1a3780153787ba4edc))
9
+ * **roman:** add PROPER-convention transforms, masks and resampling weights ([df3fb93](https://github.com/CoreySpohn/physicaloptix/commit/df3fb93800cf199d7e0d6845cfec58141fa4d52f))
10
+ * **roman:** compile and run the full Roman train on pilot-beam grids ([c3d1b44](https://github.com/CoreySpohn/physicaloptix/commit/c3d1b449d9143c9e9d07e977af3dbc699e2d9815))
11
+ * **roman:** plan PROPER-style pilot-beam propagation and run it in JAX ([4a72f9b](https://github.com/CoreySpohn/physicaloptix/commit/4a72f9b5eb1e700aeb92ed710129bcc7f4ef99ec))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * **roman:** normalize batched transforms by the grid, expose the full-train build helpers, and state the full-train agreement ([87c4bb3](https://github.com/CoreySpohn/physicaloptix/commit/87c4bb3009c0477094adca788f57de2df3829dec))
17
+
3
18
  ## [2.1.0](https://github.com/CoreySpohn/physicaloptix/compare/v2.0.0...v2.1.0) (2026-09-29)
4
19
 
5
20
 
@@ -0,0 +1,90 @@
1
+ physicaloptix
2
+ Copyright (c) 2026 Corey Spohn, released under the MIT License (see LICENSE).
3
+
4
+ Third-party notices
5
+ ===================
6
+
7
+ PROPER
8
+ ------
9
+ Parts of physicaloptix are ports of routines from the PROPER optical propagation
10
+ library (John Krist, Jet Propulsion Laboratory; Python translation by Navtej Saini,
11
+ with Luis Marchen and Nikta Amiri):
12
+
13
+ - physicaloptix/instruments/_proper_ops.py: ellipse_mask (from prop_ellipse),
14
+ cubic_conv_weights and resample_map (the prop_cubic_conv edge rule),
15
+ szoom_weights (from prop_szoom_c).
16
+ - physicaloptix/instruments/_proper_beam.py: the pilot-beam schedule and its
17
+ operations (from prop_propagate, prop_lens, prop_ptp, prop_stw and prop_wts).
18
+
19
+ PROPER carries the following notice, reproduced as its terms require:
20
+
21
+
22
+ © 2006-2019. California Institute of Technology ("Caltech"). This
23
+ software, including source and object code, and any accompanying documentation
24
+ ("Software") is owned by Caltech. Caltech has designated this Software as
25
+ Technology and Software Publicly Available ("TSPA"), which means that this
26
+ Software is publicly available under U.S. Export Laws. With the TSPA
27
+ designation, a user may use and distribute the Software on a royalty-free basis
28
+ with the understanding that:
29
+
30
+ (1) THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE CALIFORNIA
31
+ INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. GOVERNMENT CONTRACT WITH THE
32
+ NATIONAL AERONAUTICS AND SPACE ADMINISTRATION (NASA). THE SOFTWARE IS
33
+ TECHNOLOGY AND SOFTWARE PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS
34
+ PROVIDED "AS-IS" TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
35
+ WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR
36
+ PURPOSE (AS SET FORTH IN UNITED STATES UCC §2312-§2313) OR FOR ANY PURPOSE
37
+ WHATSOEVER, FOR THE SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
38
+
39
+ IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA BE LIABLE FOR
40
+ ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT LIMITED TO, INCIDENTAL OR
41
+ CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR INJURY TO
42
+ PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE
43
+ ADVISED, HAVE REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
44
+
45
+ RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE
46
+ AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY CALTECH AND NASA FOR ALL
47
+ THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS OF RECIPIENT IN THE USE OF THE
48
+ SOFTWARE; and
49
+
50
+ (2) Caltech is under no obligation to provide technical support for the
51
+ Software; and
52
+
53
+ (3) all copies of the Software released by user must be marked with this
54
+ marking language, inclusive of the copyright statement, TSPA designation and
55
+ user understandings.
56
+
57
+ (4) License for the Python wrapper for Intel MKL FFT routines (https://github.com/LCAV/mkl_fft)
58
+
59
+ Copyright (c) 2016 Ivan Dokmanić, Robin Scheibler
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
62
+ this software and associated documentation files (the "Software"), to deal in
63
+ the Software without restriction, including without limitation the rights to
64
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
65
+ of the Software, and to permit persons to whom the Software is furnished to do
66
+ so, subject to the following conditions:
67
+
68
+ The above copyright notice and this permission notice shall be included in all
69
+ copies or substantial portions of the Software.
70
+
71
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
72
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
73
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
74
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
76
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
77
+ SOFTWARE.
78
+
79
+
80
+
81
+ Roman Preflight PROPER prescription
82
+ -----------------------------------
83
+ The Roman Coronagraph models in physicaloptix/instruments/roman.py and
84
+ roman_full.py, and the prescription helpers in _proper_ops.py (ffts, mft2,
85
+ noll_z6), follow the public version of the Roman Preflight PROPER prescription
86
+ (roman_preflight_proper, John Krist; Copyright 2019-2026 California Institute of
87
+ Technology). That prescription is distributed publicly by the Roman Coronagraph
88
+ team. No prescription source files or data files are included in physicaloptix;
89
+ the models take the prescription's masks, maps and DM data as inputs supplied by
90
+ the user.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: physicaloptix
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Physical optics (PSFs and diffraction) for the HWO direct imaging simulation suite
5
5
  Project-URL: Homepage, https://github.com/CoreySpohn/physicaloptix
6
6
  Project-URL: Issues, https://github.com/CoreySpohn/physicaloptix/issues
@@ -27,6 +27,7 @@ License: MIT License
27
27
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
28
  SOFTWARE.
29
29
  License-File: LICENSE
30
+ License-File: NOTICE
30
31
  Classifier: Development Status :: 2 - Pre-Alpha
31
32
  Classifier: Intended Audience :: Science/Research
32
33
  Classifier: License :: OSI Approved :: MIT License
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.1.0'
22
- __version_tuple__ = version_tuple = (2, 1, 0)
21
+ __version__ = version = '2.2.0'
22
+ __version_tuple__ = version_tuple = (2, 2, 0)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -11,6 +11,7 @@ from physicaloptix.instruments.nircam import (
11
11
  nircam_band_image,
12
12
  )
13
13
  from physicaloptix.instruments.roman import RomanCompact
14
+ from physicaloptix.instruments.roman_full import RomanFull, compile_train
14
15
 
15
16
  __all__ = [
16
17
  "BandLimitedRoundMask",
@@ -18,7 +19,9 @@ __all__ = [
18
19
  "NIRCamConfig",
19
20
  "NIRCamInputs",
20
21
  "RomanCompact",
22
+ "RomanFull",
21
23
  "build_nircam",
24
+ "compile_train",
22
25
  "integrate_detector_pixels",
23
26
  "mask_plane_field",
24
27
  "nircam_band_image",
@@ -0,0 +1,304 @@
1
+ """Pilot-beam propagation in the convention of the PROPER library (internal module).
2
+
3
+ PROPER (Krist 2007) carries a Gaussian pilot beam beside the field. A propagation
4
+ whose ends both lie within a Rayleigh distance of the pilot waist uses the
5
+ paraxial Fresnel transfer function on a fixed grid. Any other is split at the
6
+ waist: a leg inside the Rayleigh distance uses the transfer function, and a leg
7
+ outside it is carried relative to a spherical reference surface and moved to or
8
+ from the waist by a single-FFT Fresnel transform, which sets the sample spacing to
9
+ ``lambda |dz| / (n dx)`` with ``dz`` the leg length. A lens
10
+ updates the pilot waist and applies only the part of its phase that the change of
11
+ reference surface does not absorb.
12
+
13
+ The beam state never reads the field, so :func:`plan_propagate` and
14
+ :func:`plan_lens` resolve the schedule in NumPy when a model is built and
15
+ :func:`run_ops` executes the fixed operation list in JAX. Arrays are held in
16
+ PROPER's layout, with the grid center ``n // 2`` rolled to the ``[0, 0]`` corner.
17
+ Expressions follow PROPER's operation order so the schedule reproduces its beam
18
+ state to rounding.
19
+
20
+ The schedule is ported from PROPER's prop_propagate, prop_lens, prop_ptp,
21
+ prop_stw and prop_wts (Copyright California Institute of Technology, designated
22
+ Technology and Software Publicly Available); see the NOTICE file for its terms.
23
+ """
24
+
25
+ import dataclasses
26
+ from typing import NamedTuple
27
+
28
+ import jax.numpy as jnp
29
+ import numpy as np
30
+
31
+ RAYLEIGH_FACTOR = 1.0
32
+
33
+
34
+ @dataclasses.dataclass(frozen=True)
35
+ class PilotBeam:
36
+ """Gaussian pilot-beam state; lengths in meters, ``n`` samples across the grid.
37
+
38
+ Attributes:
39
+ lam_m: Wavelength.
40
+ n: Grid size (even).
41
+ dx: Sample spacing of the field at ``z``.
42
+ z: Position along the beam.
43
+ z_w0: Position of the pilot waist.
44
+ w0: Pilot waist radius.
45
+ z_rayleigh: Rayleigh distance of the pilot beam.
46
+ reference: Reference surface the field is stored against, ``"PLANAR"``
47
+ or ``"SPHERI"`` (spherical, centered on the waist).
48
+ beam_type_old: Whether ``z`` was last classified ``"INSIDE_"`` or
49
+ ``"OUTSIDE"`` the Rayleigh range.
50
+ """
51
+
52
+ lam_m: float
53
+ n: int
54
+ dx: float
55
+ z: float
56
+ z_w0: float
57
+ w0: float
58
+ z_rayleigh: float
59
+ reference: str
60
+ beam_type_old: str
61
+
62
+ def __post_init__(self):
63
+ """Hold plain Python floats (static data under jit, never NumPy scalars)."""
64
+ for name in ("lam_m", "dx", "z", "z_w0", "w0", "z_rayleigh"):
65
+ object.__setattr__(self, name, float(getattr(self, name)))
66
+
67
+ @classmethod
68
+ def begin(cls, beam_diameter_m, lam_m, n, beam_diam_fraction):
69
+ """Entrance state: a collimated beam of ``beam_diameter_m`` at its waist.
70
+
71
+ Args:
72
+ beam_diameter_m: Entrance beam diameter.
73
+ lam_m: Wavelength.
74
+ n: Grid size; must be even.
75
+ beam_diam_fraction: Fraction of the grid the beam diameter spans.
76
+
77
+ Raises:
78
+ ValueError: If ``n`` is not an even integer.
79
+ """
80
+ if int(n) != n or int(n) % 2:
81
+ raise ValueError(f"grid size n={n} must be an even integer")
82
+ n = int(n)
83
+ diam = float(beam_diameter_m)
84
+ lam = float(lam_m)
85
+ w0 = diam / 2.0
86
+ return cls(
87
+ lam_m=lam,
88
+ n=n,
89
+ dx=diam / (n * beam_diam_fraction),
90
+ z=0.0,
91
+ z_w0=0.0,
92
+ w0=w0,
93
+ z_rayleigh=np.pi * w0**2 / lam,
94
+ reference="PLANAR",
95
+ beam_type_old="INSIDE_",
96
+ )
97
+
98
+ @property
99
+ def radius(self):
100
+ """Pilot-beam radius at ``z``."""
101
+ return self.w0 * np.sqrt(
102
+ 1.0 + (self.lam_m * (self.z - self.z_w0) / (np.pi * self.w0**2)) ** 2
103
+ )
104
+
105
+
106
+ class Op(NamedTuple):
107
+ """One scheduled array operation.
108
+
109
+ ``kind`` is ``"ptp"``, ``"stw"``, ``"wts"`` or ``"lens"``; ``value`` is the
110
+ distance in meters (for a lens, the applied curvature in 1/m); ``dx`` is the
111
+ sample spacing the operation's phase uses; ``forward`` selects the FFT
112
+ direction of ``stw`` and ``wts``.
113
+ """
114
+
115
+ kind: str
116
+ value: float
117
+ dx: float
118
+ forward: bool
119
+
120
+
121
+ def _op(kind, value, dx, forward):
122
+ return Op(kind, float(value), float(dx), bool(forward))
123
+
124
+
125
+ def _ptp(beam, dz):
126
+ if np.abs(dz) < 1e-12:
127
+ return beam, ()
128
+ if beam.reference != "PLANAR":
129
+ raise ValueError("ptp: input reference surface is not planar")
130
+ return dataclasses.replace(beam, z=beam.z + dz), (_op("ptp", dz, beam.dx, True),)
131
+
132
+
133
+ def _stw(beam, dz=0.0):
134
+ if beam.reference != "SPHERI":
135
+ return _ptp(beam, dz)
136
+ if dz == 0.0:
137
+ dz = beam.z_w0 - beam.z
138
+ dx = beam.lam_m * np.abs(dz) / (beam.n * beam.dx)
139
+ beam = dataclasses.replace(beam, z=beam.z + dz, dx=dx, reference="PLANAR")
140
+ return beam, (_op("stw", dz, dx, dz >= 0.0),)
141
+
142
+
143
+ def _wts(beam, dz):
144
+ beam = dataclasses.replace(beam, reference="SPHERI")
145
+ if dz == 0.0:
146
+ return beam, ()
147
+ op = _op("wts", dz, beam.dx, dz >= 0.0)
148
+ dx = beam.lam_m * np.abs(dz) / (beam.n * beam.dx)
149
+ return dataclasses.replace(beam, z=beam.z + dz, dx=dx), (op,)
150
+
151
+
152
+ def plan_propagate(beam, dz, *, to_plane=False):
153
+ """Schedule a propagation by ``dz`` meters (PROPER's prop_propagate).
154
+
155
+ Args:
156
+ beam: Pilot beam before the propagation.
157
+ dz: Signed distance.
158
+ to_plane: End on a planar reference regardless of the beam (PROPER's
159
+ ``TO_PLANE``); the recorded beam type keeps its selected value.
160
+
161
+ Returns:
162
+ The new beam, the scheduled operations, and the propagator type
163
+ (``"INSIDE__to_OUTSIDE"`` and so on).
164
+ """
165
+ newz = beam.z + dz
166
+ if np.abs(beam.z_w0 - newz) < RAYLEIGH_FACTOR * beam.z_rayleigh:
167
+ new = "INSIDE_"
168
+ else:
169
+ new = "OUTSIDE"
170
+ ptype = beam.beam_type_old + "_to_" + new
171
+ beam = dataclasses.replace(beam, beam_type_old=new)
172
+ z1 = beam.z
173
+ z2 = z1 + dz
174
+ if to_plane:
175
+ ptype = ptype[:11] + "INSIDE_"
176
+ if ptype == "INSIDE__to_INSIDE_":
177
+ plan = ((_ptp, dz),)
178
+ elif ptype == "INSIDE__to_OUTSIDE":
179
+ plan = ((_ptp, beam.z_w0 - z1), (_wts, z2 - beam.z_w0))
180
+ elif ptype == "OUTSIDE_to_INSIDE_":
181
+ plan = ((_stw, beam.z_w0 - z1), (_ptp, z2 - beam.z_w0))
182
+ else:
183
+ plan = ((_stw, beam.z_w0 - z1), (_wts, z2 - beam.z_w0))
184
+ ops = ()
185
+ for step, d in plan:
186
+ beam, new_ops = step(beam, d)
187
+ ops = ops + new_ops
188
+ return beam, ops, ptype
189
+
190
+
191
+ def plan_lens(beam, lens_fl):
192
+ """Schedule a thin lens of focal length ``lens_fl`` meters (PROPER's prop_lens).
193
+
194
+ Positive focal lengths converge. Returns the new beam and the lens operation.
195
+ """
196
+ lam = beam.lam_m
197
+ z_rayleigh = np.pi * beam.w0**2 / lam
198
+ w_at_surface = beam.w0 * np.sqrt(1.0 + ((beam.z - beam.z_w0) / z_rayleigh) ** 2)
199
+ g_inf = False
200
+ g_new = 0.0
201
+ if (beam.z - beam.z_w0) != 0.0:
202
+ g_old = (beam.z - beam.z_w0) + z_rayleigh**2 / (beam.z - beam.z_w0)
203
+ if g_old != lens_fl:
204
+ g_new = 1.0 / (1.0 / g_old - 1.0 / lens_fl)
205
+ else:
206
+ g_inf = True
207
+ else:
208
+ g_new = -lens_fl
209
+ if beam.beam_type_old == "INSIDE_" or beam.reference == "PLANAR":
210
+ r_old = 0.0
211
+ else:
212
+ r_old = beam.z - beam.z_w0
213
+ if not g_inf:
214
+ z_w0 = -g_new / (1.0 + (lam * g_new / (np.pi * w_at_surface**2)) ** 2) + beam.z
215
+ w0 = w_at_surface / np.sqrt(
216
+ 1.0 + (np.pi * w_at_surface**2 / (lam * g_new)) ** 2
217
+ )
218
+ else:
219
+ z_w0, w0 = beam.z, w_at_surface
220
+ z_rayleigh = np.pi * w0**2 / lam
221
+ if np.abs(z_w0 - beam.z) < RAYLEIGH_FACTOR * z_rayleigh:
222
+ new, r_new = "INSIDE_", 0.0
223
+ else:
224
+ new, r_new = "OUTSIDE", beam.z - z_w0
225
+ ptype = beam.beam_type_old + "_to_" + new
226
+ if ptype == "INSIDE__to_INSIDE_":
227
+ phase = 1.0 / lens_fl
228
+ elif ptype == "INSIDE__to_OUTSIDE":
229
+ phase = 1.0 / lens_fl + 1.0 / r_new
230
+ elif ptype == "OUTSIDE_to_INSIDE_":
231
+ phase = 1.0 / lens_fl - 1.0 / r_old
232
+ elif r_old == 0.0:
233
+ phase = 1.0 / lens_fl + 1.0 / r_new
234
+ elif r_new == 0.0:
235
+ phase = 1.0 / lens_fl - 1.0 / r_old
236
+ else:
237
+ phase = 1.0 / lens_fl - 1.0 / r_old + 1.0 / r_new
238
+ beam = dataclasses.replace(
239
+ beam,
240
+ z_w0=z_w0,
241
+ w0=w0,
242
+ z_rayleigh=z_rayleigh,
243
+ reference="PLANAR" if new == "INSIDE_" else "SPHERI",
244
+ beam_type_old=new,
245
+ )
246
+ return beam, _op("lens", phase, beam.dx, True)
247
+
248
+
249
+ def _to_corner(a):
250
+ n = a.shape[-1]
251
+ return jnp.roll(a, (n // 2, n // 2), axis=(-2, -1))
252
+
253
+
254
+ def _fft_forward(a, n):
255
+ size = a.shape[-2] * a.shape[-1]
256
+ return jnp.fft.fft2(a) / size * n
257
+
258
+
259
+ def _fft_backward(a, n):
260
+ size = a.shape[-2] * a.shape[-1]
261
+ return jnp.fft.ifft2(a) * size / n
262
+
263
+
264
+ def _ptp_array(a, lam, dz, dx, n):
265
+ x = ((jnp.arange(n, dtype=float) - n // 2) / (n * dx)) ** 2
266
+ rhosqr = _to_corner(x[None, :] + x[:, None])
267
+ a = _fft_forward(a, n)
268
+ a = a * jnp.exp((-1j * jnp.pi * lam * dz) * rhosqr)
269
+ return _fft_backward(a, n)
270
+
271
+
272
+ def _qphase_array(a, lam, c, dx, n):
273
+ xsqr = ((jnp.arange(n, dtype=float) - n / 2.0) * dx) ** 2
274
+ rsqr = _to_corner(xsqr[None, :] + xsqr[:, None])
275
+ return a * jnp.exp(1j * jnp.pi / (lam * c) * rsqr)
276
+
277
+
278
+ def _lens_array(a, lam, lens_phase, dx, n):
279
+ x2 = (jnp.arange(n, dtype=float) - n // 2) ** 2
280
+ rho = jnp.sqrt(x2[None, :] + x2[:, None]) * dx
281
+ phase = -(rho**2) * (lens_phase / 2.0)
282
+ return a * jnp.exp(2 * jnp.pi * 1j / lam * _to_corner(phase))
283
+
284
+
285
+ def apply_op(a, op, lam_m):
286
+ """Execute one scheduled operation on a corner-layout field."""
287
+ n = a.shape[-1]
288
+ if op.kind == "ptp":
289
+ return _ptp_array(a, lam_m, op.value, op.dx, n)
290
+ if op.kind == "lens":
291
+ return _lens_array(a, lam_m, op.value, op.dx, n)
292
+ fft = _fft_forward if op.forward else _fft_backward
293
+ if op.kind == "stw":
294
+ return _qphase_array(fft(a, n), lam_m, op.value, op.dx, n)
295
+ if op.kind == "wts":
296
+ return fft(_qphase_array(a, lam_m, op.value, op.dx, n), n)
297
+ raise ValueError(f"unknown operation {op.kind!r}")
298
+
299
+
300
+ def run_ops(a, ops, lam_m):
301
+ """Execute a fixed operation list; ``ops`` and ``lam_m`` are static under jit."""
302
+ for op in ops:
303
+ a = apply_op(a, op, lam_m)
304
+ return a
@@ -0,0 +1,194 @@
1
+ """Array helpers in PROPER and Roman-prescription conventions (internal module).
2
+
3
+ These reproduce reference conventions that the general transforms in hwoutils do
4
+ not share on purpose: PROPER's cubic-convolution edge rule (the integer tap is
5
+ clamped to ``[2, n - 2]`` while the fractional offset is kept, and taps beyond
6
+ the array are dropped), its damped-sinc zoom, its antialiased circle, and the
7
+ prescription's centered FFT and matrix Fourier transform. Samples are
8
+ integer-centered at ``n // 2``. The weight builders and the mask run in NumPy at
9
+ build time; the transforms are JAX.
10
+
11
+ ellipse_mask, cubic_conv_weights, resample_map and szoom_weights are ported from
12
+ PROPER (prop_ellipse, prop_cubic_conv, prop_szoom_c; Copyright California
13
+ Institute of Technology, designated Technology and Software Publicly Available);
14
+ ffts, mft2 and noll_z6 follow the Roman Preflight PROPER prescription. See the
15
+ NOTICE file for the terms.
16
+ """
17
+
18
+ import jax.numpy as jnp
19
+ import numpy as np
20
+
21
+
22
+ def shift_center(a):
23
+ """Roll the center sample ``n // 2`` to the corner (self-inverse for even sizes)."""
24
+ s = a.shape
25
+ return jnp.roll(a, (s[-2] // 2, s[-1] // 2), axis=(-2, -1))
26
+
27
+
28
+ def ffts(a, direction):
29
+ """Centered FFT (``direction=-1``, divided by the size) or its inverse (``+1``).
30
+
31
+ The inverse is multiplied by the size, so the pair round-trips.
32
+ """
33
+ n = a.shape[-1]
34
+ a = jnp.roll(a, (-n // 2, -n // 2), axis=(-2, -1))
35
+ size = a.shape[-2] * a.shape[-1]
36
+ a = jnp.fft.fft2(a) / size if direction == -1 else jnp.fft.ifft2(a) * size
37
+ return jnp.roll(a, (n // 2, n // 2), axis=(-2, -1))
38
+
39
+
40
+ def mft2(field, dout, d, nout, direction):
41
+ """Matrix Fourier transform of a square field to ``nout`` samples.
42
+
43
+ Args:
44
+ field: Square input, integer-centered.
45
+ dout: Output sample spacing in units of 1 / ``d`` (lambda / D for a pupil
46
+ of ``d`` samples).
47
+ d: Pupil diameter in input samples.
48
+ nout: Output size.
49
+ direction: -1 (forward) or +1 (inverse).
50
+ """
51
+ nin = field.shape[-1]
52
+ x = jnp.arange(nin) - nin // 2
53
+ u = (jnp.arange(nout) - nout // 2) * (dout / d)
54
+ xu = jnp.outer(x, u)
55
+ expxu = dout / d * jnp.exp(direction * 2.0 * jnp.pi * 1j * xu)
56
+ expyv = jnp.exp(direction * 2.0 * jnp.pi * 1j * xu).T
57
+ return (expyv @ field) @ expxu
58
+
59
+
60
+ def ellipse_mask(n, dx, radius_m, xc_m=0.0, yc_m=0.0, nsub=11):
61
+ """Antialiased circular aperture (PROPER's prop_ellipse for a circle), NumPy.
62
+
63
+ Args:
64
+ n: Grid size.
65
+ dx: Sample spacing in meters.
66
+ radius_m: Aperture radius.
67
+ xc_m: Offset of the aperture center from sample ``n // 2`` along x.
68
+ yc_m: Offset of the aperture center from sample ``n // 2`` along y.
69
+ nsub: Subsamples per axis for edge pixels.
70
+
71
+ Returns:
72
+ Transmission ``(n, n)``, centered like the field.
73
+ """
74
+ xcenter = n // 2 + xc_m / dx
75
+ ycenter = n // 2 + yc_m / dx
76
+ rad = radius_m / dx
77
+ minx = int(np.clip(np.round(xcenter - rad) - 1, 0, n - 1))
78
+ maxx = int(np.clip(np.round(xcenter + rad) + 1, 0, n - 1))
79
+ miny = int(np.clip(np.round(ycenter - rad) - 1, 0, n - 1))
80
+ maxy = int(np.clip(np.round(ycenter + rad) + 1, 0, n - 1))
81
+ ny, nx = maxy - miny + 1, maxx - minx + 1
82
+ y_array, x_array = np.mgrid[0:ny, 0:nx]
83
+ x = x_array + (minx - xcenter)
84
+ y = y_array + (miny - ycenter)
85
+ r = np.sqrt((x / rad) ** 2 + (y / rad) ** 2)
86
+ dr = 1.0 / rad
87
+ mask = np.full((ny, nx), -1, dtype=np.float64)
88
+ mask *= 1 - (r > 1 + dr)
89
+ inside = r <= 1 - dr
90
+ mask = mask * (1 - inside) + inside
91
+ y_edge, x_edge = np.where(mask == -1)
92
+ sy, sx = np.mgrid[0:nsub, 0:nsub]
93
+ sub_x = (sx - nsub // 2) / float(nsub) + (minx - xcenter)
94
+ sub_y = (sy - nsub // 2) / float(nsub) + (miny - ycenter)
95
+ for j, i in zip(y_edge, x_edge, strict=True):
96
+ xs = (sub_x + i) / rad
97
+ ys = (sub_y + j) / rad
98
+ mask[j, i] = np.sum(xs * xs + ys * ys <= 1 + 1e-10) / float(nsub * nsub)
99
+ image = np.zeros((n, n), dtype=np.float64)
100
+ image[miny : miny + ny, minx : minx + nx] = mask
101
+ return image
102
+
103
+
104
+ def _roundval(x):
105
+ return np.floor(x + 0.5) if x > 0.0 else -np.floor(-x + 0.5)
106
+
107
+
108
+ def cubic_conv_weights(coords, n_in, a=-0.5):
109
+ """1-D cubic-convolution weights ``(len(coords), n_in)`` with PROPER's C edge rule.
110
+
111
+ Output sample ``k`` is ``weights[k] @ samples``; the 2-D kernel is the
112
+ product of two such rows.
113
+ """
114
+ w = np.zeros((len(coords), n_in))
115
+ for k, x in enumerate(np.asarray(coords, dtype=np.float64)):
116
+ xr = _roundval(x)
117
+ xp = int(min(max(xr, 2), n_in - 2))
118
+ xc = xr - x
119
+ for j in range(-2, 3):
120
+ d = abs(xc + j)
121
+ if d <= 1:
122
+ k0, k1 = d * d * (2 * d - 3) + 1, d * d * (d - 1)
123
+ elif d <= 2:
124
+ k0, k1 = 0.0, d * (d * d - 5 * d + 8) - 4
125
+ else:
126
+ k0 = k1 = 0.0
127
+ off = xp + j
128
+ if 0 <= off < n_in:
129
+ w[k, off] += k0 + a * k1
130
+ return w
131
+
132
+
133
+ def resample_map(
134
+ dmap, pixscale_m, dx_m, n, xc=None, yc=None, xshift_m=0.0, yshift_m=0.0
135
+ ):
136
+ """A surface map resampled onto an ``n``-sample grid (PROPER's prop_readmap).
137
+
138
+ Args:
139
+ dmap: Map with row index y, sampled at ``pixscale_m``.
140
+ pixscale_m: Map sample spacing.
141
+ dx_m: Wavefront sample spacing.
142
+ n: Wavefront grid size.
143
+ xc: Map column on the optical axis (default ``shape[0] // 2``).
144
+ yc: Map row on the optical axis (default ``shape[1] // 2``).
145
+ xshift_m: Shift of the map on the wavefront along x.
146
+ yshift_m: Shift of the map on the wavefront along y.
147
+
148
+ Returns:
149
+ The resampled map ``(n, n)``, centered like the field.
150
+ """
151
+ dmap = np.asarray(dmap, dtype=np.float64)
152
+ xc = dmap.shape[0] // 2 if xc is None else xc
153
+ yc = dmap.shape[1] // 2 if yc is None else yc
154
+ grid = np.arange(n, dtype=np.float64) - int(n / 2)
155
+ x = grid * dx_m / pixscale_m + (xc - xshift_m / pixscale_m)
156
+ y = grid * dx_m / pixscale_m + (yc - yshift_m / pixscale_m)
157
+ wy = cubic_conv_weights(y, dmap.shape[0])
158
+ wx = cubic_conv_weights(x, dmap.shape[1])
159
+ return wy @ dmap @ wx.T
160
+
161
+
162
+ def szoom_weights(n_in, n_out, mag, k=13, dk=6):
163
+ """1-D damped-sinc zoom weights ``(n_out, n_in)`` (PROPER's prop_szoom_c).
164
+
165
+ The zoomed image is ``w @ image @ w.T``.
166
+
167
+ Raises:
168
+ ValueError: If an output sample's kernel window leaves the input grid.
169
+ """
170
+ w = np.zeros((n_out, n_in))
171
+ for i in range(n_out):
172
+ x_in = (i - n_out // 2) / mag
173
+ x_phase = x_in - _roundval(x_in)
174
+ x_pix = int(_roundval(x_in)) + n_in // 2
175
+ x1, x2 = x_pix - k // 2, x_pix + k // 2
176
+ if x1 < 0 or x2 >= n_in:
177
+ raise ValueError(f"zoom window [{x1}, {x2}] leaves the {n_in}-sample input")
178
+ for ik in range(k):
179
+ x = (ik - k // 2) - x_phase
180
+ if abs(x) <= dk:
181
+ if x != 0.0:
182
+ x = x * 3.141592653589793
183
+ w[i, x1 + ik] = np.sin(x) / x * np.sin(x / dk) / (x / dk)
184
+ else:
185
+ w[i, x1 + ik] = 1.0
186
+ return w
187
+
188
+
189
+ def noll_z6(n, dx_m, beam_radius_m):
190
+ """Noll Z6 (0-degree astigmatism, unit RMS over ``beam_radius_m``), centered."""
191
+ x = (jnp.arange(n, dtype=float) - n // 2) * dx_m / beam_radius_m
192
+ r2 = x[None, :] ** 2 + x[:, None] ** 2
193
+ t = jnp.arctan2(x[:, None], x[None, :])
194
+ return jnp.sqrt(6.0) * r2 * jnp.cos(2 * t)