Skip to content

1D Wavelength Calibration and 2D tilt correction #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 76 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
2ccf22d
Added "Spectrum" to ``__all__` in ``specreduce.compat``.
hpparvi Jul 15, 2025
705d232
Added a new approach to 1D wavelength calibration based on minimizing…
hpparvi Jan 13, 2025
f63fab8
Fixed a minor 1D wavelength solution rebinning issue.
hpparvi Jan 13, 2025
885f0ef
Added utility functions to differentiate 1d and 2d polynomial models …
hpparvi Jan 14, 2025
82d1e00
Renamed and refactored the 1D wavelength calibration module.
hpparvi Jan 15, 2025
0c8f574
Added 2D wavelength calibration class and associated methods.
hpparvi Jan 15, 2025
3e5c36b
Introduced a 2D WCS property that constructs a WCS pipeline using pix…
hpparvi Jan 15, 2025
6bfa846
Started working on 1D wavelength calibration documentation.
hpparvi Jan 16, 2025
fd58c2a
Cleaning up and documenting the 1D wavelength calibration code.
hpparvi Jan 16, 2025
3b42370
Continuing 1D spectrum calibration documentation and cleanup.
hpparvi Jan 16, 2025
4669afd
Refactored and enhanced WavelengthSolution1D class methods to improve…
hpparvi Jan 16, 2025
ba0b58a
Added unit handling for wavelength and RMS/residual plotting.
hpparvi Jan 16, 2025
4b788be
Added a basic example notebook for 1D wavelength calibration with Spe…
hpparvi Jan 16, 2025
8b64079
Renamed some parameters for clarity in 2D wavelength calibration.
hpparvi Jan 16, 2025
25ab353
Updated the 1D wavelength calibration plotting routines handle cases …
hpparvi Jan 17, 2025
f995f85
Updated logic to handle cases where `arc_spectra` is `None` and added…
hpparvi Jan 17, 2025
c6a6b7a
Refactored `WavelengthSolution1D` to improve readability, flexibility…
hpparvi Apr 4, 2025
58d3bbd
Replaced internal `_lines_pix` and `_lines_wav` attribute modificatio…
hpparvi Apr 5, 2025
30cc05d
Fixed line matching to work with masked arrays.
hpparvi Apr 8, 2025
a6d0816
Fixed transformation to work with masked arrays.
hpparvi Apr 8, 2025
e668b53
Updated the handling of observed and catalog lines. Introduced new me…
hpparvi Apr 13, 2025
12f38d6
Introduced new optional parameters like `refine_fit` and enhanced doc…
hpparvi Apr 13, 2025
901825b
Renamed `lines_pix` to `observed_lines` and `lines_wav` to `catalog_l…
hpparvi Apr 13, 2025
ac0a282
The refine_fit method now supports a max_iter parameter to control th…
hpparvi Apr 13, 2025
098622a
Added 1D wavelength calibration tests.
hpparvi Apr 20, 2025
dafa2b7
Updated WaveCal1D tests.
hpparvi Apr 20, 2025
cd32b07
Fixed minor issues while writing tests.
hpparvi Apr 20, 2025
6d4853f
Updated tests.
hpparvi Apr 20, 2025
9615a1a
Added tests for wavelength-pixel transformations and WCS creation.
hpparvi Apr 21, 2025
a8e6aac
Added new tests for WavelengthSolution1D and plotting methods.
hpparvi Apr 21, 2025
588324e
Removed redundant warnings and improved error handling.
hpparvi Apr 21, 2025
3b31270
Polished the tests.
hpparvi Apr 22, 2025
e1f5220
Cleaned up an error message.
hpparvi Apr 22, 2025
42af922
Removed 2D wavelength calibration code from this branch. Will work on…
hpparvi Apr 22, 2025
3a23cd7
Renamed WavelengthSolution1D -> WavelengthCalibration1D.
hpparvi Apr 22, 2025
8a25549
Added the first version of the WavelengthCalibration1D docs with Jupy…
hpparvi Apr 22, 2025
c9fe759
removed a reference to old wavelength_calibration module from the mai…
hpparvi Apr 22, 2025
26b8c49
Updated the wavelength calibration tutorial notebooks.
hpparvi Apr 23, 2025
fb49f15
Introduced the `value_fontsize` parameter to control font size in spe…
hpparvi Apr 24, 2025
a41d033
Revised the wavelength calibration notebooks.
hpparvi Apr 24, 2025
3465567
Finalised 1D wavelength calibration tutorial 1.
hpparvi Apr 24, 2025
e41cea7
Changed the wcs attribute to gwcs.
hpparvi Apr 24, 2025
1b55d63
Finalised 1D wavelength calibration tutorial 2 and polished the first…
hpparvi Apr 24, 2025
0823c4a
Finished 1D wavelength calibration tutorial 3.
hpparvi Apr 24, 2025
11f8fca
Cleaned up the wavelength calibration docs.
hpparvi Apr 24, 2025
eb0ed36
Codestyle fixes for the 1D wavelength calibration code.
hpparvi Apr 24, 2025
25144b8
Changed the documentation API.
hpparvi Apr 24, 2025
39a5d5c
Brought back the original wavelength_calibration.py code so that we d…
hpparvi Apr 24, 2025
1d361f1
Fixed a broken WavelengthCalibration1D tests.
hpparvi Apr 24, 2025
1243b7f
Added a docstring for the WavelengthCalibration1D initialiser.
hpparvi Apr 24, 2025
f247cf7
Small wavelength calibration documentation fixes.
hpparvi Apr 24, 2025
fc8c0b9
Updated the changelog.
hpparvi Apr 24, 2025
6fa9b3c
Made sure the basic WavelengthCalibration1D functionality can be used…
hpparvi Apr 24, 2025
f74c904
Made matplotlib a basic dependecy.
hpparvi Apr 24, 2025
e4ed588
Revised wavelength calibration tests.
hpparvi Apr 24, 2025
1b2a960
Codestyle fix.
hpparvi Apr 24, 2025
b349d03
Added a TiltCorrection class for 2D rectification.
hpparvi May 9, 2025
b8f2fdc
Refactored the tilt correction code to improve readability, structure…
hpparvi May 9, 2025
567ec43
Added type annotations and a docstring for the `diff_poly2d_x` function.
hpparvi May 9, 2025
e21c95a
Renamed private methods to public and adjusted their parameters for c…
hpparvi May 13, 2025
ae49deb
Introduced a method to transform coordinates from rectified space to …
hpparvi May 13, 2025
a65bcfa
Refactored plot functionality and add fit quality visualization.
hpparvi May 13, 2025
8cf8ffd
Added tilt correction tutorial and sample data.
hpparvi May 13, 2025
db5f962
Introduced `disp_axis` and `mask_treatment` parameters to enhance fle…
hpparvi May 15, 2025
bf503bf
Added basic unit tests for TiltCorrection. Cover that the procedure r…
hpparvi May 15, 2025
e7d399d
Updated docs related to tilt correction.
hpparvi May 15, 2025
f8e92b4
Codestyle fixes.
hpparvi May 15, 2025
a4c9864
Documentation fixes.
hpparvi May 15, 2025
bf4b47c
Documentation hack. Needs to be addressed correctly.
hpparvi May 15, 2025
f722a3c
Removed an old Jupyter Notebook file.
hpparvi Jun 17, 2025
9fb67ce
Added `matplotlib>=3.7` as a testing dependency in `pyproject.toml`.
hpparvi Jun 17, 2025
77c63b8
Replaced `Spectrum1D` with `Spectrum` throughout `wavecal1d.py` for c…
hpparvi Jun 17, 2025
b46fdb5
Revised wavecal1d tests.
hpparvi Jun 17, 2025
538d2b8
Fixed `flux` assignment in `tilt_correction.py` to ensure proper hand…
hpparvi Jun 17, 2025
786bded
Refactored observed line handling in `wavecal1d.py`, added amplitude …
hpparvi Jul 8, 2025
2785323
Improved uncertainty type handling in WavelengthCalibration1D.
hpparvi Jul 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ New Features

- Added a ``disp_bounds`` argument to ``tracing.FitTrace``. The argument allows for adjusting the
dispersion-axis window from which the trace peaks are estimated.
- Added a new ``specreduce.wavecal1d.WavelengthCalibration1D`` class for one-dimensional wavelength
calibration. The old ``specreduce.wavelength_calibration.WavelengthCalibration1D`` is
deprecated and will be removed in v. 2.0.

1.6.0 (2025-06-18)
------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ API Index
.. automodapi:: specreduce.extract
:no-inheritance-diagram:

.. automodapi:: specreduce.wavecal1d
:no-inheritance-diagram:

.. automodapi:: specreduce.calibration_data
:no-inheritance-diagram:
:include-all-objects:
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
man_pages = [('index', project.lower(), project + u' Documentation',
[author], 1)]

extensions.append('nbsphinx')

# -- Options for the edit_on_github extension ---------------------------------

Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Calibration
.. toctree::
:maxdepth: 1

wavelength_calibration.rst
tilt_correction/tilt_correction.rst
wavelength_calibration/wavelength_calibration.rst
extinction.rst
specphot_standards.rst
mask_treatment/mask_treatment.rst
Expand Down
19 changes: 19 additions & 0 deletions docs/tilt_correction/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path

from astropy import units as u
from astropy.io import fits as pf
from astropy.nddata import CCDData, VarianceUncertainty


def read_file(fname, bias):
d = pf.getdata(fname).astype('d')
return CCDData(d - bias, unit=u.dn, uncertainty=VarianceUncertainty(d))


def read_data():
bias = pf.getdata('gtc_osiris_example/osiris_bias.fits.bz2').astype('d')
obj = read_file('gtc_osiris_example/osiris_tres_3b.fits.bz2', bias)
lamps = 'HgAr', 'Ne', 'Xe'
arc_files = sorted(Path('gtc_osiris_example').glob('*arc*'))
arcs = [read_file(f, bias) for f in arc_files]
return arcs, lamps, obj
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
454 changes: 454 additions & 0 deletions docs/tilt_correction/osiris_example.ipynb

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions docs/tilt_correction/tilt_correction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Tilt Correction
===============

In astronomical spectroscopy, tilt correction is a calibration step that addresses optical
distortions and misalignments in spectroscopic instruments. These distortions cause wavelength
to vary along the cross-dispersion (spatial) axis, resulting in spectral features appearing
tilted or curved across the detector rather than being perfectly aligned with detector columns.

Tilt correction is performed by modeling a two-dimensional tilt function that describes how
wavelength positions shift across the spatial axis. This function can be determined empirically
from arc lamp calibration spectra by measuring how the centroids of emission lines vary along
the cross-dispersion axis.

Once characterized, the tilt function enables transformation of two-dimensional spectroscopic
images so that wavelengths become aligned along straight lines parallel to the detector axes (a
process known as 2D rectification). This alignment is essential for achieving accurate
wavelength calibration and performing robust sky subtraction.

In the `specreduce` package, the tilt function is represented as a 2D polynomial using an
``~astropy.modeling.models.Polynomial2D`` instance of a specified degree. The
``~specreduce.tilt_correction.TiltCorrection`` class implements this correction through several
steps:

1. Identifying emission lines in one or more arc lamp calibration spectra for a given number of
cross-dispersion sample positions
2. Fitting a 2D polynomial model to characterize the geometric distortion
3. Computing a transformation that maps the tilted features to straight lines
4. Applying this transformation to rectify the observed frames


Tutorials
---------

The following tutorial provides hands-on examples demonstrating the usage of the
``~specreduce.tilt_correction.TiltCorrection`` class.

.. toctree::
:maxdepth: 1

osiris_example.ipynb
53 changes: 0 additions & 53 deletions docs/wavelength_calibration.rst

This file was deleted.

Binary file added docs/wavelength_calibration/osiris_arcs.fits
Binary file not shown.
Binary file not shown.
596 changes: 596 additions & 0 deletions docs/wavelength_calibration/wavecal1d_example_01.ipynb

Large diffs are not rendered by default.

339 changes: 339 additions & 0 deletions docs/wavelength_calibration/wavecal1d_example_02.ipynb

Large diffs are not rendered by default.

398 changes: 398 additions & 0 deletions docs/wavelength_calibration/wavecal1d_example_03.ipynb

Large diffs are not rendered by default.

Loading
Loading