Skip to content

Commit

Permalink
JP-3102 follow-up: Catch source_pos nans from msa file (#8874)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro authored Oct 24, 2024
1 parent 17b7133 commit 476283a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/8874.assign_wcs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Catch NaN values in msa tables for source positions in slit and replace with slit center.
9 changes: 5 additions & 4 deletions jwst/assign_wcs/nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,9 @@ def get_open_msa_slits(prog_id, msa_file, msa_metadata_id, dither_position,
if n_main_shutter == 1:
# Source is marked primary
source_id = slitlet['source_id']
source_xpos = slitlet['estimated_source_in_shutter_x']
source_ypos = slitlet['estimated_source_in_shutter_y']
source_xpos = np.nan_to_num(slitlet['estimated_source_in_shutter_x'], nan=0.5)
source_ypos = np.nan_to_num(slitlet['estimated_source_in_shutter_y'], nan=0.5)

log.info(f'Found fixed slit {slitlet_id} with source_id = {source_id}.')

# Get source info for this slitlet:
Expand Down Expand Up @@ -746,8 +747,8 @@ def get_open_msa_slits(prog_id, msa_file, msa_metadata_id, dither_position,
elif n_main_shutter == 1:
xcen, ycen, quadrant, source_xpos, source_ypos = [
(s['shutter_row'], s['shutter_column'], s['shutter_quadrant'],
s['estimated_source_in_shutter_x'],
s['estimated_source_in_shutter_y'])
np.nan_to_num(s['estimated_source_in_shutter_x'], nan=0.5),
np.nan_to_num(s['estimated_source_in_shutter_y'], nan=0.5))
for s in slitlet_rows if s['background'] == 'N'][0]
shutter_id = xcen + (ycen - 1) * 365 # shutter numbers in MSA file are 1-indexed

Expand Down
32 changes: 32 additions & 0 deletions jwst/assign_wcs/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,38 @@ def test_msa_missing_source(tmp_path):
_compare_slits(slitlet_info[1], ref_slit)


def test_msa_nan_source_posn(tmp_path):
"""
Test the get_open_msa_slits function with nan values for source position.
"""
# modify an existing MSA file to remove source info
msaconfl = get_file_path('msa_fs_configuration.fits')
bad_confl = str(tmp_path / 'nan_msa_fs_configuration.fits')
shutil.copy(msaconfl, bad_confl)

with fits.open(bad_confl) as msa_hdu_list:
shutter_table = table.Table(msa_hdu_list['SHUTTER_INFO'].data)
shutter_table[-5:]['estimated_source_in_shutter_x'] = np.nan
msa_hdu_list['SHUTTER_INFO'] = fits.table_to_hdu(shutter_table)
msa_hdu_list[2].name = 'SHUTTER_INFO'
msa_hdu_list.writeto(bad_confl, overwrite=True)

prog_id = '1234'
msa_meta_id = 12
dither_position = 1

slitlet_info = nirspec.get_open_msa_slits(
prog_id, bad_confl, msa_meta_id, dither_position, slit_y_range=[-.5, .5])

# MSA slit: virtual source name assigned
ref_slit = trmodels.Slit(name='S200A1', shutter_id=0, dither_position=1, xcen=0, ycen=0,
ymin=-0.5, ymax=0.5, quadrant=5, source_id=3, shutter_state='x',
source_name='95065_3', source_alias='3', stellarity=1.0,
source_xpos=0.0, source_ypos=-0.2290000021457672,
source_ra=53.139904, source_dec=-27.805002)
_compare_slits(slitlet_info[1], ref_slit)


open_shutters = [[24], [23, 24], [22, 23, 25, 27], [22, 23, 25, 27, 28]]
main_shutter = [24, 23, 25, 28]
result = ["x", "x1", "110x01", "110101x"]
Expand Down

0 comments on commit 476283a

Please sign in to comment.