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 = "") -> None:
    """
    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.raw_data = None
    super().__init__()

__str__()

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

Source code in borealis/detector/detector_base.py
88
89
90
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:

Type Description
data
Source code in borealis/detector/detector_base.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@abstractmethod
def acquisition(self, acquisition_time: float) -> DataTemplate:
    """
    ABC method for acquisition (derived must override).

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

    Returns
    -------
    data

    """

get_datasets_schemas() abstractmethod

ABC method for getting raw data HDF5 schema. (derived must override).

Source code in borealis/detector/detector_base.py
62
63
64
@abstractmethod
def get_datasets_schemas(self) -> SchemaCollection:
    """ABC method for getting raw data HDF5 schema. (derived must override)."""

get_det_info()

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

Source code in borealis/detector/detector_base.py
66
67
68
69
70
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.

DO NOT OVERWRITE THIS METHOD

Source code in borealis/detector/detector_base.py
78
79
80
81
82
83
84
85
86
def log(self, level, msg, *args, **kwargs) -> None:
    """
    Log a message with prepending the device's alias in front of the message.

    DO NOT OVERWRITE THIS METHOD

    """
    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
58
59
60
@abstractmethod
def stop(self) -> None:
    """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
103
104
105
106
107
def __init__(self, alias: str = "DummyDet"):
    self.mca_size = 2048
    super().__init__(alias=alias)

    LOGGER.info("Detector %s successfully initialised", self)