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

Fix old tests

parent ce294243
No related branches found
No related tags found
3 merge requests!29Always use 352 memory cells for SlopesFF for AGIPD,!26Add CPU kernels for some big detectors,!21Draft: small JF tweaks from HED installation
......@@ -80,38 +80,35 @@ def corr_rel_gain_pc_cpu(data, cell_table, gain_map, slopes_pc):
def test_thresholding():
kernel_runner.load_cell_table(cell_table)
kernel_runner.load_data(raw_data)
kernel_runner.load_thresholds(thresholds)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.load_constant(AgipdCorrection.Constants.ThresholdsDark, thresholds)
kernel_runner.correct(AgipdCorrection.CorrectionFlags.THRESHOLD)
gpu_res = kernel_runner.gain_map_gpu.get()
gpu_res = kernel_runner.gain_map.get()
assert np.allclose(gpu_res, gain_map_cpu)
def test_offset():
kernel_runner.load_cell_table(cell_table)
kernel_runner.load_data(raw_data)
kernel_runner.load_thresholds(thresholds)
kernel_runner.load_offset_map(offset_map)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.load_constant(AgipdCorrection.Constants.ThresholdsDark, thresholds)
kernel_runner.load_constant(AgipdCorrection.Constants.Offset, offset_map)
# have to do thresholding, otherwise all is treated as high gain
kernel_runner.correct(
AgipdCorrection.CorrectionFlags.THRESHOLD
| AgipdCorrection.CorrectionFlags.OFFSET
)
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.get()
assert np.allclose(gpu_res, cpu_res)
def test_rel_gain_pc():
kernel_runner.load_cell_table(cell_table)
kernel_runner.load_data(raw_data)
kernel_runner.load_thresholds(thresholds)
kernel_runner.load_rel_gain_pc_map(slopes_pc_map)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.load_constant(AgipdCorrection.Constants.ThresholdsDark, thresholds)
kernel_runner.load_constant(AgipdCorrection.Constants.SlopesPC, slopes_pc_map)
kernel_runner.correct(
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)
gpu_res = kernel_runner.processed_data_gpu.get()
gpu_res = kernel_runner.processed_data.get()
assert np.allclose(gpu_res, cpu_res)
import pathlib
from calng import AgipdCorrection, DsscCorrection
from calng.corrections import AgipdCorrection, DsscCorrection
from calng.utils import Stopwatch
from karabo.bound import Hash, Schema
import pytest
......
......@@ -42,46 +42,44 @@ kernel_runner = DsscCorrection.DsscGpuRunner(
def test_only_cast():
kernel_runner.load_data(raw_data)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.correct(DsscCorrection.CorrectionFlags.NONE)
assert np.allclose(
kernel_runner.processed_data_gpu.get(), raw_data.astype(output_dtype)
kernel_runner.processed_data.get(), raw_data.astype(output_dtype)
)
def test_correct():
kernel_runner.load_offset_map(offset_map)
kernel_runner.load_data(raw_data)
kernel_runner.load_cell_table(cell_table)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.correct(DsscCorrection.CorrectionFlags.OFFSET)
assert np.allclose(kernel_runner.processed_data_gpu.get(), corrected_data)
assert np.allclose(kernel_runner.processed_data.get(), corrected_data)
def test_correct_oob_cells():
kernel_runner.load_offset_map(offset_map)
kernel_runner.load_data(raw_data)
# here, half the cell IDs will be out of bounds
wild_cell_table = cell_table * 2
kernel_runner.load_cell_table(wild_cell_table)
kernel_runner.load_data(raw_data, wild_cell_table)
# should not crash
kernel_runner.correct(DsscCorrection.CorrectionFlags.OFFSET)
# should correct as much as possible
assert np.allclose(
kernel_runner.processed_data_gpu.get(),
kernel_runner.processed_data.get(),
correct_cpu(raw_data, wild_cell_table, offset_map),
)
def test_reshape():
kernel_runner.processed_data_gpu.set(corrected_data)
kernel_runner.processed_data.set(corrected_data)
assert np.allclose(
kernel_runner.reshape(output_order="xyf"), corrected_data.transpose()
)
def test_preview_slice():
kernel_runner.load_data(raw_data)
kernel_runner.processed_data_gpu.set(corrected_data)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.processed_data.set(corrected_data)
preview_raw, preview_corrected = kernel_runner.compute_previews(42)
assert np.allclose(
preview_raw,
......@@ -95,8 +93,8 @@ def test_preview_slice():
def test_preview_max():
# note: in case correction failed, still test this separately
kernel_runner.load_data(raw_data)
kernel_runner.processed_data_gpu.set(corrected_data)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.processed_data.set(corrected_data)
preview_raw, preview_corrected = kernel_runner.compute_previews(-1)
assert np.allclose(preview_raw, np.max(raw_data, axis=0).astype(np.float32))
assert np.allclose(
......@@ -105,8 +103,8 @@ def test_preview_max():
def test_preview_mean():
kernel_runner.load_data(raw_data)
kernel_runner.processed_data_gpu.set(corrected_data)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.processed_data.set(corrected_data)
preview_raw, preview_corrected = kernel_runner.compute_previews(-2)
assert np.allclose(preview_raw, np.nanmean(raw_data, axis=0, dtype=np.float32))
assert np.allclose(
......@@ -115,8 +113,8 @@ def test_preview_mean():
def test_preview_sum():
kernel_runner.load_data(raw_data)
kernel_runner.processed_data_gpu.set(corrected_data)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.processed_data.set(corrected_data)
preview_raw, preview_corrected = kernel_runner.compute_previews(-3)
assert np.allclose(preview_raw, np.nansum(raw_data, axis=0, dtype=np.float32))
assert np.allclose(
......@@ -125,8 +123,8 @@ def test_preview_sum():
def test_preview_std():
kernel_runner.load_data(raw_data)
kernel_runner.processed_data_gpu.set(corrected_data)
kernel_runner.load_data(raw_data, cell_table)
kernel_runner.processed_data.set(corrected_data)
preview_raw, preview_corrected = kernel_runner.compute_previews(-4)
assert np.allclose(preview_raw, np.nanstd(raw_data, axis=0, dtype=np.float32))
assert np.allclose(
......
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