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 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
7b808c9
Added a new approach to 1D wavelength calibration based on minimizing…
hpparvi Jan 13, 2025
d6e2105
Fixed a minor 1D wavelength solution rebinning issue.
hpparvi Jan 13, 2025
ae5e097
Added utility functions to differentiate 1d and 2d polynomial models …
hpparvi Jan 14, 2025
459d945
Renamed and refactored the 1D wavelength calibration module.
hpparvi Jan 15, 2025
01c0b61
Added 2D wavelength calibration class and associated methods.
hpparvi Jan 15, 2025
4092340
Introduced a 2D WCS property that constructs a WCS pipeline using pix…
hpparvi Jan 15, 2025
5c28ea7
Started working on 1D wavelength calibration documentation.
hpparvi Jan 16, 2025
6174fdd
Cleaning up and documenting the 1D wavelength calibration code.
hpparvi Jan 16, 2025
daf4a80
Continuing 1D spectrum calibration documentation and cleanup.
hpparvi Jan 16, 2025
1fed51a
Refactored and enhanced WavelengthSolution1D class methods to improve…
hpparvi Jan 16, 2025
fe1c030
Added unit handling for wavelength and RMS/residual plotting.
hpparvi Jan 16, 2025
cd40364
Added a basic example notebook for 1D wavelength calibration with Spe…
hpparvi Jan 16, 2025
d492d32
Renamed some parameters for clarity in 2D wavelength calibration.
hpparvi Jan 16, 2025
3e210e1
Updated the 1D wavelength calibration plotting routines handle cases …
hpparvi Jan 17, 2025
8f2e9af
Updated logic to handle cases where `arc_spectra` is `None` and added…
hpparvi Jan 17, 2025
05080e2
Refactored `WavelengthSolution1D` to improve readability, flexibility…
hpparvi Apr 4, 2025
e884ed4
Replaced internal `_lines_pix` and `_lines_wav` attribute modificatio…
hpparvi Apr 5, 2025
eb5bd35
Fixed line matching to work with masked arrays.
hpparvi Apr 8, 2025
73aa1a1
Fixed transformation to work with masked arrays.
hpparvi Apr 8, 2025
486ee14
Updated the handling of observed and catalog lines. Introduced new me…
hpparvi Apr 13, 2025
b02f484
Introduced new optional parameters like `refine_fit` and enhanced doc…
hpparvi Apr 13, 2025
3bfdae7
Renamed `lines_pix` to `observed_lines` and `lines_wav` to `catalog_l…
hpparvi Apr 13, 2025
3f0c911
The refine_fit method now supports a max_iter parameter to control th…
hpparvi Apr 13, 2025
0a829ef
Added 1D wavelength calibration tests.
hpparvi Apr 20, 2025
c19290f
Updated WaveCal1D tests.
hpparvi Apr 20, 2025
0a6116f
Fixed minor issues while writing tests.
hpparvi Apr 20, 2025
9678d28
Updated tests.
hpparvi Apr 20, 2025
8fddbce
Added tests for wavelength-pixel transformations and WCS creation.
hpparvi Apr 21, 2025
02ed5f3
Added new tests for WavelengthSolution1D and plotting methods.
hpparvi Apr 21, 2025
159049c
Removed redundant warnings and improved error handling.
hpparvi Apr 21, 2025
e0deb65
Polished the tests.
hpparvi Apr 22, 2025
d552ce4
Cleaned up an error message.
hpparvi Apr 22, 2025
910f19e
Removed 2D wavelength calibration code from this branch. Will work on…
hpparvi Apr 22, 2025
08676f7
Renamed WavelengthSolution1D -> WavelengthCalibration1D.
hpparvi Apr 22, 2025
448bcd7
Added the first version of the WavelengthCalibration1D docs with Jupy…
hpparvi Apr 22, 2025
ba8c433
removed a reference to old wavelength_calibration module from the mai…
hpparvi Apr 22, 2025
f726665
Updated the wavelength calibration tutorial notebooks.
hpparvi Apr 23, 2025
45cb0ff
Introduced the `value_fontsize` parameter to control font size in spe…
hpparvi Apr 24, 2025
dea76cf
Revised the wavelength calibration notebooks.
hpparvi Apr 24, 2025
07cfb82
Finalised 1D wavelength calibration tutorial 1.
hpparvi Apr 24, 2025
6a03abc
Changed the wcs attribute to gwcs.
hpparvi Apr 24, 2025
7fbaace
Finalised 1D wavelength calibration tutorial 2 and polished the first…
hpparvi Apr 24, 2025
74603a4
Finished 1D wavelength calibration tutorial 3.
hpparvi Apr 24, 2025
32fa5b8
Cleaned up the wavelength calibration docs.
hpparvi Apr 24, 2025
e516189
Codestyle fixes for the 1D wavelength calibration code.
hpparvi Apr 24, 2025
2d499b9
Changed the documentation API.
hpparvi Apr 24, 2025
3034da5
Brought back the original wavelength_calibration.py code so that we d…
hpparvi Apr 24, 2025
7ac91a7
Fixed a broken WavelengthCalibration1D tests.
hpparvi Apr 24, 2025
1d7a41f
Added a docstring for the WavelengthCalibration1D initialiser.
hpparvi Apr 24, 2025
8efc5e5
Small wavelength calibration documentation fixes.
hpparvi Apr 24, 2025
20757bf
Updated the changelog.
hpparvi Apr 24, 2025
9b5dc66
Made sure the basic WavelengthCalibration1D functionality can be used…
hpparvi Apr 24, 2025
6cf7b8a
Made matplotlib a basic dependecy.
hpparvi Apr 24, 2025
dfc40c3
Revised wavelength calibration tests.
hpparvi Apr 24, 2025
f854cbe
Codestyle fix.
hpparvi Apr 24, 2025
41eda51
Added a TiltCorrection class for 2D rectification.
hpparvi May 9, 2025
fa2463c
Refactored the tilt correction code to improve readability, structure…
hpparvi May 9, 2025
9935efb
Added type annotations and a docstring for the `diff_poly2d_x` function.
hpparvi May 9, 2025
3743ccf
Renamed private methods to public and adjusted their parameters for c…
hpparvi May 13, 2025
a1c5be3
Introduced a method to transform coordinates from rectified space to …
hpparvi May 13, 2025
d2e3f43
Refactored plot functionality and add fit quality visualization.
hpparvi May 13, 2025
4eedf14
Added tilt correction tutorial and sample data.
hpparvi May 13, 2025
91a4324
Introduced `disp_axis` and `mask_treatment` parameters to enhance fle…
hpparvi May 15, 2025
8281cba
Added basic unit tests for TiltCorrection. Cover that the procedure r…
hpparvi May 15, 2025
3c2a4f1
Updated docs related to tilt correction.
hpparvi May 15, 2025
becd161
Codestyle fixes.
hpparvi May 15, 2025
4d831ba
Documentation fixes.
hpparvi May 15, 2025
fbb76c0
Documentation hack. Needs to be addressed correctly.
hpparvi May 15, 2025
e026cf0
Removed an old Jupyter Notebook file.
hpparvi Jun 17, 2025
a153d16
Added `matplotlib>=3.7` as a testing dependency in `pyproject.toml`.
hpparvi Jun 17, 2025
f15e7cb
Replaced `Spectrum1D` with `Spectrum` throughout `wavecal1d.py` for c…
hpparvi Jun 17, 2025
25bced2
Revised wavecal1d tests.
hpparvi Jun 17, 2025
1c40831
Fixed `flux` assignment in `tilt_correction.py` to ensure proper hand…
hpparvi Jun 17, 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
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
New Features
^^^^^^^^^^^^

- 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.

API Changes
^^^^^^^^^^^

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