import copy
from typing import Union
from .version import (
SDP_ASSIGNRES_PREFIX,
SDP_CONFIGURE_PREFIX,
SDP_RECVADDRS_PREFIX,
SDP_RELEASERES_PREFIX,
SDP_SCAN_PREFIX,
check_sdp_interface_version,
normalise_sdp_interface_version,
)
SDP_ASSIGNRES_0_2 = {
"id": "sbi-mvp01-20200325-00001",
"max_length": 100.0,
"scan_types": [
{
"id": "science",
"coordinate_system": "ICRS",
"ra": "02:42:40.771",
"dec": "-00:00:47.84",
"channels": [
{
"count": 744,
"start": 0,
"stride": 2,
"freq_min": 0.35e9,
"freq_max": 0.368e9,
"link_map": [[0, 0], [200, 1], [744, 2], [944, 3]],
},
{
"count": 744,
"start": 2000,
"stride": 1,
"freq_min": 0.36e9,
"freq_max": 0.368e9,
"link_map": [[2000, 4], [2200, 5]],
},
],
},
{
"id": "calibration",
"coordinate_system": "ICRS",
"ra": "12:29:06.699",
"dec": "02:03:08.598",
"channels": [
{
"count": 744,
"start": 0,
"stride": 2,
"freq_min": 0.35e9,
"freq_max": 0.368e9,
"link_map": [[0, 0], [200, 1], [744, 2], [944, 3]],
},
{
"count": 744,
"start": 2000,
"stride": 1,
"freq_min": 0.36e9,
"freq_max": 0.368e9,
"link_map": [[2000, 4], [2200, 5]],
},
],
},
],
"processing_blocks": [
{
"id": "pb-mvp01-20200325-00001",
"workflow": {
"type": "realtime",
"id": "vis_receive",
"version": "0.1.0",
},
"parameters": {},
},
{
"id": "pb-mvp01-20200325-00002",
"workflow": {
"type": "realtime",
"id": "test_realtime",
"version": "0.1.0",
},
"parameters": {},
},
{
"id": "pb-mvp01-20200325-00003",
"workflow": {"type": "batch", "id": "ical", "version": "0.1.0"},
"parameters": {},
"dependencies": [
{"pb_id": "pb-mvp01-20200325-00001", "type": ["visibilities"]}
],
},
{
"id": "pb-mvp01-20200325-00004",
"workflow": {"type": "batch", "id": "dpreb", "version": "0.1.0"},
"parameters": {},
"dependencies": [
{"pb_id": "pb-mvp01-20200325-00003", "type": ["calibration"]}
],
},
],
}
SDP_ASSIGNRES_0_3 = {
"eb_id": "eb-mvp01-20210623-00000",
"max_length": 100.0,
"scan_types": [
{
"scan_type_id": "science",
"reference_frame": "ICRS",
"ra": "02:42:40.771",
"dec": "-00:00:47.84",
"channels": [
{
"count": 744,
"start": 0,
"stride": 2,
"freq_min": 0.35e9,
"freq_max": 0.368e9,
"link_map": [[0, 0], [200, 1], [744, 2], [944, 3]],
},
{
"count": 744,
"start": 2000,
"stride": 1,
"freq_min": 0.36e9,
"freq_max": 0.368e9,
"link_map": [[2000, 4], [2200, 5]],
},
],
},
{
"scan_type_id": "calibration",
"reference_frame": "ICRS",
"ra": "12:29:06.699",
"dec": "02:03:08.598",
"channels": [
{
"count": 744,
"start": 0,
"stride": 2,
"freq_min": 0.35e9,
"freq_max": 0.368e9,
"link_map": [[0, 0], [200, 1], [744, 2], [944, 3]],
},
{
"count": 744,
"start": 2000,
"stride": 1,
"freq_min": 0.36e9,
"freq_max": 0.368e9,
"link_map": [[2000, 4], [2200, 5]],
},
],
},
],
"processing_blocks": [
{
"pb_id": "pb-mvp01-20210623-00000",
"workflow": {
"kind": "realtime",
"name": "vis_receive",
"version": "0.1.0",
},
"parameters": {},
},
{
"pb_id": "pb-mvp01-20210623-00001",
"workflow": {
"kind": "realtime",
"name": "test_realtime",
"version": "0.1.0",
},
"parameters": {},
},
{
"pb_id": "pb-mvp01-20210623-00002",
"workflow": {"kind": "batch", "name": "ical", "version": "0.1.0"},
"parameters": {},
"dependencies": [
{"pb_id": "pb-mvp01-20210623-00000", "kind": ["visibilities"]}
],
},
{
"pb_id": "pb-mvp01-20210623-00003",
"workflow": {"kind": "batch", "name": "dpreb", "version": "0.1.0"},
"parameters": {},
"dependencies": [
{"pb_id": "pb-mvp01-20210623-00002", "kind": ["calibration"]}
],
},
],
}
SDP_ASSIGNRES_0_4 = {
"execution_block": {
"eb_id": "eb-mvp01-20210623-00000",
"max_length": 100.0,
"context": {},
"beams": [
{
"beam_id": "vis0",
"function": "visibilities",
},
{
"beam_id": "pss1",
"search_beam_id": 1,
"function": "pulsar search",
},
{
"beam_id": "pss2",
"search_beam_id": 2,
"function": "pulsar search",
},
{
"beam_id": "pst1",
"timing_beam_id": 1,
"function": "pulsar timing",
},
{
"beam_id": "pst2",
"timing_beam_id": 2,
"function": "pulsar timing",
},
{
"beam_id": "vlbi1",
"vlbi_beam_id": 1,
"function": "vlbi",
},
],
"scan_types": [
{
"scan_type_id": ".default",
"beams": {
"vis0": {
"channels_id": "vis_channels",
"polarisations_id": "all",
},
"pss1": {
"field_id": "pss_field_0",
"channels_id": "pulsar_channels",
"polarisations_id": "all",
},
"pss2": {
"field_id": "pss_field_1",
"channels_id": "pulsar_channels",
"polarisations_id": "all",
},
"pst1": {
"field_id": "pst_field_0",
"channels_id": "pulsar_channels",
"polarisations_id": "all",
},
"pst2": {
"field_id": "pst_field_1",
"channels_id": "pulsar_channels",
"polarisations_id": "all",
},
"vlbi": {
"field_id": "vlbi_field",
"channels_id": "vlbi_channels",
"polarisations_id": "all",
},
},
},
{
"scan_type_id": "target:a",
"derive_from": ".default",
"beams": {"vis0": {"field_id": "field_a"}},
},
],
"channels": [
{
"channels_id": "vis_channels",
"spectral_windows": [
{
"spectral_window_id": "fsp_1_channels",
"count": 744,
"start": 0,
"stride": 2,
"freq_min": 350000000.0,
"freq_max": 368000000.0,
"link_map": [[0, 0], [200, 1], [744, 2], [944, 3]],
},
{
"spectral_window_id": "fsp_2_channels",
"count": 744,
"start": 2000,
"stride": 1,
"freq_min": 360000000.0,
"freq_max": 368000000.0,
"link_map": [[2000, 4], [2200, 5]],
},
{
"spectral_window_id": "zoom_window_1",
"count": 744,
"start": 4000,
"stride": 1,
"freq_min": 360000000.0,
"freq_max": 361000000.0,
"link_map": [[4000, 6], [4200, 7]],
},
],
},
{
"channels_id": "pulsar_channels",
"spectral_windows": [
{
"spectral_window_id": "pulsar_fsp_channels",
"count": 744,
"start": 0,
"freq_min": 350000000.0,
"freq_max": 368000000.0,
}
],
},
],
"polarisations": [
{"polarisations_id": "all", "corr_type": ["XX", "XY", "YY", "YX"]}
],
"fields": [
{
"field_id": "field_a",
"phase_dir": {
"ra": [123, 0.1],
"dec": [80, 0.1],
"reference_time": "...",
"reference_frame": "ICRF3",
},
"pointing_fqdn": "low-tmc/telstate/0/pointing",
}
],
},
"processing_blocks": [
{
"pb_id": "pb-mvp01-20210623-00000",
"sbi_ids": ["sbi-mvp01-20200325-00001"],
"script": {
"kind": "realtime",
"name": "vis_receive",
"version": "0.1.0",
},
"parameters": {},
},
{
"pb_id": "pb-mvp01-20210623-00001",
"sbi_ids": ["sbi-mvp01-20200325-00001"],
"script": {
"kind": "realtime",
"name": "test_realtime",
"version": "0.1.0",
},
"parameters": {},
},
{
"pb_id": "pb-mvp01-20210623-00002",
"sbi_ids": ["sbi-mvp01-20200325-00002"],
"script": {"kind": "batch", "name": "ical", "version": "0.1.0"},
"parameters": {},
"dependencies": [
{"pb_id": "pb-mvp01-20210623-00000", "kind": ["visibilities"]}
],
},
{
"pb_id": "pb-mvp01-20210623-00003",
"sbi_ids": [
"sbi-mvp01-20200325-00001",
"sbi-mvp01-20200325-00002",
],
"script": {"kind": "batch", "name": "dpreb", "version": "0.1.0"},
"parameters": {},
"dependencies": [
{"pb_id": "pb-mvp01-20210623-00002", "kind": ["calibration"]}
],
},
],
}
EXTERNAL_RESOURCES = {
# All permanent resources are grouped under a "resources" key
# to make clear that they are permanent
"resources": {
# If lists are given, they are treated as sets.
# So we could "release" [4,3] here,
# and would end up with [1,2] still assigned.
"csp_links": [1, 2, 3, 4],
# Similar logic with receptors (Mid: dishes, Low: [sub]stations).
# See above for name discussion.
# The example below is the (planned) AA2 layout.
"receptors": [
"FS4",
"FS8",
"FS16",
"FS17",
"FS22",
"FS23",
"FS30",
"FS31",
"FS32",
"FS33",
"FS36",
"FS52",
"FS56",
"FS57",
"FS59",
"FS62",
"FS66",
"FS69",
"FS70",
"FS72",
"FS73",
"FS78",
"FS80",
"FS88",
"FS89",
"FS90",
"FS91",
"FS98",
"FS108",
"FS111",
"FS132",
"FS144",
"FS146",
"FS158",
"FS165",
"FS167",
"FS176",
"FS183",
"FS193",
"FS200",
"FS345",
"FS346",
"FS347",
"FS348",
"FS349",
"FS350",
"FS351",
"FS352",
"FS353",
"FS354",
"FS355",
"FS356",
"FS429",
"FS430",
"FS431",
"FS432",
"FS433",
"FS434",
"FS465",
"FS466",
"FS467",
"FS468",
"FS469",
"FS470",
],
# Allocated receive nodes
"receive_nodes": 10,
}
}
# This not-so-nice syntax for merging dicts can
# be replaced with a nicer one from Python 3.9.
SDP_ASSIGNRES_0_4 = {**SDP_ASSIGNRES_0_4, **EXTERNAL_RESOURCES}
SDP_RELEASERES_0_4 = EXTERNAL_RESOURCES
[docs]def get_sdp_assignres_example(version: Union[int, str]) -> dict:
"""
Generate example of SDP assign resources argument.
:param version: SDP assign resources version
:returns: Example dictionary
"""
version = normalise_sdp_interface_version(version, SDP_ASSIGNRES_PREFIX)
number = check_sdp_interface_version(version, SDP_ASSIGNRES_PREFIX)
if number == "0.2":
return copy.deepcopy(SDP_ASSIGNRES_0_2)
if number == "0.3":
return copy.deepcopy(SDP_ASSIGNRES_0_3)
if number == "0.4":
return copy.deepcopy(SDP_ASSIGNRES_0_4)
raise ValueError(f"Could not generate example for schema {version}!")
[docs]def get_sdp_releaseres_example(version: Union[int, str]) -> dict:
"""
Generate example of SDP release resources argument.
:param version: SDP release resources version
:returns: Example dictionary
"""
version = normalise_sdp_interface_version(version, SDP_RELEASERES_PREFIX)
number = check_sdp_interface_version(version, SDP_RELEASERES_PREFIX)
if number == "0.4":
return copy.deepcopy(SDP_RELEASERES_0_4)
raise ValueError(f"Could not generate example for schema {version}!")
SDP_CONFIGURE_0_2 = {"scan_type": "science"}
SDP_CONFIGURE_NEW_SCAN_0_2 = {
"new_scan_types": [
{
"id": "new_calibration",
"channels": [
{
"count": 372,
"start": 0,
"stride": 2,
"freq_min": 0.35e9,
"freq_max": 0.358e9,
"link_map": [[0, 0], [200, 1]],
}
],
}
],
"scan_type": "new_calibration",
}
SDP_CONFIGURE_0_3 = {"scan_type": "science"}
SDP_CONFIGURE_NEW_SCAN_0_3 = {
"new_scan_types": [
{
"scan_type_id": "new_calibration",
"channels": [
{
"count": 372,
"start": 0,
"stride": 2,
"freq_min": 0.35e9,
"freq_max": 0.358e9,
"link_map": [[0, 0], [200, 1]],
}
],
}
],
"scan_type": "new_calibration",
}
SDP_SCAN_0_2 = {"id": 1}
SDP_SCAN_0_3 = {"scan_id": 1}
[docs]def get_sdp_scan_example(version: Union[int, str], scan_id: int = 1) -> dict:
"""
Generate example of SDP scan argument.
:param version: SDP scan version
:param scan_id: Scan ID to start
:returns: Example dictionary
"""
version = normalise_sdp_interface_version(version, SDP_SCAN_PREFIX)
number = check_sdp_interface_version(version, SDP_SCAN_PREFIX)
if number == "0.2":
config = copy.deepcopy(SDP_SCAN_0_2)
config["id"] = scan_id
return config
if number in ["0.3", "0.4"]:
config = copy.deepcopy(SDP_SCAN_0_3)
config["scan_id"] = scan_id
return config
raise ValueError(f"Could not generate example for schema {version}!")
SDP_RECVADDRS_V1 = {
"scanId": 1,
"totalChannels": 7,
"receiveAddresses": [
{
"phaseBinId": 0,
"fspId": 1,
"hosts": [
{
"host": "192.168.0.0",
"channels": [
{
"portOffset": 9153,
"startChannel": 153,
"numChannels": 1,
},
{
"portOffset": 9273,
"startChannel": 273,
"numChannels": 1,
},
{
"portOffset": 9313,
"startChannel": 313,
"numChannels": 1,
},
{
"portOffset": 9529,
"startChannel": 529,
"numChannels": 1,
},
{
"portOffset": 9665,
"startChannel": 665,
"numChannels": 1,
},
{
"portOffset": 9681,
"startChannel": 681,
"numChannels": 2,
},
],
}
],
}
],
}
SDP_RECVADDRS_V2 = {
"science": {
"host": [
[0, "192.168.0.1"],
[400, "192.168.0.2"],
[744, "192.168.0.3"],
[1144, "192.168.0.4"],
],
"mac": [[0, "06-00-00-00-00-00"], [744, "06-00-00-00-00-01"]],
"port": [
[0, 9000, 1],
[400, 9000, 1],
[744, 9000, 1],
[1144, 9000, 1],
],
},
"calibration": {"host": [[0, "192.168.1.1"]], "port": [[0, 9000, 1]]},
}
SDP_RECVADDRS_V3 = {
"science": {
"vis0": {
"function": "visibilities",
"host": [
[0, "192.168.0.1"],
[400, "192.168.0.2"],
[744, "192.168.0.3"],
[1144, "192.168.0.4"],
],
"port": [
[0, 9000, 1],
[400, 9000, 1],
[744, 9000, 1],
[1144, 9000, 1],
],
"mac": [[0, "06-00-00-00-00-00"], [744, "06-00-00-00-00-01"]],
"delay_cal": [
[0, "low-sdp/telstate/rcal0/delay0"],
[400, "low-sdp/telstate/rcal0/delay1"],
[744, "low-sdp/telstate/rcal0/delay2"],
[1144, "low-sdp/telstate/rcal0/delay2"],
],
},
"pss1": {
"function": "pulsar search",
"search_beam_id": 1,
"host": [[0, "192.168.60.0"]],
"port": [[0, 8000]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
[400, "low-sdp/telstate/rcal0/jones1"],
[744, "low-sdp/telstate/rcal0/jones2"],
[1144, "low-sdp/telstate/rcal0/jones2"],
],
},
"pss2": {
"function": "pulsar search",
"search_beam_id": 2,
"host": [[0, "192.168.60.1"]],
"port": [[0, 8000]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
[400, "low-sdp/telstate/rcal0/jones1"],
[744, "low-sdp/telstate/rcal0/jones2"],
[1144, "low-sdp/telstate/rcal0/jones2"],
],
},
"pst1": {
"function": "pulsar timing",
"timing_beam_id": 1,
"host": [[0, "192.168.60.2"]],
"port": [[0, 8001]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
[400, "low-sdp/telstate/rcal0/jones1"],
[744, "low-sdp/telstate/rcal0/jones2"],
[1144, "low-sdp/telstate/rcal0/jones2"],
],
},
"pst2": {
"function": "pulsar timing",
"timing_beam_id": 2,
"host": [[0, "192.168.60.3"]],
"port": [[0, 8002]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
[400, "low-sdp/telstate/rcal0/jones1"],
[744, "low-sdp/telstate/rcal0/jones2"],
[1144, "low-sdp/telstate/rcal0/jones2"],
],
},
},
"calibration": {
"vis0": {
"function": "visibilities",
"host": [
[0, "192.168.1.1"],
],
"port": [
[0, 9000, 1],
],
"delay_cal": [
[0, "low-sdp/telstate/rcal0/delay0"],
],
},
"pss1": {
"function": "pulsar search",
"search_beam_id": 1,
"host": [[0, "192.168.60.0"]],
"port": [[0, 8003]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
],
},
"pss2": {
"function": "pulsar search",
"search_beam_id": 2,
"host": [[0, "192.168.60.1"]],
"port": [[0, 8002]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
],
},
"pst1": {
"function": "pulsar timing",
"timing_beam_id": 0,
"host": [[0, "192.168.60.2"]],
"port": [[0, 8001]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
],
},
"pst2": {
"function": "pulsar timing",
"timing_beam_id": 1,
"host": [[0, "192.168.60.3"]],
"port": [[0, 8000]],
"jones_cal": [
[0, "low-sdp/telstate/rcal0/jones0"],
],
},
},
}
SDP_RECVADDRS_V4 = copy.deepcopy(SDP_RECVADDRS_V3)
SDP_RECVADDRS_V4["science"]["vis0"][
"pointing_cal"
] = "tango://low-sdp/queueconnector/01/pointing_offsets_{dish_id}"
SDP_RECVADDRS_V4["calibration"]["vis0"][
"pointing_cal"
] = "tango://low-sdp/queueconnector/01/pointing_offsets_{dish_id}"
SDP_RECVADDRS_V4["science"]["vis0"][
"delay_cal"
] = "low-sdp/telstate/rcal0/delay"
SDP_RECVADDRS_V4["calibration"]["vis0"][
"delay_cal"
] = "low-sdp/telstate/rcal0/delay"
[docs]def get_sdp_recvaddrs_example(version: Union[int, str]) -> dict:
"""
Generate example of SDP receive addresses map.
:param version: SDP receive addresses version
:returns: Example dictionary
"""
version = normalise_sdp_interface_version(version, SDP_RECVADDRS_PREFIX)
number = check_sdp_interface_version(version, SDP_RECVADDRS_PREFIX)
if number == "0.1":
return copy.deepcopy(SDP_RECVADDRS_V1)
if number in ("0.2", "0.3"):
return copy.deepcopy(SDP_RECVADDRS_V2)
if number == "0.4":
return copy.deepcopy(SDP_RECVADDRS_V3)
if number == "0.5":
return copy.deepcopy(SDP_RECVADDRS_V4)
raise ValueError(f"Could not generate example for schema {version}!")