@@ -116,15 +116,15 @@ class BoxcarExtract(SpecreduceOperation):
116116
117117 Parameters
118118 ----------
119- image : nddata-compatible image
119+ image : `~astropy. nddata.NDData`-like or array-like, required
120120 image with 2-D spectral image data
121- trace_object : Trace
121+ trace_object : Trace, required
122122 trace object
123- width : float
123+ width : float, optional
124124 width of extraction aperture in pixels
125- disp_axis : int
125+ disp_axis : int, optional
126126 dispersion axis
127- crossdisp_axis : int
127+ crossdisp_axis : int, optional
128128 cross-dispersion axis
129129
130130 Returns
@@ -150,15 +150,15 @@ def __call__(self, image=None, trace_object=None, width=None,
150150
151151 Parameters
152152 ----------
153- image : nddata-compatible image
153+ image : `~astropy. nddata.NDData`-like or array-like, required
154154 image with 2-D spectral image data
155- trace_object : Trace
155+ trace_object : Trace, required
156156 trace object
157- width : float
157+ width : float, optional
158158 width of extraction aperture in pixels [default: 5]
159- disp_axis : int
159+ disp_axis : int, optional
160160 dispersion axis [default: 1]
161- crossdisp_axis : int
161+ crossdisp_axis : int, optional
162162 cross-dispersion axis [default: 0]
163163
164164
@@ -174,25 +174,33 @@ def __call__(self, image=None, trace_object=None, width=None,
174174 disp_axis = disp_axis if disp_axis is not None else self .disp_axis
175175 crossdisp_axis = crossdisp_axis if crossdisp_axis is not None else self .crossdisp_axis
176176
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+
177185 # TODO: this check can be removed if/when implemented as a check in FlatTrace
178186 if isinstance (trace_object , FlatTrace ):
179187 if trace_object .trace_pos < 1 :
180188 raise ValueError ('trace_object.trace_pos must be >= 1' )
181189
182190 # weight image to use for extraction
183- wimage = _ap_weight_image (
191+ wimg = _ap_weight_image (
184192 trace_object ,
185193 width ,
186194 disp_axis ,
187195 crossdisp_axis ,
188- image .shape )
196+ img .shape )
189197
190198 # extract
191- ext1d = np .sum (image * wimage , axis = crossdisp_axis )
199+ ext1d = np .sum (img * wimg , axis = crossdisp_axis ) * unit
192200
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 )
196204
197205 return spec
198206
@@ -206,7 +214,7 @@ class HorneExtract(SpecreduceOperation):
206214 Parameters
207215 ----------
208216
209- image : `~astropy.nddata.NDData` or array-like, required
217+ image : `~astropy.nddata.NDData`-like or array-like, required
210218 The input 2D spectrum from which to extract a source. An
211219 NDData object must specify uncertainty and a mask. An array
212220 requires use of the ``variance``, ``mask``, & ``unit`` arguments.
@@ -269,7 +277,7 @@ def __call__(self, image=None, trace_object=None,
269277 Parameters
270278 ----------
271279
272- image : `~astropy.nddata.NDData` or array-like, required
280+ image : `~astropy.nddata.NDData`-like or array-like, required
273281 The input 2D spectrum from which to extract a source. An
274282 NDData object must specify uncertainty and a mask. An array
275283 requires use of the ``variance``, ``mask``, & ``unit`` arguments.
@@ -322,6 +330,7 @@ def __call__(self, image=None, trace_object=None,
322330
323331 # handle image and associated data based on image's type
324332 if isinstance (image , NDData ):
333+ # (NDData includes Spectrum1D under its umbrella)
325334 img = np .ma .array (image .data , mask = image .mask )
326335 unit = image .unit if image .unit is not None else u .Unit ()
327336
0 commit comments