Skip to content
Snippets Groups Projects
Commit b9630090 authored by David Hammer's avatar David Hammer
Browse files

Update tests

parent e3377901
No related branches found
No related tags found
2 merge requests!12Snapshot: field test deployed version as of end of run 202201,!3Base correction device, CalCat interaction, DSSC and AGIPD devices
from calng import utils
calls = 0
@utils.threadsafe_cache
def will_raise_once(argument):
global calls
calls += 1
if calls == 1:
raise Exception("That's just what I do")
return argument + 1
try:
will_raise_once(0)
except Exception as ex:
print("As expected, firs call raised:", ex)
print("Now calling again:")
print(will_raise_once(0))
...@@ -3,7 +3,7 @@ import numpy as np ...@@ -3,7 +3,7 @@ import numpy as np
import pathlib import pathlib
import pytest import pytest
from calng import agipd_gpu from calng import AgipdCorrection
input_dtype = np.uint16 input_dtype = np.uint16
output_dtype = np.float16 output_dtype = np.float16
...@@ -30,7 +30,7 @@ with h5py.File(caldb_prefix / "cal.1619543664.1545036.h5", "r") as fd: ...@@ -30,7 +30,7 @@ with h5py.File(caldb_prefix / "cal.1619543664.1545036.h5", "r") as fd:
with h5py.File(caldb_prefix / "cal.1615377705.8904035.h5", "r") as fd: with h5py.File(caldb_prefix / "cal.1615377705.8904035.h5", "r") as fd:
slopes_pc_map = np.array(fd["/AGIPD_SIV1_AGIPDV11_M305/SlopesPC/0/data"]) slopes_pc_map = np.array(fd["/AGIPD_SIV1_AGIPDV11_M305/SlopesPC/0/data"])
kernel_runner = agipd_gpu.AgipdGpuRunner( kernel_runner = AgipdCorrection.AgipdGpuRunner(
pixels_x, pixels_x,
pixels_y, pixels_y,
memory_cells, memory_cells,
...@@ -85,7 +85,7 @@ def test_thresholding(): ...@@ -85,7 +85,7 @@ def test_thresholding():
kernel_runner.load_cell_table(cell_table) kernel_runner.load_cell_table(cell_table)
kernel_runner.load_data(raw_data) kernel_runner.load_data(raw_data)
kernel_runner.load_thresholds(thresholds) kernel_runner.load_thresholds(thresholds)
kernel_runner.correct(agipd_gpu.CorrectionFlags.THRESHOLD) kernel_runner.correct(AgipdCorrection.CorrectionFlags.THRESHOLD)
gpu_res = kernel_runner.gain_map_gpu.get() gpu_res = kernel_runner.gain_map_gpu.get()
assert np.allclose(gpu_res, gain_map_cpu) assert np.allclose(gpu_res, gain_map_cpu)
...@@ -97,7 +97,8 @@ def test_offset(): ...@@ -97,7 +97,8 @@ def test_offset():
kernel_runner.load_offset_map(offset_map) kernel_runner.load_offset_map(offset_map)
# have to do thresholding, otherwise all is treated as high gain # have to do thresholding, otherwise all is treated as high gain
kernel_runner.correct( kernel_runner.correct(
agipd_gpu.CorrectionFlags.THRESHOLD | agipd_gpu.CorrectionFlags.OFFSET AgipdCorrection.CorrectionFlags.THRESHOLD
| AgipdCorrection.CorrectionFlags.OFFSET
) )
cpu_res = corr_offset_cpu(raw_data, cell_table, gain_map_cpu, offset_map) cpu_res = corr_offset_cpu(raw_data, cell_table, gain_map_cpu, offset_map)
gpu_res = kernel_runner.processed_data_gpu.get() gpu_res = kernel_runner.processed_data_gpu.get()
...@@ -110,7 +111,8 @@ def test_rel_gain_pc(): ...@@ -110,7 +111,8 @@ def test_rel_gain_pc():
kernel_runner.load_thresholds(thresholds) kernel_runner.load_thresholds(thresholds)
kernel_runner.load_rel_gain_pc_map(slopes_pc_map) kernel_runner.load_rel_gain_pc_map(slopes_pc_map)
kernel_runner.correct( kernel_runner.correct(
agipd_gpu.CorrectionFlags.THRESHOLD | agipd_gpu.CorrectionFlags.REL_GAIN_PC AgipdCorrection.CorrectionFlags.THRESHOLD
| AgipdCorrection.CorrectionFlags.REL_GAIN_PC
) )
cpu_res = corr_rel_gain_pc_cpu(raw_data, cell_table, gain_map_cpu, slopes_pc_map) cpu_res = corr_rel_gain_pc_cpu(raw_data, cell_table, gain_map_cpu, slopes_pc_map)
gpu_res = kernel_runner.processed_data_gpu.get() gpu_res = kernel_runner.processed_data_gpu.get()
......
import pathlib import pathlib
import timeit import timeit
from calng import calcat_utils from calng import AgipdCorrection, DsscCorrection
from calng.utils import Stopwatch from calng.utils import Stopwatch
from karabo.bound import Hash, Schema from karabo.bound import Hash, Schema
import pytest
# TODO: secrets management # TODO: secrets management
_test_dir = pathlib.Path(__file__).absolute().parent _test_dir = pathlib.Path(__file__).absolute().parent
...@@ -39,13 +40,13 @@ class DummyAgipdDevice(DummyBaseDevice): ...@@ -39,13 +40,13 @@ class DummyAgipdDevice(DummyBaseDevice):
@staticmethod @staticmethod
def expectedParameters(expected): def expectedParameters(expected):
calcat_utils.AgipdCalcatFriend.add_schema( AgipdCorrection.AgipdCalcatFriend.add_schema(
expected, DummyAgipdDevice.managed_keys expected, DummyAgipdDevice.managed_keys
) )
def __init__(self, config): def __init__(self, config):
self.schema = config self.schema = config
self.calibration_constant_manager = calcat_utils.AgipdCalcatFriend( self.calibration_constant_manager = AgipdCorrection.AgipdCalcatFriend(
self, self,
_test_calcat_secrets_fn, _test_calcat_secrets_fn,
) )
...@@ -53,8 +54,6 @@ class DummyAgipdDevice(DummyBaseDevice): ...@@ -53,8 +54,6 @@ class DummyAgipdDevice(DummyBaseDevice):
DummyAgipdDevice.expectedParameters(DummyAgipdDevice.device_class_schema) DummyAgipdDevice.expectedParameters(DummyAgipdDevice.device_class_schema)
print(DummyAgipdDevice.device_class_schema)
print(DummyAgipdDevice.managed_keys)
class DummyDsscDevice(DummyBaseDevice): class DummyDsscDevice(DummyBaseDevice):
...@@ -63,13 +62,14 @@ class DummyDsscDevice(DummyBaseDevice): ...@@ -63,13 +62,14 @@ class DummyDsscDevice(DummyBaseDevice):
@staticmethod @staticmethod
def expectedParameters(expected): def expectedParameters(expected):
# super(DummyDsscDevice, DummyDsscDevice).expectedParameters(expected) DsscCorrection.DsscCalcatFriend.add_schema(
calcat_utils.DsscCalcatFriend.add_schema(expected, DummyDsscDevice.managed_keys) expected, DummyDsscDevice.managed_keys
)
def __init__(self, config): def __init__(self, config):
# TODO: check config against schema (as Karabo would) # TODO: check config against schema (as Karabo would)
self.schema = config self.schema = config
self.calibration_constant_manager = calcat_utils.DsscCalcatFriend( self.calibration_constant_manager = DsscCorrection.DsscCalcatFriend(
self, self,
_test_calcat_secrets_fn, _test_calcat_secrets_fn,
) )
...@@ -78,6 +78,7 @@ class DummyDsscDevice(DummyBaseDevice): ...@@ -78,6 +78,7 @@ class DummyDsscDevice(DummyBaseDevice):
DummyDsscDevice.expectedParameters(DummyDsscDevice.device_class_schema) DummyDsscDevice.expectedParameters(DummyDsscDevice.device_class_schema)
@pytest.mark.skip(reason="Async currently behind lock, so no concurrent funt")
def test_agipd_constants_and_caching_and_async(): def test_agipd_constants_and_caching_and_async():
# def test_agipd_constants(): # def test_agipd_constants():
conf = Hash() conf = Hash()
...@@ -101,7 +102,7 @@ def test_agipd_constants_and_caching_and_async(): ...@@ -101,7 +102,7 @@ def test_agipd_constants_and_caching_and_async():
with Stopwatch() as timer_async_cold: with Stopwatch() as timer_async_cold:
# TODO: put this sort of thing in BaseCalcatFriend # TODO: put this sort of thing in BaseCalcatFriend
threads = [] threads = []
for constant in calcat_utils.AgipdConstants: for constant in AgipdCorrection.AgipdConstants:
thread = device.calibration_constant_manager.get_constant_version_and_call_me_back( thread = device.calibration_constant_manager.get_constant_version_and_call_me_back(
constant, backcall constant, backcall
) )
...@@ -111,7 +112,7 @@ def test_agipd_constants_and_caching_and_async(): ...@@ -111,7 +112,7 @@ def test_agipd_constants_and_caching_and_async():
with Stopwatch() as timer_async_warm: with Stopwatch() as timer_async_warm:
threads = [] threads = []
for constant in calcat_utils.AgipdConstants: for constant in AgipdCorrection.AgipdConstants:
thread = device.calibration_constant_manager.get_constant_version_and_call_me_back( thread = device.calibration_constant_manager.get_constant_version_and_call_me_back(
constant, backcall constant, backcall
) )
...@@ -120,7 +121,7 @@ def test_agipd_constants_and_caching_and_async(): ...@@ -120,7 +121,7 @@ def test_agipd_constants_and_caching_and_async():
thread.join() thread.join()
with Stopwatch() as timer_sync_warm: with Stopwatch() as timer_sync_warm:
for constant in calcat_utils.AgipdConstants: for constant in AgipdCorrection.AgipdConstants:
data = device.calibration_constant_manager.get_constant_version( data = device.calibration_constant_manager.get_constant_version(
constant, constant,
) )
......
import numpy as np import numpy as np
import pytest import pytest
from calng import dssc_gpu from calng import DsscCorrection
input_dtype = np.uint16 input_dtype = np.uint16
output_dtype = np.float16 output_dtype = np.float16
...@@ -31,7 +31,7 @@ corrected_data = correct_cpu(raw_data, cell_table, offset_map) ...@@ -31,7 +31,7 @@ corrected_data = correct_cpu(raw_data, cell_table, offset_map)
only_cast_data = np.squeeze(raw_data).astype(output_dtype) only_cast_data = np.squeeze(raw_data).astype(output_dtype)
kernel_runner = dssc_gpu.DsscGpuRunner( kernel_runner = DsscCorrection.DsscGpuRunner(
pixels_x, pixels_x,
pixels_y, pixels_y,
memory_cells, memory_cells,
...@@ -43,7 +43,7 @@ kernel_runner = dssc_gpu.DsscGpuRunner( ...@@ -43,7 +43,7 @@ kernel_runner = dssc_gpu.DsscGpuRunner(
def test_only_cast(): def test_only_cast():
kernel_runner.load_data(raw_data) kernel_runner.load_data(raw_data)
kernel_runner.correct(dssc_gpu.CorrectionFlags.NONE) kernel_runner.correct(DsscCorrection.CorrectionFlags.NONE)
assert np.allclose( assert np.allclose(
kernel_runner.processed_data_gpu.get(), raw_data.astype(output_dtype) kernel_runner.processed_data_gpu.get(), raw_data.astype(output_dtype)
) )
...@@ -53,7 +53,7 @@ def test_correct(): ...@@ -53,7 +53,7 @@ def test_correct():
kernel_runner.load_offset_map(offset_map) kernel_runner.load_offset_map(offset_map)
kernel_runner.load_data(raw_data) kernel_runner.load_data(raw_data)
kernel_runner.load_cell_table(cell_table) kernel_runner.load_cell_table(cell_table)
kernel_runner.correct(dssc_gpu.CorrectionFlags.OFFSET) kernel_runner.correct(DsscCorrection.CorrectionFlags.OFFSET)
assert np.allclose(kernel_runner.processed_data_gpu.get(), corrected_data) assert np.allclose(kernel_runner.processed_data_gpu.get(), corrected_data)
...@@ -64,7 +64,7 @@ def test_correct_oob_cells(): ...@@ -64,7 +64,7 @@ def test_correct_oob_cells():
wild_cell_table = cell_table * 2 wild_cell_table = cell_table * 2
kernel_runner.load_cell_table(wild_cell_table) kernel_runner.load_cell_table(wild_cell_table)
# should not crash # should not crash
kernel_runner.correct(dssc_gpu.CorrectionFlags.OFFSET) kernel_runner.correct(DsscCorrection.CorrectionFlags.OFFSET)
# should correct as much as possible # should correct as much as possible
assert np.allclose( assert np.allclose(
kernel_runner.processed_data_gpu.get(), kernel_runner.processed_data_gpu.get(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment