Skip to content

Commit

Permalink
fix passing single Trace object to Background
Browse files Browse the repository at this point in the history
* Background(image, trace, width) used to expect trace to be an iterable and interpret the trace as a list of floats, each representing a trace (and therefore raise an error about window overlaps).  This syntax is now handled as expected.
  • Loading branch information
kecnry committed Oct 13, 2022
1 parent f8c67a9 commit 86d501c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ API Changes
Bug Fixes
^^^^^^^^^

- Fixed passing a single ``Trace`` object to ``Background`` [#146]


1.2.0
-----
Expand Down
3 changes: 3 additions & 0 deletions specreduce/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def _to_trace(trace):
self.bkg_array = np.zeros(self.image.shape[self.disp_axis])
return

if isinstance(self.traces, Trace):
self.traces = [self.traces]

bkg_wimage = np.zeros_like(self.image, dtype=np.float64)
for trace in self.traces:
trace = _to_trace(trace)
Expand Down
3 changes: 3 additions & 0 deletions specreduce/tests/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def test_background():
# test that creating a one_sided background works
Background.one_sided(image, trace, bkg_sep, width=bkg_width)

# test that passing a single trace works
bg = Background(image, trace, width=bkg_width)

# test that image subtraction works
sub1 = image - bg1
sub2 = bg1.sub_image(image)
Expand Down

0 comments on commit 86d501c

Please sign in to comment.