Skip to content

Commit

Permalink
Merge pull request #348 from simontorres/fix_bug_on_bias_subtraction
Browse files Browse the repository at this point in the history
Fix bug on double bias subtraction
  • Loading branch information
Simon Torres committed Apr 19, 2021
2 parents 3886952 + 86b2c8d commit 33e030c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 52 deletions.
8 changes: 8 additions & 0 deletions docs/change_history.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change History
##############

.. _v1.3.3:

V1.3.3 19-04-2021
^^^^^^^^^^^^^^^^^

- Fixed bug that caused overscan and bias correction happen in the same image
resulting in double bias level subtraction.

.. _v1.3.2:

V1.3.2 09-10-2020
Expand Down
8 changes: 4 additions & 4 deletions goodman_pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def call_cosmic_rejection(ccd,

_create(instrument=_instrument, binning=_binning, path=red_path)

full_path = os.path.join(red_path, out_prefix + image_name)
full_path = os.path.join(red_path, f"{out_prefix}_{image_name}")

ccd.header.set('GSP_COSM',
value="DCR",
Expand All @@ -333,7 +333,7 @@ def call_cosmic_rejection(ccd,
write_fits(ccd=ccd, full_path=full_path)
log.info('Saving image: {:s}'.format(full_path))

in_file = out_prefix + image_name
in_file = f"{out_prefix}_{image_name}"

# This is to return the prefix that will be used by dcr
# Not to be used by dcr_cosmicray_rejection
Expand All @@ -352,15 +352,15 @@ def call_cosmic_rejection(ccd,
save_mask=keep_files)

out_prefix = prefix + out_prefix
full_path = os.path.join(red_path, out_prefix + image_name)
full_path = os.path.join(red_path, f"{out_prefix}_{image_name}")

if save:
log.info('Saving image: {:s}'.format(full_path))
write_fits(ccd=ccd, full_path=full_path)
return ccd, out_prefix

elif method == 'none':
full_path = os.path.join(red_path, out_prefix + image_name)
full_path = os.path.join(red_path, f"{out_prefix}_{image_name}")
if save:
log.info('Saving image: {:s}'.format(full_path))
write_fits(ccd=ccd, full_path=full_path)
Expand Down
46 changes: 23 additions & 23 deletions goodman_pipeline/core/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ def test_call_cosmic_rejection_default_1x1(self):
method='default',
save=False)
self.assertAlmostEqual(initial_value, ccd.data[50, 50])
self.assertEqual(out_prefix, prefix + self.out_prefix)
self.assertEqual(ccd.header['GSP_FNAM'],
prefix + self.out_prefix + self.file_name)
self.assertEqual(ccd.header['GSP_COSM'], 'DCR')
self.assertEqual(prefix + self.out_prefix, out_prefix)
self.assertEqual(f"{prefix}{self.out_prefix}_{self.file_name}",
ccd.header['GSP_FNAM'])
self.assertEqual('DCR', ccd.header['GSP_COSM'])

self.assertTrue(os.path.isfile('dcr.par'))

Expand Down Expand Up @@ -451,11 +451,11 @@ def test_call_cosmic_rejection_default_2x2(self):
method='default',
save=True)
self.assertAlmostEqual(initial_value, ccd.data[50, 50])
self.assertEqual(out_prefix, prefix + self.out_prefix)
self.assertEqual(ccd.header['GSP_FNAM'],
prefix + self.out_prefix + self.file_name)
self.assertEqual(ccd.header['GSP_COSM'], 'LACosmic')
self.assertTrue(os.path.isfile('new_prefixcr_test.fits'))
self.assertEqual(prefix + self.out_prefix, out_prefix)
self.assertEqual(f"{prefix}{self.out_prefix}_{self.file_name}",
ccd.header['GSP_FNAM'])
self.assertEqual('LACosmic', ccd.header['GSP_COSM'])
self.assertTrue(os.path.isfile('new_prefix_cr_test.fits'))

def test_call_cosmic_rejection_default_3x3(self):
self.ccd.header.set('CCDSUM', value='3 3')
Expand All @@ -472,12 +472,12 @@ def test_call_cosmic_rejection_default_3x3(self):
method='default',
save=True)
self.assertAlmostEqual(initial_value, ccd.data[50, 50])
self.assertEqual(out_prefix, prefix + self.out_prefix)
self.assertEqual(ccd.header['GSP_FNAM'],
prefix + self.out_prefix + self.file_name)
self.assertEqual(ccd.header['GSP_COSM'], 'LACosmic')
self.assertEqual(prefix + self.out_prefix, out_prefix)
self.assertEqual(f"{prefix}{self.out_prefix}_{self.file_name}",
ccd.header['GSP_FNAM'])
self.assertEqual('LACosmic', ccd.header['GSP_COSM'])

self.assertTrue(os.path.isfile('new_prefixcr_test.fits'))
self.assertTrue(os.path.isfile('new_prefix_cr_test.fits'))

def test_call_cosmic_rejection_none(self):
prefix = 'new_'
Expand All @@ -489,11 +489,11 @@ def test_call_cosmic_rejection_none(self):
prefix=prefix,
method='none',
save=True)
self.assertEqual(out_prefix, self.out_prefix)
self.assertEqual(ccd.header['GSP_FNAM'],
self.out_prefix + self.file_name)
self.assertEqual(ccd.header['GSP_COSM'], 'none')
self.assertTrue(os.path.isfile('prefixcr_test.fits'))
self.assertEqual(self.out_prefix, out_prefix)
self.assertEqual(f"{self.out_prefix}_{self.file_name}",
ccd.header['GSP_FNAM'])
self.assertEqual('none', ccd.header['GSP_COSM'])
self.assertTrue(os.path.isfile('prefix_cr_test.fits'))

def test_call_cosmic_rejection_comp_lamp(self):
self.ccd.header.set('OBSTYPE', value='COMP')
Expand All @@ -506,10 +506,10 @@ def test_call_cosmic_rejection_comp_lamp(self):
prefix=prefix,
method='lacosmic',
save=True)
self.assertEqual(out_prefix, prefix + self.out_prefix)
self.assertEqual(ccd.header['GSP_FNAM'],
prefix + self.out_prefix + self.file_name)
self.assertEqual(ccd.header['GSP_COSM'], 'none')
self.assertEqual(prefix + self.out_prefix, out_prefix)
self.assertEqual(f"{prefix}{self.out_prefix}_{self.file_name}",
ccd.header['GSP_FNAM'])
self.assertEqual('none', ccd.header['GSP_COSM'])

def test_call_cosmic_rejection_not_implemented_error(self):
prefix = 'new_'
Expand Down
39 changes: 16 additions & 23 deletions goodman_pipeline/images/image_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def process_spectroscopy_science(self, science_group, save_all=False):
list of science images that where observed at the same pointing
and time. It also contains a set of selected keywords from the
image's header.
save_all (bool): If True the pipeline will save all the intermadiate
save_all (bool): If True the pipeline will save all the intermediate
files such as after overscan correction or bias corrected and
etc.
Expand Down Expand Up @@ -311,15 +311,17 @@ def process_spectroscopy_science(self, science_group, save_all=False):
ccd = read_fits(image_full_path, technique=self.technique)

# apply overscan
ccd = image_overscan(ccd, overscan_region=self.overscan_region)
self.out_prefix += 'o_'
if self.args.ignore_bias:
ccd = image_overscan(ccd, overscan_region=self.overscan_region)
self.out_prefix += 'o'

if save_all:
full_path = os.path.join(self.args.red_path,
self.out_prefix + science_image)
if save_all:
full_path = os.path.join(
self.args.red_path,
f"{self.out_prefix}_{science_image}")

# ccd.write(full_path, clobber=True)
write_fits(ccd=ccd, full_path=full_path)
# ccd.write(full_path, clobber=True)
write_fits(ccd=ccd, full_path=full_path)

if slit_trim is not None:
# There is a double trimming of the image, this is to match
Expand All @@ -338,7 +340,7 @@ def process_spectroscopy_science(self, science_group, save_all=False):
if save_all:
full_path = os.path.join(
self.args.red_path,
self.out_prefix + science_image)
f"{self.out_prefix}_{science_image}")

# ccd.write(full_path, clobber=True)
write_fits(ccd=ccd, full_path=full_path)
Expand All @@ -353,16 +355,12 @@ def process_spectroscopy_science(self, science_group, save_all=False):
if save_all:
full_path = os.path.join(
self.args.red_path,
self.out_prefix + science_image)
f"{self.out_prefix}_{science_image}")

# ccd.write(full_path, clobber=True)
write_fits(ccd=ccd, full_path=full_path)

if not self.args.ignore_bias:
# TODO (simon): Add check that bias is compatible
print(ccd.data.shape)
print(master_bias.data.shape)

ccd = ccdproc.subtract_bias(ccd=ccd,
master=master_bias,
add_keyword=False)
Expand All @@ -376,7 +374,7 @@ def process_spectroscopy_science(self, science_group, save_all=False):
if save_all:
full_path = os.path.join(
self.args.red_path,
self.out_prefix + science_image)
f"{self.out_prefix}_{science_image}")

# ccd.write(full_path, clobber=True)
write_fits(ccd=ccd, full_path=full_path)
Expand Down Expand Up @@ -415,7 +413,7 @@ def process_spectroscopy_science(self, science_group, save_all=False):
if save_all:
full_path = os.path.join(
self.args.red_path,
self.out_prefix + science_image)
f"{self.out_prefix}_{science_image}")

# ccd.write(full_path, clobber=True)
write_fits(ccd=ccd, full_path=full_path)
Expand Down Expand Up @@ -452,11 +450,6 @@ def process_spectroscopy_science(self, science_group, save_all=False):
log.info("Combining {:d} OBJECT images"
"".format(len(all_object_image)))

# object_group = object_comp_group[(
# (object_comp_group.obstype == "OBJECT") |
# (object_comp_group.obstype == "SPECTRUM"))]

# print(object_group, len(all_object_image))

combined_data = combine_data(all_object_image,
dest_path=self.args.red_path,
Expand Down Expand Up @@ -561,7 +554,7 @@ def process_imaging_science(self, imaging_group):
ccd = image_trim(ccd=ccd,
trim_section=self.trim_section,
trim_type='trimsec')
self.out_prefix = 't_'
self.out_prefix = 't'
if not self.args.ignore_bias:

ccd = ccdproc.subtract_bias(ccd,
Expand Down Expand Up @@ -596,7 +589,7 @@ def process_imaging_science(self, imaging_group):
print('Clean Cosmic ' + str(self.args.clean_cosmic))

final_name = os.path.join(self.args.red_path,
self.out_prefix + image_file)
f"{self.out_prefix}_{image_file}")
# ccd.write(final_name, clobber=True)
write_fits(ccd=ccd, full_path=final_name)
log.info('Created science file: {:s}'.format(final_name))
Expand Down
2 changes: 1 addition & 1 deletion goodman_pipeline/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This is an automatic generated file please do not edit
__version__ = '1.3.2.dev1'
__version__ = '1.3.3'
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ install_requires =
ccdproc
astroplan
# version should be PEP440 compatible (http://www.python.org/dev/peps/pep-0440)
version = 1.3.2
version = 1.3.3

0 comments on commit 33e030c

Please sign in to comment.