2626from astropy .io import fits
2727import numpy as np
2828import pysiaf
29- import webbpsf
30- from webbpsf .gridded_library import CreatePSFLibrary
31- from webbpsf .utils import to_griddedpsfmodel
29+ import stpsf
30+ from stpsf .gridded_library import CreatePSFLibrary
31+ from stpsf .utils import to_griddedpsfmodel
3232
3333import multiprocessing
3434import functools
@@ -56,7 +56,7 @@ def _generate_psfs_for_one_segment(inst, ote, segment_tilts, out_dir, boresight,
5656
5757 i_segment = i + 1
5858
59- segname = webbpsf . webbpsf_core .segname (i_segment )
59+ segname = stpsf . stpsf_core .segname (i_segment )
6060 logger .info ('GENERATING SEGMENT {} DATA' .format (segname ))
6161
6262 det_filt_match = False
@@ -76,12 +76,12 @@ def _generate_psfs_for_one_segment(inst, ote, segment_tilts, out_dir, boresight,
7676 inst .detector = det
7777
7878 # Restrict the pupil to the current segment
79- pupil = webbpsf . webbpsf_core .one_segment_pupil (i_segment )
79+ pupil = stpsf . stpsf_core .one_segment_pupil (i_segment )
8080 ote .amplitude = pupil [0 ].data
8181 inst .pupil = ote
8282
8383 # Determine normalization factor - what fraction of total pupil is in this one segment?
84- full_pupil = fits .getdata (os .path .join (webbpsf .utils .get_webbpsf_data_path (), 'jwst_pupil_RevW_npix1024.fits.gz' ))
84+ full_pupil = fits .getdata (os .path .join (stpsf .utils .get_stpsf_data_path (), 'jwst_pupil_RevW_npix1024.fits.gz' ))
8585 pupil_fraction_for_this_segment = pupil [0 ].data .sum () / full_pupil .sum ()
8686
8787 # Generate the PSF grid
@@ -191,7 +191,12 @@ def generate_segment_psfs(ote, segment_tilts, out_dir, filters=['F212N', 'F480M'
191191 logger = logging .getLogger ('mirage.psf.segment_psfs.generate_segment_psfs' )
192192
193193 # Create webbpsf NIRCam instance
194- inst = webbpsf .Instrument (instrument )
194+ if instrument .lower () == 'nircam' :
195+ inst = stpsf .NIRCam ()
196+ elif instrument .lower () == 'fgs' :
197+ inst = stpsf .FGS ()
198+ else :
199+ raise ValueError (f'Unsupported instrument: { instrument } ' )
195200
196201 # Create dummy CreatePSFLibrary instance to get lists of filter and detectors
197202 lib = CreatePSFLibrary
@@ -415,14 +420,14 @@ def get_segment_offset(segment_number, detector, library_list):
415420 }
416421
417422 x_rot = control_xaxis_rotations [segment ] # degrees
418- x_rot_rad = x_rot * np .pi / 180 # radians
423+ x_rot_rad = np . float64 ( x_rot * np .pi / 180 ) # radians
419424
420425 # Note that y is defined as the x component and x is defined as the y component.
421426 # This is because "xtilt" moves the PSF in the y direction, and vice versa.
422- tilt_onto_y = ( xtilt * np .cos (x_rot_rad )) - (ytilt * np .sin (x_rot_rad ))
423- tilt_onto_x = ( xtilt * np .sin (x_rot_rad )) + (ytilt * np .cos (x_rot_rad ))
427+ tilt_onto_y = np . float64 (( xtilt * np .cos (x_rot_rad )) - (ytilt * np .sin (x_rot_rad ) ))
428+ tilt_onto_x = np . float64 (( xtilt * np .sin (x_rot_rad )) + (ytilt * np .cos (x_rot_rad ) ))
424429
425- umrad_to_arcsec = 1e-6 * (180. / np .pi ) * 3600
430+ umrad_to_arcsec = np . float64 ( 1e-6 * (180. / np .pi ) * 3600 )
426431 x_arcsec = 2 * umrad_to_arcsec * tilt_onto_x
427432 y_arcsec = 2 * umrad_to_arcsec * tilt_onto_y
428433
@@ -450,11 +455,11 @@ def get_segment_offset(segment_number, detector, library_list):
450455 # between different OTE pose terms into optical tip and tilt. In particular, this is needed for
451456 # accurate modeling of radial translation corrections when using incoherent PSF calculations.
452457 if f'S{ segment_number :02d} XTILT' in header :
453- hexike_to_arcsec = 206265 / webbpsf .constants .JWST_SEGMENT_RADIUS
458+ hexike_to_arcsec = 206265 / stpsf .constants .JWST_SEGMENT_RADIUS
454459 # recall that Hexike tilt _around the X axis_ produces an offset _into Y_, and vice versa.
455- x_arcsec = header [f'S{ segment_number :02d} YTILT' ] * hexike_to_arcsec
460+ x_arcsec = np . float64 ( header [f'S{ segment_number :02d} YTILT' ] * hexike_to_arcsec )
456461 # also recall coord flip of Y axis from OTE L.O.M in entrance pupil to exit pupil
457- y_arcsec = - header [f'S{ segment_number :02d} XTILT' ] * hexike_to_arcsec
462+ y_arcsec = np . float64 ( - header [f'S{ segment_number :02d} XTILT' ] * hexike_to_arcsec )
458463
459464 # Optionally, arbitrary boresight offset may also be present in the FITS header metadata.
460465 # If so, include that in the PSF too. Be careful about coordinate sign for the V2 axis!
0 commit comments