merge from 7.0.0

This commit is contained in:
2023-02-24 10:39:51 +01:00
101 changed files with 4009 additions and 2128 deletions

View File

@ -34,6 +34,7 @@ set( PYTHON_FILES
slsdet/eiger.py
slsdet/enums.py
slsdet/errors.py
slsdet/gaincaps.py
slsdet/gotthard.py
slsdet/pattern.py
slsdet/gotthard2.py

View File

@ -2,7 +2,7 @@
# Copyright (C) 2021 Contributors to the SLS Detector Package
import subprocess
import locale
out = subprocess.run(['g', 'list'], stdout = subprocess.PIPE, encoding=locale.getpreferredencoding())
out = subprocess.run(['sls_detector_get', 'list'], stdout = subprocess.PIPE, encoding=locale.getpreferredencoding())
cmd = out.stdout.splitlines()
cmd.pop(0)
@ -99,7 +99,6 @@ intentionally_missing = [
'temp_slowadc',
'temp_sodl',
'temp_sodr',
'trigger', #use sendSoftwareTrigger
'update', #use updateServerAndFirmare
'udp_validate', #use validateUdpConfiguration
'udp_reconfigure', #use reconfigureUdpDestination

View File

@ -11,7 +11,7 @@ from .gotthard2 import Gotthard2
from .gotthard import Gotthard
from .moench import Moench
from .pattern import Pattern, patternParameters
from .gaincaps import Mythen3GainCapsWrapper
import _slsdet
xy = _slsdet.xy

View File

@ -26,6 +26,7 @@ SHORT_STR_LENGTH=20
MAX_PATTERN_LENGTH=0x2000
MAX_PATTERN_LEVELS=6
M3_MAX_PATTERN_LEVELS=3
MAX_NUM_COUNTERS=3
DEFAULT_STREAMING_TIMER_IN_MS=500
NUM_RX_THREAD_IDS=9
MAX_NUM_PACKETS=512

View File

@ -16,6 +16,7 @@ defs = slsDetectorDefs
from .utils import element_if_equal, all_equal, get_set_bits, list_to_bitmask
from .utils import Geometry, to_geo, element, reduce_time, is_iterable, hostname_list
from _slsdet import xy
from .gaincaps import Mythen3GainCapsWrapper
from . import utils as ut
from .proxy import JsonProxy, SlowAdcProxy, ClkDivProxy, MaxPhaseProxy, ClkFreqProxy, PatLoopProxy, PatNLoopProxy, PatWaitProxy, PatWaitTimeProxy
from .registers import Register, Adc_register
@ -231,7 +232,7 @@ class Detector(CppDetectorApi):
"""
[Jungfrau][Moench][Gotthard2][Myhten3][Gotthard][Ctb] Hardware version of detector.
"""
return ut.lhex(self.getHardwareVersion())
return self.getHardwareVersion()
@property
@element
@ -263,11 +264,17 @@ class Detector(CppDetectorApi):
"""Receiver version """
return self.getReceiverVersion()
@property
@element
def serialnumber(self):
"""Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench] Serial number of detector """
return ut.lhex(self.getSerialNumber())
@property
@element
def rx_threads(self):
"""
Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping].
Get kernel thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping].
Note
-----
@ -451,6 +458,56 @@ class Detector(CppDetectorApi):
def triggers(self, n_triggers):
self.setNumberOfTriggers(n_triggers)
def resetdacs(self, use_hardware_values):
self.resetToDefaultDacs(use_hardware_values)
def trigger(self):
self.sendSoftwareTrigger()
def blockingtrigger(self):
self.sendSoftwareTrigger(True)
@property
@element
def gaincaps(self):
"""
[Mythen3] Gain caps. Enum: M3_GainCaps \n
Note
----
Options: M3_GainCaps, M3_C15sh, M3_C30sh, M3_C50sh, M3_C225ACsh, M3_C15pre
Example
-------
>>> d.gaincaps
C15pre, C30sh
>>> d.gaincaps = M3_GainCaps.M3_C30sh
>>> d.gaincaps
C30sh
>>> d.gaincaps = M3_GainCaps.M3_C30sh | M3_GainCaps.M3_C15sh
>>> d.gaincaps
C15sh, C30sh
"""
res = [Mythen3GainCapsWrapper(it) for it in self.getGainCaps()]
return res
@gaincaps.setter
def gaincaps(self, caps):
#convert to int if called with Wrapper
if isinstance(caps, Mythen3GainCapsWrapper):
self.setGainCaps(caps.value)
elif isinstance(caps, dict):
corr = {}
for key, value in caps.items():
if isinstance(value, Mythen3GainCapsWrapper):
corr[key] = value.value
else:
corr[key] = value
ut.set_using_dict(self.setGainCaps, corr)
else:
self.setGainCaps(caps)
@property
def exptime(self):
"""
@ -498,7 +555,7 @@ class Detector(CppDetectorApi):
@exptime.setter
def exptime(self, t):
if self.type == detectorType.MYTHEN3 and is_iterable(t):
if self.type == detectorType.MYTHEN3 and is_iterable(t) and not isinstance(t,dict):
for i, v in enumerate(t):
if isinstance(v, int):
v = float(v)
@ -507,8 +564,6 @@ class Detector(CppDetectorApi):
ut.set_time_using_dict(self.setExptime, t)
@property
def period(self):
"""
@ -647,6 +702,10 @@ class Detector(CppDetectorApi):
"""Start detector acquisition. Status changes to RUNNING or WAITING and automatically returns to idle at the end of acquisition."""
self.startDetector()
def clearbusy(self):
"""If acquisition aborted during acquire command, use this to clear acquiring flag in shared memory before starting next acquisition"""
self.clearAcquiringFlag()
def rx_start(self):
"""Starts receiver listener for detector data packets and create a data file (if file write enabled)."""
self.startReceiver()
@ -1563,6 +1622,20 @@ class Detector(CppDetectorApi):
def trimval(self, value):
ut.set_using_dict(self.setAllTrimbits, value)
@property
@element
def fliprows(self):
"""
[Eiger] flips rows paramater sent to slsreceiver to stream as json parameter to flip rows in gui. \n
[Jungfrau] flips rows in the detector itself. For bottom module and number of interfaces must be set to 2. slsReceiver and slsDetectorGui does not handle.
"""
return self.getFlipRows()
@fliprows.setter
def fliprows(self, value):
ut.set_using_dict(self.setFlipRows, value)
@property
@element
def master(self):
@ -1588,6 +1661,19 @@ class Detector(CppDetectorApi):
def sync(self, value):
ut.set_using_dict(self.setSynchronization, value)
@property
@element
def badchannels(self):
"""
[fname|none|0]\n\t[Gotthard2][Mythen3] Sets the bad channels (from file of bad channel numbers) to be masked out. None or 0 unsets all the badchannels.\n
[Mythen3] Also does trimming
"""
return self.getBadChannels()
@badchannels.setter
def badchannels(self, value):
ut.set_using_dict(self.setBadChannels, value)
@property
@element
def lock(self):
@ -1696,6 +1782,11 @@ class Detector(CppDetectorApi):
"""Gets the list of timing modes (timingMode) for this detector."""
return self.getTimingModeList()
@property
def readoutspeedlist(self):
"""List of readout speed levels implemented for this detector."""
return self.getReadoutSpeedList()
@property
def templist(self):
"""List of temperature enums (dacIndex) implemented for this detector."""
@ -1797,25 +1888,24 @@ class Detector(CppDetectorApi):
@property
def versions(self):
if self.type == detectorType.EIGER:
return {'type': self.type,
version_list = {'type': self.type,
'package': self.packageversion,
'client': self.clientversion,
'firmware (Beb)': self.firmwareversion,
'firmware(Febl)': self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_LEFT),
'firmware (Febr)': self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_RIGHT),
'detectorserver': self.detectorserverversion,
'kernel': self.kernelversion,
'receiver': self.rx_version}
'kernel': self.kernelversion}
return {'type': self.type,
'package': self.packageversion,
'client': self.clientversion,
'firmware': self.firmwareversion,
'detectorserver': self.detectorserverversion,
'hardware':self.hardwareversion,
'kernel': self.kernelversion,
'receiver': self.rx_version}
if self.type == detectorType.EIGER:
version_list ['firmware (Beb)'] = self.firmwareversion
version_list ['firmware(Febl)'] = self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_LEFT)
version_list ['firmware (Febr)'] = self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_RIGHT)
else:
version_list ['firmware'] = self.firmwareversion
version_list ['hardware'] = self.hardwareversion
if self.use_receiver:
version_list ['receiver'] = self.rx_version
return version_list
@property
def virtual(self):
@ -3103,6 +3193,17 @@ class Detector(CppDetectorApi):
def dbitclk(self, value):
ut.set_using_dict(self.setDBITClock, value)
@property
@element
def adcvpp(self):
"""[Ctb][Moench] Vpp of ADC. [0 -> 1V | 1 -> 1.14V | 2 -> 1.33V | 3 -> 1.6V | 4 -> 2V] \n
Advanced User function!"""
return self.getADCVpp(False)
@adcvpp.setter
def adcvpp(self, value):
ut.set_using_dict(self.setADCVpp, value, False)
@property
@element
def dbitpipeline(self):
@ -3713,6 +3814,23 @@ class Detector(CppDetectorApi):
"""
return self.getMeasuredCurrent(dacIndex.I_POWER_IO)
@property
def clkphase(self):
"""
[Gotthard2][Mythen3] Phase shift of all clocks.
Example
-------
>>> d.clkphase[0] = 20
>>> d.clkphase
0: 20
1: 10
2: 20
3: 10
4: 10
5: 5
"""
return ClkPhaseProxy(self)
@property
def clkdiv(self):

42
python/slsdet/gaincaps.py Normal file
View File

@ -0,0 +1,42 @@
import _slsdet
gc = _slsdet.slsDetectorDefs.M3_GainCaps
class Mythen3GainCapsWrapper:
"""Holds M3_GainCaps enums and facilitates printing"""
# 'M3_C10pre', 'M3_C15pre', 'M3_C15sh', 'M3_C225ACsh', 'M3_C30sh', 'M3_C50sh'
all_bits = gc.M3_C10pre | gc.M3_C15pre | gc.M3_C15sh | gc.M3_C225ACsh | gc.M3_C30sh | gc.M3_C50sh
all_caps = (gc.M3_C10pre, gc.M3_C15pre, gc.M3_C15sh, gc.M3_C225ACsh, gc.M3_C30sh, gc.M3_C50sh)
def __init__(self, value = 0):
self._validate(value)
self.value = value
def __eq__(self, other) -> bool:
if isinstance(other, Mythen3GainCapsWrapper):
return self.value == other.value
else:
return self.value == other
def __ne__(self, other) -> bool:
return not self.__eq__(other)
def __str__(self) -> str:
s = ', '.join(str(c).rsplit('_', 1)[1] for c in self.all_caps if self.value & c)
return s
def __repr__(self) -> str:
return self.__str__()
def _validate(self, value):
"""Check that only bits representing real capacitors are set"""
if isinstance(value, gc):
return True
elif isinstance(value, int):
if value & (~self.all_bits):
raise ValueError(f"The value: {value} is not allowed for Mythen3GainCapsWrapper")
else:
raise ValueError("GainCaps can only be initialized from int or M3_GainCaps enum")

View File

@ -13,6 +13,7 @@ from .detector import Detector, freeze
from .dacs import DetectorDacs
import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex
gc_enums = _slsdet.slsDetectorDefs.M3_GainCaps
from .detector_property import DetectorProperty
@ -62,4 +63,6 @@ class Mythen3(Detector):
@property
def dacs(self):
return self._dacs
return self._dacs

View File

@ -4,6 +4,7 @@ from .utils import element_if_equal
from .enums import dacIndex
from .defines import M3_MAX_PATTERN_LEVELS, MAX_PATTERN_LEVELS
from _slsdet import slsDetectorDefs
detectorType = slsDetectorDefs.detectorType
def set_proxy_using_dict(func, key, value, unpack = False):
@ -87,7 +88,10 @@ class ClkDivProxy:
def __repr__(self):
rstr = ''
for i in range(6):
num_clocks = 6
if self.det.type == detectorType.MYTHEN3:
num_clocks = 5
for i in range(num_clocks):
r = element_if_equal(self.__getitem__(i))
if isinstance(r, list):
rstr += ' '.join(f'{item}' for item in r)
@ -96,10 +100,35 @@ class ClkDivProxy:
return rstr.strip('\n')
class ClkPhaseProxy:
"""
Proxy class to allow for more intuitive reading clock phase
"""
def __init__(self, det):
self.det = det
def __getitem__(self, key):
return element_if_equal(self.det.getClockPhase(key))
def __setitem__(self, key, value):
set_proxy_using_dict(self.det.setClockPhase, key, value)
def __repr__(self):
rstr = ''
if self.det.type == detectorType.MYTHEN3:
num_clocks = 5
for i in range(num_clocks):
r = element_if_equal(self.__getitem__(i))
if isinstance(r, list):
rstr += ' '.join(f'{item}' for item in r)
else:
rstr += f'{i}: {r}\n'
return rstr.strip('\n')
class MaxPhaseProxy:
"""
Proxy class to allow for more intuitive reading clockdivider
Proxy class to allow for more intuitive reading max clock phase shift
"""
def __init__(self, det):
self.det = det
@ -109,7 +138,9 @@ class MaxPhaseProxy:
def __repr__(self):
rstr = ''
for i in range(5):
if self.det.type == detectorType.MYTHEN3:
num_clocks = 5
for i in range(num_clocks):
r = element_if_equal(self.__getitem__(i))
if isinstance(r, list):
rstr += ' '.join(f'{item}' for item in r)
@ -120,7 +151,7 @@ class MaxPhaseProxy:
class ClkFreqProxy:
"""
Proxy class to allow for more intuitive reading clockdivider
Proxy class to allow for more intuitive reading clock frequency
"""
def __init__(self, det):
self.det = det
@ -130,7 +161,9 @@ class ClkFreqProxy:
def __repr__(self):
rstr = ''
for i in range(5):
if self.det.type == detectorType.MYTHEN3:
num_clocks = 5
for i in range(num_clocks):
r = element_if_equal(self.__getitem__(i))
if isinstance(r, list):
rstr += ' '.join(f'{item}' for item in r)

View File

@ -224,6 +224,21 @@ void init_det(py::module &m) {
(void (Detector::*)(const std::string &, sls::Positions)) &
Detector::setBadChannels,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def(
"getBadChannels",
(Result<std::vector<int>>(Detector::*)(sls::Positions) const) &
Detector::getBadChannels,
py::arg() = Positions{});
CppDetectorApi.def(
"setBadChannels",
(void (Detector::*)(const std::vector<int>, sls::Positions)) &
Detector::setBadChannels,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def(
"setBadChannels",
(void (Detector::*)(const std::vector<std::vector<int>>)) &
Detector::setBadChannels,
py::arg());
CppDetectorApi.def("isVirtualDetectorServer",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::isVirtualDetectorServer,

View File

@ -0,0 +1,24 @@
import pytest
from slsdet import Mythen3GainCapsWrapper
from slsdet.enums import M3_GainCaps #this is the c++ enum
def test_comapre_with_int():
c = Mythen3GainCapsWrapper(128) #C10pre
assert c == 128
assert c != 5
assert c != 1280
def test_compare_with_other():
a = Mythen3GainCapsWrapper(128)
b = Mythen3GainCapsWrapper(1<<10)
c = Mythen3GainCapsWrapper(128)
assert a!=b
assert (a==b) == False
assert a==c
def test_can_be_default_constructed():
c = Mythen3GainCapsWrapper()
assert c == 0