5
5
6
6
import numpy as np
7
7
from astropy .nddata import NDData
8
+ from astropy import units as u
8
9
9
- from specreduce .extract import _ap_weight_image
10
+ from specreduce .extract import _ap_weight_image , _to_spectrum1d_pixels
10
11
from specreduce .tracing import Trace , FlatTrace
11
12
12
13
__all__ = ['Background' ]
@@ -193,8 +194,8 @@ def bkg_image(self, image=None):
193
194
Parameters
194
195
----------
195
196
image : nddata-compatible image or None
196
- image with 2-D spectral image data. If None, will use ``image`` passed
197
- to extract the background .
197
+ image with 2-D spectral image data. If None, will extract
198
+ the background from ``image`` used to initialize the class .
198
199
199
200
Returns
200
201
-------
@@ -205,15 +206,37 @@ def bkg_image(self, image=None):
205
206
206
207
return np .tile (self .bkg_array , (image .shape [0 ], 1 ))
207
208
209
+ def bkg_spectrum (self , image = None ):
210
+ """
211
+ Expose the 1D spectrum of the background.
212
+
213
+ Parameters
214
+ ----------
215
+ image : nddata-compatible image or None
216
+ image with 2-D spectral image data. If None, will extract
217
+ the background from ``image`` used to initialize the class.
218
+
219
+ Returns
220
+ -------
221
+ spec : `~specutils.Spectrum1D`
222
+ The background 1-D spectrum, with flux expressed in the same
223
+ units as the input image (or u.DN if none were provided) and
224
+ the spectral axis expressed in pixel units.
225
+ """
226
+ bkg_image = self .bkg_image (image = image )
227
+
228
+ ext1d = np .sum (bkg_image , axis = self .crossdisp_axis )
229
+ return _to_spectrum1d_pixels (ext1d * getattr (image , 'unit' , u .DN ))
230
+
208
231
def sub_image (self , image = None ):
209
232
"""
210
233
Subtract the computed background from ``image``.
211
234
212
235
Parameters
213
236
----------
214
237
image : nddata-compatible image or None
215
- image with 2-D spectral image data. If None, will use ``image`` passed
216
- to extract the background .
238
+ image with 2-D spectral image data. If None, will extract
239
+ the background from ``image`` used to initialize the class .
217
240
218
241
Returns
219
242
-------
@@ -228,6 +251,28 @@ def sub_image(self, image=None):
228
251
else :
229
252
return image - self .bkg_image (image )
230
253
254
+ def sub_spectrum (self , image = None ):
255
+ """
256
+ Expose the 1D spectrum of the background-subtracted image.
257
+
258
+ Parameters
259
+ ----------
260
+ image : nddata-compatible image or None
261
+ image with 2-D spectral image data. If None, will extract
262
+ the background from ``image`` used to initialize the class.
263
+
264
+ Returns
265
+ -------
266
+ spec : `~specutils.Spectrum1D`
267
+ The background 1-D spectrum, with flux expressed in the same
268
+ units as the input image (or u.DN if none were provided) and
269
+ the spectral axis expressed in pixel units.
270
+ """
271
+ sub_image = self .sub_image (image = image )
272
+
273
+ ext1d = np .sum (sub_image , axis = self .crossdisp_axis )
274
+ return _to_spectrum1d_pixels (ext1d * getattr (image , 'unit' , u .DN ))
275
+
231
276
def __rsub__ (self , image ):
232
277
"""
233
278
Subtract the background from an image.
0 commit comments