From 87ab2e3b08350e670afaaa6ab3a4a2af5c7fca1c Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Tue, 10 Dec 2024 14:37:47 -0500 Subject: [PATCH] Add start_position argument to seq.scan() Resolves #190. --- src/sorunlib/seq.py | 14 +++++++++++--- tests/test_seq.py | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/sorunlib/seq.py b/src/sorunlib/seq.py index 7d3b4d0e..6234a8ec 100644 --- a/src/sorunlib/seq.py +++ b/src/sorunlib/seq.py @@ -9,8 +9,8 @@ OP_TIMEOUT = 60 -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: @@ -18,9 +18,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. @@ -36,7 +40,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 0a090153..52a63a06 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