diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py index 4fe567030157c268a2fd63275fc23f6fbe8b6ff4..71b949d0c020dfcb75264816257aaaaa7b5fa2f2 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py @@ -299,6 +299,7 @@ def create_observation_control_subtask_from_task_blueprint(task_blueprint: TaskB # an observation has no input, it just produces output data subtask_output = SubtaskOutput.objects.create(subtask=subtask, task_blueprint=task_blueprint) + logger.warning("######## created subtaskoutput id=%s for tb=%s" % (subtask_output.id, task_blueprint.name)) # step 3: set state to DEFINED, unless we have a target obs with a related parallel calibrator obs defined = True @@ -1021,12 +1022,32 @@ def schedule_observation_subtask(observation_subtask: Subtask): specifications_doc = observation_subtask.specifications_doc dataproduct_specifications_template = DataproductSpecificationsTemplate.objects.get(name="SAP") # todo: should this be derived from the task relation specification template? dataproduct_feedback_template = DataproductFeedbackTemplate.objects.get(name="empty") - subtask_output = observation_subtask.outputs.first() # TODO: make proper selection, not default first() directory = "/data/%s/%s/L%s/uv" % ("projects" if isProductionEnvironment() else "test-projects", observation_subtask.task_blueprints.first().scheduling_unit_blueprint.draft.scheduling_set.project.name, # todo: first? observation_subtask.id) + # select correct output for each pointing based on name + subtask_output_dict = {} + for task_blueprint in observation_subtask.task_blueprints.all(): + output = observation_subtask.outputs.filter(task_blueprint=task_blueprint).first() + logger.warning('########### tb=%s | output=%s' % (task_blueprint.name, output)) + if not output: + # todo: Do not fall back. But why don't outputs alsways match the task blueprints + output = observation_subtask.outputs.first() + #raise Exception('####### %s | %s' % (observation_subtask.task_blueprints.all(), [out.task_blueprint for out in observation_subtask.outputs.all()])) + if 'SAPs' in task_blueprint.specifications_doc: # target + for sap in task_blueprint.specifications_doc['SAPs']: + logger.warning('########### tb=%s | output=%s | pointing=%s' % (task_blueprint.name, output, sap['name'])) + subtask_output_dict[sap['name']] = output + if 'pointing' in task_blueprint.specifications_doc: # calibrator + subtask_output_dict[task_blueprint.specifications_doc['name']] = output + logger.warning('########### tb=%s | output=%s | pointing=%s' % (task_blueprint.name, output, task_blueprint.specifications_doc['name'])) + for sap_nr, pointing in enumerate(specifications_doc['stations']['digital_pointings']): + if pointing['name'] in subtask_output_dict: + subtask_output = subtask_output_dict[pointing['name']] + else: + raise SubtaskSchedulingException('Cannot schedule subtask id=%s because the output for pointing name=%s cannot be determined.' % (observation_subtask.id, pointing['name'])) antennaset = specifications_doc['stations']['antenna_set'] antennafields = [] for station in specifications_doc['stations']['station_list']: @@ -1050,7 +1071,7 @@ def schedule_observation_subtask(observation_subtask: Subtask): directory=directory, dataformat=Dataformat.objects.get(value="MeasurementSet"), datatype=Datatype.objects.get(value="visibilities"), - producer=subtask_output, # Select correct output for target or calibrator. Depending on pointing name? + producer=subtask_output, specifications_doc={"sap": [str(sap_nr)]}, specifications_template=dataproduct_specifications_template, feedback_doc=get_default_json_object_for_schema(dataproduct_feedback_template.schema), diff --git a/SAS/TMSS/backend/test/t_scheduling.py b/SAS/TMSS/backend/test/t_scheduling.py index 877248bf200226035620a0c00eea3e9146772a40..99c3555396cef4377553c3132f08959badba9f0c 100755 --- a/SAS/TMSS/backend/test/t_scheduling.py +++ b/SAS/TMSS/backend/test/t_scheduling.py @@ -470,13 +470,16 @@ class SubtaskInputOutputTest(unittest.TestCase): placement=models.SchedulingRelationPlacement.objects.get(value='parallel')) # specify two beams with known number of subbands - target_task_blueprint.specifications_doc['SAPs'] = [{'name': 'target1', 'target': '', 'subbands': [0, 1], + target_task_blueprint.specifications_doc['SAPs'] = [{'name': 'target1_combined', 'target': '', 'subbands': [0, 1], 'digital_pointing': {'angle1': 0.1, 'angle2': 0.1, 'angle3': 0.1, 'direction_type': 'J2000'}}, - {'name': 'target2', 'target': '', 'subbands': [2, 3, 4], + {'name': 'target2_combined', 'target': '', 'subbands': [2, 3, 4], 'digital_pointing': {'angle1': 0.1, 'angle2': 0.1, 'angle3': 0.1, 'direction_type': 'J2000'}} ] + target_task_blueprint.save() + cal_task_blueprint.specifications_doc['name'] = "calibrator_combined" + cal_task_blueprint.save() # create subtask create_observation_control_subtask_from_task_blueprint(target_task_blueprint)