From 86d501cca01a60596a90ae173740387b1f4b2295 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 13 Oct 2022 15:17:07 -0400 Subject: [PATCH] fix passing single Trace object to Background * 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. --- CHANGES.rst | 2 ++ specreduce/background.py | 3 +++ specreduce/tests/test_background.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 18d45934..1e408f7f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,8 @@ API Changes Bug Fixes ^^^^^^^^^ +- Fixed passing a single ``Trace`` object to ``Background`` [#146] + 1.2.0 ----- diff --git a/specreduce/background.py b/specreduce/background.py index 47ccf9f4..88482695 100644 --- a/specreduce/background.py +++ b/specreduce/background.py @@ -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) diff --git a/specreduce/tests/test_background.py b/specreduce/tests/test_background.py index 28e4c3a7..53d13892 100644 --- a/specreduce/tests/test_background.py +++ b/specreduce/tests/test_background.py @@ -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)