Skip to content

Commit

Permalink
Begin deprecation process for bkg_array
Browse files Browse the repository at this point in the history
  • Loading branch information
ojustino committed Nov 21, 2022
1 parent c9e076e commit 89fb30c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions specreduce/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
from astropy.nddata import NDData
from astropy.utils.decorators import deprecated_attribute
from astropy import units as u
from specutils import Spectrum1D

Expand Down Expand Up @@ -56,6 +57,9 @@ class Background(_ImageParser):
disp_axis: int = 1
crossdisp_axis: int = 0

# TO-DO: update bkg_array with Spectrum1D alternative (is bkg_image enough?)
bkg_array = deprecated_attribute('bkg_array', '1.3')

def __post_init__(self):
"""
Determine the background from an image for subtraction.
Expand Down Expand Up @@ -93,7 +97,7 @@ def _to_trace(trace):
if self.width < 0:
raise ValueError("width must be positive")
if self.width == 0:
self.bkg_array = np.zeros(self.image.shape[self.disp_axis])
self._bkg_array = np.zeros(self.image.shape[self.disp_axis])
return

if isinstance(self.traces, Trace):
Expand Down Expand Up @@ -130,13 +134,13 @@ def _to_trace(trace):
self.bkg_wimage = bkg_wimage

if self.statistic == 'average':
self.bkg_array = np.average(self.image.data,
weights=self.bkg_wimage,
axis=self.crossdisp_axis)
self._bkg_array = np.average(self.image.data,
weights=self.bkg_wimage,
axis=self.crossdisp_axis)
elif self.statistic == 'median':
med_image = self.image.data.copy()
med_image[np.where(self.bkg_wimage) == 0] = np.nan
self.bkg_array = np.nanmedian(med_image, axis=self.crossdisp_axis)
self._bkg_array = np.nanmedian(med_image, axis=self.crossdisp_axis)
else:
raise ValueError("statistic must be 'average' or 'median'")

Expand Down Expand Up @@ -231,7 +235,7 @@ def bkg_image(self, image=None):
Spectrum1D object with same shape as ``image``.
"""
image = self._parse_image(image)
return Spectrum1D(np.tile(self.bkg_array,
return Spectrum1D(np.tile(self._bkg_array,
(image.shape[0], 1)) * image.unit,
spectral_axis=image.spectral_axis)

Expand Down

0 comments on commit 89fb30c

Please sign in to comment.