Skip to content

Commit 13af649

Browse files
committed
Add elevation nod sequence
1 parent ddbc3a4 commit 13af649

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

src/sorunlib/seq.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime as dt
2+
import time
23

34
import sorunlib as run
45

@@ -9,16 +10,20 @@
910
OP_TIMEOUT = 60
1011

1112

12-
def _stop_scan():
13-
acu = run.CLIENTS['acu']
14-
15-
print("Stopping scan.")
13+
def _stop_smurfs():
1614
# Stop SMuRF streams
1715
try:
1816
run.smurf.stream('off')
1917
except RuntimeError as e:
2018
print(f"Caught error while shutting down SMuRF streams: {e}")
2119

20+
21+
def _stop_scan():
22+
acu = run.CLIENTS['acu']
23+
24+
print("Stopping scan.")
25+
_stop_smurfs()
26+
2227
# Stop motion
2328
acu.generate_scan.stop()
2429
resp = acu.generate_scan.wait(timeout=OP_TIMEOUT)
@@ -85,3 +90,43 @@ def scan(description, stop_time, width, az_drift=0, tag=None, subtype=None,
8590
monitor_process(acu, 'generate_scan', stop_time)
8691
finally:
8792
_stop_scan()
93+
94+
95+
def el_nod(el1, el2, num=5, pause=5):
96+
"""Perform a set of elevation nods.
97+
98+
Elevation nods will be peformed at the current azimuth, and will start from
99+
and return to the current elevation. The nod first moves to ``el1``,
100+
pauses, then moves to ``el2``, pauses, and then repeats for the
101+
specified number of iterations.
102+
103+
Args:
104+
el1 (float): First elevation to move to during the nod.
105+
el2 (float): Second elevation to move to during the nod.
106+
num (int): Number of nods to peform. Defaults to 5.
107+
pause (float): Length of pause, in seconds, at each elevation. Defaults
108+
to 5 seconds.
109+
110+
"""
111+
acu = run.CLIENTS['acu']
112+
113+
# Enable SMuRF streams
114+
run.smurf.stream('on', subtype='cal', tag='el_nods')
115+
116+
try:
117+
# Grab current telescope position
118+
resp = acu.monitor.status()
119+
init_az = resp.session['data']['StatusDetailed']['Azimuth current position']
120+
init_el = resp.session['data']['StatusDetailed']['Elevation current position']
121+
122+
# Perform nods
123+
for x in range(num):
124+
run.acu.move_to(az=init_az, el=el1)
125+
time.sleep(pause)
126+
run.acu.move_to(az=init_az, el=el2)
127+
time.sleep(pause)
128+
else:
129+
# Return to initial position
130+
run.acu.move_to(az=init_az, el=init_el)
131+
finally:
132+
_stop_smurfs()

tests/test_seq.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import ocs
77
import pytest
8-
from unittest.mock import MagicMock, patch
8+
from unittest.mock import call, MagicMock, patch
99
from ocs.ocs_client import OCSReply
1010

1111
import sorunlib
@@ -92,3 +92,18 @@ def test_scan_failed_smurfs_on_shutdown(patch_clients):
9292

9393
seq._stop_scan()
9494
seq.run.CLIENTS['acu'].generate_scan.wait.assert_called()
95+
96+
97+
@patch('sorunlib.seq.time.sleep', MagicMock())
98+
def test_el_nod(patch_clients):
99+
sorunlib.acu.move_to(az=180, el=50)
100+
seq.el_nod(el1=40, el2=60)
101+
102+
# Calls will be repeated, but these three are representative of the el nod
103+
calls = [call(az=180, el=50),
104+
call(az=180, el=40),
105+
call(az=180, el=60)]
106+
seq.run.CLIENTS['acu'].go_to.assert_has_calls(calls, any_order=True)
107+
108+
# Move back to initial position
109+
seq.run.CLIENTS['acu'].go_to.assert_called_with(az=180, el=50)

0 commit comments

Comments
 (0)