55from jwst .extract_1d import psf_profile as pp
66
77
8- @pytest .mark .parametrize ("exp_type " , ["MIR_LRS-FIXEDSLIT" , "NRS_FIXEDSLIT " , "UNKNOWN" ])
9- def test_open_psf (psf_reference_file , exp_type ):
10- # for any exptype, a model that can be read
11- # as SpecPsfModel will be, since it's the only
12- # one implemented so far
13- with pp . open_psf ( psf_reference_file , exp_type = exp_type ) as model :
14- assert isinstance ( model , SpecPsfModel )
8+ @pytest .mark .parametrize ("slit_name " , [None , "ANY " , "UNKNOWN" ])
9+ def test_open_psf (psf_reference_file , slit_name ):
10+ # for any slit name passed in, the first aperture will be matched,
11+ # since there's only one available and it has no specific slit name
12+ aperture = pp . open_psf ( psf_reference_file , slit_name )
13+ assert aperture . data . size != 0
14+ assert aperture . wave . size != 0
1515
1616
1717def test_open_psf_fail ():
1818 with pytest .raises (NotImplementedError , match = "could not be read" ):
1919 pp .open_psf ("bad_file" , "UNKNOWN" )
2020
2121
22+ def test_open_psf_no_aperture_found (psf_reference_file ):
23+ # If no PSF aperture matches the slit, an error is raised
24+ with SpecPsfModel (psf_reference_file ) as psf_model :
25+ psf_model .apertures [0 ].name = "GOOD_SLIT"
26+ with pytest .raises (ValueError , match = "No matching aperture" ):
27+ pp .open_psf (psf_model , "BAD_SLIT" )
28+
29+
2230@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
2331def test_normalize_profile (nod_profile , dispaxis ):
2432 profile = 2 * nod_profile
@@ -42,11 +50,12 @@ def test_normalize_profile_with_nans(nod_profile, dispaxis):
4250
4351@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
4452def test_make_cutout_profile_default (psf_reference , dispaxis ):
45- data_shape = psf_reference .data .shape
53+ psf_aper = psf_reference .apertures [0 ]
54+ data_shape = psf_aper .data .shape
4655 yidx , xidx = np .mgrid [: data_shape [0 ], : data_shape [1 ]]
4756
48- psf_subpix = psf_reference . meta . psf .subpix
49- profiles = pp ._make_cutout_profile (xidx , yidx , psf_subpix , psf_reference .data , dispaxis )
57+ psf_subpix = psf_aper .subpix
58+ profiles = pp ._make_cutout_profile (xidx , yidx , psf_subpix , psf_aper .data , dispaxis )
5059 assert len (profiles ) == 1
5160 assert profiles [0 ].shape == data_shape
5261
@@ -60,12 +69,13 @@ def test_make_cutout_profile_default(psf_reference, dispaxis):
6069@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
6170@pytest .mark .parametrize ("extra_shift" , [1 , 2 ])
6271def test_make_cutout_profile_shift_down (psf_reference , dispaxis , extra_shift ):
63- data_shape = psf_reference .data .shape
72+ psf_aper = psf_reference .apertures [0 ]
73+ data_shape = psf_aper .data .shape
6474 yidx , xidx = np .mgrid [: data_shape [0 ], : data_shape [1 ]]
65- psf_subpix = psf_reference . meta . psf .subpix
75+ psf_subpix = psf_aper .subpix
6676
6777 profiles = pp ._make_cutout_profile (
68- xidx , yidx , psf_subpix , psf_reference .data , dispaxis , extra_shift = extra_shift
78+ xidx , yidx , psf_subpix , psf_aper .data , dispaxis , extra_shift = extra_shift
6979 )
7080 assert len (profiles ) == 1
7181 assert profiles [0 ].shape == data_shape
@@ -84,12 +94,13 @@ def test_make_cutout_profile_shift_down(psf_reference, dispaxis, extra_shift):
8494@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
8595@pytest .mark .parametrize ("extra_shift" , [- 1 , - 2 ])
8696def test_make_cutout_profile_shift_up (psf_reference , dispaxis , extra_shift ):
87- data_shape = psf_reference .data .shape
97+ psf_aper = psf_reference .apertures [0 ]
98+ data_shape = psf_aper .data .shape
8899 yidx , xidx = np .mgrid [: data_shape [0 ], : data_shape [1 ]]
89- psf_subpix = psf_reference . meta . psf .subpix
100+ psf_subpix = psf_aper .subpix
90101
91102 profiles = pp ._make_cutout_profile (
92- xidx , yidx , psf_subpix , psf_reference .data , dispaxis , extra_shift = extra_shift
103+ xidx , yidx , psf_subpix , psf_aper .data , dispaxis , extra_shift = extra_shift
93104 )
94105 assert len (profiles ) == 1
95106 assert profiles [0 ].shape == data_shape
@@ -107,13 +118,14 @@ def test_make_cutout_profile_shift_up(psf_reference, dispaxis, extra_shift):
107118
108119@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
109120def test_make_cutout_profile_with_nod (psf_reference , dispaxis ):
110- data_shape = psf_reference .data .shape
121+ psf_aper = psf_reference .apertures [0 ]
122+ data_shape = psf_aper .data .shape
111123 yidx , xidx = np .mgrid [: data_shape [0 ], : data_shape [1 ]]
112- psf_subpix = psf_reference . meta . psf .subpix
124+ psf_subpix = psf_aper .subpix
113125
114126 offset = 2
115127 profiles = pp ._make_cutout_profile (
116- xidx , yidx , psf_subpix , psf_reference .data , dispaxis , nod_offset = offset
128+ xidx , yidx , psf_subpix , psf_aper .data , dispaxis , nod_offset = offset
117129 )
118130 assert len (profiles ) == 2
119131 source , nod = profiles
@@ -138,9 +150,10 @@ def test_make_cutout_profile_with_nod(psf_reference, dispaxis):
138150
139151@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
140152def test_profile_residual (psf_reference , dispaxis ):
153+ psf_aper = psf_reference .apertures [0 ]
141154 data_shape = (50 , 50 )
142155 yidx , xidx = np .mgrid [: data_shape [0 ], : data_shape [1 ]]
143- psf_subpix = psf_reference . meta . psf .subpix
156+ psf_subpix = psf_aper .subpix
144157
145158 # Set data to all ones, so residual should be zero
146159 # when background is not fit
@@ -149,16 +162,17 @@ def test_profile_residual(psf_reference, dispaxis):
149162
150163 param = [0 , None ]
151164 residual = pp ._profile_residual (
152- param , data , var , xidx , yidx , psf_subpix , psf_reference .data , dispaxis , fit_bkg = False
165+ param , data , var , xidx , yidx , psf_subpix , psf_aper .data , dispaxis , fit_bkg = False
153166 )
154167 assert np .isclose (residual , 0.0 )
155168
156169
157170@pytest .mark .parametrize ("dispaxis" , [1 , 2 ])
158171def test_profile_residual_with_bkg (psf_reference , dispaxis ):
172+ psf_aper = psf_reference .apertures [0 ]
159173 data_shape = (50 , 50 )
160174 yidx , xidx = np .mgrid [: data_shape [0 ], : data_shape [1 ]]
161- psf_subpix = psf_reference . meta . psf .subpix
175+ psf_subpix = psf_aper .subpix
162176
163177 # Set data to all ones, so it is all background - residual
164178 # should be all of the data
@@ -167,7 +181,7 @@ def test_profile_residual_with_bkg(psf_reference, dispaxis):
167181
168182 param = [0 , None ]
169183 residual = pp ._profile_residual (
170- param , data , var , xidx , yidx , psf_subpix , psf_reference .data , dispaxis , fit_bkg = True
184+ param , data , var , xidx , yidx , psf_subpix , psf_aper .data , dispaxis , fit_bkg = True
171185 )
172186 assert np .isclose (residual , np .sum (data ** 2 / var ))
173187
0 commit comments