Skip to content

Commit

Permalink
Merge pull request #387 from simontorres/fix_old_keywords
Browse files Browse the repository at this point in the history
Fix Wavemode Detection
  • Loading branch information
simontorres authored Mar 13, 2024
2 parents b7840b1 + 5f24b5e commit b3a57ce
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 55 deletions.
61 changes: 31 additions & 30 deletions goodman_pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ def name_master_flats(header,
dome_sky = '*'

if technique == 'Spectroscopy':
if header['GRATING'] != '<NO GRATING>':
if header['GRATING'] not in ['<NO GRATING>', 'NO_GRATING']:
flat_grating = '_' + re.sub('[A-Za-z_ ]',
'',
header['GRATING'])
Expand All @@ -2297,15 +2297,15 @@ def name_master_flats(header,
spectroscopic_mode = SpectroscopicMode()
wavmode = spectroscopic_mode(header=header)
else:
flat_grating = '_no_grating'
flat_grating = '_NO_GRATING'
wavmode = ''

flat_slit = re.sub('[A-Za-z_ ]',
'',
header['SLIT'])

filter2 = header['FILTER2']
if filter2 == '<NO FILTER>':
if filter2 in ['<NO FILTER>', 'NO_FILTER']:
filter2 = ''
else:
filter2 = '_' + filter2
Expand All @@ -2320,9 +2320,9 @@ def name_master_flats(header,
+ '.fits'

elif technique == 'Imaging':
if header['FILTER'] != 'NO_FILTER':
if header['FILTER'] not in ['<NO FILTER>', 'NO_FILTER']:
flat_filter = header['FILTER']
elif header['FILTER2'] != 'NO_FILTER':
elif header['FILTER2'] not in ['<NO FILTER>', 'NO_FILTER']:
flat_filter = header['FILTER2']
else:
flat_filter = "NO_FILTER"
Expand Down Expand Up @@ -4084,30 +4084,30 @@ def __init__(self):
"""
self.log = logging.getLogger(__name__)
columns = ['grating_freq', 'wavmode', 'camtarg', 'grttarg', 'ob_filter']
spec_mode = [['400', 'm1', '11.6', '5.8', 'None'],
['400', 'm2', '16.1', '7.5', 'GG455'],
['600', 'UV', '15.25', '7.0', 'None'],
['600', 'Blue', '17.0', '7.0', 'None'],
['600', 'Mid', '20.0', '10.0', 'GG385'],
['600', 'Red', '27.0', '12.0', 'GG495'],
['930', 'm1', '20.6', '10.3', 'None'],
['930', 'm2', '25.2', '12.6', 'None'],
['930', 'm3', '29.9', '15.0', 'GG385'],
['930', 'm4', '34.6', '18.3', 'GG495'],
['930', 'm5', '39.4', '19.7', 'GG495'],
['930', 'm6', '44.2', '22.1', 'OG570'],
['1200', 'm0', '26.0', '16.3', 'None'],
['1200', 'm1', '29.5', '16.3', 'None'],
['1200', 'm2', '34.4', '18.7', 'None'],
['1200', 'm3', '39.4', '20.2', 'None'],
['1200', 'm4', '44.4', '22.2', 'GG455'],
['1200', 'm5', '49.6', '24.8', 'GG455'],
['1200', 'm6', '54.8', '27.4', 'GG495'],
['1200', 'm7', '60.2', '30.1', 'OG570'],
['1800', 'Custom', 'None', 'None', 'None'],
['2100', 'Custom', 'None', 'None', 'None'],
['2400', 'Custom', 'None', 'None', 'None']
columns = ['grating_freq', 'wavmode', 'camtarg', 'grttarg', 'ob_filter', 'ob_filter_old']
spec_mode = [['400', 'm1', '11.6', '5.8', 'NO_FILTER', '<NO FILTER>'],
['400', 'm2', '16.1', '7.5', 'GG455', 'GG455'],
['600', 'UV', '15.25', '7.0', 'NO_FILTER', '<NO FILTER>'],
['600', 'Blue', '17.0', '7.0', 'NO_FILTER', '<NO FILTER>'],
['600', 'Mid', '20.0', '10.0', 'GG385', 'GG385'],
['600', 'Red', '27.0', '12.0', 'GG495', 'GG495'],
['930', 'm1', '20.6', '10.3', 'NO_FILTER', '<NO FILTER>'],
['930', 'm2', '25.2', '12.6', 'NO_FILTER', '<NO FILTER>'],
['930', 'm3', '29.9', '15.0', 'GG385', 'GG385'],
['930', 'm4', '34.6', '18.3', 'GG495', 'GG495'],
['930', 'm5', '39.4', '19.7', 'GG495', 'GG495'],
['930', 'm6', '44.2', '22.1', 'OG570', 'OG570'],
['1200', 'm0', '26.0', '16.3', 'NO_FILTER', '<NO FILTER>'],
['1200', 'm1', '29.5', '16.3', 'NO_FILTER', '<NO FILTER>'],
['1200', 'm2', '34.4', '18.7', 'NO_FILTER', '<NO FILTER>'],
['1200', 'm3', '39.4', '20.2', 'NO_FILTER', '<NO FILTER>'],
['1200', 'm4', '44.4', '22.2', 'GG455', 'GG455'],
['1200', 'm5', '49.6', '24.8', 'GG455', 'GG455'],
['1200', 'm6', '54.8', '27.4', 'GG495', 'GG495'],
['1200', 'm7', '60.2', '30.1', 'OG570', 'OG570'],
['1800', 'Custom', 'None', 'None', 'NO_FILTER', '<NO FILTER>'],
['2100', 'Custom', 'None', 'None', 'NO_FILTER', '<NO FILTER>'],
['2400', 'Custom', 'None', 'None', 'NO_FILTER', '<NO FILTER>']
]
self.modes_data_frame = pandas.DataFrame(spec_mode, columns=columns)

Expand Down Expand Up @@ -4186,7 +4186,8 @@ def get_mode(self, grating, camera_targ, grating_targ, blocking_filter):
((self.modes_data_frame['grating_freq'] == grating) &
(self.modes_data_frame['camtarg'] == camera_targ) &
(self.modes_data_frame['grttarg'] == grating_targ) &
(self.modes_data_frame['ob_filter'] == blocking_filter))]
((self.modes_data_frame['ob_filter'] == blocking_filter) |
(self.modes_data_frame['ob_filter_old'] == blocking_filter)))]
if _mode.empty:
central_wavelength = get_central_wavelength(
grating=grating,
Expand Down
60 changes: 35 additions & 25 deletions goodman_pipeline/core/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,6 @@ class NameMasterFlatsTest(TestCase):

def setUp(self):
self.reduced_data = os.getcwd()

#reference
date = '2019-08-28'
self.twilight_start_evening = '2019-08-27T23:45:00.022'
self.twilight_end_morning = '2019-08-28T09:43:20.023'
Expand Down Expand Up @@ -1462,7 +1460,7 @@ def test_name_master_flats_spectroscopy(self):

def test_name_master_flats_spectroscopy_no_grating_no_filter2(self):

expected_name = 'master_flat_TestSubject_no_grating_1.0_sky.fits'
expected_name = 'master_flat_TestSubject_NO_GRATING_1.0_sky.fits'

self.header.set('GRATING', value='<NO GRATING>')
self.header.set('DATE-OBS', value='2019-08-27T23:40:00.022')
Expand Down Expand Up @@ -2059,24 +2057,15 @@ def setUp(self):
def test_get_slit_trim_section__slit_within_data(self):

slit_trim = get_slit_trim_section(master_flat=self.fake_image)
# print(fake_image.data[:,5])
# print(slit_trim)
self.assertEqual(slit_trim, self.reference_slit_trim)

def test_get_slit_trim_section__slit_full_data(self):
self.fake_image.data[:, :] = 100

slit_trim = get_slit_trim_section(master_flat=self.fake_image)
# print(fake_image.data[:,5])
self.assertEqual(slit_trim, '[1:100,1:100]')

def test_image_trim_slit(self):
# # define
# slit_low_limit = 5
# slit_high_limit = 95
#
# slit_trim = '[1:100,{:d}:{:d}]'.format(slit_low_limit + 10 + 1,
# slit_high_limit - 10)
self.fake_image = image_trim(ccd=self.fake_image,
trim_section=self.reference_slit_trim,
trim_type='slit')
Expand All @@ -2089,8 +2078,6 @@ def test_image_trim_slit(self):
self.reference_slit_trim)




class SpectroscopicModeTest(TestCase):

def setUp(self):
Expand All @@ -2117,7 +2104,7 @@ def test__call__(self):

self.assertEqual(mode_m2_keywords, 'm2')

def test_get_mode(self):
def test_get_modes(self):
mode_m2 = self.sm.get_mode(grating='400',
camera_targ='16.1',
grating_targ='7.5',
Expand All @@ -2137,6 +2124,39 @@ def test_get_mode(self):
blocking_filter='GG455')
self.assertEqual(mode_custom_2100, 'Custom_1334nm')

def test_get_mode_400_m1_from_header(self):
header = fits.Header()
header.set('GRATING', value='400_SYZY')
header.set('CAM_TARG', value='11.6')
header.set('GRT_TARG', value='5.8')
header.set('FILTER2', value='NO_FILTER')

spectroscopic_mode = self.sm(header=header)

self.assertEqual(spectroscopic_mode, 'm1')

def test_get_mode_400_m1_from_old_header(self):
header = fits.Header()
header.set('GRATING', value='SYZY_400')
header.set('CAM_TARG', value='11.6')
header.set('GRT_TARG', value='5.8')
header.set('FILTER2', value='<NO FILTER>')

spectroscopic_mode = self.sm(header=header)

self.assertEqual(spectroscopic_mode, 'm1')

def test_get_mode_1200_m3_from_header(self):
header = fits.Header()
header.set('GRATING', value='1200')
header.set('CAM_TARG', value='39.4')
header.set('GRT_TARG', value='20.2')
header.set('FILTER2', value='NO_FILTER')

spectroscopic_mode = self.sm(header=header)

self.assertEqual(spectroscopic_mode, 'm3')

def test_get_cam_grt_targ_angle(self):

cam_targ, grt_targ = self.sm.get_cam_grt_targ_angle(1800, 'm10')
Expand Down Expand Up @@ -2181,15 +2201,6 @@ def setUp(self):
self.ccd.data[:, i] *= profile_sum(range(self.ccd.data.shape[0]))
self.ccd2.data[:, i] *= self.profile_3(
range(self.ccd2.data.shape[0]))
# this add noise to test the removal of masked values
# self.ccd.data[
# random.randrange(self.ccd.data.shape[0]),
# random.randrange(self.ccd.data.shape[1])] *= 300
# self.ccd2.data[
# random.randrange(self.ccd2.data.shape[0]),
# random.randrange(self.ccd2.data.shape[1])] *= 300



def tearDown(self):
del self.ccd
Expand Down Expand Up @@ -2331,4 +2342,3 @@ def test_validate_ccd_region_valid(self):

def test_validate_ccd_region_invalid(self):
self.assertRaises(SyntaxError, validate_ccd_region, "10:10:10]")

0 comments on commit b3a57ce

Please sign in to comment.