-
Notifications
You must be signed in to change notification settings - Fork 3
/
RemoteClient.py
116 lines (93 loc) · 3.88 KB
/
RemoteClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from __future__ import print_function
#
# Client for SISPI Remote CommandServer
# Code from Klaus Honscheid, 2015-11-06, [decam-chatter 1546]
#
import Pyro.core
class RemoteClient():
def __init__(self, cs_host='system1', cs_port=15555, cs_name = 'CMDSRV'):
""" Initialize remote client class """
self.host = str(cs_host)
self.port = int(cs_port)
self.name = str(cs_name)
self.uri = "PYROLOC://%s:%d/%s" % (self.host, self.port, self.name)
# Connect to command server. Exceptions to be handled by caller
self.cs = Pyro.core.getProxyForURI(self.uri)
def execute(self, command, parameter=None):
""" execute remote command """
if parameter == None:
return self.cs.execute('command=%s' % command)
else:
cmd = 'command=%s, params = %s' % (command, parameter)
print('Sending execute("%s")' % cmd)
return self.cs.execute('command=%s, params = %s' % (command, parameter))
# Added by Dustin -- expose specific functions Klaus has provided for us
'''
execute('modifyexposure', params="")
params is
filter={"object":"DECaLS_134_g"},modifications={"expTime":99}
Returns SUCCESS or FAILED: qManager.modify: No matching... checking pipeline
'''
def modifyexposure(self, select=None, update=None):
if select is None or update is None:
raise ValueError('Need to set select= and update=')
select_str = json.dumps(select)
update_str = json.dumps(update)
param_str = 'filter=' + select_str + ',modifications=' + update_str
return self.execute('modifyexposure', params=param_str)
def get_propid(self):
return self.execute('get_propid')
def stopexposure(self):
return self.execute('stopexposure')
def get_n_queued(self):
n = self.execute('get_nqueue')
return int(n)
def clear_queue(self):
return self.execute('clear_queue')
def addexposure(self, exptime=10., exptype='object', filter='r',
object=None, ra=0., dec=0., verbose=False, propid=None):
import json
kw = dict(expType=exptype, object=object)
if propid is not None:
kw.update(propid=propid)
if exptype == 'object':
if object is None:
object = 'Object'
kw.update(expTime=exptime, filter=filter, RA=ra, dec=dec)
paramstr = json.dumps(kw)
elif exptype == 'dark':
if object is None:
object = 'dark'
kw.update(expTime=exptime)
paramstr = json.dumps(kw)
elif exptype == 'dome flat':
if object is None:
object = 'flat'
kw.update(expTime=exptime, filter=filter)
paramstr = json.dumps(kw)
elif exptype == 'zero':
if object is None:
object = 'zero'
paramstr = json.dumps(kw)
#paramstr = 'exptype=%s' % exptype
if verbose:
print("Calling addexposure, parameter='%s'" % paramstr)
return self.execute('addexposure', parameter=paramstr)
if __name__ == '__main__':
# rc = RemoteClient(cs_host='10.10.168.162', cs_port=7767)
# rc.addexposure()
# rc.addexposure(exptype='dark')
# rc.addexposure(exptype='zero')
# rc.addexposure(exptype='dome flat', filter='z', exptime=50)
rc = RemoteClient()
#res = rc.addexposure(exptype='zero')
#res = rc.addexposure(ra=42, dec=12, exptime=17., filter='g')
res = rc.get_propid()
print('Got propid:', res)
res = rc.get_n_queued()
print('Got N queued:', res)
res = rc.addexposure(ra=80., dec=-10., verbose=True,
propid='2014B-0404',
#propid='2023A-140687',
object='DECaLS_5774_z')
print('Addexposure: got', res)