Skip to content

Commit fd5ece3

Browse files
committed
Changed the 2D image rectification function name to 'align_2d_spectrum_along_trace' and improved its docstring.
1 parent 984fefe commit fd5ece3

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

specreduce/utils/utils.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from specreduce.tracing import Trace, FlatTrace
1010
from specreduce.extract import _ap_weight_image, _align_along_trace
1111

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']
1313

1414

1515
def _get_image_ndim(image):
@@ -21,38 +21,45 @@ def _get_image_ndim(image):
2121
raise ValueError('Unrecognized image data format.')
2222

2323

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:
2828
"""
2929
Align a 2D spectrum image along a trace either with an integer or sub-pixel precision.
3030
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+
3138
Parameters
3239
----------
3340
image
3441
The 2D image to align.
3542
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.
3745
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.
4149
disp_axis
4250
The index of the image's dispersion axis. [default: 1]
4351
4452
Returns
4553
-------
4654
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.
5663
"""
5764
if _get_image_ndim(image) > 2:
5865
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,
300307

301308
# now that we have figured out the mask for the window in cross-disp. axis,
302309
# 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)
304311
pixel_mask[:, pixels] = 0
305312

306313
# combine these masks to isolate the rows and cols used to measure profile

0 commit comments

Comments
 (0)