Skip to content

Commit

Permalink
fix issue with units (#221)
Browse files Browse the repository at this point in the history
* fix issue with units

* .

* add section for 1.4.1
  • Loading branch information
cshanahan1 authored Jun 20, 2024
1 parent 388adb0 commit 5620d7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
16 changes: 16 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ API Changes
Bug Fixes
^^^^^^^^^


Other changes

1.4.1 (unreleased)
------------------

New Features
^^^^^^^^^^^^

API Changes
^^^^^^^^^^^

Bug Fixes
^^^^^^^^^
- Fix bug where Background one sided / two sided was not correctly assigning units to data. [#221]

Other changes
^^^^^^^^^^^^^

Expand Down
27 changes: 15 additions & 12 deletions specreduce/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ def _parse_image(self, image, disp_axis=1):
# useful for Background's instance methods
return self.image

img = self._get_data_from_image(image)
img = self._get_data_from_image(image, disp_axis=disp_axis)

return img

@staticmethod
def _get_data_from_image(image, disp_axis=1):
"""Extract data array from various input types for `image`.
Retruns `np.ndarray` of image data."""

if isinstance(image, u.quantity.Quantity):
img = image.value
elif isinstance(image, np.ndarray):
img = image
else: # NDData, including CCDData and Spectrum1D
img = image.data

# mask and uncertainty are set as None when they aren't specified upon
# creating a Spectrum1D object, so we must check whether these
Expand All @@ -74,17 +88,6 @@ def _parse_image(self, image, disp_axis=1):
return Spectrum1D(img * unit, spectral_axis=spectral_axis,
uncertainty=uncertainty, mask=mask)

@staticmethod
def _get_data_from_image(image):
"""Extract data array from various input types for `image`.
Retruns `np.ndarray` of image data."""

if isinstance(image, u.quantity.Quantity):
img = image.value
if isinstance(image, np.ndarray):
img = image
else: # NDData, including CCDData and Spectrum1D
img = image.data
return img


Expand Down

0 comments on commit 5620d7b

Please sign in to comment.