Skip to content

fix issue with units #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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