Skip to content

detector_base

borealis.detector.detector_base

Created on Fri May 13 14:48:59 2022.

@author: A. Vancraeyenest

Detector(alias='')

Bases: SensorComponent

Abstract base class for Detector classes.

Defines the public API of any detector class.

ABC method for detector initialisation. (derived must override).

Inherited class must call super().init(alias=) in their init() or otherwise populate the alias and serial_number attributes themselves in the sub_class init method.

Source code in borealis/detector/detector_base.py
28
29
30
31
32
33
34
35
36
37
38
39
40
@abstractmethod
def __init__(self, alias: str = ""):
    """
    ABC method for detector initialisation. (derived must override).

    Inherited class must call super().__init__(alias=<new_alias>) in their __init__()
    or otherwise populate the alias and serial_number attributes themselves in the sub_class __init__ method.

    """
    self.alias = alias if alias != "" else "Undefined"
    self.serial_number = 'Unknown'
    self.mca_size = 4096
    super().__init__(session_orchestrator)

__str__()

Custom str method for Detector class (DO NOT OVERWRITE THIS METHOD).

Source code in borealis/detector/detector_base.py
42
43
44
def __str__(self):
    """Custom __str__ method for Detector class (DO NOT OVERWRITE THIS METHOD)."""
    return f'{self.__class__.__name__}(alias={self.alias})'

acquisition(acquisition_time) abstractmethod

ABC method for acquisition (derived must override).

Parameters:

Name Type Description Default
acquisition_time float

Acquisition time in seconds.

required

Returns:

Name Type Description
mca MCA

MCA object with spectrum counts and metadata.

Source code in borealis/detector/detector_base.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@abstractmethod
def acquisition(self, acquisition_time: float) -> mca.MCA:
    """
    ABC method for acquisition (derived must override).

    Parameters
    ----------
    acquisition_time : float
        Acquisition time in seconds.

    Returns
    -------
    mca : mca.MCA
        MCA object with spectrum counts and metadata.

    """

get_det_info()

Return the detector info as dictionary (stored in the MCA metadata).

Source code in borealis/detector/detector_base.py
67
68
69
70
71
def get_det_info(self):
    """Return the detector info as dictionary (stored in the MCA metadata)."""
    return {'serial_number': self.serial_number,
            'alias': self.alias,
            'type': self.__class__.__name__}

log(level, msg, *args, **kwargs)

Log a message with prepending the device's alias in front of the message.

Source code in borealis/detector/detector_base.py
81
82
83
84
def log(self, level, msg, *args, **kwargs):
    """Log a message with prepending the device's alias in front of the message."""
    kwargs['stacklevel'] = 2
    LOGGER.log(level, f'{self.alias}: {msg}', *args, **kwargs)

stop() abstractmethod

ABC method for stopping detector. (derived must override).

Source code in borealis/detector/detector_base.py
63
64
65
@abstractmethod
def stop(self):
    """ABC method for stopping detector. (derived must override)."""

DummyDet(alias='DummyDet')

Bases: Detector

When in need for a detector but no access to a real device.

Source code in borealis/detector/detector_base.py
97
98
99
def __init__(self, alias: str = "DummyDet"):
    super().__init__(alias=alias)
    LOGGER.info("Detector %s successfully initialised", self)