Commit 6a1a30ed9ea86f258d7e4ced760a0050e9d0a418

Authored by carens_p
1 parent 28e8d4bb
Exists in master and in 1 other branch dev

grammar for instruments in JSON file

simulators/CameraNIR.py
1   -import configparser
2 1 import socket
3 2 from enum import Enum
4 3 import time
5 4 import os
6 5 from random import randint
  6 +from Device import Device
7 7  
8 8 IMAGES_FOLDER = '../src/images'
9   -CONFIG_FILE = "socket_config.ini"
10 9  
11 10 EXPOSURE_TIME = 5
12 11 SHUTTER_TIME = 3
13 12 COOLER_TIME = 10
14 13  
15   -class ReadmodeEnum(Enum):
16   - ramp = "Ramp"
17   - # TODO: définir les modes de lecture
18 14  
19   -class ShutterEnum(Enum):
20   - synchro = "Synchro"
21   - closed = "Closed"
22   - opened = "Opened"
  15 +class CameraNIR(Device):
23 16  
24   -
25   -class CameraNIR():
26 17 def __init__(self):
27   - config = configparser.ConfigParser()
28   - config.read(CONFIG_FILE)
29   -
30   - ip = config.get("CameraNIR", "ip")
31   - port = int(config.get("CameraNIR", "port"))
32   -
33   - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
34   - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
35   - self.sock.bind((ip, port))
36   - self.sock.listen(122)
37   -
38   - self.set_msgs = [
39   - ("WINDOW", [4, ], int),
40   - ("READMODE", [1, ], ReadmodeEnum),
41   - ("FILENAME", [1, ], str),
42   - ("HEADER", [1, ], dict),
43   - ("READOUT_FREQUENCY", [1, ], float),
44   - ("NB_IMAGES", [1, ], int),
45   - ]
46   -
47   - self.get_msgs = [
48   - "STATUS",
49   - "SETUP",
50   - "TEMPERATURE",
51   - "TIMER",
52   - ]
53   -
54   - self.do_msgs = [
55   - ("COOLER", [2, ], float),
56   - ("SHUTTER", [1, ], ShutterEnum),
57   - ("START", [0, ]),
58   - ("ABORT", [0, ]),
59   - ("STOP", [0, ]),
60   - ]
  18 + super().__init__("CameraNIR")
61 19  
62 20 ''' I will just fill the attributes with their names and params without regarding them '''
63 21 self.attributes = {}
... ...
simulators/CameraVIS.py
1   -import configparser
2 1 import socket
3 2 from enum import Enum
4 3 import time
5 4 import os
6 5 from random import randint
  6 +from Device import Device
7 7  
8 8 IMAGES_FOLDER = '../src/images'
9   -CONFIG_FILE = "socket_config.ini"
10 9  
11 10 EXPOSURE_TIME = 5
12 11 SHUTTER_TIME = 3
13 12 COOLER_TIME = 10
14 13  
15   -class ReadmodeEnum(Enum):
16   - ramp = "Ramp"
17   - # TODO: définir les modes de lecture
18 14  
19   -class ShutterEnum(Enum):
20   - synchro = "Synchro"
21   - closed = "Closed"
22   - opened = "Opened"
23   -
24   -
25   -class CameraVIS():
  15 +class CameraVIS(Device):
26 16 def __init__(self):
27   - config = configparser.ConfigParser()
28   - config.read(CONFIG_FILE)
29   -
30   - ip = config.get("CameraVIS", "ip")
31   - port = int(config.get("CameraVIS", "port"))
32   -
33   - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
34   - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
35   - self.sock.bind((ip, port))
36   - self.sock.listen(12)
37   -
38   - self.set_msgs = [
39   - ("WINDOW", [4, ], int),
40   - ("READMODE", [1, ], ReadmodeEnum),
41   - ("FILENAME", [1, ], str),
42   - ("HEADER", [1, ], dict),
43   - ("READOUT_FREQUENCY", [1, ], float),
44   - ("EXPOSURE", [1, ], int),
45   - ("BINNING", [2, ], int),
46   - ]
47   -
48   - self.get_msgs = [
49   - "STATUS",
50   - "SETUP",
51   - "TEMPERATURE",
52   - "TIMER",
53   - ]
54   -
55   - self.do_msgs = [
56   - ("COOLER", [2, ], float),
57   - ("SHUTTER", [1, ], ShutterEnum),
58   - ("START", [0, ]),
59   - ("ABORT", [0, ]),
60   - ("STOP", [0, ]),
61   - ]
  17 + super().__init__("CameraVIS")
62 18  
63 19 ''' I will just fill the attributes with their names and params without regarding them '''
64 20 self.attributes = {}
... ...
simulators/Device.py 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +import configparser
  2 +import socket
  3 +import json
  4 +
  5 +
  6 +# from enum import Enum
  7 +# import time
  8 +# import os
  9 +# from random import randint
  10 +
  11 +IMAGES_FOLDER = '../src/images'
  12 +CONFIG_FILE = "socket_config.ini"
  13 +GRAMMAR_FILE = "grammar.json"
  14 +
  15 +class Device():
  16 +
  17 + def __init__(self, simul_name):
  18 +
  19 + config = configparser.ConfigParser()
  20 + config.read(CONFIG_FILE)
  21 +
  22 + ip = config.get(simul_name, "ip")
  23 + port = int(config.get(simul_name, "port"))
  24 +
  25 + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  26 + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  27 + self.sock.bind((ip, port))
  28 + self.sock.listen(122)
  29 +
  30 + self.set_msgs = []
  31 + self.get_msgs = []
  32 + self.do_msgs = []
  33 +
  34 + self.enums = {}
  35 +
  36 + with open("grammar.json") as grammar_file:
  37 + grammar = json.load(grammar_file)
  38 +
  39 + enums = grammar["Enums"]
  40 +
  41 + for enum in enums :
  42 + self.enums[enum] = enums[enum]
  43 +
  44 + if simul_name[:6] == "Camera":
  45 + device = grammar["Camera"]
  46 +
  47 + for item in device["set"]:
  48 + self.set_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum
  49 + for item in device["get"]:
  50 + self.get_msgs.append(item)
  51 + for item in device["do"]:
  52 + self.do_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum
  53 +
  54 + device = grammar[simul_name]
  55 +
  56 + for item in device["set"]:
  57 + self.set_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum
  58 + for item in device["get"]:
  59 + self.get_msgs.append(item)
  60 + for item in device["do"]:
  61 + self.do_msgs.append((item["name"], item["nb_param"], item["param_type"])) # TODO : transformer les param_type qui ne sont pas des enum
... ...
simulators/PLC.py
1   -import configparser
2 1 import socket
3 2 from enum import Enum
  3 +from Device import Device
4 4  
5   -CONFIG_FILE = "socket_config.ini"
6   -
7   -class PLC():
  5 +class PLC(Device):
8 6  
9 7 def __init__(self):
10   - config = configparser.ConfigParser()
11   - config.read(CONFIG_FILE)
12   -
13   - ip = config.get("PLC", "ip")
14   - port = int(config.get("PLC", "port"))
15   -
16   - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17   - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
18   - self.sock.bind((ip, port))
19   - self.sock.listen(12)
20   -
21   - self.set_msgs = []
22   -
23   - get_msgs = [
24   - "STATUS",
25   - ]
26   -
27   - do_msgs = []
28   -
  8 + super().__init__("PLC")
29 9  
30 10 def loop(self):
31 11 while True:
... ...
simulators/Telescope.py
1   -import configparser
2 1 import socket
3 2 from enum import Enum
4 3 import time
5   -
6   -CONFIG_FILE = "socket_config.ini"
7   -
8   -class RotatorEnum(Enum):
9   - none = "None"
10   - synchro = "Synchro"
11   - tracking = "Tracking"
12   -
13   -class MoveModeEnum(Enum):
14   - goto = "Goto"
15   - track = "Track"
16   - goto_track = "GotoTrack"
17   -
18   -class CoordsFrameEnum(Enum):
19   - hadec = "Hadec"
20   - radec = "Radec"
21   - altaz = "Altaz"
  4 +from Device import Device
22 5  
23 6 DOORS_TIME = 5
24 7 MOVE_TIME = 5
25 8  
26   -class Telescope():
  9 +class Telescope(Device):
27 10  
28 11 def __init__(self):
29   - config = configparser.ConfigParser()
30   - config.read(CONFIG_FILE)
31   -
32   - ip = config.get("Telescope", "ip")
33   - port = int(config.get("Telescope", "port"))
34   -
35   - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
36   - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
37   - self.sock.bind((ip, port))
38   - self.sock.listen(12)
39   -
40   -
41   - self.set_msgs = [
42   - ("SPEED", [2, 3], float),
43   - ("COORDS", [2, 3], float),
44   - ("TRACKING_SPEED", [2, 3], float),
45   - ("ACCEL", [2, 3], float),
46   -
47   - ("ROTATOR", [1, ], RotatorEnum),
48   - ("FOCUS", [1, ], float),
49   - ("MOVE_MODE", [1, ], MoveModeEnum),
50   - ("COORDS_FRAME", [1, ], CoordsFrameEnum),
51   - ]
52   -
53   - get_msgs = [
54   - "POSITION",
55   - "STATUS",
56   - "SETUP",
57   - ]
58   -
59   - do_msgs = [
60   - ("DOORS", [1, ], bool),
61   - ("START", [0, ],),
62   - ("ABORT", [0, ],),
63   - ("STOP", [0, ],),
64   - ("HOMING", [0, ],),
65   - ]
  12 + super().__init__("Telescope")
66 13  
67 14 ''' I will just fill the attributes with their names and params without regarding them '''
68 15 self.attributes = {}
... ...
simulators/grammar.json 0 → 100644
... ... @@ -0,0 +1,229 @@
  1 +{
  2 + "Telescope" : {
  3 + "set": [
  4 + {
  5 + "name": "SPEED",
  6 + "nb_param": [2, 3],
  7 + "param_type": "float"
  8 + },
  9 + {
  10 + "name": "COORDS",
  11 + "nb_param": [2, 3],
  12 + "param_type": "float"
  13 + },
  14 + {
  15 + "name": "TRACKING_SPEED",
  16 + "nb_param": [2, 3],
  17 + "param_type": "float"
  18 + },
  19 + {
  20 + "name": "ACCEL",
  21 + "nb_param": [2, 3],
  22 + "param_type": "float"
  23 + },
  24 + {
  25 + "name": "ROTATOR",
  26 + "nb_param": [1],
  27 + "param_type": "EnumRotator"
  28 + },
  29 + {
  30 + "name": "FOCUS",
  31 + "nb_param": [1],
  32 + "param_type": "float"
  33 + },
  34 + {
  35 + "name": "MOVE_MODE",
  36 + "nb_param": [1],
  37 + "param_type": "EnumMoveMode"
  38 + },
  39 + {
  40 + "name": "COORDS_FRAME",
  41 + "nb_param": [1],
  42 + "param_type": "EnumCoordsFrame"
  43 + }
  44 +
  45 + ],
  46 + "get": [
  47 + "POSITION",
  48 + "STATUS",
  49 + "SETUP"
  50 + ],
  51 +
  52 + "do": [
  53 + {
  54 + "name": "DOORS",
  55 + "nb_param": [1],
  56 + "param_type": "bool"
  57 + },
  58 + {
  59 + "name": "START",
  60 + "nb_param": [0],
  61 + "param_type": ""
  62 + },
  63 + {
  64 + "name": "ABORT",
  65 + "nb_param": [0],
  66 + "param_type": ""
  67 + },
  68 + {
  69 + "name": "STOP",
  70 + "nb_param": [0],
  71 + "param_type": ""
  72 + },
  73 + {
  74 + "name": "HOMING",
  75 + "nb_param": [0],
  76 + "param_type": ""
  77 + }
  78 +
  79 + ]
  80 + },
  81 +
  82 + "Camera" : {
  83 + "set" : [
  84 + {
  85 + "name": "WINDOW",
  86 + "nb_param": [4],
  87 + "param_type": "int"
  88 + },
  89 + {
  90 + "name": "READMODE",
  91 + "nb_param": [1],
  92 + "param_type": "EnumReadMode"
  93 + },
  94 + {
  95 + "name": "FILENAME",
  96 + "nb_param": [1],
  97 + "param_type": "str"
  98 + },
  99 + {
  100 + "name": "HEADER",
  101 + "nb_param": [1],
  102 + "param_type": "dict"
  103 + },
  104 + {
  105 + "name": "READOUT_FREQUENCY",
  106 + "nb_param": [1],
  107 + "param_type": "float"
  108 + },
  109 + {
  110 + "name": "FILTER",
  111 + "nb_param": [1],
  112 + "param_type": "EnumFilter"
  113 + }
  114 + ],
  115 + "get" : [
  116 + "STATUS",
  117 + "TEMPERATURE",
  118 + "SETUP",
  119 + "TIMER"
  120 + ],
  121 +
  122 + "do" : [
  123 + {
  124 + "name": "COOLER",
  125 + "nb_param": [2],
  126 + "param_type": "float"
  127 + },
  128 + {
  129 + "name": "SHUTTER",
  130 + "nb_param": [1],
  131 + "param_type": "EnumShutter"
  132 + },
  133 + {
  134 + "name": "START",
  135 + "nb_param": [0],
  136 + "param_type": ""
  137 + },
  138 + {
  139 + "name": "STOP",
  140 + "nb_param": [0],
  141 + "param_type": ""
  142 + },
  143 + {
  144 + "name": "ABORT",
  145 + "nb_param": [0],
  146 + "param_type": ""
  147 + }
  148 + ]
  149 + },
  150 +
  151 + "CameraVIS" : {
  152 + "set" : [
  153 + {
  154 + "name": "EXPOSURE",
  155 + "nb_param": [1],
  156 + "param_type": "int"
  157 + },
  158 + {
  159 + "name": "BINNING",
  160 + "nb_param": [2],
  161 + "param_type": "int"
  162 + }
  163 + ],
  164 + "get" : [],
  165 + "do" : []
  166 + },
  167 +
  168 + "CameraNIR" : {
  169 + "set" : [
  170 + {
  171 + "name": "NB_IMAGES",
  172 + "nb_param": [1],
  173 + "param_type": "int"
  174 + }
  175 + ],
  176 + "get" : [],
  177 + "do" : []
  178 + },
  179 +
  180 + "CameraNIR" : {
  181 + "set" : [
  182 + {
  183 + "name": "NB_IMAGES",
  184 + "nb_param": [1],
  185 + "param_type": "int"
  186 + }
  187 + ],
  188 + "get" : [],
  189 + "do" : []
  190 + },
  191 +
  192 + "PLC" : {
  193 + "set" : [],
  194 + "get" : [
  195 + "STATUS"
  196 + ],
  197 + "do" : []
  198 + },
  199 +
  200 + "Enums" : {
  201 + "EnumReadMode" : [
  202 + "Ramp"
  203 + ],
  204 + "EnumShutter" : [
  205 + "Synchro",
  206 + "Closed",
  207 + "Opened"
  208 + ],
  209 + "EnumFilter" : [
  210 + "T",
  211 + "H"
  212 + ],
  213 + "EnumRotator" : [
  214 + "None",
  215 + "Synchro",
  216 + "Tracking"
  217 + ],
  218 + "EnumMoveMode" : [
  219 + "Goto",
  220 + "Track",
  221 + "GotoTrack"
  222 + ],
  223 + "EnumCoordsFrame" : [
  224 + "Hadec",
  225 + "Radec",
  226 + "Altaz"
  227 + ]
  228 + }
  229 +}
... ...
src/common/RequestBuilder.py
... ... @@ -171,6 +171,7 @@ class RequestBuilder():
171 171  
172 172 if settings.CELERY_TEST == False:
173 173 pass
  174 + # TODO: mettre une condition de temps pour lancer le scheduling (il faut être nuit -2 min au minimum)
174 175 # scheduler.tasks.scheduling.delay(first_schedule=True, alert=self.request.is_alert) # TODO : changer le first_schedule ...
175 176  
176 177 return self.request
... ...
src/majordome/tasks.py
... ... @@ -47,16 +47,16 @@ class execute_sequence(Task):
47 47 scheduler.tasks.scheduling.delay(first_schedule=True, alert=False) # TODO : changer le first_schedule à False
48 48 return
49 49  
50   - tel = Tel.TelescopeObj()
  50 + tel = Tel.TelescopeController()
51 51  
52 52 tel.set("SPEED", 10.0, 10.0, 10.0)
53 53 tel.set("COORDS", 104.0, 12.0, 88.0)
54   - tel.set("COORDS_FRAME", Tel.CoordsFrameEnum.radec)
  54 + tel.set("COORDS_FRAME", "Radec")
55 55 tel.set("TRACKING_SPEED", 0.3, 0.3, 0.3)
56 56 tel.set("ACCEL", 1.0, 1.0, 1.0)
57   - tel.set("ROTATOR", Tel.RotatorEnum.tracking)
  57 + tel.set("ROTATOR", "Tracking")
58 58 tel.set("FOCUS", 23562.0)
59   - tel.set("MOVE_MODE", Tel.MoveModeEnum.goto_track)
  59 + tel.set("MOVE_MODE", "GotoTrack")
60 60  
61 61 tel.do("START")
62 62  
... ...
src/observation_manager/tasks.py
... ... @@ -53,11 +53,11 @@ class execute_plan_vis(Task):
53 53  
54 54 # TODO: mettre les vraies configurations en fct du plan
55 55 cam.set("WINDOW", 0, 100, 10, 100)
56   - cam.set("READMODE", VIS.ReadmodeEnum.ramp)
  56 + cam.set("READMODE", "Ramp")
57 57 cam.set("FILENAME", plan.name)
58 58 cam.set("HEADER", {})
59 59 cam.set("READOUT_FREQUENCY", 20.0)
60   - cam.set("FILTER", VIS.FilterEnum.h)
  60 + cam.set("FILTER", "H")
61 61  
62 62 cam.set("EXPOSURE", 180)
63 63 cam.set("BINNING", 300, 300)
... ... @@ -134,11 +134,11 @@ class execute_plan_nir(Task):
134 134 def set_camera(self, cam, plan):
135 135  
136 136 cam.set("WINDOW", 0, 100, 10, 100)
137   - cam.set("READMODE", NIR.ReadmodeEnum.ramp)
  137 + cam.set("READMODE", "Ramp")
138 138 cam.set("FILENAME", plan.name)
139 139 cam.set("HEADER", {})
140 140 cam.set("READOUT_FREQUENCY", 20.0)
141   - cam.set("FILTER", NIR.FilterEnum.h)
  141 + cam.set("FILTER", "H")
142 142  
143 143 cam.set("NB_IMAGES", 28)
144 144  
... ...
src/pyros/settings.py
... ... @@ -29,7 +29,7 @@ MODULES_VERSIONS = {
29 29 # Set MYSQL to False if you want to use SQLITE
30 30 # This line MUST NOT be changed at all except from changing True/False
31 31 # (or install_requirements script will become invalid)
32   -MYSQL = True
  32 +MYSQL = False
33 33  
34 34 import os
35 35  
... ...
src/routine_manager/views.py
... ... @@ -27,7 +27,9 @@ def requests_list(request, status=0, message=""):
27 27  
28 28 # TODO: uncomment for alert filter
29 29 # requests_objs = Request.objects.filter(pyros_user=request.user.pyros_user).filter(is_alert=False).order_by("-updated")
30   - requests_objs = Request.objects.filter(pyros_user=request.user.pyros_user).order_by("-updated")
  30 +# requests_objs = Request.objects.filter(pyros_user=request.user.pyros_user).order_by("-updated")
  31 +
  32 + requests_objs = Request.objects.all().order_by("-updated")
31 33  
32 34 requests = []
33 35  
... ...
src/user_manager/forms.py
... ... @@ -61,6 +61,7 @@ class PyrosUserCreationForm(forms.ModelForm):
61 61 user.last_name = self.cleaned_data['last_name']
62 62 user.save()
63 63  
  64 + # Default values for country and user level
64 65 pyros_user = PyrosUser.objects.create(user=user, country=Country.objects.all()[0],
65 66 user_level=UserLevel.objects.all()[0],
66 67 tel=self.cleaned_data['tel'], laboratory=self.cleaned_data['laboratory'],
... ...