Skip to content
Snippets Groups Projects
Commit 52a1c748 authored by Cyril Danilevski's avatar Cyril Danilevski :scooter:
Browse files

Add test for module_index_to_qm

parent e894d0bd
No related branches found
No related tags found
1 merge request!438Feat/agipd add fixed gain mode to dark notebook
......@@ -51,9 +51,9 @@ class SnowResolution(Enum):
class AgipdGainMode(IntEnum):
"""Encoding added to distinguish between adaptive and fixed gain"""
"""Gain Modes where the values is 0 if Adaptive, or High/Medium/Low."""
ADAPTIVE_GAIN = 0 # adaptive is default (if gain mode missing in slow data)
FIXED_HIGH_GAIN = 1 # non-zero means fixed gain
ADAPTIVE_GAIN = 0
FIXED_HIGH_GAIN = 1
FIXED_MEDIUM_GAIN = 2
FIXED_LOW_GAIN = 3
......@@ -675,6 +675,7 @@ def get_constant_from_db_and_time(karabo_id: str, karabo_da: str,
def module_index_to_qm(index: int, total_modules: int = 16):
"""Maps module index (0-indexed) to quadrant + module string (1-indexed)"""
assert index < total_modules, f'{index} is greater than {total_modules}'
modules_per_quad = total_modules // 4
quad, mod = divmod(index, modules_per_quad)
return f"Q{quad+1}M{mod+1}"
......
......@@ -3,7 +3,7 @@ from pathlib import Path
import pytest
from cal_tools.plotting import show_processed_modules
from cal_tools.tools import get_dir_creation_date
from cal_tools.tools import get_dir_creation_date, module_index_to_qm
def test_show_processed_modules():
......@@ -30,3 +30,19 @@ def test_dir_creation_date():
date = get_dir_creation_date(folder, 9999)
assert isinstance(date, datetime)
assert str(date) == '2019-12-16 08:52:25.196603'
def test_module_index_to_qm():
assert module_index_to_qm(0) == 'Q1M1'
assert module_index_to_qm(1) == 'Q1M2'
assert module_index_to_qm(4) == 'Q2M1'
assert module_index_to_qm(6) == 'Q2M3'
assert module_index_to_qm(4, 5) == 'Q5M1'
with pytest.raises(AssertionError):
module_index_to_qm(18)
with pytest.raises(AssertionError):
module_index_to_qm(7, 5)
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