From ba4b946d9d06abf9706b99476c87502c1cec4c49 Mon Sep 17 00:00:00 2001 From: Josh Veitch-Michaelis Date: Sat, 12 Aug 2023 22:52:09 +0200 Subject: [PATCH] update tests for refactor --- test/test_effective_pixel.py | 12 ++++++++---- test/test_fitted_coefficients.py | 26 ++++++++++++++------------ test/test_hough_transform.py | 2 +- test/test_lt_sprat_auto_atlas.py | 9 +++------ 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/test/test_effective_pixel.py b/test/test_effective_pixel.py index f12f8b0..b091890 100644 --- a/test/test_effective_pixel.py +++ b/test/test_effective_pixel.py @@ -30,7 +30,7 @@ # Effective pixel: arbitrarily we'll set the number of pixels to 768 (i.e. # a max range of around 1500 nm config = { - "data": { + "detector": { "contiguous_range": [1.0, 344.0, 345.37, 634.37], "num_pix": 634, }, @@ -62,7 +62,7 @@ def test_effective_pixel_not_affecting_fit_int_peaks(): # Set up the calibrator with the pixel values of our # wavelengths a = Atlas( - elements="Test", + element="Test", source="manual", wavelengths=np.arange(10), min_wavelength=0, @@ -105,7 +105,7 @@ def test_effective_pixel_not_affecting_fit_perfect_peaks(): # Set up the calibrator with the pixel values of our # wavelengths a = Atlas( - elements="Test", + element="Test", source="manual", wavelengths=np.arange(10), min_wavelength=0, @@ -113,10 +113,14 @@ def test_effective_pixel_not_affecting_fit_perfect_peaks(): ) # Arbitrarily we'll set the number of pixels to 768 (i.e. # a max range of around 1500 nm + + _config = config.copy() + _config["ransac"]["max_tries"] = 2000 + _config["ransac"]["degree"] = 3 c = Calibrator(peaks=peaks, atlas_lines=a.atlas_lines, config=config) # And let's try and fit... - res = c.fit(max_tries=2000, fit_deg=3) + res = c.fit() assert res diff --git a/test/test_fitted_coefficients.py b/test/test_fitted_coefficients.py index ac5d6e0..4edf97c 100644 --- a/test/test_fitted_coefficients.py +++ b/test/test_fitted_coefficients.py @@ -105,7 +105,7 @@ def test_gmos_fit(): peaks = util.refine_peaks(spectrum, peaks, window_width=3) config = { - "data": { + "detector": { "contiguous_range": [0, 1023, 1057.5, 2080.5, 2115.0, 3138.0] }, "hough": { @@ -118,6 +118,8 @@ def test_gmos_fit(): "sample_size": 5, "top_n_candidate": 10, "minimum_matches": 18, + "max_tries": 5000, + "degree": 4, }, } @@ -172,8 +174,6 @@ def test_gmos_fit(): 9787.186, ] - element = ["CuAr"] * len(gmos_atlas_lines) - atlas = Atlas( source="manual", wavelengths=gmos_atlas_lines, @@ -186,7 +186,7 @@ def test_gmos_fit(): pressure=61700.0, temperature=276.55, relative_humidity=4.0, - elements=element, + element="CuAr", ) # Initialise the calibrator @@ -197,7 +197,7 @@ def test_gmos_fit(): c.do_hough_transform() # Run the wavelength calibration - res = c.fit(max_tries=5000, fit_deg=4) + res = c.fit() assert res["success"] assert np.isclose( @@ -229,7 +229,6 @@ def test_osiris_fit(): 7635.106, 7723.98, ] - element = ["HgAr"] * len(osiris_atlas_lines) atlas = Atlas( source="manual", @@ -237,7 +236,7 @@ def test_osiris_fit(): min_wavelength=3500.0, max_wavelength=8000.0, range_tolerance=500.0, - elements=element, + element="HgAr", ) config = { @@ -259,6 +258,9 @@ def test_osiris_fit(): "hough_weight": 1.0, "minimum_matches": 11, "sampler": "probabilistic", + "max_tries": 5000, + "fit_tolerance": 10.0, + "degree": 4, }, } @@ -290,7 +292,7 @@ def test_osiris_fit(): c.do_hough_transform() # Run the wavelength calibration - res = c.fit(max_tries=5000, fit_tolerance=10.0, fit_deg=4) + res = c.fit() assert np.isclose( res["fit_coeff"][:2], osiris_fit_coeff[:2], rtol=0.02 @@ -366,15 +368,13 @@ def test_sprat_fit(): 7967.34, 8057.258, ] - element = ["Xe"] * len(sprat_atlas_lines) - atlas = Atlas( source="manual", wavelengths=sprat_atlas_lines, min_wavelength=3500.0, max_wavelength=8000.0, range_tolerance=500.0, - elements=element, + elements="Xe", pressure=pressure, temperature=temperature, relative_humidity=relative_humidity, @@ -392,6 +392,8 @@ def test_sprat_fit(): "sample_size": 5, "top_n_candidate": 5, "filter_close": True, + "max_tries": 5000, + "candidate_tolerance": 3.0, }, } @@ -403,7 +405,7 @@ def test_sprat_fit(): c.do_hough_transform() # Run the wavelength calibration - res = c.fit(max_tries=5000, candidate_tolerance=3.0) + res = c.fit() assert np.isclose( res["fit_coeff"][:2], sprat_fit_coeff[:2], rtol=0.02 diff --git a/test/test_hough_transform.py b/test/test_hough_transform.py index 98419c5..909292b 100644 --- a/test/test_hough_transform.py +++ b/test/test_hough_transform.py @@ -169,7 +169,7 @@ def test_extending_ht_expect_fail(): def test_loading_ht_into_calibrator(): user_atlas = Atlas( - elements="Test", + element="Test", source="manual", wavelengths=np.arange(10), min_wavelength=0, diff --git a/test/test_lt_sprat_auto_atlas.py b/test/test_lt_sprat_auto_atlas.py index 71cc75d..1e4ec15 100644 --- a/test/test_lt_sprat_auto_atlas.py +++ b/test/test_lt_sprat_auto_atlas.py @@ -6,16 +6,13 @@ import pkg_resources import pytest from astropy.io import fits -from rascal import util -from rascal.atlas import Atlas -from rascal.calibrator import Calibrator from scipy.signal import find_peaks # Suppress tqdm output from tqdm import tqdm from rascal import util -from rascal.atlas import AtlasCollection +from rascal.atlas import Atlas, AtlasCollection from rascal.calibrator import Calibrator logging.basicConfig(level=logging.DEBUG) @@ -61,7 +58,7 @@ print(len(sprat_atlas_lines)) config = { - "data": { + "detector": { "contiguous_range": None, "detector_min_wave": 3500.0, "detector_max_wave": 8200.0, @@ -83,7 +80,7 @@ }, "atlases": [ { - "elements": ["Xe"], + "element": "Xe", "min_wavelength": 3500, "max_wavelength": 8200, "min_intensity": 10.0,