-
-
Notifications
You must be signed in to change notification settings - Fork 40
Implement 1D wavelength calibration classes #162
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d58f652
Working on line pixel refinement
rosteen 1f3483a
Testing/debugging CalibrationLine, starting on WavelengthCalibration
rosteen c54aed7
Working on model fitting and construction of resulting GWCS
rosteen 5eb4aaa
Working through bugs/testing
rosteen baa706c
Working initial implementation
rosteen 02ed67e
Codestyle
rosteen 1df8621
Match order of pixel/wavelength between CalibrationLine and Wavelengt…
rosteen eb5feea
Fix codestyle in test
rosteen 6ea98e4
Adding tests for CalibrationLine
rosteen af4a523
Fix codestlye
rosteen 568fd09
Increase atol for gaussian center
rosteen be35c09
Remove autoidentify for now, add Polynomial1D test
rosteen f3b1b9f
Add cache clearing, avoid AstropyUserWarning
rosteen 8117864
Add input_spectrum property and clear cache on setting it
rosteen 8f1535b
Add default range if method is set but not range, remove check for un…
rosteen 22e2d68
Also clear cache when updating lines or model
rosteen 4a508e3
Move fitter default to wcs call
rosteen a8ca23f
Keep storing fitter as None
rosteen 1941a26
Add docs, improve importing of new classes
rosteen 829dc5c
Remove CalibrationLine, move to astropy tables internallyt
rosteen c3ba30d
Codestyle
rosteen 62c8025
Apply suggestions from code review
rosteen 12a8661
Remove speactral_units arg, add docstring for fitter arg
rosteen 5063b5e
Update documentation, add NotImplementedError for catalog input
rosteen b6a92f8
Reverse sort frequencies
rosteen 1aa62c6
Codestyle
rosteen 7f31b61
Increase test coverage
rosteen 45939a9
Fix tests and bugs found by tests
rosteen f92bac5
Codestyle
rosteen d573219
Add QTable to catalog options
rosteen 82170a5
Finish addressing review comments
rosteen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from numpy.testing import assert_allclose | ||
|
||
import astropy.units as u | ||
from astropy.modeling.models import Polynomial1D | ||
from astropy.tests.helper import assert_quantity_allclose | ||
|
||
from specreduce.wavelength_calibration import CalibrationLine, WavelengthCalibration1D | ||
|
||
|
||
def test_linear_from_list(spec1d): | ||
test = WavelengthCalibration1D(spec1d, [(5000*u.AA, 0), (5100*u.AA, 10), | ||
(5198*u.AA, 20), (5305*u.AA, 30)]) | ||
spec2 = test.apply_to_spectrum(spec1d) | ||
|
||
assert_quantity_allclose(spec2.spectral_axis[0], 4998.8*u.AA) | ||
assert_quantity_allclose(spec2.spectral_axis[-1], 5495.169999*u.AA) | ||
|
||
|
||
def test_linear_from_calibrationline(spec1d): | ||
lines = [CalibrationLine(spec1d, 5000*u.AA, 0), CalibrationLine(spec1d, 5100*u.AA, 10), | ||
CalibrationLine(spec1d, 5198*u.AA, 20), CalibrationLine(spec1d, 5305*u.AA, 30)] | ||
test = WavelengthCalibration1D(spec1d, lines) | ||
spec2 = test.apply_to_spectrum(spec1d) | ||
|
||
assert_quantity_allclose(spec2.spectral_axis[0], 4998.8*u.AA) | ||
assert_quantity_allclose(spec2.spectral_axis[-1], 5495.169999*u.AA) | ||
|
||
|
||
def test_poly_from_calibrationline(spec1d): | ||
# This test is mostly to prove that you can use other models | ||
lines = [CalibrationLine(spec1d, 5005*u.AA, 0), CalibrationLine(spec1d, 5110*u.AA, 10), | ||
CalibrationLine(spec1d, 5214*u.AA, 20), CalibrationLine(spec1d, 5330*u.AA, 30), | ||
CalibrationLine(spec1d, 5438*u.AA, 40)] | ||
test = WavelengthCalibration1D(spec1d, lines, model=Polynomial1D(2)) | ||
test.apply_to_spectrum(spec1d) | ||
|
||
assert_allclose(test.model.parameters, [5.00477143e+03, 1.03457143e+01, 1.28571429e-02]) | ||
|
||
|
||
def test_calibrationline(spec1d_with_emission_line, spec1d_with_absorption_line): | ||
|
||
line = CalibrationLine(spec1d_with_emission_line, 5000*u.AA, 128, refinement_method='gaussian', | ||
refinement_kwargs={'range': 25}) | ||
assert_allclose(line.refine(), 129.44371, atol=0.01) | ||
|
||
line2 = CalibrationLine(spec1d_with_emission_line, 5000*u.AA, 130, refinement_method='max', | ||
refinement_kwargs={'range': 10}) | ||
assert line2.refine() == 128 | ||
|
||
line3 = CalibrationLine(spec1d_with_absorption_line, 5000*u.AA, 128, refinement_method='min', | ||
refinement_kwargs={'range': 10}) | ||
assert line3.refine() == 130 | ||
|
||
|
||
def test_replace_spectrum(spec1d, spec1d_with_emission_line): | ||
lines = [CalibrationLine(spec1d, 5000*u.AA, 0), CalibrationLine(spec1d, 5100*u.AA, 10), | ||
CalibrationLine(spec1d, 5198*u.AA, 20), CalibrationLine(spec1d, 5305*u.AA, 30)] | ||
test = WavelengthCalibration1D(spec1d, lines) | ||
# Accessing this property causes fits the model and caches the resulting WCS | ||
test.wcs | ||
assert "wcs" in test.__dict__ | ||
for line in test.lines: | ||
assert "refined_pixel" in line.__dict__ | ||
|
||
# Replace the input spectrum, which should clear the cached properties | ||
test.input_spectrum = spec1d_with_emission_line | ||
assert "wcs" not in test.__dict__ | ||
for line in test.lines: | ||
assert "refined_pixel" not in line.__dict__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this benefit from using the synthetic spectra from #165?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I think using that to expand/improve the tests can be another PR once both of these are merged.