diff --git a/docs/src/ska_mid_csp_scan.rst b/docs/src/ska_mid_csp_scan.rst new file mode 100644 index 0000000000000000000000000000000000000000..2bfcaa4f53366c34f4293f16409aa02617018043 --- /dev/null +++ b/docs/src/ska_mid_csp_scan.rst @@ -0,0 +1,14 @@ + +ska-mid-csp-scan +================ + +.. ska-schema:: https://schema.skatelescope.org/ska-mid-csp-scan/1.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skatelescope.org/ska-tmc-scan/1.0 + + Example JSON. diff --git a/docs/src/ska_mid_sdp_scan.rst b/docs/src/ska_mid_sdp_scan.rst new file mode 100644 index 0000000000000000000000000000000000000000..7201991990518868bd973c8241a713d8468e8fe8 --- /dev/null +++ b/docs/src/ska_mid_sdp_scan.rst @@ -0,0 +1,14 @@ + +ska-mid-sdp-scan +================ + +.. ska-schema:: https://schema.skatelescope.org/ska-mid-sdp-scan/1.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skatelescope.org/ska-mid-sdp-scan/1.0 + + Example JSON. diff --git a/docs/src/ska_mid_tmc_scan.rst b/docs/src/ska_mid_tmc_scan.rst new file mode 100644 index 0000000000000000000000000000000000000000..7ae88bd693481ae3d6eaadb33a834ec2b856db7d --- /dev/null +++ b/docs/src/ska_mid_tmc_scan.rst @@ -0,0 +1,14 @@ + +ska-tmc-scan +================ + +.. ska-schema:: https://schema.skatelescope.org/ska-tmc-scan/1.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skatelescope.org/ska-tmc-scan/1.0 + + Example JSON. diff --git a/src/ska_telmodel/csp/examples.py b/src/ska_telmodel/csp/examples.py index 71a896a4d72655887630731e3d50a49955cea562..198f1c850f0642b05a586bd176d3cca9cc0c194a 100644 --- a/src/ska_telmodel/csp/examples.py +++ b/src/ska_telmodel/csp/examples.py @@ -211,6 +211,11 @@ CSP_CONFIG_SCIENCE_A_0_1 = { ], } +CSP_MID_SCAN_1_0 = { + "interface": "https://schema.skatelescope.org/ska-mid-csp-scan/1.0", + "scan_id": 1, +} + def get_csp_config_example(version: str, scan: str = None) -> dict: """Generate examples for CSP configuration strings @@ -238,3 +243,14 @@ def get_csp_config_example(version: str, scan: str = None) -> dict: return copy.deepcopy(CSP_CONFIG_SCIENCE_A_1_0) raise ValueError(f"Could not generate example for schema {version} scan {scan}!") + + +def get_csp_mid_scan_example(version: str): + """Generate examples for CSP MID scan strings. + + :param version: Version URI of configuration format + """ + if version.startswith(csp_mid_scan_uri(1, 0)): + return copy.deepcopy(CSP_MID_SCAN_1_0) + + raise ValueError(f"Could not generate example for schema {version})!") diff --git a/src/ska_telmodel/csp/schema.py b/src/ska_telmodel/csp/schema.py index d8d0cbda2d03f6e9e8d6138cd519179ce313d5eb..3526ecc24f72fc5da49587bceb888e96d1fcbc70 100644 --- a/src/ska_telmodel/csp/schema.py +++ b/src/ska_telmodel/csp/schema.py @@ -590,3 +590,37 @@ def get_csp_config_schema(version: str, strict: bool) -> Schema: else: raise ValueError(f"Invalid JSON Schema URI {version}") + + +def get_csp_mid_scan_schema(version: str, strict: bool) -> Schema: + """SKA Mid CSP scan Schema + + :param version: Interface Version URI + :param strict: Schema strictness + :return: Schema + """ + + items = { + Literal( + "interface", + description=cleandoc( + """ + URI of JSON schema applicable to this JSON payload. + """ + ), + ): str, + Literal( + "scan_id", + description=cleandoc( + """ + Scan ID to associate with the data. + + The scan ID and SBI ID are used together to uniquely associate + the data taken with the telescope configuration in effect at + the moment of observation. + """ + ), + ): int, + } + + return _common.make("Mid CSP scan", version, strict, items) diff --git a/src/ska_telmodel/csp/version.py b/src/ska_telmodel/csp/version.py index b71a560093972d10fdeca8d5c82a674edf9180c8..02e99c19947e86550828a832a413bfdfd160b090 100644 --- a/src/ska_telmodel/csp/version.py +++ b/src/ska_telmodel/csp/version.py @@ -1,9 +1,12 @@ from typing import Union import logging -from .._common import split_interface_version +from .._common import split_interface_version, interface_uri +from functools import partial CSP_CONFIG_PREFIX = "https://schema.skatelescope.org/ska-csp-configure/" +CSP_MID_SCAN_PREFIX = "https://schema.skatelescope.org/ska-mid-csp-scan/" + CSP_CONFIG_VER0 = CSP_CONFIG_PREFIX + "0" # ADR-3 Configuring and Scanning, # ADR-4 Link map CSP configuration @@ -14,6 +17,8 @@ CSP_CONFIG_VER0_1 = CSP_CONFIG_PREFIX + "0.1" CSP_CONFIG_VER1 = CSP_CONFIG_PREFIX + "1" CSP_CONFIG_VER1_0 = CSP_CONFIG_PREFIX + "1.0" +CSP_MID_SCAN_VER1_0 = CSP_MID_SCAN_PREFIX + "1.0" + # CSP configuration versions, chronologically sorted CSP_CONFIG_VERSIONS = sorted( [CSP_CONFIG_VER0_0, CSP_CONFIG_VER0_1, CSP_CONFIG_VER1_0], @@ -56,3 +61,6 @@ def get_csp_config_version( f"CSP interface URI '%s' not recognised!", csp_interface_version ) return csp_interface_version + + +csp_mid_scan_uri = partial(interface_uri, CSP_MID_SCAN_PREFIX) diff --git a/src/ska_telmodel/schema.py b/src/ska_telmodel/schema.py index 88384082425f0b5848d23f49d6716fafafa2f49d..f66fb9064c0c3caff5e4d01f39d43b4f1523d40c 100644 --- a/src/ska_telmodel/schema.py +++ b/src/ska_telmodel/schema.py @@ -15,10 +15,12 @@ _LOGGER = logging.getLogger("ska_telmodel") # the schema for them URI_SCHEMA_MAP = { csp.CSP_CONFIG_PREFIX: csp.get_csp_config_schema, + csp.CSP_MID_SCAN_PREFIX: csp.get_csp_mid_scan_schema, # SDP schemas sdp.SDP_ASSIGNRES_PREFIX: sdp.get_sdp_assign_resources_schema, sdp.SDP_CONFIG_PREFIX: sdp.get_sdp_config_schema, sdp.SDP_SCAN_PREFIX: sdp.get_sdp_scan_schema, + sdp.SDP_MID_SCAN_PREFIX: sdp.get_sdp_mid_scan_schema, sdp.SDP_RECVADDRS_PREFIX: sdp.get_sdp_receive_addresses_schema, # MCCS schemas mccs.MCCS_ASSIGNEDRES_PREFIX: mccs.get_mccs_assignedres_schema, @@ -32,15 +34,19 @@ URI_SCHEMA_MAP = { tmc.TMC_RELEASERES_PREFIX: tmc.get_tmc_releaseres_schema, tmc.TMC_SCAN_PREFIX: tmc.get_tmc_scan_schema, tmc.TMC_ASSIGNEDRES_PREFIX: tmc.get_tmc_assignedres_schema, + # TMC MID schemas + tmc.TMC_MID_SCAN_PREFIX: tmc.get_tmc_mid_scan_schema, } # As above, but for example generation URI_EXAMPLE_MAP = { csp.CSP_CONFIG_PREFIX: csp_examples.get_csp_config_example, + csp.CSP_MID_SCAN_PREFIX: csp_examples.get_csp_mid_scan_example, # SDP schemas sdp.SDP_ASSIGNRES_PREFIX: sdp_examples.get_sdp_assignres_example, sdp.SDP_CONFIG_PREFIX: sdp_examples.get_sdp_config_example, sdp.SDP_SCAN_PREFIX: sdp_examples.get_sdp_scan_example, + sdp.SDP_MID_SCAN_PREFIX: sdp_examples.get_sdp_mid_scan_example, sdp.SDP_RECVADDRS_PREFIX: sdp_examples.get_sdp_recvaddrs_example, # MCCS schemas mccs.MCCS_ASSIGNEDRES_PREFIX: mccs_examples.get_mccs_assignedres_example, @@ -54,6 +60,8 @@ URI_EXAMPLE_MAP = { tmc.TMC_SCAN_PREFIX: tmc_examples.get_tmc_scan_example, tmc.TMC_RELEASERES_PREFIX: tmc_examples.get_tmc_releaseres_example, tmc.TMC_ASSIGNEDRES_PREFIX: tmc_examples.get_tmc_assignedres_example, + # TMC MID schemas + tmc.TMC_MID_SCAN_PREFIX: tmc_examples.get_tmc_mid_scan_example, } diff --git a/src/ska_telmodel/sdp/examples.py b/src/ska_telmodel/sdp/examples.py index 38fce2da36e701a7dae5396c0056ddacdb81de86..4c71766fc0c7ea90f54f874c711bad8ffa10a65e 100644 --- a/src/ska_telmodel/sdp/examples.py +++ b/src/ska_telmodel/sdp/examples.py @@ -143,6 +143,11 @@ def get_sdp_config_example(version: str, scan_type: str = "science_A") -> dict: SDP_SCAN = {"scan_type": "science_A"} +MID_SDP_SCAN = { + "interface": "https://schema.skatelescope.org/ska-mid-sdp-scan/1.0", + "scan_id": 1, +} + def get_sdp_scan_example(version: str, scan_type: str = "science_A") -> dict: """Generate examples for SDP scan command @@ -160,6 +165,19 @@ def get_sdp_scan_example(version: str, scan_type: str = "science_A") -> dict: raise ValueError(f"Could not generate example for schema {version}!") +def get_sdp_mid_scan_example(version: str) -> dict: + """Generate examples for Mid SDP scan command + + :param version: Version URI of resource assignment schema + :returns: Example dictionary + """ + + if version.startswith(SDP_MID_SCAN_PREFIX + "1.0"): + return copy.deepcopy(MID_SDP_SCAN) + + raise ValueError(f"Could not generate example for schema {version}!") + + SDP_RECEIVE_ADDR_MAP = { "science_A": { "host": [ diff --git a/src/ska_telmodel/sdp/schema.py b/src/ska_telmodel/sdp/schema.py index b3b87ba5540e6d3de061bf5f9252396548bd3254..258c1edef59cf389a6ff83dc0770ea1bf6a86f78 100644 --- a/src/ska_telmodel/sdp/schema.py +++ b/src/ska_telmodel/sdp/schema.py @@ -5,6 +5,7 @@ Used for checking SDP strings for conformance from schema import Schema, Optional, And, Or, Literal from .. import _common from .version import * +from inspect import cleandoc def get_sbi_name_schema(version: str, strict: bool) -> Schema: @@ -134,7 +135,7 @@ def get_sdp_config_schema(version: str, strict: bool) -> Schema: def get_sdp_scan_schema(version: str, strict: bool) -> Schema: """ - Returns a schema to verify a SDP scan parameter + Returns a schema to verify a Low SDP scan parameter :param version: SDP Interface version :param strict: Strict mode @@ -150,6 +151,45 @@ def get_sdp_scan_schema(version: str, strict: bool) -> Schema: ) +def get_sdp_mid_scan_schema(version: str, strict: bool) -> Schema: + """ + Returns a schema to verify a Mid SDP scan parameter + + :param version: Mid SDP Interface version + :param strict: Strict mode + """ + + items = { + Literal( + "interface", + description=cleandoc( + """ + URI of JSON schema applicable to this JSON payload. + """ + ), + ): str, + Literal( + "scan_id", + description=cleandoc( + """ + Scan ID to associate with the data. + + The scan ID and SBI ID are used together to uniquely associate + the data taken with the telescope configuration in effect at + the moment of observation. + """ + ), + ): int, + } + + return _common.make( + "Mid SDP scan", + version, + strict, + items, + ) + + def get_sdp_receive_addresses_schema(version: str, strict: bool) -> Schema: """ Returns a schema to verify an SDP receive address map diff --git a/src/ska_telmodel/sdp/version.py b/src/ska_telmodel/sdp/version.py index d7212706cbd076bdce8891898a0eaa92a241ff0e..98c056f0888bae6bc56b4bc82eec6cde47a1b0f0 100644 --- a/src/ska_telmodel/sdp/version.py +++ b/src/ska_telmodel/sdp/version.py @@ -4,6 +4,7 @@ import logging SDP_ASSIGNRES_PREFIX = "https://schema.skatelescope.org/ska-sdp-assignres/" SDP_CONFIG_PREFIX = "https://schema.skatelescope.org/ska-sdp-configure/" SDP_SCAN_PREFIX = "https://schema.skatelescope.org/ska-sdp-scan/" +SDP_MID_SCAN_PREFIX = "https://schema.skatelescope.org/ska-mid-sdp-scan/" SDP_RECVADDRS_PREFIX = "https://schema.skatelescope.org/ska-sdp-recvaddrs/" SDP_CONFIG_VER0 = SDP_CONFIG_PREFIX + "0" @@ -20,6 +21,7 @@ _PREFIXES = [ SDP_ASSIGNRES_PREFIX, SDP_CONFIG_PREFIX, SDP_SCAN_PREFIX, + SDP_MID_SCAN_PREFIX, SDP_RECVADDRS_PREFIX, ] diff --git a/src/ska_telmodel/tmc/examples.py b/src/ska_telmodel/tmc/examples.py index 59fd18ddc5ba20caa196e609ed3d202a6a157726..a5acda4da769e3d1fa802190f9dc3af20d905093 100644 --- a/src/ska_telmodel/tmc/examples.py +++ b/src/ska_telmodel/tmc/examples.py @@ -47,6 +47,11 @@ TMC_SCAN_1_0 = { "scan_id": 1, } +TMC_MID_SCAN_1_0 = { + "interface": "https://schema.skatelescope.org/ska-tmc-scan/1.0", + "scan_id": 1, +} + TMC_ASSIGNEDRES_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-assignedresources/1.0", "mccs": { @@ -110,6 +115,17 @@ def get_tmc_scan_example(version: str): raise ValueError(f"Could not generate example for schema {version})!") +def get_tmc_mid_scan_example(version: str): + """Generate examples for TMC MID scan strings. + + :param version: Version URI of configuration format + """ + if version.startswith(tmc_mid_scan_uri(1, 0)): + return copy.deepcopy(TMC_MID_SCAN_1_0) + + raise ValueError(f"Could not generate example for schema {version})!") + + def get_tmc_assignedres_example(version: str, empty: bool = False): """Generate examples for TMC assigned resources strings. diff --git a/src/ska_telmodel/tmc/schema.py b/src/ska_telmodel/tmc/schema.py index 7e13effdecade3c01338d73659540d7475fd272e..277ca7b5741f85d1984103e2a7ff94e07c0f8583 100644 --- a/src/ska_telmodel/tmc/schema.py +++ b/src/ska_telmodel/tmc/schema.py @@ -435,6 +435,40 @@ def get_tmc_scan_schema(version: str, strict: bool) -> Schema: return _common.make("Low TMC scan", version, strict, items) +def get_tmc_mid_scan_schema(version: str, strict: bool) -> Schema: + """SKA Mid Monitoring and Control scan schema + + :param version: Interface Version URI + :param strict: Schema strictness + :return: Schema + """ + + items = { + Literal( + "interface", + description=cleandoc( + """ + URI of JSON schema applicable to this JSON payload. + """ + ), + ): str, + Literal( + "scan_id", + description=cleandoc( + """ + Scan ID to associate with the data. + + The scan ID and SBI ID are used together to uniquely associate + the data taken with the telescope configuration in effect at + the moment of observation. + """ + ), + ): int, + } + + return _common.make("Mid TMC scan", version, strict, items) + + def get_tmc_releaseres_schema(version: str, strict: bool) -> Schema: """SKA Low Monitoring and Control resources release schema diff --git a/src/ska_telmodel/tmc/version.py b/src/ska_telmodel/tmc/version.py index 272ac94cfd03b4ecd98b0da59e03f9a67bf9fa6f..96e019b89d829c41349a2b809187b79d6716b7e2 100644 --- a/src/ska_telmodel/tmc/version.py +++ b/src/ska_telmodel/tmc/version.py @@ -9,9 +9,15 @@ TMC_ASSIGNEDRES_PREFIX = ( "https://schema.skatelescope.org/ska-low-tmc-assignedresources/" ) +TMC_MID_SCAN_PREFIX = "https://schema.skatelescope.org/ska-tmc-scan/" + + # JSON strings for MVP-Low for PI#10 tmc_assignedres_uri = partial(interface_uri, TMC_ASSIGNEDRES_PREFIX) tmc_assignres_uri = partial(interface_uri, TMC_ASSIGNRES_PREFIX) tmc_configure_uri = partial(interface_uri, TMC_CONFIGURE_PREFIX) tmc_scan_uri = partial(interface_uri, TMC_SCAN_PREFIX) tmc_releaseres_uri = partial(interface_uri, TMC_RELEASERES_PREFIX) + +# JSON strings for Mid for PI#11 +tmc_mid_scan_uri = partial(interface_uri, TMC_MID_SCAN_PREFIX) diff --git a/tests/test_csp_config.py b/tests/test_csp_config.py index aabb367e391b1c4570912c7fec3cc82ecd8b41b4..b078978578a3fc5220c32f45c5eed32b4d12f1c3 100644 --- a/tests/test_csp_config.py +++ b/tests/test_csp_config.py @@ -208,3 +208,27 @@ def test_schema_example_with_invalid_parameters(): msg = "Unknown schema URI kind for example: https://invalid_uri/2.0!" with pytest.raises(ValueError, match=msg): example_by_uri("https://invalid_uri/2.0") + + +def test_mid_csp_scan(): + """Test CSP scan schema correctly validates the + expected JSON. + """ + scan_ver = csp_mid_scan_uri(1, 0) + validate(scan_ver, example_by_uri(scan_ver), 2) + + # Check that an error is raised if 'scan_id' is omitted + csp_scan_erronous = example_by_uri(scan_ver) + del csp_scan_erronous["scan_id"] + validate(scan_ver, csp_scan_erronous, 0) + with pytest.raises(ValueError): + validate(scan_ver, csp_scan_erronous, 1) + + # Try with interface version given as part of JSON object + csp_scan_versioned = example_by_uri(scan_ver) + csp_scan_versioned["interface"] = scan_ver + validate(None, csp_scan_versioned, 1) + + # Check invalid version raises error + with pytest.raises(ValueError, match=r"Could not generate example"): + example_by_uri(CSP_MID_SCAN_PREFIX + "0.0") diff --git a/tests/test_sdp_schemas.py b/tests/test_sdp_schemas.py index 20035180009a526e52c2923ec63c442a44d0f026..b70991c0891c99affd0bbcfb897265b38088faeb 100644 --- a/tests/test_sdp_schemas.py +++ b/tests/test_sdp_schemas.py @@ -96,6 +96,13 @@ def test_sdp_scan(): validate(scan_ver1, example_by_uri(scan_ver1), 2) +def test_mid_sdp_scan(): + + scan_ver1 = SDP_MID_SCAN_PREFIX + "1.0" + + validate(scan_ver1, example_by_uri(scan_ver1), 2) + + def test_sdp_invalid_examples(): with pytest.raises(ValueError, match=r"Could not generate example"):