diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py index 0bdfdf731b5dc9c5c23e93b549cf8f9787c087f7..added8cc3514b8057c72300f9fa4eaa6ccfc3cb2 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py @@ -28,7 +28,7 @@ from lofar.common.cobaltblocksize import CorrelatorSettings, StokesSettings, Blo from lofar.mac.observation_control_rpc import ObservationControlRPCClient from lofar.mac.pipeline_control_rpc import PipelineControlRPCClient -from lofar.sas.tmss.tmss.tmssapp.conversions import antennafields_for_antennaset_and_station, create_astroplan_observer_for_station +from lofar.sas.tmss.tmss.tmssapp.conversions import antennafields_for_antennaset_and_station, create_location_for_station, Time from lofar.sas.tmss.tmss.exceptions import TMSSException, TooManyStationsUnavailableException from django.db import transaction from django.db.models import Q @@ -1637,14 +1637,8 @@ def schedule_observation_subtask(observation_subtask: Subtask): # create the dataproducts _bulk_create_dataproducts_with_global_identifiers(dataproducts) - # compute and set the scheduled central LST - from astropy.time import Time - scheduled_central_time = observation_subtask.scheduled_start_time + 0.5*(observation_subtask.scheduled_stop_time - observation_subtask.scheduled_start_time) - cs002_location = create_astroplan_observer_for_station('CS002').location - astropy_scheduled_central_time = Time(scheduled_central_time, scale='utc', location=cs002_location) - scheduled_central_lst = astropy_scheduled_central_time.sidereal_time('apparent') - scheduled_central_lst = datetime.fromordinal(scheduled_central_time.date().toordinal()) + timedelta(hours=scheduled_central_lst.hour) - observation_subtask.scheduled_central_lst = round_to_second_precision(scheduled_central_lst) + # compute and set the central LST + compute_scheduled_central_lst(observation_subtask) # step 4: set state to SCHEDULED (resulting in the qaservice to pick this subtask up and run it) observation_subtask.state = SubtaskState.objects.get(value=SubtaskState.Choices.SCHEDULED.value) @@ -1653,6 +1647,26 @@ def schedule_observation_subtask(observation_subtask: Subtask): observation_subtask.refresh_from_db() return observation_subtask +def compute_scheduled_central_lst(subtask: Subtask) -> Subtask: + '''compute and set the scheduled central LST''' + if subtask.specifications_template.type.value != SubtaskType.Choices.OBSERVATION.value: + raise ValueError("Cannot compute scheduled_central_lst for subtask id=%d type=%s but type should be %s" % (subtask.pk, + subtask.specifications_template.type, + SubtaskType.Choices.OBSERVATION.value)) + + # what is the timestamp in UTC halfway during the observation? + scheduled_duration = subtask.scheduled_stop_time - subtask.scheduled_start_time + scheduled_central_time = subtask.scheduled_start_time + 0.5*scheduled_duration + + # convert the UTC timestamp to LST at CS002 + cs002_location = create_location_for_station('CS002') + scheduled_central_lst = Time(scheduled_central_time, scale='utc', location=cs002_location).sidereal_time('apparent') + + # convert the astropy Longitude LST time back to a native python datetime including date + scheduled_central_lst = datetime.fromordinal(scheduled_central_time.date().toordinal()) + timedelta(hours=scheduled_central_lst.hour) + subtask.scheduled_central_lst = round_to_second_precision(scheduled_central_lst) + return subtask + def get_used_stations_in_timewindow(lower_bound: datetime, upper_bound: datetime) -> list: """ Get a list of all stations which are used in observations in the given timewindow.