-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRemoteClient.py
More file actions
executable file
·161 lines (134 loc) · 5.63 KB
/
Copy pathRemoteClient.py
File metadata and controls
executable file
·161 lines (134 loc) · 5.63 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#! /usr/bin/env python2.7
from __future__ import print_function
import json
#
# 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
print('Sending command:', param_str)
return self.execute('modifyexposure', parameter=param_str)
def get_propid(self):
return self.execute('get_propid')
def stopexposure(self):
return self.execute('stopexposure')
def stoprequested(self):
return self.execute('stoprequested')
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., efftime=None, verbose=False, propid=None):
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)
if efftime is not None:
kw.update(efftime=efftime)
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)
def main():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--stop', action='store_true', help='Run stop-exposure')
parser.add_argument('--stop-requested', action='store_true', help='Run stop-requested')
parser.add_argument('--get-n-queued', action='store_true', help='Get number of queued exposures')
parser.add_argument('--add-exposure', type=str, help='Enqueue the given JSON-encoded exposure')
parser.add_argument('--modify-exposure', nargs=2, type=str, help='Modify an exposure given the JSON-encoded selection and JSON-encoded update arguments')
parser.add_argument('--clear-queue', action='store_true', help='Remove all exposures from queue')
opt = parser.parse_args()
rc = RemoteClient()
if opt.stop:
rc.stopexposure()
if opt.stop_requested:
rc.stoprequested()
if opt.get_n_queued:
n = rc.get_n_queued()
print('n_queued = %i' % n)
if opt.clear_queue:
rc.clear_queue()
if opt.add_exposure is not None:
exp = json.loads(opt.add_exposure)
rc.addexposure(**exp)
if opt.modify_exposure is not None:
sel,up = opt.modify_exposure
select = json.loads(sel)
update = json.loads(up)
rc.modifyexposure(select=select, update=update)
return 0
if __name__ == '__main__':
import sys
sys.exit(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)
res = rc.modifyexposure(select=dict(object='IBIS_deep_desi220_M464_29'),
update=dict(expTime=401))#filter='M411'))#
#"IBIS_deep_cosmos_M464_1"
print('Got', res)