# -*- coding: utf-8 -*-
#
# This file is part of the SKA PST project
#
# Distributed under the terms of the BSD 3-clause new license.
# See LICENSE for more info.
"""Module provides helper method to convert PstProcessingMode to a CSP scan example string."""
__all__ = ["csp_scan_type"]
from ska_control_model import PstProcessingMode
from ska_schemas.csp.version import split_interface_version
from ska_schemas.pst.version import PST_CONFIG_VER4_0
from ska_pst.common import TelescopeFacilityEnum
[docs]def csp_scan_type(
mode: PstProcessingMode, facility: TelescopeFacilityEnum, version: str = PST_CONFIG_VER4_0
) -> str:
"""
Get CSP Scan example string.
This is to be used when calling the
:py:meth:`ska_schemas.pst.examples.get_pst_config_example` method
to retrieve the correct example CSP-PST JSON data.
:param mode: the PST processing mode to get the CSP scan type for.
:type mode: PstProcessingMode
:param facility: the telescope facility, for SKAMid the value is prefixed
with 'mid'.
:type facility: TelescopeFacilityEnum
:param version: the interface version to use, defaults to PST_CONFIG_VER4_0.
This is used to ensure compatibility of detected filterbank processing mode
in legacy versions as the string is ``pst_scan_ds``
:type version: str, optional
:return: the CSP Scan example string
:rtype: str
"""
def _inner() -> str:
if mode == PstProcessingMode.PULSAR_TIMING:
return "pst_scan_pt"
elif mode == PstProcessingMode.DETECTED_FILTERBANK:
major, minor = split_interface_version(version=version)
# the ska_schemas examples use "pst_scan_ds" for legacy 2.x versions
if (major, minor) < (3, 0):
return "pst_scan_ds"
return "pst_scan_df"
elif mode == PstProcessingMode.FLOW_THROUGH:
return "pst_scan_ft"
elif mode == PstProcessingMode.VOLTAGE_RECORDER:
return "pst_scan_vr"
else:
raise ValueError(f"Invalid enum value of {mode}.")
scan_type = _inner()
if facility == TelescopeFacilityEnum.Mid:
scan_type = f"mid_{scan_type}"
else:
scan_type = f"low_{scan_type}"
return scan_type