Skip to content

Commit 89fb30c

Browse files
committed
Begin deprecation process for bkg_array
1 parent c9e076e commit 89fb30c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

specreduce/background.py

+10-6
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

0 commit comments

Comments
 (0)