Skip to content

Set Roman pupil radius correctly, even if pupil files have zero padding#152

Merged
ojustino merged 3 commits into
spacetelescope:developfrom
mperrin:fix_151_roman_pupil_radius
Jun 18, 2026
Merged

Set Roman pupil radius correctly, even if pupil files have zero padding#152
ojustino merged 3 commits into
spacetelescope:developfrom
mperrin:fix_151_roman_pupil_radius

Conversation

@mperrin

@mperrin mperrin commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

This should fix #151 reported by @bergkoet.

Currently, we are setting both a RomanTelescope.PUPIL_RADIUS class attribute (~correctly) and a self.pupil_radius instance attribute (incorrectly), which is both not working and also more complex than is necessary. This PR simplifies to just setting a self.pupil_radius value, correctly. Conveniently the PUPIL_RADIUS one was only used in one single place in the code so this is not a complex edit.

I moved the numeric value definition to constants.py which is a better place for it anyhow.

@mperrin
mperrin requested a review from ojustino June 17, 2026 18:08
@mperrin mperrin self-assigned this Jun 17, 2026
@mperrin mperrin added bug Something isn't working Roman Affects Roman Space Telescope models in STPSF labels Jun 17, 2026
@bergkoet

Copy link
Copy Markdown

Thanks for the fast response!

This doesn't quite fix it because the .calc_psf method has the side effect of changing the pupil radius (by way of .get_optical_system). It happens here:
https://github.com/mperrin/stpsf/blob/dfad7477ffbb330177c7be792d1234063df4f6b4/stpsf/stpsf_core.py#L450

Here's a minimal example:

import stpsf

WL = 1.577e-6         # F158 central wavelength [m]
DEFOCUS_WV = 0.25     # requested defocus [waves P-V]
EXPECTED_RADIUS_M = 2.36312 / 2  # physical entrance pupil radius [m]

stpsf.setup_logging()
wfi = stpsf.roman.WFI()
wfi.filter = 'F158'
wfi.options['defocus_waves'] = DEFOCUS_WV
wfi.options['defocus_wavelength'] = WL
found_radius_before_m = wfi.pupil_radius

psf, wavefronts = wfi.calc_psf(monochromatic=WL, return_intermediates=True)

found_radius_after_m = wfi.pupil_radius.to_value('m')
rho_max = EXPECTED_RADIUS_M/found_radius_after_m

print(f"\n")
print(f"Physical entrance pupil radius:   {EXPECTED_RADIUS_M:.4f} m")
print(f"wfi.pupil_radius before calc_psf: {found_radius_before_m:.4f} m")
print(f"wfi.pupil_radius after calc_psf:  {found_radius_after_m:.4f} m")
print(f"rho_max = physical / ThinLens radius:    {rho_max:.4f}")
print(f"Expected defocus underscale (rho_max^2): {rho_max**2:.4f}")

Result:

Physical entrance pupil radius:   1.1816 m
wfi.pupil_radius before calc_psf: 1.1816 m
wfi.pupil_radius after calc_psf:  1.2763 m
rho_max = physical / ThinLens radius:    0.9258
Expected defocus underscale (rho_max^2): 0.8571

@mperrin

mperrin commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

@bergkoet OK let's try this again. Thanks for the minimal example code, and for pointing out the exact line causing the error; that was very helpful. With the latest commit just added to this branch, I have your test code passing:

rho_max = physical / ThinLens radius:    1.0000
Expected defocus underscale (rho_max^2): 1.0000

@bergkoet

Copy link
Copy Markdown

@bergkoet OK let's try this again. Thanks for the minimal example code, and for pointing out the exact line causing the error; that was very helpful. With the latest commit just added to this branch, I have your test code passing:

rho_max = physical / ThinLens radius:    1.0000
Expected defocus underscale (rho_max^2): 1.0000

That works for me, too. Many thanks!

@ojustino
ojustino merged commit 2953723 into spacetelescope:develop Jun 18, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Roman Affects Roman Space Telescope models in STPSF

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pupil radius is sometimes derived from padded array extent, not physical pupil radius (Roman WFI)

3 participants