Blame view

src/observation_manager/tasks.py 5.03 KB
5b5566ab   haribo   added celery
1
2
3
from __future__ import absolute_import

from celery.task import Task
77816f10   haribo   Workflow implemen...
4
from analyzer.tasks import analysis
ddf59dd4   haribo   Remaniement :
5
from common.models import *
5b5566ab   haribo   added celery
6

ddf59dd4   haribo   Remaniement :
7
8
9
from devices import VISCamera as VIS
from devices import NIRCamera as NIR
from devices import Telescope
ad85da7c   haribo   Date: 28/06/2016
10

5b5566ab   haribo   added celery
11
import time
77816f10   haribo   Workflow implemen...
12
13
import os

9774228b   haribo   Date: 22/06/2016
14
class execute_plan_vis(Task):
9b5bad52   haribo   Commented all the...
15
16
    '''
        Gives the orders to the instruments to retrieve the image(s) of a plan VIS.
164eebbd   haribo   UML and comments
17
        Send the images to the analyzer
9b5bad52   haribo   Commented all the...
18
    '''
5b5566ab   haribo   added celery
19

ad85da7c   haribo   Date: 28/06/2016
20
    def run(self, plan_id, countdown):
00fa2456   haribo   Debug adaption code
21

9774228b   haribo   Date: 22/06/2016
22
23
        if countdown > 0:
            time.sleep(countdown)
bb45cd4a   haribo   Date: 25/05/2016
24
        TaskId.objects.filter(task_id=self.request.id).delete()
ec372f36   haribo   Date: 28/06/2016
25

ad85da7c   haribo   Date: 28/06/2016
26
        message = 'Start plan ' + str(plan_id) + ' execution'
77816f10   haribo   Workflow implemen...
27
        Log.objects.create(agent='Observation manager', message=message)
ad85da7c   haribo   Date: 28/06/2016
28
29
30
31
        print("execute_plan VIS : ", plan_id)

        plan = Plan.objects.get(id=plan_id)

ddf59dd4   haribo   Remaniement :
32
33
        self.tel = Telescope.TelescopeController()
        cam = VIS.VISCameraController()
ad85da7c   haribo   Date: 28/06/2016
34

00fa2456   haribo   Debug adaption code
35
        self.set_camera(cam, plan)
ad85da7c   haribo   Date: 28/06/2016
36
37
        self.wait_camera_ready(cam)

00fa2456   haribo   Debug adaption code
38
        cam.do("START")
ad85da7c   haribo   Date: 28/06/2016
39
40

# TODO: décommenter quand on aura un simulateur
ad85da7c   haribo   Date: 28/06/2016
41
42
#         st = self.wait_camera_finished(cam)

5d61cbfe   haribo   Just adding / rem...
43
        # TODO: récupérer les vraies images ? je fais quoi ?
9774228b   haribo   Date: 22/06/2016
44
        time.sleep(1)
ad85da7c   haribo   Date: 28/06/2016
45
46
        analysis.delay(plan_id)
        message = 'Finished plan ' + str(plan_id) + ' execution'
9774228b   haribo   Date: 22/06/2016
47
48
        Log.objects.create(agent='Observation manager', message=message)

ad85da7c   haribo   Date: 28/06/2016
49
    def set_camera(self, cam, plan):
9b5bad52   haribo   Commented all the...
50
51
52
        '''
            Set the camera configuration
        '''
ad85da7c   haribo   Date: 28/06/2016
53

00fa2456   haribo   Debug adaption code
54
        # TODO: mettre les vraies configurations en fct du plan
ad85da7c   haribo   Date: 28/06/2016
55
56
        cam.set("WINDOW", 0, 100, 10, 100)
        cam.set("READMODE", VIS.ReadmodeEnum.ramp)
aed99094   haribo   Debug routine MGR...
57
        cam.set("FILENAME", plan.name)
ad85da7c   haribo   Date: 28/06/2016
58
59
        cam.set("HEADER", {})
        cam.set("READOUT_FREQUENCY", 20.0)
00fa2456   haribo   Debug adaption code
60
        cam.set("FILTER", VIS.FilterEnum.h)
ad85da7c   haribo   Date: 28/06/2016
61
62
63
64
65

        cam.set("EXPOSURE", 180)
        cam.set("BINNING", 300, 300)

    def wait_camera_ready(self, cam):
9b5bad52   haribo   Commented all the...
66
67
68
        '''
            Loop to wait for the configuration to be done
        '''
ad85da7c   haribo   Date: 28/06/2016
69
70
        st = 0
        while st == 0:
ac26ad2b   haribo   Date: 22/07/2016
71
72
            st_tel = self.tel.get("STATUS")

00fa2456   haribo   Debug adaption code
73
            st_cam = cam.get("STATUS")
ac26ad2b   haribo   Date: 22/07/2016
74

ad85da7c   haribo   Date: 28/06/2016
75
            st = 1
ac26ad2b   haribo   Date: 22/07/2016
76

ad85da7c   haribo   Date: 28/06/2016
77
            # TODO: checker les statuts comme il faut, et repasser à 0 si on a des statuts pas bons
00fa2456   haribo   Debug adaption code
78
            if st_tel != "IDLE" or st_cam != "IDLE":
ac26ad2b   haribo   Date: 22/07/2016
79
                st = 0
ad85da7c   haribo   Date: 28/06/2016
80
81
82


    def wait_camera_finished(self, cam):
9b5bad52   haribo   Commented all the...
83
84
85
        '''
            Loop to wait for the observation to be finished
        '''
00fa2456   haribo   Debug adaption code
86
87
88
89
90

        countdown = int(cam.get("TIMER"))
        while countdown > 5:
            time.sleep(5)
            countdown = int(cam.get("TIMER"))
5d61cbfe   haribo   Just adding / rem...
91

ad85da7c   haribo   Date: 28/06/2016
92
93
        st = 0
        while st == 0:
00fa2456   haribo   Debug adaption code
94
            timer = int(cam.get("TIMER"))
ad85da7c   haribo   Date: 28/06/2016
95
96
            if timer == -1:
                st = 1
00fa2456   haribo   Debug adaption code
97
98
            else:
                time.sleep(1)
ad85da7c   haribo   Date: 28/06/2016
99

9774228b   haribo   Date: 22/06/2016
100
101

class execute_plan_nir(Task):
9b5bad52   haribo   Commented all the...
102
103
104
105
    '''
        Gives the orders to the instruments to retrieve the image(s) of a plan NIR.
        Send the images to the analyzer
    '''
9774228b   haribo   Date: 22/06/2016
106

ad85da7c   haribo   Date: 28/06/2016
107
    def run(self, plan_id, countdown):
9774228b   haribo   Date: 22/06/2016
108
109
110
        if countdown > 0:
            time.sleep(countdown)
        TaskId.objects.filter(task_id=self.request.id).delete()
ad85da7c   haribo   Date: 28/06/2016
111
112

        message = 'Start plan ' + str(plan_id) + ' execution'
9774228b   haribo   Date: 22/06/2016
113
        Log.objects.create(agent='Observation manager', message=message)
ad85da7c   haribo   Date: 28/06/2016
114
115
116
117
        print("execute_plan NIR : ", plan_id)

        plan = Plan.objects.get(pk=plan_id)

ddf59dd4   haribo   Remaniement :
118
119
        self.tel = Telescope.TelescopeController()
        cam = NIR.NIRCameraController()
ad85da7c   haribo   Date: 28/06/2016
120
121
122
123
124
125

        self.set_camera(cam, plan)
        self.wait_camera_ready(cam)

        cam.do("START")

00fa2456   haribo   Debug adaption code
126
        st = self.wait_camera_finished(cam)
ad85da7c   haribo   Date: 28/06/2016
127

77816f10   haribo   Workflow implemen...
128
        time.sleep(1)
aed99094   haribo   Debug routine MGR...
129

ad85da7c   haribo   Date: 28/06/2016
130
131
        analysis.delay(plan_id)
        message = 'Finished plan ' + str(plan_id) + ' execution'
77816f10   haribo   Workflow implemen...
132
        Log.objects.create(agent='Observation manager', message=message)
ad85da7c   haribo   Date: 28/06/2016
133
134
135

    def set_camera(self, cam, plan):

ad85da7c   haribo   Date: 28/06/2016
136
137
        cam.set("WINDOW", 0, 100, 10, 100)
        cam.set("READMODE", NIR.ReadmodeEnum.ramp)
aed99094   haribo   Debug routine MGR...
138
        cam.set("FILENAME", plan.name)
ad85da7c   haribo   Date: 28/06/2016
139
140
        cam.set("HEADER", {})
        cam.set("READOUT_FREQUENCY", 20.0)
00fa2456   haribo   Debug adaption code
141
        cam.set("FILTER", NIR.FilterEnum.h)
ad85da7c   haribo   Date: 28/06/2016
142
143
144
145

        cam.set("NB_IMAGES", 28)

    def wait_camera_ready(self, cam):
00fa2456   haribo   Debug adaption code
146
147
148
        '''
            Loop to wait for the configuration to be done
        '''
ad85da7c   haribo   Date: 28/06/2016
149
150
        st = 0
        while st == 0:
00fa2456   haribo   Debug adaption code
151
152
            st_tel = self.tel.get("STATUS")

ad85da7c   haribo   Date: 28/06/2016
153
            st_cam = cam.get("STATUS")
00fa2456   haribo   Debug adaption code
154

ad85da7c   haribo   Date: 28/06/2016
155
            st = 1
00fa2456   haribo   Debug adaption code
156
157
158

            if st_tel != "IDLE" or st_cam != "IDLE":
                st = 0
ad85da7c   haribo   Date: 28/06/2016
159
160
161


    def wait_camera_finished(self, cam):
00fa2456   haribo   Debug adaption code
162
163
164
165
166
167
168
169
        '''
            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"))
ad85da7c   haribo   Date: 28/06/2016
170

ad85da7c   haribo   Date: 28/06/2016
171
172
        st = 0
        while st == 0:
00fa2456   haribo   Debug adaption code
173
            timer = int(cam.get("TIMER"))
ad85da7c   haribo   Date: 28/06/2016
174
175
            if timer == -1:
                st = 1
00fa2456   haribo   Debug adaption code
176
177
            else:
                time.sleep(1)
ad85da7c   haribo   Date: 28/06/2016
178

c5a3b4a0   haribo   Date: 05/07/2016
179

164eebbd   haribo   UML and comments
180
class create_calibrations(Task):
c5a3b4a0   haribo   Date: 05/07/2016
181
182
183
184
185
     '''
         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):
ddf59dd4   haribo   Remaniement :
186
         # TODO: attendre que tout soit idle
9b5bad52   haribo   Commented all the...
187
         pass