Skip to content

Commit

Permalink
move part of image parsing to its own function to avoid issue with cl…
Browse files Browse the repository at this point in the history
…assmethod
  • Loading branch information
cshanahan1 committed Feb 8, 2024
1 parent 715361e commit bd36e2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions specreduce/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from astropy.utils.decorators import deprecated_attribute
from specutils import Spectrum1D

from specreduce.core import _ImageParser
from specreduce.core import _ImageParser, _get_data_from_image
from specreduce.extract import _ap_weight_image
from specreduce.tracing import Trace, FlatTrace

Expand Down Expand Up @@ -183,7 +183,7 @@ def two_sided(cls, image, trace_object, separation, **kwargs):
crossdisp_axis : int
cross-dispersion axis
"""
image = cls._parse_image(cls, image)
image = _get_data_from_image(image) if image is not None else cls.image
kwargs['traces'] = [trace_object-separation, trace_object+separation]
return cls(image=image, **kwargs)

Expand Down Expand Up @@ -220,7 +220,7 @@ def one_sided(cls, image, trace_object, separation, **kwargs):
crossdisp_axis : int
cross-dispersion axis
"""
image = cls._parse_image(cls, image)
image = _get_data_from_image(image) if image is not None else cls.image
kwargs['traces'] = [trace_object+separation]
return cls(image=image, **kwargs)

Expand Down
18 changes: 12 additions & 6 deletions specreduce/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

__all__ = ['SpecreduceOperation']

def _get_data_from_image(image):
"""Extract data array from various input types for `image`."""

if isinstance(image, np.ndarray):
img = image
elif isinstance(image, u.quantity.Quantity):
img = image.value

Check warning on line 19 in specreduce/core.py

View check run for this annotation

Codecov / codecov/patch

specreduce/core.py#L19

Added line #L19 was not covered by tests
else: # NDData, including CCDData and Spectrum1D
img = image.data
return img


class _ImageParser:
"""
Expand Down Expand Up @@ -50,12 +61,7 @@ def _parse_image(self, image, disp_axis=1):
# useful for Background's instance methods
return self.image

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

# mask and uncertainty are set as None when they aren't specified upon
# creating a Spectrum1D object, so we must check whether these
Expand Down

0 comments on commit bd36e2b

Please sign in to comment.