@@ -116,15 +116,15 @@ class BoxcarExtract(SpecreduceOperation):
116
116
117
117
Parameters
118
118
----------
119
- image : nddata-compatible image
119
+ image : `~astropy. nddata.NDData`-like or array-like, required
120
120
image with 2-D spectral image data
121
- trace_object : Trace
121
+ trace_object : Trace, required
122
122
trace object
123
- width : float
123
+ width : float, optional
124
124
width of extraction aperture in pixels
125
- disp_axis : int
125
+ disp_axis : int, optional
126
126
dispersion axis
127
- crossdisp_axis : int
127
+ crossdisp_axis : int, optional
128
128
cross-dispersion axis
129
129
130
130
Returns
@@ -150,15 +150,15 @@ def __call__(self, image=None, trace_object=None, width=None,
150
150
151
151
Parameters
152
152
----------
153
- image : nddata-compatible image
153
+ image : `~astropy. nddata.NDData`-like or array-like, required
154
154
image with 2-D spectral image data
155
- trace_object : Trace
155
+ trace_object : Trace, required
156
156
trace object
157
- width : float
157
+ width : float, optional
158
158
width of extraction aperture in pixels [default: 5]
159
- disp_axis : int
159
+ disp_axis : int, optional
160
160
dispersion axis [default: 1]
161
- crossdisp_axis : int
161
+ crossdisp_axis : int, optional
162
162
cross-dispersion axis [default: 0]
163
163
164
164
@@ -174,25 +174,33 @@ def __call__(self, image=None, trace_object=None, width=None,
174
174
disp_axis = disp_axis if disp_axis is not None else self .disp_axis
175
175
crossdisp_axis = crossdisp_axis if crossdisp_axis is not None else self .crossdisp_axis
176
176
177
+ # handle image processing based on its type
178
+ if isinstance (image , Spectrum1D ):
179
+ img = image .data
180
+ unit = image .unit
181
+ else :
182
+ img = image
183
+ unit = getattr (image , 'unit' , u .DN )
184
+
177
185
# TODO: this check can be removed if/when implemented as a check in FlatTrace
178
186
if isinstance (trace_object , FlatTrace ):
179
187
if trace_object .trace_pos < 1 :
180
188
raise ValueError ('trace_object.trace_pos must be >= 1' )
181
189
182
190
# weight image to use for extraction
183
- wimage = _ap_weight_image (
191
+ wimg = _ap_weight_image (
184
192
trace_object ,
185
193
width ,
186
194
disp_axis ,
187
195
crossdisp_axis ,
188
- image .shape )
196
+ img .shape )
189
197
190
198
# extract
191
- ext1d = np .sum (image * wimage , axis = crossdisp_axis )
199
+ ext1d = np .sum (img * wimg , axis = crossdisp_axis ) * unit
192
200
193
- # TODO: add wavelenght units, uncertainty and mask to spectrum1D object
194
- spec = Spectrum1D ( spectral_axis = np .arange (len ( ext1d )) * u .pixel ,
195
- flux = ext1d * getattr ( image , 'unit' , u . DN ) )
201
+ # TODO: add wavelength units, uncertainty and mask to Spectrum1D object
202
+ pixels = np .arange (ext1d . shape [ crossdisp_axis ]) * u .pixel
203
+ spec = Spectrum1D ( spectral_axis = pixels , flux = ext1d )
196
204
197
205
return spec
198
206
@@ -206,7 +214,7 @@ class HorneExtract(SpecreduceOperation):
206
214
Parameters
207
215
----------
208
216
209
- image : `~astropy.nddata.NDData` or array-like, required
217
+ image : `~astropy.nddata.NDData`-like or array-like, required
210
218
The input 2D spectrum from which to extract a source. An
211
219
NDData object must specify uncertainty and a mask. An array
212
220
requires use of the ``variance``, ``mask``, & ``unit`` arguments.
@@ -269,7 +277,7 @@ def __call__(self, image=None, trace_object=None,
269
277
Parameters
270
278
----------
271
279
272
- image : `~astropy.nddata.NDData` or array-like, required
280
+ image : `~astropy.nddata.NDData`-like or array-like, required
273
281
The input 2D spectrum from which to extract a source. An
274
282
NDData object must specify uncertainty and a mask. An array
275
283
requires use of the ``variance``, ``mask``, & ``unit`` arguments.
@@ -322,6 +330,7 @@ def __call__(self, image=None, trace_object=None,
322
330
323
331
# handle image and associated data based on image's type
324
332
if isinstance (image , NDData ):
333
+ # (NDData includes Spectrum1D under its umbrella)
325
334
img = np .ma .array (image .data , mask = image .mask )
326
335
unit = image .unit if image .unit is not None else u .Unit ()
327
336
0 commit comments