diff --git a/src/sorunlib/seq.py b/src/sorunlib/seq.py index 217f99ed..4082a33a 100644 --- a/src/sorunlib/seq.py +++ b/src/sorunlib/seq.py @@ -26,8 +26,8 @@ def _stop_scan(): print("Scan finished.") -def scan(description, stop_time, width, az_drift=0, tag=None, subtype=None, - min_duration=None): +def scan(description, stop_time, width, az_drift=0, start_position=None, + tag=None, subtype=None, min_duration=None): """Run a constant elevation scan, collecting detector data. Args: @@ -35,9 +35,13 @@ def scan(description, stop_time, width, az_drift=0, tag=None, subtype=None, stop_time (str): Time in ISO format to scan until, i.e. "2022-06-21T15:58:00" width (float): Scan width in azimuth. The scan will start at the - current position and move in the positive azimuth direction. + current position unless specified in ``start_position``. The scan + moves in the positive azimuth direction. az_drift (float): Drift velocity in deg/s, causing scan extrema to move accordingly. + start_position (tuple, optional): Starting position given as (azimuth, + elevation). If provided, the telescope will move to this position + before starting the scan. tag (str, optional): Tag or comma-separated listed of tags to attach to the operation. Passed through to the smurf stream command. subtype (str, optional): Operation subtype used to tag the stream. @@ -53,7 +57,11 @@ def scan(description, stop_time, width, az_drift=0, tag=None, subtype=None, if now > scan_stop: return + if start_position: + run.acu.move_to(*start_position) + # Check there is enough time to perform scan + now = dt.datetime.now(dt.timezone.utc) if min_duration is not None: start_by_time = scan_stop - dt.timedelta(seconds=min_duration) if now > start_by_time: diff --git a/tests/test_seq.py b/tests/test_seq.py index 67d57c3f..a9fb9530 100644 --- a/tests/test_seq.py +++ b/tests/test_seq.py @@ -24,6 +24,15 @@ def test_scan(patch_clients): seq.scan(description='test', stop_time=target.isoformat(), width=20.) +@patch('sorunlib._internal.time.sleep', MagicMock()) +def test_scan_start_position(patch_clients): + # This affects test runtime duration keep it short + target = dt.datetime.now(dt.timezone.utc) + dt.timedelta(seconds=0.01) + seq.scan(description='test', stop_time=target.isoformat(), width=20., + start_position=(208.5, 60.0)) + seq.run.CLIENTS['acu'].go_to.assert_called_with(az=208.5, el=60.0) + + @patch('sorunlib._internal.time.sleep', MagicMock()) def test_scan_passed_stop_time(patch_clients): # This affects test runtime duration keep it short