tasks.py
4.96 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
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 Telescope
import time
import os
class execute_plan_vis(Task):
'''
Gives the orders to the instruments to retrieve the image(s) of a plan VIS.
Send the images to the analyzer
'''
def run(self, plan_id, countdown):
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)
self.tel = Telescope.TelescopeObj()
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)
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
'''
# TODO: mettre les vraies configurations en fct du plan
cam.set("WINDOW", 0, 100, 10, 100)
cam.set("READMODE", VIS.ReadmodeEnum.ramp)
cam.set("FILENAME", plan.name)
cam.set("HEADER", {})
cam.set("READOUT_FREQUENCY", 20.0)
cam.set("FILTER", VIS.FilterEnum.h)
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:
st_tel = self.tel.get("STATUS")
st_cam = cam.get("STATUS")
st = 1
# TODO: checker les statuts comme il faut, et repasser à 0 si on a des statuts pas bons
if st_tel != "IDLE" or st_cam != "IDLE":
st = 0
def wait_camera_finished(self, cam):
'''
Loop to wait for the observation to be finished
'''
countdown = int(cam.get("TIMER"))
while countdown > 5:
time.sleep(5)
countdown = int(cam.get("TIMER"))
st = 0
while st == 0:
timer = int(cam.get("TIMER"))
if timer == -1:
st = 1
else:
time.sleep(1)
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):
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)
self.tel = Telescope.TelescopeObj()
cam = NIR.NIRCameraObj()
self.set_camera(cam, plan)
self.wait_camera_ready(cam)
cam.do("START")
st = self.wait_camera_finished(cam)
time.sleep(1)
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.set("WINDOW", 0, 100, 10, 100)
cam.set("READMODE", NIR.ReadmodeEnum.ramp)
cam.set("FILENAME", plan.name)
cam.set("HEADER", {})
cam.set("READOUT_FREQUENCY", 20.0)
cam.set("FILTER", NIR.FilterEnum.h)
cam.set("NB_IMAGES", 28)
def wait_camera_ready(self, cam):
'''
Loop to wait for the configuration to be done
'''
st = 0
while st == 0:
st_tel = self.tel.get("STATUS")
st_cam = cam.get("STATUS")
st = 1
if st_tel != "IDLE" or st_cam != "IDLE":
st = 0
def wait_camera_finished(self, cam):
'''
Loop to wait for the observation to be finished
'''
countdown = int(cam.get("TIMER"))
while countdown > 5:
time.sleep(5)
countdown = int(cam.get("TIMER"))
st = 0
while st == 0:
timer = int(cam.get("TIMER"))
if timer == -1:
st = 1
else:
time.sleep(1)
class create_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