9
9
from specreduce .tracing import Trace , FlatTrace
10
10
from specreduce .extract import _ap_weight_image , _align_along_trace
11
11
12
- __all__ = ['measure_cross_dispersion_profile' , '_align_along_trace' , 'align_spectrum_along_trace ' ]
12
+ __all__ = ['measure_cross_dispersion_profile' , '_align_along_trace' , 'align_2d_spectrum_along_trace ' ]
13
13
14
14
15
15
def _get_image_ndim (image ):
@@ -21,38 +21,45 @@ def _get_image_ndim(image):
21
21
raise ValueError ('Unrecognized image data format.' )
22
22
23
23
24
- def align_spectrum_along_trace (image : NDData | np .ndarray ,
25
- trace : Trace | np .ndarray | Number ,
26
- method : Literal ['interpolate' , 'shift' ] = 'interpolate' ,
27
- disp_axis : int = 1 ) -> Spectrum1D :
24
+ def align_2d_spectrum_along_trace (image : NDData | np .ndarray ,
25
+ trace : Trace | np .ndarray | Number ,
26
+ method : Literal ['interpolate' , 'shift' ] = 'interpolate' ,
27
+ disp_axis : int = 1 ) -> Spectrum1D :
28
28
"""
29
29
Align a 2D spectrum image along a trace either with an integer or sub-pixel precision.
30
30
31
+ This function rectifies a 2D spectrum by aligning its cross-dispersion profile along a given
32
+ trace. The function also updates the mask to reflect alignment operations and propagates
33
+ uncertainties when using the 'interpolate' method. The rectification process can use either
34
+ sub-pixel precision through interpolation or integer shifts for simplicity. The method assumes
35
+ the input spectrum is rectilinear, meaning the dispersion direction and spatial direction are
36
+ aligned with the pixel grid.
37
+
31
38
Parameters
32
39
----------
33
40
image
34
41
The 2D image to align.
35
42
trace
36
- A Trace object that defines the center of the cross-dispersion profile.
43
+ Either a ``Trace`` object, a 1D ndarray, or a single value that defines the center
44
+ of the cross-dispersion profile.
37
45
method
38
- The method used to align the image columns : ``interpolate`` aligns the
39
- image columns with a sub-pixel precision while ``shift`` does this using
40
- integer shifts.
46
+ The method used to align the image: ``interpolate`` aligns the image
47
+ with a sub-pixel precision using linear interpolation while ``shift``
48
+ aligns the image using integer shifts.
41
49
disp_axis
42
50
The index of the image's dispersion axis. [default: 1]
43
51
44
52
Returns
45
53
-------
46
54
Spectrum1D
47
- A 1D spectral representation of the input image, aligned along the specified
48
- trace and corrected for displacements. The output includes adjusted mask
49
- and uncertainty information.
50
-
51
- Raises
52
- ------
53
- ValueError
54
- If the number of dimensions of the image is not equal to 2, or
55
- if the displacement axis is not 0 or 1.
55
+ A rectified version of the image aligned along the specified trace.
56
+
57
+ Notes
58
+ -----
59
+ - This function is intended only for rectilinear spectra, where the dispersion
60
+ and spatial axes are already aligned with the image grid. Non-rectilinear spectra
61
+ require additional pre-processing (e.g., geometric rectification) before using
62
+ this function.
56
63
"""
57
64
if _get_image_ndim (image ) > 2 :
58
65
raise ValueError ('The number of image dimensions must be 2.' )
@@ -300,7 +307,7 @@ def measure_cross_dispersion_profile(image, trace=None, crossdisp_axis=0,
300
307
301
308
# now that we have figured out the mask for the window in cross-disp. axis,
302
309
# select only the pixel(s) we want to include in measuring the avg. profile
303
- pixel_mask = np .ones (( image .shape ) )
310
+ pixel_mask = np .ones (image .shape )
304
311
pixel_mask [:, pixels ] = 0
305
312
306
313
# combine these masks to isolate the rows and cols used to measure profile
0 commit comments