Files
debye_bec/tests/tests_devices/test_mo1_bragg_utils.py
gac-x01da 0fbc700f1b Moved spline computation to separate file
Added tests for spline computation
Refactoring
2024-09-13 11:47:47 +02:00

22 lines
2.0 KiB
Python

# pylint: skip-file
import debye_bec.devices.utils.mo1_bragg_utils as utils
import numpy as np
def test_compute_spline():
p, v, dt = utils.compute_spline(low_deg=10, high_deg=12, p_kink=50, e_kink_deg=11, scan_time=0.5)
rtol = 1e-6
atol = 1e-3
p_desired = [9.98,9.98376125,9.99479,10.01270375,10.03712,10.06765625,10.10393,10.14555875,10.19216,10.24335125,10.29875,10.35797375,10.42064,10.48636625,10.55477,10.62546875,10.69808,10.77222125,10.84751,10.92356375,11.,11.07643625,11.15249,11.22777875,11.30192,11.37453125,11.44523,11.51363375,11.57936,11.64202625,11.70125,11.75664875,11.80784,11.85444125,11.89607,11.93234375,11.96288,11.98729625,12.00521,12.01623875,12.02]
v_desired = [0.,1.50156441,2.35715667,2.90783907,3.29035796,3.57019636,3.78263174,3.9483388,4.08022441,4.18675043,4.27368333,4.34507577,4.40384627,4.45213618,4.49153736,4.52324148,4.54814006,4.5668924,4.57997194,4.58769736,4.59025246,4.58769736,4.57997194,4.5668924,4.54814006,4.52324148,4.49153736,4.45213618,4.40384627,4.34507577,4.27368333,4.18675043,4.08022441,3.9483388,3.78263174,3.57019636,3.29035796,2.90783907,2.35715667,1.50156441,0.]
dt_desired = [0.,4.34081063,5.57222438,6.73882688,7.84061813,8.87759812,9.84976688,10.75712437,11.59967063,12.37740563,13.09032937,13.73844188,14.32174313,14.84023312,15.29391188,15.68277937,16.00683562,16.26608063,16.46051438,16.59013687,16.65494813,16.65494813,16.59013687,16.46051438,16.26608063,16.00683562,15.68277938,15.29391188,14.84023312,14.32174313,13.73844187,13.09032938,12.37740562,11.59967063,10.75712437,9.84976687,8.87759813,7.84061812,6.73882688,5.57222437,4.34081063]
np.testing.assert_allclose(p, p_desired, rtol, atol)
np.testing.assert_allclose(v, v_desired, rtol, atol)
np.testing.assert_allclose(dt, dt_desired, rtol, atol)
assert(utils.SAFETY_FACTOR == 0.025)
assert(utils.N_SAMPLES == 41)
assert(utils.DEGREE_SPLINE == 3)
assert(utils.TIME_COMPENSATE_SPLINE == 0.0062)
assert(utils.POSITION_COMPONSATION == 0.02)