Blame view

src/observation_manager/tasks.py 6.26 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
bb45cd4a   haribo   Date: 25/05/2016
5
from pyrosapp.models import *
5b5566ab   haribo   added celery
6

ad85da7c   haribo   Date: 28/06/2016
7
8
9
10
from common import VISCamera as VIS
from common import NIRCamera as NIR
from common import FilterWheel as FilterW

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

IMAGES_FOLDER = 'simulation_images'
5b5566ab   haribo   added celery
15

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

ad85da7c   haribo   Date: 28/06/2016
22
    def run(self, plan_id, countdown):
bb45cd4a   haribo   Date: 25/05/2016
23
#         print("ex plan : ", self.request.id)
9774228b   haribo   Date: 22/06/2016
24
25
        if countdown > 0:
            time.sleep(countdown)
bb45cd4a   haribo   Date: 25/05/2016
26
        TaskId.objects.filter(task_id=self.request.id).delete()
ec372f36   haribo   Date: 28/06/2016
27

ad85da7c   haribo   Date: 28/06/2016
28
        message = 'Start plan ' + str(plan_id) + ' execution'
77816f10   haribo   Workflow implemen...
29
        Log.objects.create(agent='Observation manager', message=message)
ad85da7c   haribo   Date: 28/06/2016
30
31
32
33
34
35
36
37
38
39
40
41
42
43
        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
ad85da7c   haribo   Date: 28/06/2016
44
45
#         st = self.wait_camera_finished(cam)

5d61cbfe   haribo   Just adding / rem...
46
        # TODO: récupérer les vraies images ? je fais quoi ?
9774228b   haribo   Date: 22/06/2016
47
        time.sleep(1)
ad85da7c   haribo   Date: 28/06/2016
48
        with open(os.path.join(IMAGES_FOLDER, str(plan_id)), 'w'):
9774228b   haribo   Date: 22/06/2016
49
            pass
ad85da7c   haribo   Date: 28/06/2016
50
51
        analysis.delay(plan_id)
        message = 'Finished plan ' + str(plan_id) + ' execution'
9774228b   haribo   Date: 22/06/2016
52
53
        Log.objects.create(agent='Observation manager', message=message)

ad85da7c   haribo   Date: 28/06/2016
54
    def set_camera(self, cam, plan):
9b5bad52   haribo   Commented all the...
55
56
57
        '''
            Set the camera configuration
        '''
ad85da7c   haribo   Date: 28/06/2016
58
59
60
61
62
63
64
65
66
67
68
69
70
71

        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):
9b5bad52   haribo   Commented all the...
72
73
74
        '''
            Loop to wait for the configuration to be done
        '''
ad85da7c   haribo   Date: 28/06/2016
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        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):
9b5bad52   haribo   Commented all the...
89
90
91
        '''
            Loop to wait for the observation to be finished
        '''
5d61cbfe   haribo   Just adding / rem...
92
93
94
95
96
#         countdown = cam.get("TIMER")
#         while countdown > 5:
#             time.sleep(5)
#             countdown = cam.get("TIMER")

ad85da7c   haribo   Date: 28/06/2016
97
98
99
100
101
102
103
104
105
106
107
        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

9774228b   haribo   Date: 22/06/2016
108
109

class execute_plan_nir(Task):
9b5bad52   haribo   Commented all the...
110
111
112
113
    '''
        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
114

ad85da7c   haribo   Date: 28/06/2016
115
    def run(self, plan_id, countdown):
9774228b   haribo   Date: 22/06/2016
116
117
118
119
#         print("ex plan : ", self.request.id)
        if countdown > 0:
            time.sleep(countdown)
        TaskId.objects.filter(task_id=self.request.id).delete()
ad85da7c   haribo   Date: 28/06/2016
120
121

        message = 'Start plan ' + str(plan_id) + ' execution'
9774228b   haribo   Date: 22/06/2016
122
        Log.objects.create(agent='Observation manager', message=message)
ad85da7c   haribo   Date: 28/06/2016
123
124
125
126
127
128
129
130
131
132
133
134
135
136
        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
ad85da7c   haribo   Date: 28/06/2016
137
138
#         st = self.wait_camera_finished(cam)

5d61cbfe   haribo   Just adding / rem...
139
        # TODO: récupérer les vraies images ? je fais quoi ?
77816f10   haribo   Workflow implemen...
140
        time.sleep(1)
ad85da7c   haribo   Date: 28/06/2016
141
        with open(os.path.join(IMAGES_FOLDER, str(plan_id)), 'w'):
77816f10   haribo   Workflow implemen...
142
            pass
ad85da7c   haribo   Date: 28/06/2016
143
144
        analysis.delay(plan_id)
        message = 'Finished plan ' + str(plan_id) + ' execution'
77816f10   haribo   Workflow implemen...
145
        Log.objects.create(agent='Observation manager', message=message)
ad85da7c   haribo   Date: 28/06/2016
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

    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):

5d61cbfe   haribo   Just adding / rem...
177
178
179
180
#         countdown = cam.get("TIMER")
#         while countdown > 5:
#             time.sleep(5)
#             countdown = cam.get("TIMER")
ad85da7c   haribo   Date: 28/06/2016
181
182
183
184
185
186
187
188
189
190
191
        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

c5a3b4a0   haribo   Date: 05/07/2016
192
193
194
195
196
197
198

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):
9b5bad52   haribo   Commented all the...
199
         pass