tasks.py
3.53 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
from __future__ import absolute_import
from celery.task import Task
from analyzer.tasks import analysis
from common.models import *
from devices import CameraVIS as VIS
from devices import CameraNIR as NIR
from devices import Telescope
import time
'''
Super class for execute_plan_vis / _nir
'''
class execute_plan(Task):
def run(self, plan_id, countdown, type):
if countdown > 0:
time.sleep(countdown)
TaskId.objects.filter(task_id=self.request.id).delete()
self.type = type
plan = Plan.objects.get(id=plan_id)
message = 'Start plan ' + plan.name + ' execution'
Log.objects.create(agent='Observation manager', message=message)
print("execute_plan " + self.type + " : ", plan.name)
self.tel = Telescope.TelescopeController()
if self.type == "VIS":
cam = VIS.VISCameraController()
else:
cam = NIR.NIRCameraController()
self.set_camera(cam, plan)
self.wait_camera_ready(cam)
cam.do("START")
st = self.wait_camera_finished(cam)
# TODO: récupérer les vraies images ? je fais quoi ?
time.sleep(1)
# Penser qu'un plan peut créer plusieurs images (et analyser image par image)
analysis.delay(plan_id)
message = 'Finished plan ' + plan.name + ' execution'
Log.objects.create(agent='Observation manager', message=message)
'''
Set the camera configuration
'''
def set_camera(self, cam, plan):
# TODO: mettre les vraies configurations en fct du plan
cam.set("WINDOW", 0, 100, 10, 100)
cam.set("READMODE", "Ramp")
cam.set("FILENAME", plan.name)
cam.set("HEADER", {})
cam.set("READOUT_FREQUENCY", 20.0)
cam.set("FILTER", "H")
if self.type == "VIS":
cam.set("EXPOSURE", 180)
cam.set("BINNING", 300, 300)
else:
cam.set("NB_IMAGES", 28)
'''
Loop to wait for the configuration to be done
'''
def wait_camera_ready(self, cam):
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
'''
Loop to wait for the observation to be finished
'''
def wait_camera_finished(self, cam):
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)
'''
Gives the orders to the instruments to retrieve the image(s) of a plan VIS.
Send the images to the analyzer
'''
class execute_plan_vis(execute_plan):
def run(self, plan_id, countdown):
super().run(plan_id, countdown, "VIS")
'''
Gives the orders to the instruments to retrieve the image(s) of a plan NIR.
Send the images to the analyzer
'''
class execute_plan_nir(execute_plan):
def run(self, plan_id, countdown):
super().run(plan_id, countdown, "NIR")
'''
Directly make the right calls to the instruments to create the calibration files.
When they are all finished, it creates the 'super' calibration files.
'''
class create_calibrations(Task):
def run(self):
# TODO: attendre que tout soit idle
pass