|
5 | 5 |
|
6 | 6 | import numpy as np |
7 | 7 | from astropy.nddata import NDData |
| 8 | +from astropy.utils.decorators import deprecated_attribute |
8 | 9 | from astropy import units as u |
9 | 10 | from specutils import Spectrum1D |
10 | 11 |
|
@@ -56,6 +57,9 @@ class Background(_ImageParser): |
56 | 57 | disp_axis: int = 1 |
57 | 58 | crossdisp_axis: int = 0 |
58 | 59 |
|
| 60 | + # TO-DO: update bkg_array with Spectrum1D alternative (is bkg_image enough?) |
| 61 | + bkg_array = deprecated_attribute('bkg_array', '1.3') |
| 62 | + |
59 | 63 | def __post_init__(self): |
60 | 64 | """ |
61 | 65 | Determine the background from an image for subtraction. |
@@ -93,7 +97,7 @@ def _to_trace(trace): |
93 | 97 | if self.width < 0: |
94 | 98 | raise ValueError("width must be positive") |
95 | 99 | 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]) |
97 | 101 | return |
98 | 102 |
|
99 | 103 | if isinstance(self.traces, Trace): |
@@ -130,13 +134,13 @@ def _to_trace(trace): |
130 | 134 | self.bkg_wimage = bkg_wimage |
131 | 135 |
|
132 | 136 | 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) |
136 | 140 | elif self.statistic == 'median': |
137 | 141 | med_image = self.image.data.copy() |
138 | 142 | 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) |
140 | 144 | else: |
141 | 145 | raise ValueError("statistic must be 'average' or 'median'") |
142 | 146 |
|
@@ -231,7 +235,7 @@ def bkg_image(self, image=None): |
231 | 235 | Spectrum1D object with same shape as ``image``. |
232 | 236 | """ |
233 | 237 | image = self._parse_image(image) |
234 | | - return Spectrum1D(np.tile(self.bkg_array, |
| 238 | + return Spectrum1D(np.tile(self._bkg_array, |
235 | 239 | (image.shape[0], 1)) * image.unit, |
236 | 240 | spectral_axis=image.spectral_axis) |
237 | 241 |
|
|
0 commit comments