tasks.py
6.26 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
from __future__ import absolute_import
from celery.task import Task
from analyzer.tasks import analysis
from pyrosapp.models import *
from common import VISCamera as VIS
from common import NIRCamera as NIR
from common import FilterWheel as FilterW
import time
import os
IMAGES_FOLDER = 'simulation_images'
class execute_plan_vis(Task):
'''
Gives the orders to the instruments to retrieve the image(s) of a plan VIS.
Send hte images to the analyzer
'''
def run(self, plan_id, countdown):
# print("ex plan : ", self.request.id)
if countdown > 0:
time.sleep(countdown)
TaskId.objects.filter(task_id=self.request.id).delete()
message = 'Start plan ' + str(plan_id) + ' execution'
Log.objects.create(agent='Observation manager', message=message)
print("execute_plan VIS : ", plan_id)
plan = Plan.objects.get(id=plan_id)
# TODO: pour l'instant je crée une fake camera temporaire, mais à l'avenir
# j'aurais un objet global
cam = VIS.VISCameraObj()
self.set_camera(cam, plan)
self.wait_camera_ready(cam)
cam.do("START")
# TODO: décommenter quand on aura un simulateur
# st = self.wait_camera_finished(cam)
# TODO: récupérer les vraies images ? je fais quoi ?
time.sleep(1)
with open(os.path.join(IMAGES_FOLDER, str(plan_id)), 'w'):
pass
analysis.delay(plan_id)
message = 'Finished plan ' + str(plan_id) + ' execution'
Log.objects.create(agent='Observation manager', message=message)
def set_camera(self, cam, plan):
'''
Set the camera configuration
'''
cam.filter_wheel.set("FILTER", FilterW.FilterEnum.h)
cam.filter_wheel.do("CHANGE_FILTER")
cam.set("WINDOW", 0, 100, 10, 100)
cam.set("READMODE", VIS.ReadmodeEnum.ramp)
cam.set("FILENAME", "toto_a_la_campagne")
cam.set("HEADER", {})
cam.set("READOUT_FREQUENCY", 20.0)
cam.set("EXPOSURE", 180)
cam.set("BINNING", 300, 300)
def wait_camera_ready(self, cam):
'''
Loop to wait for the configuration to be done
'''
st = 0
while st == 0:
# TODO: uncomment quand on caura la télescope en global
# st_tel = tel.get("STATUS")
st_cam = cam.get("STATUS")
st_fw = cam.filter_wheel.get("STATUS")
# TODO: uncomment quand on aura le plc en global
# st_plc = plc.get("STATUS")
st = 1
# TODO: checker les statuts comme il faut, et repasser à 0 si on a des statuts pas bons
def wait_camera_finished(self, cam):
'''
Loop to wait for the observation to be finished
'''
# countdown = cam.get("TIMER")
# while countdown > 5:
# time.sleep(5)
# countdown = cam.get("TIMER")
st = 0
while st == 0:
timer = cam.get("TIMER")
# st_plc = pls.get("STATUS") # TODO: quand le plc sera fait ...
# TODO: checks PLC, mais c'est peut-être pas nécessaire, si c'est le PLC qui abort direct la camera
if timer == -1:
st = 1
if st > 1:
cam.do("ABORT") # normalement ça ne devrait jamais arriver
class execute_plan_nir(Task):
'''
Gives the orders to the instruments to retrieve the image(s) of a plan NIR.
Send the images to the analyzer
'''
def run(self, plan_id, countdown):
# print("ex plan : ", self.request.id)
if countdown > 0:
time.sleep(countdown)
TaskId.objects.filter(task_id=self.request.id).delete()
message = 'Start plan ' + str(plan_id) + ' execution'
Log.objects.create(agent='Observation manager', message=message)
print("execute_plan NIR : ", plan_id)
plan = Plan.objects.get(pk=plan_id)
# TODO: pour l'instant je crée une fake camera temporaire, mais à l'avenir
# j'aurais un objet global
cam = NIR.NIRCameraObj()
self.set_camera(cam, plan)
self.wait_camera_ready(cam)
cam.do("START")
# TODO: décommenter quand on aura un simulateur
# st = self.wait_camera_finished(cam)
# TODO: récupérer les vraies images ? je fais quoi ?
time.sleep(1)
with open(os.path.join(IMAGES_FOLDER, str(plan_id)), 'w'):
pass
analysis.delay(plan_id)
message = 'Finished plan ' + str(plan_id) + ' execution'
Log.objects.create(agent='Observation manager', message=message)
def set_camera(self, cam, plan):
cam.filter_wheel.set("FILTER", FilterW.FilterEnum.h)
cam.filter_wheel.do("CHANGE_FILTER")
cam.set("WINDOW", 0, 100, 10, 100)
cam.set("READMODE", NIR.ReadmodeEnum.ramp)
cam.set("FILENAME", "toto_a_la_campagne")
cam.set("HEADER", {})
cam.set("READOUT_FREQUENCY", 20.0)
cam.set("NB_IMAGES", 28)
def wait_camera_ready(self, cam):
st = 0
while st == 0:
# TODO: uncomment quand on caura la télescope en global
# st_tel = tel.get("STATUS")
st_cam = cam.get("STATUS")
st_fw = cam.filter_wheel.get("STATUS")
# TODO: uncomment quand on aura le plc en global
# st_plc = plc.get("STATUS")
st = 1
# TODO: checker les statuts comme il faut, et repasser à 0 si on a des statuts pas bons
def wait_camera_finished(self, cam):
# countdown = cam.get("TIMER")
# while countdown > 5:
# time.sleep(5)
# countdown = cam.get("TIMER")
st = 0
while st == 0:
timer = cam.get("TIMER")
# st_plc = pls.get("STATUS") # TODO: quand le plc sera fait ...
# TODO: checks PLC, mais c'est peut-être pas nécessaire, si c'est le PLC qui abort direct la camera
if timer == -1:
st = 1
if st > 1:
cam.do("ABORT") # normalement ça ne devrait jamais arriver
class execute_calibrations(Task):
'''
Directly make the right calls to the instruments to create the calibration files.
When they are all finished, it creates the 'super' calibration files.
'''
def run(self):
pass