Source code for ska_telmodel.csp.low_examples

import copy

from ska_telmodel.csp.low_version import (
    get_csp_subsystem_version,
    lowcsp_assignresources_uri,
    lowcsp_configure_uri,
    lowcsp_releaseresources_uri,
    lowcsp_scan_uri,
)

from .._common import split_interface_version
from ..lowcbf import get_lowcbf_configurescan_example
from ..pss.example import (
    get_pss_cheetah_configure_example,
    get_pss_configure_example,
)
from ..pst.examples import (
    get_pst_config_example,
)

LOW_CSP_ASSIGNRESOURCES_2_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-assignresources/2.0",
    "common": {"subarray_id": 1},
    "lowcbf": {
        "resources": [
            {
                "device": "fsp_01",
                "shared": True,
                "fw_image": "pst",
                "fw_mode": "unused",
            },
            {
                "device": "p4_01",
                "shared": True,
                "fw_image": "p4.bin",
                "fw_mode": "p4",
            },
        ]
    },
    "pss": {"beams_id": [1, 2, 3]},
    "pst": {"beams_id": [1]},
}

LOW_CSP_ASSIGNRESOURCES_3_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-assignresources/3.0",
    "common": {"subarray_id": 1},
    "lowcbf": {},
    "pss": {"beams_id": [1, 2, 3]},
    "pst": {"beams_id": [1]},
}

LOW_CSP_ASSIGNRESOURCES_3_2 = {
    "interface": "https://schema.skao.int/ska-low-csp-assignresources/3.2",
    "transaction_id": "txn-....-00001",
    "common": {"subarray_id": 1},
    "lowcbf": {},
    "pss": {"beams_id": [1, 2, 3]},
    "pst": {"beams_id": [1]},
}

LOW_CSP_ASSIGNRESOURCES_6_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-assignresources/6.0",
    "transaction_id": "txn-....-00001",
    "common": {"subarray_id": 1},
    "lowcbf": {},
    "pst": {"pst_beam_ids": [1, 2, 3]},
    "pss": {"pss_beam_ids": [1]},
}

LOW_CSP_CONFIGURE_2_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-configure/2.0",
    "subarray": {"subarray_name": "science period 23"},
    "common": {
        "config_id": "sbi-mvp01-20200325-00001-science_A",
        "subarray_id": 1,
        "eb_id": "eb-x449-20231105-34696",
    },
    "lowcbf": {
        "stations": {
            "stns": [[1, 0], [2, 0], [3, 0], [4, 0]],
            "stn_beams": [
                {
                    "beam_id": 1,
                    "freq_ids": [64, 65, 66, 67, 68, 69, 70, 71],
                    "boresight_dly_poly": (
                        "tango://delays.skao.int/low/stn-beam/1"
                    ),
                }
            ],
        },
    },
    "pss": {},
    "pst": {"beams": []},
}

LOW_CSP_CONFIGURE_3_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-configure/3.0",
    "subarray": {"subarray_name": "science period 23"},
    "common": {
        "config_id": "sbi-mvp01-20200325-00001-science_A",
        "subarray_id": 1,
        "eb_id": "eb-x449-20231105-34696",
    },
    "lowcbf": {
        "stations": {
            "stns": [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1]],
            "stn_beams": [
                {
                    "beam_id": 1,
                    "freq_ids": [400],
                    "delay_poly": "tango://delays.skao.int/low/stn-beam/1",
                }
            ],
        },
        "vis": {
            "fsp": {"firmware": "vis", "fsp_ids": [1]},
            "stn_beams": [
                {
                    "stn_beam_id": 1,
                    "host": [[0, "192.168.0.1"]],
                    "port": [[0, 9000, 1]],
                    "mac": [[0, "02-03-04-0a-0b-0c"]],
                    "integration_ms": 849,
                }
            ],
        },
    },
    "pss": {},
    "pst": {"beams": []},
}

LOW_CSP_CONFIGURE_3_1 = {
    "interface": "https://schema.skao.int/ska-low-csp-configure/3.1",
    "subarray": {"subarray_name": "science period 23"},
    "common": {
        "config_id": "sbi-mvp01-20200325-00001-science_A",
        "subarray_id": 1,
        "eb_id": "eb-x449-20231105-34696",
    },
    "lowcbf": {
        "stations": {
            "stns": [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1]],
            "stn_beams": [
                {
                    "beam_id": 1,
                    "freq_ids": [400],
                    "delay_poly": "tango://delays.skao.int/low/stn-beam/1",
                }
            ],
        },
        "vis": {
            "fsp": {"firmware": "vis", "fsp_ids": [1]},
            "stn_beams": [
                {
                    "stn_beam_id": 1,
                    "host": [[0, "192.168.0.1"]],
                    "port": [[0, 9000, 1]],
                    "mac": [[0, "02-03-04-0a-0b-0c"]],
                    "integration_ms": 849,
                }
            ],
        },
    },
    "pss": {},
    "pst": {"beams": []},
}


LOW_CSP_CONFIGURE_3_2 = {
    "interface": "https://schema.skao.int/ska-low-csp-configure/3.2",
    "transaction_id": "txn-....-00001",
    "subarray": {"subarray_name": "science period 23"},
    "common": {
        "config_id": "sbi-mvp01-20200325-00001-science_A",
        "subarray_id": 1,
        "eb_id": "eb-x449-20231105-34696",
    },
    "lowcbf": {
        "stations": {
            "stns": [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1]],
            "stn_beams": [
                {
                    "beam_id": 1,
                    "freq_ids": [400],
                    "delay_poly": "tango://delays.skao.int/low/stn-beam/1",
                }
            ],
        },
        "vis": {
            "fsp": {"firmware": "vis", "fsp_ids": [1]},
            "stn_beams": [
                {
                    "stn_beam_id": 1,
                    "host": [[0, "192.168.0.1"]],
                    "port": [[0, 9000, 1]],
                    "mac": [[0, "02-03-04-0a-0b-0c"]],
                    "integration_ms": 849,
                }
            ],
        },
    },
}

LOW_CSP_CONFIGURE_4_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-configure/4.0",
    "subarray": {"subarray_name": "science period 23"},
    "common": {
        "config_id": "sbi-mvp01-20200325-00001-science_A",
        "subarray_id": 1,
        "eb_id": "eb-x449-20231105-34696",
    },
    "lowcbf": {
        "stations": {
            "stns": [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1]],
            "stn_beams": [
                {
                    "stn_beam_id": 1,
                    "freq_ids": [400],
                    "delay_poly": "tango://delays.skao.int/low/stn-beam/1",
                }
            ],
        },
        "vis": {
            "fsp": {"function_mode": "vis", "fsp_ids": [1]},
            "stn_beams": [
                {
                    "stn_beam_id": 1,
                    "host": [[0, "192.168.0.1"]],
                    "port": [[0, 9000, 1]],
                    "mac": [[0, "02-03-04-0a-0b-0c"]],
                    "integration_ms": 849,
                }
            ],
        },
    },
    "pss": {},
    "pst": {"beams": []},
}

LOW_CSP_CONFIGURE_5_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-configure/5.0",
    "transaction_id": "txn-....-00001",
    "subarray": {"subarray_name": "science period 23"},
    "common": {
        "config_id": "sbi-mvp01-20200325-00001-science_A",
        "subarray_id": 1,
        "eb_id": "eb-x449-20231105-34696",
    },
}

LOW_CSP_RELEASERESOURCES_2_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-releaseresources/2.0",
    "common": {"subarray_id": 1},
    "lowcbf": {
        "resources": [
            {"device": "fsp_01"},
        ]
    },
    "pst": {"beams_id": [1]},
}

LOW_CSP_RELEASERESOURCES_3_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-releaseresources/3.0",
    "common": {"subarray_id": 1},
    "lowcbf": {},
    "pst": {"beams_id": [1]},
}

LOW_CSP_RELEASERESOURCES_3_2 = {
    "interface": "https://schema.skao.int/ska-low-csp-releaseresources/3.2",
    "transaction_id": "txn-....-00001",
    "common": {"subarray_id": 1},
    "lowcbf": {},
    "pst": {"beams_id": [1]},
}

LOW_CSP_RELEASERESOURCES_6_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-releaseresources/6.0",
    "transaction_id": "txn-....-00001",
    "common": {"subarray_id": 1},
    "lowcbf": {},
    "pst": {"pst_beam_ids": [1]},
    "pss": {"pss_beam_ids": [1]},
}

LOW_CSP_SCAN_2_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-scan/2.0",
    "common": {"subarray_id": 1},
    "lowcbf": {"scan_id": 987654321},
}

LOW_CSP_SCAN_3_2 = {
    "interface": "https://schema.skao.int/ska-low-csp-scan/3.2",
    "transaction_id": "txn-....-00001",
    "common": {"subarray_id": 1},
    "lowcbf": {"scan_id": 987654321},
}

LOW_CSP_SCAN_4_0 = {
    "interface": "https://schema.skao.int/ska-low-csp-scan/4.0",
    "transaction_id": "txn-....-00001",
    "common": {"subarray_id": 1},
    "scan_id": 987654321,
}


# Functions returning copies of the appropriate version of LOW CSP JSON strings
[docs] def get_low_csp_assignresources_example(version: str): """Get appropriate version example of LOW CSP assign resources string. :param version: Version URI of configuration format """ if version.startswith(lowcsp_assignresources_uri(2, 0)): return copy.deepcopy(LOW_CSP_ASSIGNRESOURCES_2_0) elif version.startswith(lowcsp_assignresources_uri(3, 0)): return copy.deepcopy(LOW_CSP_ASSIGNRESOURCES_3_0) elif version.startswith(lowcsp_assignresources_uri(3, 1)): return copy.deepcopy(LOW_CSP_ASSIGNRESOURCES_3_0) elif version.startswith(lowcsp_assignresources_uri(3, 2)): return copy.deepcopy(LOW_CSP_ASSIGNRESOURCES_3_2) elif version.startswith(lowcsp_assignresources_uri(4, 0)): example = update_interface(LOW_CSP_ASSIGNRESOURCES_3_2, "4.0") return copy.deepcopy(example) elif version.startswith(lowcsp_assignresources_uri(5, 0)): example = update_interface(LOW_CSP_ASSIGNRESOURCES_3_2, "5.0") return copy.deepcopy(example) elif version.startswith(lowcsp_assignresources_uri(6, 0)): return copy.deepcopy(LOW_CSP_ASSIGNRESOURCES_6_0) elif version.startswith(lowcsp_assignresources_uri(7, 0)): example = update_interface(LOW_CSP_ASSIGNRESOURCES_6_0, "7.0") return copy.deepcopy(example) elif version.startswith(lowcsp_assignresources_uri(7, 1)): example = update_interface(LOW_CSP_ASSIGNRESOURCES_6_0, "7.1") return copy.deepcopy(example) elif version.startswith(lowcsp_assignresources_uri(7, 2)): example = update_interface(LOW_CSP_ASSIGNRESOURCES_6_0, "7.2") return copy.deepcopy(example) raise ValueError(f"Could not generate example for schema {version})!")
[docs] def update_interface(json_example: dict, desired_version: str): """Update the version of the example interface.""" old_interface = json_example["interface"] subsystem_uri = "/".join(old_interface.rsplit("/", 1)[:-1]) + "/" new_interface = subsystem_uri + desired_version json_example["interface"] = new_interface return json_example
[docs] def get_low_csp_configure_example(version: str, scan_type=None): """Get appropriate version example of LOW CSP configure string. The CSP LMC low CBF example is used from CSP LMC configure > v5.0 (low CBF v > 0.2) :param version: Version URI of configuration format """ csp_version = split_interface_version(version) csp_base_example = {} if version.startswith(lowcsp_configure_uri(2, 0)): csp_base_example = copy.deepcopy(LOW_CSP_CONFIGURE_2_0) elif version.startswith(lowcsp_configure_uri(3, 0)): csp_base_example = copy.deepcopy(LOW_CSP_CONFIGURE_3_0) elif version.startswith(lowcsp_configure_uri(3, 1)): csp_base_example = copy.deepcopy(LOW_CSP_CONFIGURE_3_1) elif version.startswith(lowcsp_configure_uri(3, 2)): csp_base_example = copy.deepcopy(LOW_CSP_CONFIGURE_3_2) elif version.startswith(lowcsp_configure_uri(4, 0)): csp_base_example = copy.deepcopy(LOW_CSP_CONFIGURE_4_0) elif version.startswith(lowcsp_configure_uri(5, 0)): example = copy.deepcopy(LOW_CSP_CONFIGURE_5_0) csp_base_example = update_interface(example, "5.0") elif version.startswith(lowcsp_configure_uri(6, 0)): example = copy.deepcopy(LOW_CSP_CONFIGURE_5_0) csp_base_example = update_interface(example, "6.0") elif version.startswith(lowcsp_configure_uri(7, 0)): example = copy.deepcopy(LOW_CSP_CONFIGURE_5_0) csp_base_example = update_interface(example, "7.0") elif version.startswith(lowcsp_configure_uri(7, 1)): example = copy.deepcopy(LOW_CSP_CONFIGURE_5_0) csp_base_example = update_interface(example, "7.1") elif version.startswith(lowcsp_configure_uri(7, 2)): example = copy.deepcopy(LOW_CSP_CONFIGURE_5_0) csp_base_example = update_interface(example, "7.2") else: raise ValueError(f"Could not generate example for schema {version})!") (csp_base_example["lowcbf"]) = get_lowcbf_configure_example(version) if scan_type and "pss" in scan_type: pss_uri = "" _, pss_uri = get_csp_subsystem_version( csp_base_example["interface"], "pss" ) major, minor = split_interface_version(pss_uri) if (major, minor) >= (1, 2): # get pss example csp_base_example["pss"] = get_pss_configure_example(pss_uri) if "search_beams" in csp_base_example["lowcbf"]: update_config_cbf_keys( csp_version, csp_base_example, "pss", csp_base_example["lowcbf"]["search_beams"], ) # add and update PSS example with the part needed for CSP update_pss_config_example(csp_base_example) else: # We need this because pss 0.0 is in the low compatibility map # pss 0.0 is a dummy version for some backwards compatibility # for mid csp_base_example["pss"] = get_pss_cheetah_configure_example( pss_uri ) else: # remove search_beams if using old PSS (not supported there) if "search_beams" in csp_base_example["lowcbf"]: csp_base_example["lowcbf"].pop("search_beams") if scan_type and "pst" in scan_type: # pst beams are needed # update CBF example with the part needed for PST beam update_config_cbf_keys( csp_version, csp_base_example, "pst", csp_base_example["lowcbf"]["timing_beams"], ) pst_uri = "" _, pst_uri = get_csp_subsystem_version( csp_base_example["interface"], "pst" ) # get pst example if "pss" in scan_type: scan_type = scan_type.removeprefix("pss_") pst_example = get_pst_config_example(pst_uri, scan_type) # add and update PST example with the part needed for PST beam update_config_pst_keys(csp_version, csp_base_example, pst_example) else: if "timing_beams" in csp_base_example["lowcbf"]: csp_base_example["lowcbf"].pop("timing_beams") return copy.deepcopy(csp_base_example)
[docs] def get_lowcbf_configure_example(csp_version): """Get the LowCBF base example for the CSP LMC.""" cbf_uri = "" _, cbf_uri = get_csp_subsystem_version(csp_version, "lowcbf") json_example = get_lowcbf_configurescan_example(cbf_uri) return json_example["lowcbf"]
[docs] def update_pss_config_example(json_example): """Remove PSS example attributes that are not needed in the csp example.""" if "pss" in json_example: if "interface" in json_example["pss"]: del json_example["pss"]["interface"] if "common" in json_example["pss"]: del json_example["pss"]["common"]
[docs] def update_config_cbf_keys(csp_version, json_example, subsystem, data) -> dict: """Add/Remove CBF example attributes that differ between base CSP example.""" if "pst" in subsystem: if csp_version == (2, 0): json_example["lowcbf"]["timing_beams"] = { "beams": [ { "pst_beam_id": 13, "stn_beam_id": 1, "offset_dly_poly": "url", "stn_weights": [0.9, 1.0, 1.0, 0.9], "jones": "url", "rfi_enable": [True, True, True], "rfi_static_chans": [1, 206, 997], "rfi_dynamic_chans": [242, 1342], "rfi_weighted": 0.87, } ] } elif csp_version > (2, 0): if "destinations" in data["beams"][0]: data["beams"][0].pop("destinations", None) json_example["lowcbf"]["timing_beams"] = data elif "pss" in subsystem: for beam in data.get("beams", []): if "destinations" in beam: beam.pop("destinations") json_example["lowcbf"]["search_beams"] = data
[docs] def update_config_pst_keys(csp_version, json_example, pst_example) -> dict: """Add/Remove PST schema attributes that differ between PST and CSP schema.""" # remove common part and interface from PST example pst_beam_example = pst_example["pst"]["scan"] # remove "timing_beam_id" attributes del pst_beam_example["timing_beam_id"] # Add one or more PST beam according to the CBF schema pst_beam_section = [] pst_beam_dict = {} for beam in json_example["lowcbf"]["timing_beams"]["beams"]: # aligns CBF beam_ids with the one in the PST pst_beam_dict = { "beam_id": beam["pst_beam_id"], "scan": pst_beam_example, } pst_beam_section.append(pst_beam_dict) # add list of pst beams json_example["pst"] = {"beams": pst_beam_section}
[docs] def get_low_csp_releaseresources_example(version: str): """Get appropriate version example of LOW CSP release resources string. :param version: Version URI of configuration format """ if version.startswith(lowcsp_releaseresources_uri(2, 0)): return copy.deepcopy(LOW_CSP_RELEASERESOURCES_2_0) elif version.startswith(lowcsp_releaseresources_uri(3, 0)): return copy.deepcopy(LOW_CSP_RELEASERESOURCES_3_0) elif version.startswith(lowcsp_releaseresources_uri(3, 1)): return copy.deepcopy(LOW_CSP_RELEASERESOURCES_3_0) elif version.startswith(lowcsp_releaseresources_uri(3, 2)): return copy.deepcopy(LOW_CSP_RELEASERESOURCES_3_2) elif version.startswith(lowcsp_releaseresources_uri(4, 0)): example = update_interface(LOW_CSP_RELEASERESOURCES_3_2, "4.0") return copy.deepcopy(example) elif version.startswith(lowcsp_releaseresources_uri(5, 0)): example = update_interface(LOW_CSP_RELEASERESOURCES_3_2, "5.0") return copy.deepcopy(example) elif version.startswith(lowcsp_releaseresources_uri(6, 0)): return copy.deepcopy(LOW_CSP_RELEASERESOURCES_6_0) elif version.startswith(lowcsp_releaseresources_uri(7, 0)): example = update_interface(LOW_CSP_RELEASERESOURCES_6_0, "7.0") return copy.deepcopy(example) elif version.startswith(lowcsp_releaseresources_uri(7, 1)): example = update_interface(LOW_CSP_RELEASERESOURCES_6_0, "7.1") return copy.deepcopy(example) elif version.startswith(lowcsp_releaseresources_uri(7, 2)): example = update_interface(LOW_CSP_RELEASERESOURCES_6_0, "7.2") return copy.deepcopy(example) raise ValueError(f"Could not generate example for schema {version})!")
[docs] def get_low_csp_scan_example(version: str): """Get appropriate version example of LOW CSP scan string. :param version: Version URI of configuration format """ if version.startswith(lowcsp_scan_uri(2, 0)): return copy.deepcopy(LOW_CSP_SCAN_2_0) elif version.startswith(lowcsp_scan_uri(3, 0)): return copy.deepcopy(LOW_CSP_SCAN_2_0) elif version.startswith(lowcsp_scan_uri(3, 1)): return copy.deepcopy(LOW_CSP_SCAN_2_0) elif version.startswith(lowcsp_scan_uri(3, 2)): return copy.deepcopy(LOW_CSP_SCAN_3_2) elif version.startswith(lowcsp_scan_uri(4, 0)): return copy.deepcopy(LOW_CSP_SCAN_4_0) elif version.startswith(lowcsp_scan_uri(5, 0)): example = update_interface(LOW_CSP_SCAN_4_0, "5.0") return copy.deepcopy(example) elif version.startswith(lowcsp_scan_uri(6, 0)): example = update_interface(LOW_CSP_SCAN_4_0, "6.0") return copy.deepcopy(example) elif version.startswith(lowcsp_scan_uri(7, 0)): example = update_interface(LOW_CSP_SCAN_4_0, "7.0") return copy.deepcopy(example) elif version.startswith(lowcsp_scan_uri(7, 1)): example = update_interface(LOW_CSP_SCAN_4_0, "7.1") return copy.deepcopy(example) elif version.startswith(lowcsp_scan_uri(7, 2)): example = update_interface(LOW_CSP_SCAN_4_0, "7.2") return copy.deepcopy(example) raise ValueError(f"Could not generate example for schema {version})!")