Skip to content

Commit

Permalink
update tests for refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jveitchmichaelis committed Aug 12, 2023
1 parent d55d363 commit ba4b946
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
12 changes: 8 additions & 4 deletions test/test_effective_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -105,18 +105,22 @@ 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,
max_wavelength=10,
)
# 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

Expand Down
26 changes: 14 additions & 12 deletions test/test_fitted_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -118,6 +118,8 @@ def test_gmos_fit():
"sample_size": 5,
"top_n_candidate": 10,
"minimum_matches": 18,
"max_tries": 5000,
"degree": 4,
},
}

Expand Down Expand Up @@ -172,8 +174,6 @@ def test_gmos_fit():
9787.186,
]

element = ["CuAr"] * len(gmos_atlas_lines)

atlas = Atlas(
source="manual",
wavelengths=gmos_atlas_lines,
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -229,15 +229,14 @@ def test_osiris_fit():
7635.106,
7723.98,
]
element = ["HgAr"] * len(osiris_atlas_lines)

atlas = Atlas(
source="manual",
wavelengths=osiris_atlas_lines,
min_wavelength=3500.0,
max_wavelength=8000.0,
range_tolerance=500.0,
elements=element,
element="HgAr",
)

config = {
Expand All @@ -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,
},
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_hough_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions test/test_lt_sprat_auto_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -83,7 +80,7 @@
},
"atlases": [
{
"elements": ["Xe"],
"element": "Xe",
"min_wavelength": 3500,
"max_wavelength": 8200,
"min_intensity": 10.0,
Expand Down

0 comments on commit ba4b946

Please sign in to comment.