-
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.
add basic synthetic calibration test
- Loading branch information
1 parent
545ba1e
commit 53da7f0
Showing
1 changed file
with
48 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from rascal.synthetic import SyntheticSpectrum | ||
from rascal.calibrator import Calibrator | ||
|
||
def test_default(): | ||
|
||
# Create a test spectrum with a simple linear relationship | ||
# between pixels/wavelengths. The intercept is set to | ||
# 100 nm and the dispersion is set to 2. | ||
intercept = 100 | ||
dispersion = 2.0 | ||
s = SyntheticSpectrum(coefficients = [dispersion, intercept]) | ||
|
||
# We add a bunch of wavelegnths between 200-1200 nm | ||
waves = np.linspace(200,1200, num=20) | ||
peaks = s.get_pixels(waves) | ||
assert len(peaks) > 0 | ||
|
||
# Set up the calibrator with the pixel values of our | ||
# wavelengths | ||
c = Calibrator(peaks=peaks) | ||
|
||
# Arbitrarily we'll set the number of pixels to 768 (i.e. | ||
# a max range of around 1500 nm | ||
c.set_calibrator_properties(num_pix=768) | ||
|
||
# Setup the Hough transform parameters | ||
c.set_hough_properties(range_tolerance=100., | ||
min_wavelength=100., | ||
max_wavelength=1500.) | ||
|
||
# Add our fake lines as the atlas | ||
c.add_user_atlas(elements=["Test"]*len(waves), wavelengths=waves) | ||
assert len(c.atlas) > 0 | ||
|
||
# And let's try and fit... | ||
best_p, rms, residual, peak_utilisation = c.fit(max_tries=200) | ||
|
||
best_p, x_fit, y_fit, residual, peak_utilisation = c.match_peaks( | ||
best_p, refine=False, robust_refit=True) | ||
|
||
fit_diff = c.polyval(x_fit, best_p) - y_fit | ||
rms = np.sqrt(np.sum(fit_diff**2 / len(x_fit))) | ||
|
||
assert peak_utilisation > 0.9 | ||
assert rms < 1e-6 |