Skip to content

Commit 53fd1a4

Browse files
committed
Begin deprecation process for bkg_array
1 parent c9e076e commit 53fd1a4

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

specreduce/background.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
from astropy.nddata import NDData
8+
from astropy.utils.decorators import deprecated_attribute
89
from astropy import units as u
910
from specutils import Spectrum1D
1011

@@ -56,6 +57,9 @@ class Background(_ImageParser):
5657
disp_axis: int = 1
5758
crossdisp_axis: int = 0
5859

60+
# TO-DO: update bkg_array with Spectrum1D alternative (is bkg_image enough?)
61+
bkg_array = deprecated_attribute('bkg_array', '1.3')
62+
5963
def __post_init__(self):
6064
"""
6165
Determine the background from an image for subtraction.
@@ -93,7 +97,7 @@ def _to_trace(trace):
9397
if self.width < 0:
9498
raise ValueError("width must be positive")
9599
if self.width == 0:
96-
self.bkg_array = np.zeros(self.image.shape[self.disp_axis])
100+
self._bkg_array = np.zeros(self.image.shape[self.disp_axis])
97101
return
98102

99103
if isinstance(self.traces, Trace):
@@ -130,13 +134,13 @@ def _to_trace(trace):
130134
self.bkg_wimage = bkg_wimage
131135

132136
if self.statistic == 'average':
133-
self.bkg_array = np.average(self.image.data,
134-
weights=self.bkg_wimage,
135-
axis=self.crossdisp_axis)
137+
self._bkg_array = np.average(self.image.data,
138+
weights=self.bkg_wimage,
139+
axis=self.crossdisp_axis)
136140
elif self.statistic == 'median':
137141
med_image = self.image.data.copy()
138142
med_image[np.where(self.bkg_wimage) == 0] = np.nan
139-
self.bkg_array = np.nanmedian(med_image, axis=self.crossdisp_axis)
143+
self._bkg_array = np.nanmedian(med_image, axis=self.crossdisp_axis)
140144
else:
141145
raise ValueError("statistic must be 'average' or 'median'")
142146

@@ -231,7 +235,7 @@ def bkg_image(self, image=None):
231235
Spectrum1D object with same shape as ``image``.
232236
"""
233237
image = self._parse_image(image)
234-
return Spectrum1D(np.tile(self.bkg_array,
238+
return Spectrum1D(np.tile(self._bkg_array,
235239
(image.shape[0], 1)) * image.unit,
236240
spectral_axis=image.spectral_axis)
237241

specreduce/tests/test_background.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ def test_background():
3838
bg1 = Background(image, [trace-bkg_sep, trace+bkg_sep], width=bkg_width)
3939
bg2 = Background.two_sided(image, trace, bkg_sep, width=bkg_width)
4040
bg3 = Background.two_sided(image, trace_pos, bkg_sep, width=bkg_width)
41-
assert np.allclose(bg1.bkg_array, bg2.bkg_array)
42-
assert np.allclose(bg1.bkg_array, bg3.bkg_array)
41+
assert np.allclose(bg1.bkg_image().flux, bg2.bkg_image().flux)
42+
assert np.allclose(bg1.bkg_image().flux, bg3.bkg_image().flux)
4343

4444
bg4 = Background(image_um, [trace-bkg_sep, trace+bkg_sep], width=bkg_width)
4545
bg5 = Background.two_sided(image_um, trace, bkg_sep, width=bkg_width)
4646
bg6 = Background.two_sided(image_um, trace_pos, bkg_sep, width=bkg_width)
47-
assert np.allclose(bg1.bkg_array, bg4.bkg_array)
48-
assert np.allclose(bg1.bkg_array, bg5.bkg_array)
49-
assert np.allclose(bg1.bkg_array, bg6.bkg_array)
47+
assert np.allclose(bg1.bkg_image().flux, bg4.bkg_image().flux)
48+
assert np.allclose(bg1.bkg_image().flux, bg5.bkg_image().flux)
49+
assert np.allclose(bg1.bkg_image().flux, bg6.bkg_image().flux)
5050

5151
# test that creating a one_sided background works
5252
Background.one_sided(image, trace, bkg_sep, width=bkg_width)

0 commit comments

Comments
 (0)