-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for linear and quadratic tests, show agreement to better …
…than 0.1%. Also added basic tests for Legendre and Chebyshev polynomial fit. Potentially fixed RTD broken API generation.
- Loading branch information
1 parent
da4527f
commit 6ba4bef
Showing
12 changed files
with
186 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -133,3 +133,4 @@ iframe_figures/ | |
# test output | ||
test/*.json | ||
test/*.npy | ||
test/*.png |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -3,4 +3,4 @@ scipy | |
pynverse | ||
matplotlib | ||
tqdm | ||
pytest | ||
astropy |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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,116 @@ | ||
import numpy as np | ||
from rascal.calibrator import Calibrator | ||
|
||
peaks = np.sort(np.random.random(31) * 1000.) | ||
|
||
# Line list | ||
wavelengths_linear = 3000. + 5. * peaks | ||
wavelengths_quadratic = 3000. + 4 * peaks + 1.0e-3 * peaks**2. | ||
|
||
elements_linear = ['Linear'] * len(wavelengths_linear) | ||
elements_quadratic = ['Quadratic'] * len(wavelengths_quadratic) | ||
|
||
|
||
def test_linear_fit(): | ||
|
||
# Initialise the calibrator | ||
c = Calibrator(peaks) | ||
c.set_calibrator_properties(num_pix=1000) | ||
c.set_hough_properties(num_slopes=1000, | ||
range_tolerance=500., | ||
xbins=200, | ||
ybins=200, | ||
min_wavelength=3000., | ||
max_wavelength=8000.) | ||
c.add_user_atlas(elements=elements_linear, wavelengths=wavelengths_linear) | ||
c.set_ransac_properties() | ||
|
||
# Run the wavelength calibration | ||
best_p, rms, residual, peak_utilisation = c.fit(max_tries=500, fit_deg=1) | ||
# Refine solution | ||
best_p, x_fit, y_fit, residual, peak_utilisation = c.match_peaks( | ||
best_p, refine=False, robust_refit=True) | ||
|
||
assert (best_p[1] > 5. * 0.999) & (best_p[1] < 5. * 1.001) | ||
assert (best_p[0] > 3000. * 0.999) & (best_p[0] < 3000. * 1.001) | ||
|
||
|
||
def test_quadratic_fit(): | ||
|
||
# Initialise the calibrator | ||
c = Calibrator(peaks) | ||
c.set_calibrator_properties(num_pix=1000) | ||
c.set_hough_properties(num_slopes=1000, | ||
range_tolerance=500., | ||
xbins=100, | ||
ybins=100, | ||
min_wavelength=3000., | ||
max_wavelength=8000.) | ||
c.add_user_atlas(elements=elements_quadratic, | ||
wavelengths=wavelengths_quadratic) | ||
c.set_ransac_properties() | ||
|
||
# Run the wavelength calibration | ||
best_p, rms, residual, peak_utilisation = c.fit(max_tries=1000, fit_deg=2) | ||
# Refine solution | ||
best_p, x_fit, y_fit, residual, peak_utilisation = c.match_peaks( | ||
best_p, refine=False, robust_refit=True) | ||
|
||
assert (best_p[2] > 1e-3 * 0.999) & (best_p[2] < 1e-3 * 1.001) | ||
assert (best_p[1] > 4. * 0.999) & (best_p[1] < 4. * 1.001) | ||
assert (best_p[0] > 3000. * 0.999) & (best_p[0] < 3000. * 1.001) | ||
|
||
|
||
def test_quadratic_fit_legendre(): | ||
|
||
# Initialise the calibrator | ||
c = Calibrator(peaks) | ||
c.set_calibrator_properties(num_pix=1000) | ||
c.set_hough_properties(num_slopes=500, | ||
range_tolerance=200., | ||
xbins=100, | ||
ybins=100, | ||
min_wavelength=3000., | ||
max_wavelength=8000.) | ||
c.add_user_atlas(elements=elements_quadratic, | ||
wavelengths=wavelengths_quadratic) | ||
c.set_ransac_properties(sample_size=10) | ||
|
||
# Run the wavelength calibration | ||
best_p, rms, residual, peak_utilisation = c.fit(max_tries=1000, | ||
fit_tolerance=5., | ||
candidate_tolerance=2., | ||
fit_deg=2, | ||
fit_type='legendre') | ||
|
||
# Legendre 2nd order takes the form | ||
assert (best_p[2] > 1e-3 * 0.999) & (best_p[2] < 1e-3 * 1.001) | ||
assert (best_p[1] > 4. * 0.999) & (best_p[1] < 4. * 1.001) | ||
assert (best_p[0] > 3000. * 0.999) & (best_p[0] < 3000. * 1.001) | ||
|
||
|
||
def test_quadratic_fit_chebyshev(): | ||
|
||
# Initialise the calibrator | ||
c = Calibrator(peaks) | ||
c.set_calibrator_properties(num_pix=1000) | ||
c.set_hough_properties(num_slopes=500, | ||
range_tolerance=200., | ||
xbins=100, | ||
ybins=100, | ||
min_wavelength=3000., | ||
max_wavelength=8000.) | ||
c.add_user_atlas(elements=elements_quadratic, | ||
wavelengths=wavelengths_quadratic) | ||
c.set_ransac_properties(sample_size=10) | ||
|
||
# Run the wavelength calibration | ||
best_p, rms, residual, peak_utilisation = c.fit(max_tries=1000, | ||
fit_tolerance=5., | ||
candidate_tolerance=2., | ||
fit_deg=2, | ||
fit_type='chebyshev') | ||
|
||
assert (best_p[2] > 1e-3 * 0.999) & (best_p[2] < 1e-3 * 1.001) | ||
assert (best_p[1] > 4. * 0.999) & (best_p[1] < 4. * 1.001) | ||
assert (best_p[0] > 3000. * 0.999) & (best_p[0] < 3000. * 1.001) |
This file contains 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