Source code for blissoda.exafs.scan_utils

"""
Utilities for the EXAFS scans.

- Continuous scans: `energy scan framework <https://gitlab.esrf.fr/bliss/energy_scan>`_ which
  uses the `fast scan framework <https://gitlab.esrf.fr/bliss/fscan>`_.

- Step scans: `BM23 step energy scan framework <https://gitlab.esrf.fr/bm23/bm23/-/blob/master/bm23/BM23scanExafs.py>`_.
"""

from typing import Union

from ..import_utils import unavailable_type

try:
    from bliss.scanning.scan import Scan as BlissScanType
except ImportError as ex:
    BlissScanType = unavailable_type(ex)

try:
    from fscan.trigscan import TrigScanCustomRunner as TrigScanCustomRunnerType
except ImportError as ex:
    TrigScanCustomRunnerType = unavailable_type(ex)


ScanType = Union[BlissScanType, TrigScanCustomRunnerType]


[docs] def is_bliss_scan(scan: ScanType) -> bool: return isinstance(scan, BlissScanType)
[docs] def is_fscan(scan: ScanType) -> bool: return isinstance(scan, TrigScanCustomRunnerType)
[docs] def is_multi_xas_scan(scan: ScanType) -> bool: try: # fscan.trigscan.TrigScanPars in case of TrigScanCustomRunnerType return scan.pars.nscans > 1 except AttributeError: return False
[docs] def multi_xas_subscan_size(scan: ScanType) -> int: try: # fscan.trigscan.TrigScanPars in case of TrigScanCustomRunnerType return scan.pars.npoints + 1 # "npoints" is a badly chosen variable name. # It should be called "nsteps" and `size = nstep + 1`. except AttributeError: return 0