Controlling subarrays without SBs

At the highest level, SKA subarrays are configured and controlled by a handful of commands, some of which require JSON control strings. Scripted control of subarrays can be achieved by creating these JSON control strings - either directly or by using the ska-cdm-library to create the Python equivalent of the JSON control strings - and then sending these to the subarray via SubArray methods or the appropriate ska-oso-scripting functions.

Consult the API documentation for ska_oso_scripting.objects.SubArray for details on the methods used to assign resources to a subarray, configure a subarray, perform a scan, etc.

See ska_oso_scripting.objects.Telescope for methods used to turn the telescope on and off.

See ska_oso_scripting.functions.devicecontrol for functions you can use for high-level telescope and subarray control.

Tweaking configuration strings

Resource allocation and configuration require lengthy JSON strings as input. Modifying these JSON payloads is most easily achieved by using classes from the ska-tmc-cdm project. Use of the Control Data Model (CDM) objects allows JSON payloads to be modified via Python rather than by modifying JSON strings directly and reading/writing those changes to a file.

In the absence of an SB, the recommended way to control the telescope is to:

  1. use the ska-oso-cdm library to convert JSON contained in a file or string to the equivalent Python objects

  2. perform any required modifications to the CDM objects

  3. relay the instructions to the control system using the appropriate methods (assign_from_cdm(), configure_from_cdm(), etc.)

The script below illustrates how this can be done.

 1 from datetime import timedelta
 2 from ska_tmc_cdm.messages.central_node.assign_resources import AssignResourcesRequest
 3 from ska_tmc_cdm.messages.subarray_node.configure import ConfigureRequest
 4 from ska_tmc_cdm.schemas import CODEC
 5 from ska_oso_scripting.objects import SubArray, Telescope
 6
 7 # Create telescope object to control telescope start-up and shut-down
 8 telescope = Telescope()
 9 # Create sub-array object which will form the target for subsequent instructions
10 subarray = SubArray(1)
11
12 # Turn the telescope on
13 telescope.on()
14
15 # Create a CDM AssignResourcesRequest object. This example loads JSON
16 # from file but a request can also be formed from a JSON string using
17 # CODEC.loads(AssignResourcesRequest, allocation_json_string)
18 request = CODEC.load_from_file(AssignResourcesRequest, file_path, timeout=None)
19 # Modify request object here if necessary, e.g.
20 request.dish.receptor_ids = ["SKA001", "SKA002", "SKA003", "SKA004"]
21 # issue resource allocation request
22 subarray.assign_from_cdm(request, timeout=None)
23
24 # Similarly, create a CDM ConfigureRequest object. Again, this could
25 # also be formed from a JSON string using
26 # CODEC.loads(ConfigureRequest, configuration_json_string)
27 request = CODEC.load_from_file(ConfigureRequest, file_path)
28 # Modify request object here if necessary, e.g.
29 request.tmc.scan_duration = timedelta(seconds=10.0)
30 # issue sub-array configuration request
31 subarray.configure_from_cdm(request)
32
33 # Execute scan
34 subarray.scan(timeout=None)
35
36 # End the Scheduling Block
37 subarray.end()
38
39 # release all sub-array resources
40 subarray.release(timeout=None)
41
42 # Set telescope to standby
43 telescope.off()

Control using static JSON

For an interaction where no modifications to the CDM are required, you can also use the assign_from_file() and configure_from_file() methods, which will relay the JSON directly to the control system. The JSON will be validated against the required JSON schema and any elements that are required to be unique from observation to observation, such as scheduling block ID and processing block ID, will managed as necessary.

Note

You can also send the raw JSON directly to the control system without performing any validation or ID updates by setting with_processing=False for these methods. However, it is then your responsibility to ensure that the CDM payloads are valid!

from ska_oso_scripting.objects import SubArray, Telescope

# Create telescope object to control telescope start-up and shut-down
telescope = Telescope()

# Turn the telescope on
telescope.on()

# Create domain object for the sub-array the commands will be sent to
subarray = SubArray(1)

# Allocate resources, provide a path to a file with allocation JSON
subarray.assign_from_file(path_to_allocation_json_file, timeout=None)

# Configure sub-array, provide a path to a file with configuration JSON
subarray.configure_from_file(configuration_json_file, scan_duration=10.0, timeout=None)

# Execute scan sub-array was configured for
subarray.scan()

# End the Scheduling Block
subarray.end()

# Set telescope to standby
telescope.off()