Skip to content

Commit

Permalink
Merge pull request #361 from simontorres/fix_mask_issue
Browse files Browse the repository at this point in the history
Extracted spectrum (1 dimension) had mask it wasn't updated so saving the file would fail.
- Test updated to include a mask
- Set mask to `None` for extracted spectrum files.
  • Loading branch information
simontorres committed Nov 24, 2021
2 parents a7a6e58 + ac7ee5b commit f99ebec
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
7 changes: 5 additions & 2 deletions docs/change_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ Change History

.. _v1.3.5:

V1.3.5 Not Released
^^^^^^^^^^^^^^^^^^^
V1.3.5 24-11-2021
^^^^^^^^^^^^^^^^^

- Created `--target-min-width` and `--target-max-width` flags to allow extraction of extended sources.
- Replaced coveralls with codecov for code coverage.
- Documentation improvements and updates.
- Fixed issue with extracted spectrum that where masked in 2D.
- Code style improvements.


.. _v1.3.4:

Expand Down
2 changes: 1 addition & 1 deletion goodman_pipeline/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
identify_technique,
image_overscan,
image_trim,
interpolate,
interpolate_spectrum,
is_file_saturated,
linearize_spectrum,
name_master_flats,
Expand Down
17 changes: 8 additions & 9 deletions goodman_pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import pandas
import random
import re
import scipy
import subprocess
import sys
import time
Expand All @@ -30,7 +29,7 @@
from astropy.time import Time
from astroscrappy import detect_cosmics
from matplotlib import pyplot as plt
from scipy import signal
from scipy import signal, interpolate
from threading import Timer

from . import check_version
Expand Down Expand Up @@ -1296,6 +1295,8 @@ def extract_fractional_pixel(ccd, target_trace, target_fwhm, extraction_width,

new_ccd = ccd.copy()
new_ccd.data = np.asarray(extracted_spectrum)
log.warning("Setting mask to None, otherwise saving will fail.")
new_ccd.mask = None
if new_ccd.header['NAXIS'] != 1:
for i in range(int(new_ccd.header['NAXIS']), 1, -1):
new_ccd.header.remove(keyword="NAXIS{:d}".format(i))
Expand Down Expand Up @@ -2062,7 +2063,7 @@ def image_trim(ccd, trim_section, trim_type='trimsec', add_keyword=False):
return ccd


def interpolate(spectrum, interpolation_size):
def interpolate_spectrum(spectrum, interpolation_size):
"""Creates an interpolated version of the input spectrum
This method creates an interpolated version of the input array, it is
Expand All @@ -2089,8 +2090,8 @@ def interpolate(spectrum, interpolation_size):
last_x,
spectrum.size * interpolation_size)

tck = scipy.interpolate.splrep(x_axis, spectrum, s=0)
new_spectrum = scipy.interpolate.splev(new_x_axis, tck, der=0)
tck = interpolate.splrep(x_axis, spectrum, s=0)
new_spectrum = interpolate.splev(new_x_axis, tck, der=0)
return [new_x_axis, new_spectrum]


Expand Down Expand Up @@ -2169,10 +2170,8 @@ def linearize_spectrum(data, wavelength_solution, plots=False):
except TypeError:
pass
new_x_axis = np.linspace(x_axis[0], x_axis[-1], len(data))
tck = scipy.interpolate.splrep(x_axis, data, s=0)
linearized_data = scipy.interpolate.splev(new_x_axis,
tck,
der=0)
tck = interpolate.splrep(x_axis, data, s=0)
linearized_data = interpolate.splev(new_x_axis, tck, der=0)

smoothed_linearized_data = signal.medfilt(linearized_data)
if plots: # pragma: no cover
Expand Down
9 changes: 5 additions & 4 deletions goodman_pipeline/core/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
identify_targets,
image_overscan,
image_trim,
interpolate,
interpolate_spectrum,
is_file_saturated,
linearize_spectrum,
name_master_flats,
Expand Down Expand Up @@ -821,6 +821,7 @@ def setUp(self):
self.fake_image = CCDData(data=np.ones((100, 100)),
meta=fits.Header(),
unit='adu')
self.fake_image.mask = np.zeros((100, 100), dtype=bool)
self.fake_image.header.set('NAXIS', value=2)
self.fake_image.header.set('NAXIS1', value=100)
self.fake_image.header.set('NAXIS2', value=100)
Expand Down Expand Up @@ -1259,12 +1260,12 @@ def test__get_spectral_characteristics(self):

class InterpolationTest(TestCase):

def test_interpolate(self):
def test_interpolate_spectrum(self):
initial_array = np.sin(np.arange(0, 3 * np.pi))
initial_length = len(initial_array)

new_x_axis, new_array = interpolate(spectrum=initial_array,
interpolation_size=100)
new_x_axis, new_array = interpolate_spectrum(spectrum=initial_array,
interpolation_size=100)

self.assertEqual(len(new_x_axis), len(new_array))
self.assertEqual(len(new_array), initial_length * 100)
Expand Down
2 changes: 1 addition & 1 deletion goodman_pipeline/spectroscopy/wavelength.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _automatic_wavelength_solution(self,
except NoMatchFound as error:
raise NoMatchFound(error)
except NotImplementedError as error:
raise NotImplemented(error)
raise NotImplementedError(error)

# TODO (simon): Evaluate possibility to read iraf wcs. [#304]

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.5.dev2'
__version__ = '1.3.5'
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.5.dev2
version = 1.3.5

0 comments on commit f99ebec

Please sign in to comment.