@@ -1,1007 +1,1007 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration , User |
|
2 | from apps.main.models import Configuration , User | |
3 | from django.urls import reverse |
|
3 | from django.urls import reverse | |
4 | from celery.execute import send_task |
|
4 | from celery.execute import send_task | |
5 | from datetime import datetime |
|
5 | from datetime import datetime | |
6 | import ast |
|
6 | import ast | |
7 | import socket |
|
7 | import socket | |
8 | import json |
|
8 | import json | |
9 | import requests |
|
9 | import requests | |
10 | import struct |
|
10 | import struct | |
11 | import os, sys, time |
|
11 | import os, sys, time | |
12 |
|
12 | |||
13 | antenna_default = json.dumps({ |
|
13 | antenna_default = json.dumps({ | |
14 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
14 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
15 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
15 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
16 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
16 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
17 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
17 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
18 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
18 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], | |
19 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
19 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], | |
20 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
20 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], | |
21 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] |
|
21 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] | |
22 | ] |
|
22 | ] | |
23 | , |
|
23 | , | |
24 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
24 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
25 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
25 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
26 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
26 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
27 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
27 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], | |
28 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
28 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], | |
29 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
29 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], | |
30 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
30 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], | |
31 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], |
|
31 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], | |
32 | }) |
|
32 | }) | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | tx_default = json.dumps({ |
|
35 | tx_default = json.dumps({ | |
36 | "up": [[1,1,1,1,0,0,0,0], |
|
36 | "up": [[1,1,1,1,0,0,0,0], | |
37 | [1,1,1,1,0,0,0,0], |
|
37 | [1,1,1,1,0,0,0,0], | |
38 | [1,1,1,1,0,0,0,0], |
|
38 | [1,1,1,1,0,0,0,0], | |
39 | [1,1,1,1,0,0,0,0], |
|
39 | [1,1,1,1,0,0,0,0], | |
40 | [0,0,0,0,1,1,1,1], |
|
40 | [0,0,0,0,1,1,1,1], | |
41 | [0,0,0,0,1,1,1,1], |
|
41 | [0,0,0,0,1,1,1,1], | |
42 | [0,0,0,0,1,1,1,1], |
|
42 | [0,0,0,0,1,1,1,1], | |
43 | [0,0,0,0,1,1,1,1]], |
|
43 | [0,0,0,0,1,1,1,1]], | |
44 |
|
44 | |||
45 | "down": [[1,1,1,1,0,0,0,0], |
|
45 | "down": [[1,1,1,1,0,0,0,0], | |
46 | [1,1,1,1,0,0,0,0], |
|
46 | [1,1,1,1,0,0,0,0], | |
47 | [1,1,1,1,0,0,0,0], |
|
47 | [1,1,1,1,0,0,0,0], | |
48 | [1,1,1,1,0,0,0,0], |
|
48 | [1,1,1,1,0,0,0,0], | |
49 | [0,0,0,0,1,1,1,1], |
|
49 | [0,0,0,0,1,1,1,1], | |
50 | [0,0,0,0,1,1,1,1], |
|
50 | [0,0,0,0,1,1,1,1], | |
51 | [0,0,0,0,1,1,1,1], |
|
51 | [0,0,0,0,1,1,1,1], | |
52 | [0,0,0,0,1,1,1,1]], |
|
52 | [0,0,0,0,1,1,1,1]], | |
53 | }) |
|
53 | }) | |
54 |
|
54 | |||
55 | rx_default = json.dumps({ |
|
55 | rx_default = json.dumps({ | |
56 | "up": [[1,1,1,1,0,0,0,0], |
|
56 | "up": [[1,1,1,1,0,0,0,0], | |
57 | [1,1,1,1,0,0,0,0], |
|
57 | [1,1,1,1,0,0,0,0], | |
58 | [1,1,1,1,0,0,0,0], |
|
58 | [1,1,1,1,0,0,0,0], | |
59 | [1,1,1,1,0,0,0,0], |
|
59 | [1,1,1,1,0,0,0,0], | |
60 | [0,0,0,0,1,1,1,1], |
|
60 | [0,0,0,0,1,1,1,1], | |
61 | [0,0,0,0,1,1,1,1], |
|
61 | [0,0,0,0,1,1,1,1], | |
62 | [0,0,0,0,1,1,1,1], |
|
62 | [0,0,0,0,1,1,1,1], | |
63 | [0,0,0,0,1,1,1,1]], |
|
63 | [0,0,0,0,1,1,1,1]], | |
64 |
|
64 | |||
65 | "down": [[1,1,1,1,0,0,0,0], |
|
65 | "down": [[1,1,1,1,0,0,0,0], | |
66 | [1,1,1,1,0,0,0,0], |
|
66 | [1,1,1,1,0,0,0,0], | |
67 | [1,1,1,1,0,0,0,0], |
|
67 | [1,1,1,1,0,0,0,0], | |
68 | [1,1,1,1,0,0,0,0], |
|
68 | [1,1,1,1,0,0,0,0], | |
69 | [0,0,0,0,1,1,1,1], |
|
69 | [0,0,0,0,1,1,1,1], | |
70 | [0,0,0,0,1,1,1,1], |
|
70 | [0,0,0,0,1,1,1,1], | |
71 | [0,0,0,0,1,1,1,1], |
|
71 | [0,0,0,0,1,1,1,1], | |
72 | [0,0,0,0,1,1,1,1]], |
|
72 | [0,0,0,0,1,1,1,1]], | |
73 | }) |
|
73 | }) | |
74 |
|
74 | |||
75 | status_default = '0000000000000000000000000000000000000000000000000000000000000000' |
|
75 | status_default = '0000000000000000000000000000000000000000000000000000000000000000' | |
76 | default_messages = {} |
|
76 | default_messages = {} | |
77 |
|
77 | |||
78 | for i in range(1,65): |
|
78 | for i in range(1,65): | |
79 | default_messages[str(i)] = "Module "+str(i) |
|
79 | default_messages[str(i)] = "Module "+str(i) | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | ues_default = json.dumps({ |
|
82 | ues_default = json.dumps({ | |
83 | "up": [0.533333,0.00000,1.06667,0.00000], |
|
83 | "up": [0.533333,0.00000,1.06667,0.00000], | |
84 | "down": [0.533333,0.00000,1.06667,0.00000] |
|
84 | "down": [0.533333,0.00000,1.06667,0.00000] | |
85 | }) |
|
85 | }) | |
86 |
|
86 | |||
87 | onlyrx_default = json.dumps({ |
|
87 | onlyrx_default = json.dumps({ | |
88 | "up": False, |
|
88 | "up": False, | |
89 | "down": False |
|
89 | "down": False | |
90 | }) |
|
90 | }) | |
91 |
|
91 | |||
92 | def up_convertion(cadena): |
|
92 | def up_convertion(cadena): | |
93 | valores = [] |
|
93 | valores = [] | |
94 | for c in cadena: |
|
94 | for c in cadena: | |
95 | if c == 1.0: valores=valores+['000'] |
|
95 | if c == 1.0: valores=valores+['000'] | |
96 | if c == 2.0: valores=valores+['001'] |
|
96 | if c == 2.0: valores=valores+['001'] | |
97 | if c == 3.0: valores=valores+['010'] |
|
97 | if c == 3.0: valores=valores+['010'] | |
98 | if c == 0.0: valores=valores+['011'] |
|
98 | if c == 0.0: valores=valores+['011'] | |
99 | if c == 0.5: valores=valores+['100'] |
|
99 | if c == 0.5: valores=valores+['100'] | |
100 | if c == 1.5: valores=valores+['101'] |
|
100 | if c == 1.5: valores=valores+['101'] | |
101 | if c == 2.5: valores=valores+['110'] |
|
101 | if c == 2.5: valores=valores+['110'] | |
102 | if c == 3.5: valores=valores+['111'] |
|
102 | if c == 3.5: valores=valores+['111'] | |
103 |
|
103 | |||
104 | return valores |
|
104 | return valores | |
105 |
|
105 | |||
106 | def up_conv_bits(value): |
|
106 | def up_conv_bits(value): | |
107 |
|
107 | |||
108 | if value == 1.0: bits="000" |
|
108 | if value == 1.0: bits="000" | |
109 | if value == 2.0: bits="001" |
|
109 | if value == 2.0: bits="001" | |
110 | if value == 3.0: bits="010" |
|
110 | if value == 3.0: bits="010" | |
111 | if value == 0.0: bits="011" |
|
111 | if value == 0.0: bits="011" | |
112 | if value == 0.5: bits="100" |
|
112 | if value == 0.5: bits="100" | |
113 | if value == 1.5: bits="101" |
|
113 | if value == 1.5: bits="101" | |
114 | if value == 2.5: bits="110" |
|
114 | if value == 2.5: bits="110" | |
115 | if value == 3.5: bits="111" |
|
115 | if value == 3.5: bits="111" | |
116 |
|
116 | |||
117 | return bits |
|
117 | return bits | |
118 |
|
118 | |||
119 | def down_convertion(cadena): |
|
119 | def down_convertion(cadena): | |
120 | valores = [] |
|
120 | valores = [] | |
121 | for c in cadena: |
|
121 | for c in cadena: | |
122 | if c == 1.0: valores=valores+['000'] |
|
122 | if c == 1.0: valores=valores+['000'] | |
123 | if c == 2.0: valores=valores+['001'] |
|
123 | if c == 2.0: valores=valores+['001'] | |
124 | if c == 3.0: valores=valores+['010'] |
|
124 | if c == 3.0: valores=valores+['010'] | |
125 | if c == 0.0: valores=valores+['011'] |
|
125 | if c == 0.0: valores=valores+['011'] | |
126 | if c == 0.5: valores=valores+['100'] |
|
126 | if c == 0.5: valores=valores+['100'] | |
127 | if c == 1.5: valores=valores+['101'] |
|
127 | if c == 1.5: valores=valores+['101'] | |
128 | if c == 2.5: valores=valores+['110'] |
|
128 | if c == 2.5: valores=valores+['110'] | |
129 | if c == 3.5: valores=valores+['111'] |
|
129 | if c == 3.5: valores=valores+['111'] | |
130 |
|
130 | |||
131 | return valores |
|
131 | return valores | |
132 |
|
132 | |||
133 | def down_conv_bits(value): |
|
133 | def down_conv_bits(value): | |
134 |
|
134 | |||
135 | if value == 1.0: bits="000" |
|
135 | if value == 1.0: bits="000" | |
136 | if value == 2.0: bits="001" |
|
136 | if value == 2.0: bits="001" | |
137 | if value == 3.0: bits="010" |
|
137 | if value == 3.0: bits="010" | |
138 | if value == 0.0: bits="011" |
|
138 | if value == 0.0: bits="011" | |
139 | if value == 0.5: bits="100" |
|
139 | if value == 0.5: bits="100" | |
140 | if value == 1.5: bits="101" |
|
140 | if value == 1.5: bits="101" | |
141 | if value == 2.5: bits="110" |
|
141 | if value == 2.5: bits="110" | |
142 | if value == 3.5: bits="111" |
|
142 | if value == 3.5: bits="111" | |
143 |
|
143 | |||
144 | return bits |
|
144 | return bits | |
145 |
|
145 | |||
146 | def up_conv_value(bits): |
|
146 | def up_conv_value(bits): | |
147 |
|
147 | |||
148 | if bits == "000": value=1.0 |
|
148 | if bits == "000": value=1.0 | |
149 | if bits == "001": value=2.0 |
|
149 | if bits == "001": value=2.0 | |
150 | if bits == "010": value=3.0 |
|
150 | if bits == "010": value=3.0 | |
151 | if bits == "011": value=0.0 |
|
151 | if bits == "011": value=0.0 | |
152 | if bits == "100": value=0.5 |
|
152 | if bits == "100": value=0.5 | |
153 | if bits == "101": value=1.5 |
|
153 | if bits == "101": value=1.5 | |
154 | if bits == "110": value=2.5 |
|
154 | if bits == "110": value=2.5 | |
155 | if bits == "111": value=3.5 |
|
155 | if bits == "111": value=3.5 | |
156 |
|
156 | |||
157 | return value |
|
157 | return value | |
158 |
|
158 | |||
159 | def down_conv_value(bits): |
|
159 | def down_conv_value(bits): | |
160 |
|
160 | |||
161 | if bits == "000": value=1.0 |
|
161 | if bits == "000": value=1.0 | |
162 | if bits == "001": value=2.0 |
|
162 | if bits == "001": value=2.0 | |
163 | if bits == "010": value=3.0 |
|
163 | if bits == "010": value=3.0 | |
164 | if bits == "011": value=0.0 |
|
164 | if bits == "011": value=0.0 | |
165 | if bits == "100": value=0.5 |
|
165 | if bits == "100": value=0.5 | |
166 | if bits == "101": value=1.5 |
|
166 | if bits == "101": value=1.5 | |
167 | if bits == "110": value=2.5 |
|
167 | if bits == "110": value=2.5 | |
168 | if bits == "111": value=3.5 |
|
168 | if bits == "111": value=3.5 | |
169 |
|
169 | |||
170 | return value |
|
170 | return value | |
171 |
|
171 | |||
172 | def ip2position(module_number): |
|
172 | def ip2position(module_number): | |
173 | j=0 |
|
173 | j=0 | |
174 | i=0 |
|
174 | i=0 | |
175 | for x in range(0,module_number-1): |
|
175 | for x in range(0,module_number-1): | |
176 | j=j+1 |
|
176 | j=j+1 | |
177 | if j==8: |
|
177 | if j==8: | |
178 | i=i+1 |
|
178 | i=i+1 | |
179 | j=0 |
|
179 | j=0 | |
180 |
|
180 | |||
181 | pos = [i,j] |
|
181 | pos = [i,j] | |
182 | return pos |
|
182 | return pos | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | def fromBinary2Char(binary_string): |
|
185 | def fromBinary2Char(binary_string): | |
186 | number = int(binary_string, 2) |
|
186 | number = int(binary_string, 2) | |
187 | #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f' |
|
187 | #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f' | |
188 | number = number + 33 |
|
188 | number = number + 33 | |
189 | char = chr(number) |
|
189 | char = chr(number) | |
190 | return char |
|
190 | return char | |
191 |
|
191 | |||
192 | def fromChar2Binary(char): |
|
192 | def fromChar2Binary(char): | |
193 | number = ord(char) - 33 |
|
193 | number = ord(char) - 33 | |
194 | #Minus 33 to get the real value |
|
194 | #Minus 33 to get the real value | |
195 | bits = bin(number)[2:] |
|
195 | bits = bin(number)[2:] | |
196 | #To ensure we have a string with 6bits |
|
196 | #To ensure we have a string with 6bits | |
197 | if len(bits) < 6: |
|
197 | if len(bits) < 6: | |
198 | bits = bits.zfill(6) |
|
198 | bits = bits.zfill(6) | |
199 | return bits |
|
199 | return bits | |
200 |
|
200 | |||
201 | OPERATION_MODES = ( |
|
201 | OPERATION_MODES = ( | |
202 | (0, 'Manual'), |
|
202 | (0, 'Manual'), | |
203 | (1, 'Automatic'), |
|
203 | (1, 'Automatic'), | |
204 | ) |
|
204 | ) | |
205 |
|
205 | |||
206 | class ABSConfiguration(Configuration): |
|
206 | class ABSConfiguration(Configuration): | |
207 | active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0) |
|
207 | active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0) | |
208 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=status_default) |
|
208 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=status_default) | |
209 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) |
|
209 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) | |
210 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) |
|
210 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) | |
211 | module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages)) |
|
211 | module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages)) | |
212 |
|
212 | |||
213 | class Meta: |
|
213 | class Meta: | |
214 | db_table = 'abs_configurations' |
|
214 | db_table = 'abs_configurations' | |
215 |
|
215 | |||
216 | def get_absolute_url_plot(self): |
|
216 | def get_absolute_url_plot(self): | |
217 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) |
|
217 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | def parms_to_dict(self): |
|
220 | def parms_to_dict(self): | |
221 |
|
221 | |||
222 | parameters = {} |
|
222 | parameters = {} | |
223 |
|
223 | |||
224 | parameters['device_id'] = self.device.id |
|
224 | parameters['device_id'] = self.device.id | |
225 | parameters['label'] = self.label |
|
225 | parameters['label'] = self.label | |
226 | parameters['device_type'] = self.device.device_type.name |
|
226 | parameters['device_type'] = self.device.device_type.name | |
227 | parameters['beams'] = {} |
|
227 | parameters['beams'] = {} | |
228 |
|
228 | |||
229 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
229 | beams = ABSBeam.objects.filter(abs_conf=self) | |
230 | b=1 |
|
230 | b=1 | |
231 | for beam in beams: |
|
231 | for beam in beams: | |
232 | #absbeam = ABSBeam.objects.get(pk=beams[beam]) |
|
232 | #absbeam = ABSBeam.objects.get(pk=beams[beam]) | |
233 | parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict() |
|
233 | parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict() | |
234 | b+=1 |
|
234 | b+=1 | |
235 |
|
235 | |||
236 | return parameters |
|
236 | return parameters | |
237 |
|
237 | |||
238 |
|
238 | |||
239 | def dict_to_parms(self, parameters): |
|
239 | def dict_to_parms(self, parameters): | |
240 |
|
240 | |||
241 | self.label = parameters['label'] |
|
241 | self.label = parameters['label'] | |
242 |
|
242 | |||
243 | absbeams = ABSBeam.objects.filter(abs_conf=self) |
|
243 | absbeams = ABSBeam.objects.filter(abs_conf=self) | |
244 | beams = parameters['beams'] |
|
244 | beams = parameters['beams'] | |
245 |
|
245 | |||
246 | if absbeams: |
|
246 | if absbeams: | |
247 | beams_number = len(beams) |
|
247 | beams_number = len(beams) | |
248 | absbeams_number = len(absbeams) |
|
248 | absbeams_number = len(absbeams) | |
249 | if beams_number==absbeams_number: |
|
249 | if beams_number==absbeams_number: | |
250 | i = 1 |
|
250 | i = 1 | |
251 | for absbeam in absbeams: |
|
251 | for absbeam in absbeams: | |
252 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
252 | absbeam.dict_to_parms(beams['beam'+str(i)]) | |
253 | i = i+1 |
|
253 | i = i+1 | |
254 | elif beams_number > absbeams_number: |
|
254 | elif beams_number > absbeams_number: | |
255 | i = 1 |
|
255 | i = 1 | |
256 | for absbeam in absbeams: |
|
256 | for absbeam in absbeams: | |
257 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
257 | absbeam.dict_to_parms(beams['beam'+str(i)]) | |
258 | i=i+1 |
|
258 | i=i+1 | |
259 | for x in range(i,beams_number+1): |
|
259 | for x in range(i,beams_number+1): | |
260 | new_beam = ABSBeam( |
|
260 | new_beam = ABSBeam( | |
261 | name =beams['beam'+str(i)]['name'], |
|
261 | name =beams['beam'+str(i)]['name'], | |
262 | antenna =json.dumps(beams['beam'+str(i)]['antenna']), |
|
262 | antenna =json.dumps(beams['beam'+str(i)]['antenna']), | |
263 | abs_conf = self, |
|
263 | abs_conf = self, | |
264 | tx =json.dumps(beams['beam'+str(i)]['tx']), |
|
264 | tx =json.dumps(beams['beam'+str(i)]['tx']), | |
265 | rx =json.dumps(beams['beam'+str(i)]['rx']), |
|
265 | rx =json.dumps(beams['beam'+str(i)]['rx']), | |
266 | ues =json.dumps(beams['beam'+str(i)]['ues']), |
|
266 | ues =json.dumps(beams['beam'+str(i)]['ues']), | |
267 | only_rx =json.dumps(beams['beam'+str(i)]['only_rx']) |
|
267 | only_rx =json.dumps(beams['beam'+str(i)]['only_rx']) | |
268 | ) |
|
268 | ) | |
269 | new_beam.save() |
|
269 | new_beam.save() | |
270 | i=i+1 |
|
270 | i=i+1 | |
271 | else: #beams_number < absbeams_number: |
|
271 | else: #beams_number < absbeams_number: | |
272 | i = 1 |
|
272 | i = 1 | |
273 | for absbeam in absbeams: |
|
273 | for absbeam in absbeams: | |
274 | if i <= beams_number: |
|
274 | if i <= beams_number: | |
275 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
275 | absbeam.dict_to_parms(beams['beam'+str(i)]) | |
276 | i=i+1 |
|
276 | i=i+1 | |
277 | else: |
|
277 | else: | |
278 | absbeam.delete() |
|
278 | absbeam.delete() | |
279 | else: |
|
279 | else: | |
280 | for beam in beams: |
|
280 | for beam in beams: | |
281 | new_beam = ABSBeam( |
|
281 | new_beam = ABSBeam( | |
282 | name =beams[beam]['name'], |
|
282 | name =beams[beam]['name'], | |
283 | antenna =json.dumps(beams[beam]['antenna']), |
|
283 | antenna =json.dumps(beams[beam]['antenna']), | |
284 | abs_conf = self, |
|
284 | abs_conf = self, | |
285 | tx =json.dumps(beams[beam]['tx']), |
|
285 | tx =json.dumps(beams[beam]['tx']), | |
286 | rx =json.dumps(beams[beam]['rx']), |
|
286 | rx =json.dumps(beams[beam]['rx']), | |
287 | ues =json.dumps(beams[beam]['ues']), |
|
287 | ues =json.dumps(beams[beam]['ues']), | |
288 | only_rx =json.dumps(beams[beam]['only_rx']) |
|
288 | only_rx =json.dumps(beams[beam]['only_rx']) | |
289 | ) |
|
289 | ) | |
290 | new_beam.save() |
|
290 | new_beam.save() | |
291 |
|
291 | |||
292 |
|
292 | |||
293 |
|
293 | |||
294 | def update_from_file(self, parameters): |
|
294 | def update_from_file(self, parameters): | |
295 |
|
295 | |||
296 | self.dict_to_parms(parameters) |
|
296 | self.dict_to_parms(parameters) | |
297 | self.save() |
|
297 | self.save() | |
298 |
|
298 | |||
299 |
|
299 | |||
300 | def get_beams(self, **kwargs): |
|
300 | def get_beams(self, **kwargs): | |
301 | ''' |
|
301 | ''' | |
302 | This function returns ABS Configuration beams |
|
302 | This function returns ABS Configuration beams | |
303 | ''' |
|
303 | ''' | |
304 | return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs) |
|
304 | return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs) | |
305 |
|
305 | |||
306 | def clone(self, **kwargs): |
|
306 | def clone(self, **kwargs): | |
307 |
|
307 | |||
308 | beams = self.get_beams() |
|
308 | beams = self.get_beams() | |
309 | self.pk = None |
|
309 | self.pk = None | |
310 | self.id = None |
|
310 | self.id = None | |
311 | for attr, value in kwargs.items(): |
|
311 | for attr, value in kwargs.items(): | |
312 | setattr(self, attr, value) |
|
312 | setattr(self, attr, value) | |
313 | self.save() |
|
313 | self.save() | |
314 |
|
314 | |||
315 | for beam in beams: |
|
315 | for beam in beams: | |
316 | beam.clone(abs_conf=self) |
|
316 | beam.clone(abs_conf=self) | |
317 |
|
317 | |||
318 | #-----For Active Beam----- |
|
318 | #-----For Active Beam----- | |
319 | new_beams = ABSBeam.objects.filter(abs_conf=self) |
|
319 | new_beams = ABSBeam.objects.filter(abs_conf=self) | |
320 | self.active_beam = new_beams[0].id |
|
320 | self.active_beam = new_beams[0].id | |
321 | self.save() |
|
321 | self.save() | |
322 | #-----For Active Beam----- |
|
322 | #-----For Active Beam----- | |
323 | #-----For Device Status--- |
|
323 | #-----For Device Status--- | |
324 | self.device.status = 3 |
|
324 | self.device.status = 3 | |
325 | self.device.save() |
|
325 | self.device.save() | |
326 | #-----For Device Status--- |
|
326 | #-----For Device Status--- | |
327 |
|
327 | |||
328 | return self |
|
328 | return self | |
329 |
|
329 | |||
330 |
|
330 | |||
331 | def start_device(self): |
|
331 | def start_device(self): | |
332 |
|
332 | |||
333 | if self.device.status == 3: |
|
333 | if self.device.status == 3: | |
334 |
|
334 | |||
335 | try: |
|
335 | try: | |
336 | #self.write_device() |
|
336 | #self.write_device() | |
337 | send_task('task_change_beam', [self.id],) |
|
337 | send_task('task_change_beam', [self.id],) | |
338 | self.message = 'ABS running' |
|
338 | self.message = 'ABS running' | |
339 |
|
339 | |||
340 | except Exception as e: |
|
340 | except Exception as e: | |
341 | self.message = str(e) |
|
341 | self.message = str(e) | |
342 | return False |
|
342 | return False | |
343 |
|
343 | |||
344 | return True |
|
344 | return True | |
345 |
|
345 | |||
346 | else: |
|
346 | else: | |
347 | self.message = 'Please, select Write ABS Device first.' |
|
347 | self.message = 'Please, select Write ABS Device first.' | |
348 | return False |
|
348 | return False | |
349 |
|
349 | |||
350 |
|
350 | |||
351 | def stop_device(self): |
|
351 | def stop_device(self): | |
352 |
|
352 | |||
353 | self.device.status = 2 |
|
353 | self.device.status = 2 | |
354 | self.device.save() |
|
354 | self.device.save() | |
355 | self.message = 'ABS has been stopped.' |
|
355 | self.message = 'ABS has been stopped.' | |
356 | self.save() |
|
356 | self.save() | |
357 |
|
357 | |||
358 | return True |
|
358 | return True | |
359 |
|
359 | |||
360 |
|
360 | |||
361 | def write_device(self): |
|
361 | def write_device(self): | |
362 |
|
362 | |||
363 | """ |
|
363 | """ | |
364 | This function sends the beams list to every abs module. |
|
364 | This function sends the beams list to every abs module. | |
365 | It needs 'module_conf' function |
|
365 | It needs 'module_conf' function | |
366 | """ |
|
366 | """ | |
367 | print("Write") |
|
367 | print("Write") | |
368 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
368 | beams = ABSBeam.objects.filter(abs_conf=self) | |
369 | nbeams = len(beams) |
|
369 | nbeams = len(beams) | |
370 |
|
370 | |||
371 | # Se manda a cero RC para poder realizar cambio de beam |
|
371 | # Se manda a cero RC para poder realizar cambio de beam | |
372 | if self.experiment is None: |
|
372 | if self.experiment is None: | |
373 | confs = [] |
|
373 | confs = [] | |
374 | else: |
|
374 | else: | |
375 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
375 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) | |
376 | confdds = '' |
|
376 | confdds = '' | |
377 | confjars = '' |
|
377 | confjars = '' | |
378 | confrc = '' |
|
378 | confrc = '' | |
379 | #TO STOP DEVICES: DDS-JARS-RC |
|
379 | #TO STOP DEVICES: DDS-JARS-RC | |
380 | for i in range(0,len(confs)): |
|
380 | for i in range(0,len(confs)): | |
381 | if i==0: |
|
381 | if i==0: | |
382 | for conf in confs: |
|
382 | for conf in confs: | |
383 | if conf.device.device_type.name == 'dds': |
|
383 | if conf.device.device_type.name == 'dds': | |
384 | confdds = conf |
|
384 | confdds = conf | |
385 | confdds.stop_device() |
|
385 | confdds.stop_device() | |
386 | break |
|
386 | break | |
387 | if i==1: |
|
387 | if i==1: | |
388 | for conf in confs: |
|
388 | for conf in confs: | |
389 | if conf.device.device_type.name == 'jars': |
|
389 | if conf.device.device_type.name == 'jars': | |
390 | confjars = conf |
|
390 | confjars = conf | |
391 | confjars.stop_device() |
|
391 | confjars.stop_device() | |
392 | break |
|
392 | break | |
393 | if i==2: |
|
393 | if i==2: | |
394 | for conf in confs: |
|
394 | for conf in confs: | |
395 | if conf.device.device_type.name == 'rc': |
|
395 | if conf.device.device_type.name == 'rc': | |
396 | confrc = conf |
|
396 | confrc = conf | |
397 | confrc.stop_device() |
|
397 | confrc.stop_device() | |
398 | break |
|
398 | break | |
399 |
|
399 | |||
400 | ''' |
|
400 | ''' | |
401 | if self.connected_modules() == 0 : |
|
401 | if self.connected_modules() == 0 : | |
402 | print("No encuentra modulos") |
|
402 | print("No encuentra modulos") | |
403 | self.message = "No ABS Module detected." |
|
403 | self.message = "No ABS Module detected." | |
404 | return False |
|
404 | return False | |
405 | ''' |
|
405 | ''' | |
406 | #-------------Write each abs module----------- |
|
406 | #-------------Write each abs module----------- | |
407 |
|
407 | |||
408 | if beams: |
|
408 | if beams: | |
409 | block_id = 0 |
|
409 | block_id = 0 | |
410 | message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id) |
|
410 | message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id) | |
411 | for i, status in enumerate(self.module_status): |
|
411 | for i, status in enumerate(self.module_status): | |
412 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) |
|
412 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) | |
413 | status = ['0'] * 64 |
|
413 | status = ['0'] * 64 | |
414 | n = 0 |
|
414 | n = 0 | |
415 | print("Llega una antes entrar a multicast") |
|
415 | print("Llega una antes entrar a multicast") | |
416 | sock = self.send_multicast(message) |
|
416 | sock = self.send_multicast(message) | |
417 |
|
417 | |||
418 | while True: |
|
418 | while True: | |
419 | #for i in range(32): |
|
419 | #for i in range(32): | |
420 | try: |
|
420 | try: | |
421 | data, address = sock.recvfrom(1024) |
|
421 | data, address = sock.recvfrom(1024) | |
422 | print (address, data) |
|
422 | print (address, data) | |
423 | data = data.decode("utf-8") |
|
423 | data = data.decode("utf-8") | |
424 | if data == '1': |
|
424 | if data == '1': | |
425 | status[int(address[0][10:])-1] = '3' |
|
425 | status[int(address[0][10:])-1] = '3' | |
426 | #print (int(address[0][10:])-1) |
|
426 | #print (int(address[0][10:])-1) | |
427 | elif data == '0': |
|
427 | elif data == '0': | |
428 | status[int(address[0][10:])-1] = '1' |
|
428 | status[int(address[0][10:])-1] = '1' | |
429 | except socket.timeout: |
|
429 | except socket.timeout: | |
430 | print('Timeout') |
|
430 | print('Timeout') | |
431 | break |
|
431 | break | |
432 | except Exception as e: |
|
432 | except Exception as e: | |
433 | print ('Error {}'.format(e)) |
|
433 | print ('Error {}'.format(e)) | |
434 | n += 1 |
|
434 | n += 1 | |
435 | sock.close() |
|
435 | sock.close() | |
436 | else: |
|
436 | else: | |
437 | self.message = "ABS Configuration does not have beams" |
|
437 | self.message = "ABS Configuration does not have beams" | |
438 | print('No beams') |
|
438 | print('No beams') | |
439 | #Start DDS-RC-JARS |
|
439 | #Start DDS-RC-JARS | |
440 | if confdds: |
|
440 | if confdds: | |
441 | confdds.start_device() |
|
441 | confdds.start_device() | |
442 | if confrc: |
|
442 | if confrc: | |
443 | #print confrc |
|
443 | #print confrc | |
444 | confrc.start_device() |
|
444 | confrc.start_device() | |
445 | if confjars: |
|
445 | if confjars: | |
446 | confjars.start_device() |
|
446 | confjars.start_device() | |
447 | return False |
|
447 | return False | |
448 |
|
448 | |||
449 | if n == 64: |
|
449 | if n == 64: | |
450 | self.message = "Could not write ABS Modules" |
|
450 | self.message = "Could not write ABS Modules" | |
451 | self.device.status = 0 |
|
451 | self.device.status = 0 | |
452 | self.module_status = ''.join(status) |
|
452 | self.module_status = ''.join(status) | |
453 | self.save() |
|
453 | self.save() | |
454 | print('Could not write ABS') |
|
454 | print('Could not write ABS') | |
455 | #Start DDS-RC-JARS |
|
455 | #Start DDS-RC-JARS | |
456 | if confdds: |
|
456 | if confdds: | |
457 | confdds.start_device() |
|
457 | confdds.start_device() | |
458 | if confrc: |
|
458 | if confrc: | |
459 | #print confrc |
|
459 | #print confrc | |
460 | confrc.start_device() |
|
460 | confrc.start_device() | |
461 | if confjars: |
|
461 | if confjars: | |
462 | confjars.start_device() |
|
462 | confjars.start_device() | |
463 | return False |
|
463 | return False | |
464 | else: |
|
464 | else: | |
465 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
465 | self.message = "ABS Beams List have been sent to ABS Modules" | |
466 | print('ABS beams list sent') |
|
466 | print('ABS beams list sent') | |
467 | self.active_beam = beams[0].pk |
|
467 | self.active_beam = beams[0].pk | |
468 |
|
468 | |||
469 | #Start DDS-RC-JARS |
|
469 | #Start DDS-RC-JARS | |
470 | if confdds: |
|
470 | if confdds: | |
471 | confdds.start_device() |
|
471 | confdds.start_device() | |
472 | if confrc: |
|
472 | if confrc: | |
473 | #print confrc |
|
473 | #print confrc | |
474 | confrc.start_device() |
|
474 | confrc.start_device() | |
475 | if confjars: |
|
475 | if confjars: | |
476 | confjars.start_device() |
|
476 | confjars.start_device() | |
477 |
|
477 | |||
478 | print('Inicia intento de salvar device.status') |
|
478 | print('Inicia intento de salvar device.status') | |
479 | self.device.status = 3 |
|
479 | self.device.status = 3 | |
480 | self.module_status = ''.join(status) |
|
480 | self.module_status = ''.join(status) | |
481 | #print(status) |
|
481 | #print(status) | |
482 | self.save() |
|
482 | self.save() | |
483 | print('Estatus salvado') |
|
483 | print('Estatus salvado') | |
484 | conf_active, __ = ABSActive.objects.get_or_create(pk=1) |
|
484 | conf_active, __ = ABSActive.objects.get_or_create(pk=1) | |
485 | conf_active.conf = self |
|
485 | conf_active.conf = self | |
486 | conf_active.save() |
|
486 | conf_active.save() | |
487 | return True |
|
487 | return True | |
488 |
|
488 | |||
489 |
|
489 | |||
490 | def read_module(self, module): |
|
490 | def read_module(self, module): | |
491 |
|
491 | |||
492 | """ |
|
492 | """ | |
493 | Read out-bits (up-down) of 1 abs module NOT for Configuration |
|
493 | Read out-bits (up-down) of 1 abs module NOT for Configuration | |
494 | """ |
|
494 | """ | |
495 |
|
495 | |||
496 | ip_address = self.device.ip_address |
|
496 | ip_address = self.device.ip_address | |
497 | ip_address = ip_address.split('.') |
|
497 | ip_address = ip_address.split('.') | |
498 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
498 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) | |
499 | dot = '.' |
|
499 | dot = '.' | |
500 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
500 | module_ip = dot.join(module_seq)+'.'+str(module) | |
501 | module_port = self.device.port_address |
|
501 | module_port = self.device.port_address | |
502 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' |
|
502 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' | |
503 |
|
503 | |||
504 | module_status = json.loads(self.module_status) |
|
504 | module_status = json.loads(self.module_status) | |
505 | print(read_route) |
|
505 | print(read_route) | |
506 |
|
506 | |||
507 | module_bits = '' |
|
507 | module_bits = '' | |
508 |
|
508 | |||
509 | try: |
|
509 | try: | |
510 | r_read = requests.get(read_route, timeout=0.5) |
|
510 | r_read = requests.get(read_route, timeout=0.5) | |
511 | answer = r_read.json() |
|
511 | answer = r_read.json() | |
512 | module_bits = answer['allbits'] |
|
512 | module_bits = answer['allbits'] | |
513 | except: |
|
513 | except: | |
514 | return {} |
|
514 | return {} | |
515 |
|
515 | |||
516 | return module_bits |
|
516 | return module_bits | |
517 |
|
517 | |||
518 | def read_device(self): |
|
518 | def read_device(self): | |
519 |
|
519 | |||
520 | parms = {} |
|
520 | parms = {} | |
521 | # Reads active modules. |
|
521 | # Reads active modules. | |
522 | module_status = json.loads(self.module_status) |
|
522 | module_status = json.loads(self.module_status) | |
523 | total = 0 |
|
523 | total = 0 | |
524 | for status in module_status: |
|
524 | for status in module_status: | |
525 | if module_status[status] != 0: |
|
525 | if module_status[status] != 0: | |
526 | module_bits = self.read_module(int(status)) |
|
526 | module_bits = self.read_module(int(status)) | |
527 | bits={} |
|
527 | bits={} | |
528 | if module_bits: |
|
528 | if module_bits: | |
529 | bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) + |
|
529 | bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) + | |
530 | str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) ) |
|
530 | str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) ) | |
531 | parms[str(status)] = bits |
|
531 | parms[str(status)] = bits | |
532 |
|
532 | |||
533 | total +=1 |
|
533 | total +=1 | |
534 |
|
534 | |||
535 | if total==0: |
|
535 | if total==0: | |
536 | self.message = "No ABS Module detected. Please select 'Status'." |
|
536 | self.message = "No ABS Module detected. Please select 'Status'." | |
537 | return False |
|
537 | return False | |
538 |
|
538 | |||
539 |
|
539 | |||
540 |
|
540 | |||
541 | self.message = "ABS Modules have been read" |
|
541 | self.message = "ABS Modules have been read" | |
542 | #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10 |
|
542 | #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10 | |
543 | return parms |
|
543 | return parms | |
544 |
|
544 | |||
545 |
|
545 | |||
546 | def connected_modules(self): |
|
546 | def connected_modules(self): | |
547 | """ |
|
547 | """ | |
548 | This function returns the number of connected abs-modules without updating. |
|
548 | This function returns the number of connected abs-modules without updating. | |
549 | """ |
|
549 | """ | |
550 | num = 0 |
|
550 | num = 0 | |
551 | print(self.module_status) |
|
551 | print(self.module_status) | |
552 | for i, status in enumerate(self.module_status): |
|
552 | for i, status in enumerate(self.module_status): | |
553 | if status != '0': |
|
553 | if status != '0': | |
554 | num += 1 |
|
554 | num += 1 | |
555 | #print('status {}:{}'.format(i+1, status)) |
|
555 | #print('status {}:{}'.format(i+1, status)) | |
556 | return num |
|
556 | return num | |
557 |
|
557 | |||
558 | def send_multicast(self, message): |
|
558 | def send_multicast(self, message): | |
559 | #print("Send multicast") |
|
559 | #print("Send multicast") | |
560 | multicast_group = ('224.3.29.71', 10000) |
|
560 | multicast_group = ('224.3.29.71', 10000) | |
561 | # Create the datagram socket |
|
561 | # Create the datagram socket | |
562 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
562 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
563 | sock.settimeout(1) |
|
563 | sock.settimeout(1) | |
564 |
local_ip = os.environ.get('LOCAL_IP', '192.168. |
|
564 | local_ip = os.environ.get('LOCAL_IP', '192.168.1.128') | |
565 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) |
|
565 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) | |
566 | sock.sendto(message.encode(), multicast_group) |
|
566 | sock.sendto(message.encode(), multicast_group) | |
567 | print('Sending ' + message) |
|
567 | print('Sending ' + message) | |
568 | return sock |
|
568 | return sock | |
569 |
|
569 | |||
570 | def status_device(self): |
|
570 | def status_device(self): | |
571 | """ |
|
571 | """ | |
572 | This function returns the status of all abs-modules as one. |
|
572 | This function returns the status of all abs-modules as one. | |
573 | If at least one module is connected, its answer is "1" |
|
573 | If at least one module is connected, its answer is "1" | |
574 | """ |
|
574 | """ | |
575 | print ('Status device') |
|
575 | print ('Status device') | |
576 | print (self.active_beam) |
|
576 | print (self.active_beam) | |
577 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
577 | beams = ABSBeam.objects.filter(abs_conf=self) | |
578 | #print beams[self.active_beam-1].module_6bits(0) |
|
578 | #print beams[self.active_beam-1].module_6bits(0) | |
579 | active = ABSActive.objects.get(pk=1) |
|
579 | active = ABSActive.objects.get(pk=1) | |
580 | if active.conf != self: |
|
580 | if active.conf != self: | |
581 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() |
|
581 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() | |
582 | self.message += "\n" |
|
582 | self.message += "\n" | |
583 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' |
|
583 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' | |
584 |
|
584 | |||
585 | return False |
|
585 | return False | |
586 |
|
586 | |||
587 | sock = self.send_multicast('MNTR') |
|
587 | sock = self.send_multicast('MNTR') | |
588 |
|
588 | |||
589 | n = 0 |
|
589 | n = 0 | |
590 | status = ['0'] * 64 |
|
590 | status = ['0'] * 64 | |
591 |
|
591 | |||
592 | while True: |
|
592 | while True: | |
593 | #for i in range(32): |
|
593 | #for i in range(32): | |
594 | #if True: |
|
594 | #if True: | |
595 | try: |
|
595 | try: | |
596 | print("Recibiendo") |
|
596 | print("Recibiendo") | |
597 | address = None |
|
597 | address = None | |
598 | data, address = sock.recvfrom(2) |
|
598 | data, address = sock.recvfrom(2) | |
599 | print (address, data) |
|
599 | print (address, data) | |
600 | print("!!!!") |
|
600 | print("!!!!") | |
601 | data = data.decode() |
|
601 | data = data.decode() | |
602 | aux_mon = "1" |
|
602 | aux_mon = "1" | |
603 | aux_expected = aux_mon |
|
603 | aux_expected = aux_mon | |
604 | if(len(data)==2): |
|
604 | if(len(data)==2): | |
605 | print ("data[1]: ") |
|
605 | print ("data[1]: ") | |
606 | print (data[1]) |
|
606 | print (data[1]) | |
607 | aux_mon = fromChar2Binary(data[1]) |
|
607 | aux_mon = fromChar2Binary(data[1]) | |
608 | print (aux_mon) |
|
608 | print (aux_mon) | |
609 | aux_i = (str(address[0]).split('.'))[3] |
|
609 | aux_i = (str(address[0]).split('.'))[3] | |
610 | print (aux_i) |
|
610 | print (aux_i) | |
611 | print ('Active beam') |
|
611 | print ('Active beam') | |
612 | beam_active = ABSBeam.objects.get(pk=self.active_beam) |
|
612 | beam_active = ABSBeam.objects.get(pk=self.active_beam) | |
613 | print (beam_active) |
|
613 | print (beam_active) | |
614 | aux_expected = beam_active.module_6bits(int(aux_i)-1) |
|
614 | aux_expected = beam_active.module_6bits(int(aux_i)-1) | |
615 | print (aux_expected) |
|
615 | print (aux_expected) | |
616 |
|
616 | |||
617 | print ("data[0]: ") |
|
617 | print ("data[0]: ") | |
618 | print (data[0]) |
|
618 | print (data[0]) | |
619 |
|
619 | |||
620 | if data[0] == '1': |
|
620 | if data[0] == '1': | |
621 | status[int(address[0][10:])-1] = '3' |
|
621 | status[int(address[0][10:])-1] = '3' | |
622 | if aux_mon == aux_expected: |
|
622 | if aux_mon == aux_expected: | |
623 | print ('Es igual') |
|
623 | print ('Es igual') | |
624 | else: |
|
624 | else: | |
625 | print ('Es diferente') |
|
625 | print ('Es diferente') | |
626 | status[int(address[0][10:])-1] = '2' |
|
626 | status[int(address[0][10:])-1] = '2' | |
627 |
|
627 | |||
628 | elif data[0] == '0': |
|
628 | elif data[0] == '0': | |
629 | status[int(address[0][10:])-1] = '1' |
|
629 | status[int(address[0][10:])-1] = '1' | |
630 | n += 1 |
|
630 | n += 1 | |
631 | print('Module: {} connected'.format(address)) |
|
631 | print('Module: {} connected'.format(address)) | |
632 | except socket.timeout: |
|
632 | except socket.timeout: | |
633 | print('Timeout') |
|
633 | print('Timeout') | |
634 | break |
|
634 | break | |
635 | except: |
|
635 | except: | |
636 | print('Module: {} error'.format(address)) |
|
636 | print('Module: {} error'.format(address)) | |
637 | pass |
|
637 | pass | |
638 |
|
638 | |||
639 | sock.close() |
|
639 | sock.close() | |
640 |
|
640 | |||
641 | if n > 0: |
|
641 | if n > 0: | |
642 | self.message = 'ABS modules Status have been updated.' |
|
642 | self.message = 'ABS modules Status have been updated.' | |
643 | self.device.status = 1 |
|
643 | self.device.status = 1 | |
644 | else: |
|
644 | else: | |
645 | self.device.status = 0 |
|
645 | self.device.status = 0 | |
646 | self.message = 'No ABS module is connected.' |
|
646 | self.message = 'No ABS module is connected.' | |
647 | self.module_status = ''.join(status) |
|
647 | self.module_status = ''.join(status) | |
648 | self.save() |
|
648 | self.save() | |
649 |
|
649 | |||
650 | return self.device.status |
|
650 | return self.device.status | |
651 |
|
651 | |||
652 |
|
652 | |||
653 | def send_beam(self, beam_pos): |
|
653 | def send_beam(self, beam_pos): | |
654 | """ |
|
654 | """ | |
655 | This function connects to a multicast group and sends the beam number |
|
655 | This function connects to a multicast group and sends the beam number | |
656 | to all abs modules. |
|
656 | to all abs modules. | |
657 | """ |
|
657 | """ | |
658 | print ('Send beam') |
|
658 | print ('Send beam') | |
659 | print (self.active_beam) |
|
659 | print (self.active_beam) | |
660 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
660 | beams = ABSBeam.objects.filter(abs_conf=self) | |
661 | #print beams[self.active_beam-1].module_6bits(0) |
|
661 | #print beams[self.active_beam-1].module_6bits(0) | |
662 | active = ABSActive.objects.get(pk=1) |
|
662 | active = ABSActive.objects.get(pk=1) | |
663 | if active.conf != self: |
|
663 | if active.conf != self: | |
664 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() |
|
664 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() | |
665 | self.message += "\n" |
|
665 | self.message += "\n" | |
666 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' |
|
666 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' | |
667 |
|
667 | |||
668 | return False |
|
668 | return False | |
669 |
|
669 | |||
670 | # Se manda a cero RC para poder realizar cambio de beam |
|
670 | # Se manda a cero RC para poder realizar cambio de beam | |
671 | if self.experiment is None: |
|
671 | if self.experiment is None: | |
672 | confs = [] |
|
672 | confs = [] | |
673 | else: |
|
673 | else: | |
674 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
674 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) | |
675 | confdds = '' |
|
675 | confdds = '' | |
676 | confjars = '' |
|
676 | confjars = '' | |
677 | confrc = '' |
|
677 | confrc = '' | |
678 | #TO STOP DEVICES: DDS-JARS-RC |
|
678 | #TO STOP DEVICES: DDS-JARS-RC | |
679 | for i in range(0,len(confs)): |
|
679 | for i in range(0,len(confs)): | |
680 | if i==0: |
|
680 | if i==0: | |
681 | for conf in confs: |
|
681 | for conf in confs: | |
682 | if conf.device.device_type.name == 'dds': |
|
682 | if conf.device.device_type.name == 'dds': | |
683 | confdds = conf |
|
683 | confdds = conf | |
684 | confdds.stop_device() |
|
684 | confdds.stop_device() | |
685 | break |
|
685 | break | |
686 | if i==1: |
|
686 | if i==1: | |
687 | for conf in confs: |
|
687 | for conf in confs: | |
688 | if conf.device.device_type.name == 'jars': |
|
688 | if conf.device.device_type.name == 'jars': | |
689 | confjars = conf |
|
689 | confjars = conf | |
690 | confjars.stop_device() |
|
690 | confjars.stop_device() | |
691 | break |
|
691 | break | |
692 | if i==2: |
|
692 | if i==2: | |
693 | for conf in confs: |
|
693 | for conf in confs: | |
694 | if conf.device.device_type.name == 'rc': |
|
694 | if conf.device.device_type.name == 'rc': | |
695 | confrc = conf |
|
695 | confrc = conf | |
696 | confrc.stop_device() |
|
696 | confrc.stop_device() | |
697 | break |
|
697 | break | |
698 | if beam_pos > 0: |
|
698 | if beam_pos > 0: | |
699 | beam_pos = beam_pos - 1 |
|
699 | beam_pos = beam_pos - 1 | |
700 | else: |
|
700 | else: | |
701 | beam_pos = 0 |
|
701 | beam_pos = 0 | |
702 |
|
702 | |||
703 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
703 | #El indice del apunte debe ser menor que el numero total de apuntes | |
704 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
704 | #El servidor tcp en el embebido comienza a contar desde 0 | |
705 | status = ['0'] * 64 |
|
705 | status = ['0'] * 64 | |
706 | message = 'CHGB{}'.format(beam_pos) |
|
706 | message = 'CHGB{}'.format(beam_pos) | |
707 | sock = self.send_multicast(message) |
|
707 | sock = self.send_multicast(message) | |
708 | while True: |
|
708 | while True: | |
709 | #for i in range(32): |
|
709 | #for i in range(32): | |
710 | try: |
|
710 | try: | |
711 | data, address = sock.recvfrom(1024) |
|
711 | data, address = sock.recvfrom(1024) | |
712 | print (address, data) |
|
712 | print (address, data) | |
713 | data = data.decode() |
|
713 | data = data.decode() | |
714 | if data == '1': |
|
714 | if data == '1': | |
715 | status[int(address[0][10:])-1] = '3' |
|
715 | status[int(address[0][10:])-1] = '3' | |
716 | elif data == '0': |
|
716 | elif data == '0': | |
717 | status[int(address[0][10:])-1] = '1' |
|
717 | status[int(address[0][10:])-1] = '1' | |
718 | except socket.timeout: |
|
718 | except socket.timeout: | |
719 | print('Timeout') |
|
719 | print('Timeout') | |
720 | break |
|
720 | break | |
721 | except Exception as e: |
|
721 | except Exception as e: | |
722 | print ('Error {}'.format(e)) |
|
722 | print ('Error {}'.format(e)) | |
723 | pass |
|
723 | pass | |
724 |
|
724 | |||
725 | sock.close() |
|
725 | sock.close() | |
726 |
|
726 | |||
727 | #Start DDS-RC-JARS |
|
727 | #Start DDS-RC-JARS | |
728 | if confdds: |
|
728 | if confdds: | |
729 | confdds.start_device() |
|
729 | confdds.start_device() | |
730 | if confrc: |
|
730 | if confrc: | |
731 | #print confrc |
|
731 | #print confrc | |
732 | confrc.start_device() |
|
732 | confrc.start_device() | |
733 | if confjars: |
|
733 | if confjars: | |
734 | confjars.start_device() |
|
734 | confjars.start_device() | |
735 |
|
735 | |||
736 | self.message = "ABS Beam has been changed" |
|
736 | self.message = "ABS Beam has been changed" | |
737 | self.module_status = ''.join(status) |
|
737 | self.module_status = ''.join(status) | |
738 | self.save() |
|
738 | self.save() | |
739 | return True |
|
739 | return True | |
740 |
|
740 | |||
741 |
|
741 | |||
742 | def get_absolute_url_import(self): |
|
742 | def get_absolute_url_import(self): | |
743 | return reverse('url_import_abs_conf', args=[str(self.id)]) |
|
743 | return reverse('url_import_abs_conf', args=[str(self.id)]) | |
744 |
|
744 | |||
745 | class ABSActive(models.Model): |
|
745 | class ABSActive(models.Model): | |
746 | conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration', on_delete=models.CASCADE) |
|
746 | conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration', on_delete=models.CASCADE) | |
747 |
|
747 | |||
748 | class Meta: |
|
748 | class Meta: | |
749 | db_table = 'abs_absactive' |
|
749 | db_table = 'abs_absactive' | |
750 |
|
750 | |||
751 | class ABSBeam(models.Model): |
|
751 | class ABSBeam(models.Model): | |
752 |
|
752 | |||
753 | name = models.CharField(max_length=60, default='Beam') |
|
753 | name = models.CharField(max_length=60, default='Beam') | |
754 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) |
|
754 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) | |
755 | abs_conf = models.ForeignKey('ABSConfiguration', null=True, |
|
755 | abs_conf = models.ForeignKey('ABSConfiguration', null=True, | |
756 | verbose_name='ABS Configuration', on_delete=models.CASCADE) |
|
756 | verbose_name='ABS Configuration', on_delete=models.CASCADE) | |
757 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) |
|
757 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) | |
758 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) |
|
758 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) | |
759 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') |
|
759 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') | |
760 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') |
|
760 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') | |
761 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) |
|
761 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) | |
762 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) |
|
762 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) | |
763 |
|
763 | |||
764 | class Meta: |
|
764 | class Meta: | |
765 | db_table = 'abs_beams' |
|
765 | db_table = 'abs_beams' | |
766 |
|
766 | |||
767 | def __unicode__(self): |
|
767 | def __unicode__(self): | |
768 | return u'%s' % (self.name) |
|
768 | return u'%s' % (self.name) | |
769 |
|
769 | |||
770 | def parms_to_dict(self): |
|
770 | def parms_to_dict(self): | |
771 |
|
771 | |||
772 | parameters = {} |
|
772 | parameters = {} | |
773 | parameters['name'] = self.name |
|
773 | parameters['name'] = self.name | |
774 | parameters['antenna'] = ast.literal_eval(self.antenna) |
|
774 | parameters['antenna'] = ast.literal_eval(self.antenna) | |
775 | parameters['abs_conf'] = self.abs_conf.name |
|
775 | parameters['abs_conf'] = self.abs_conf.name | |
776 | parameters['tx'] = ast.literal_eval(self.tx) |
|
776 | parameters['tx'] = ast.literal_eval(self.tx) | |
777 | parameters['rx'] = ast.literal_eval(self.rx) |
|
777 | parameters['rx'] = ast.literal_eval(self.rx) | |
778 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") |
|
778 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") | |
779 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") |
|
779 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") | |
780 | parameters['ues'] = ast.literal_eval(self.ues) |
|
780 | parameters['ues'] = ast.literal_eval(self.ues) | |
781 | parameters['only_rx'] = json.loads(self.only_rx) |
|
781 | parameters['only_rx'] = json.loads(self.only_rx) | |
782 |
|
782 | |||
783 | return parameters |
|
783 | return parameters | |
784 |
|
784 | |||
785 | def dict_to_parms(self, parameters): |
|
785 | def dict_to_parms(self, parameters): | |
786 |
|
786 | |||
787 | self.name = parameters['name'] |
|
787 | self.name = parameters['name'] | |
788 | self.antenna = json.dumps(parameters['antenna']) |
|
788 | self.antenna = json.dumps(parameters['antenna']) | |
789 | #self.abs_conf = parameters['abs_conf'] |
|
789 | #self.abs_conf = parameters['abs_conf'] | |
790 | self.tx = json.dumps(parameters['tx']) |
|
790 | self.tx = json.dumps(parameters['tx']) | |
791 | self.rx = json.dumps(parameters['rx']) |
|
791 | self.rx = json.dumps(parameters['rx']) | |
792 | #self.s_time = parameters['s_time'] |
|
792 | #self.s_time = parameters['s_time'] | |
793 | #self.e_time = parameters['e_time'] |
|
793 | #self.e_time = parameters['e_time'] | |
794 | self.ues = json.dumps(parameters['ues']) |
|
794 | self.ues = json.dumps(parameters['ues']) | |
795 | self.only_rx = json.dumps(parameters['only_rx']) |
|
795 | self.only_rx = json.dumps(parameters['only_rx']) | |
796 | self.save() |
|
796 | self.save() | |
797 |
|
797 | |||
798 |
|
798 | |||
799 | def clone(self, **kwargs): |
|
799 | def clone(self, **kwargs): | |
800 |
|
800 | |||
801 | self.pk = None |
|
801 | self.pk = None | |
802 | self.id = None |
|
802 | self.id = None | |
803 | for attr, value in kwargs.items(): |
|
803 | for attr, value in kwargs.items(): | |
804 | setattr(self, attr, value) |
|
804 | setattr(self, attr, value) | |
805 |
|
805 | |||
806 | self.save() |
|
806 | self.save() | |
807 |
|
807 | |||
808 | return self |
|
808 | return self | |
809 |
|
809 | |||
810 |
|
810 | |||
811 | def module_6bits(self, module): |
|
811 | def module_6bits(self, module): | |
812 | """ |
|
812 | """ | |
813 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
813 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module | |
814 | """ |
|
814 | """ | |
815 | module += 1 |
|
815 | module += 1 | |
816 | if module > 64: |
|
816 | if module > 64: | |
817 | beam_bits = "" |
|
817 | beam_bits = "" | |
818 | return beam_bits |
|
818 | return beam_bits | |
819 |
|
819 | |||
820 | data = ast.literal_eval(self.antenna) |
|
820 | data = ast.literal_eval(self.antenna) | |
821 | up_data = data['antenna_up'] |
|
821 | up_data = data['antenna_up'] | |
822 | down_data = data['antenna_down'] |
|
822 | down_data = data['antenna_down'] | |
823 |
|
823 | |||
824 | pos = ip2position(module) |
|
824 | pos = ip2position(module) | |
825 | up_value = up_data[pos[0]][pos[1]] |
|
825 | up_value = up_data[pos[0]][pos[1]] | |
826 | down_value = down_data[pos[0]][pos[1]] |
|
826 | down_value = down_data[pos[0]][pos[1]] | |
827 |
|
827 | |||
828 | up_bits = up_conv_bits(up_value) |
|
828 | up_bits = up_conv_bits(up_value) | |
829 | down_bits = down_conv_bits(down_value) |
|
829 | down_bits = down_conv_bits(down_value) | |
830 | beam_bits = up_bits+down_bits |
|
830 | beam_bits = up_bits+down_bits | |
831 |
|
831 | |||
832 | return beam_bits |
|
832 | return beam_bits | |
833 |
|
833 | |||
834 |
|
834 | |||
835 | @property |
|
835 | @property | |
836 | def get_upvalues(self): |
|
836 | def get_upvalues(self): | |
837 | """ |
|
837 | """ | |
838 | This function reads antenna pattern and show the up-value of one abs module |
|
838 | This function reads antenna pattern and show the up-value of one abs module | |
839 | """ |
|
839 | """ | |
840 |
|
840 | |||
841 | data = ast.literal_eval(self.antenna) |
|
841 | data = ast.literal_eval(self.antenna) | |
842 | up_data = data['antenna_up'] |
|
842 | up_data = data['antenna_up'] | |
843 |
|
843 | |||
844 | up_values = [] |
|
844 | up_values = [] | |
845 | for data in up_data: |
|
845 | for data in up_data: | |
846 | for i in range(0,8): |
|
846 | for i in range(0,8): | |
847 | up_values.append(data[i]) |
|
847 | up_values.append(data[i]) | |
848 |
|
848 | |||
849 | return up_values |
|
849 | return up_values | |
850 |
|
850 | |||
851 | @property |
|
851 | @property | |
852 | def antenna_upvalues(self): |
|
852 | def antenna_upvalues(self): | |
853 | """ |
|
853 | """ | |
854 | This function reads antenna pattern and show the up - values of one abs beam |
|
854 | This function reads antenna pattern and show the up - values of one abs beam | |
855 | in a particular order |
|
855 | in a particular order | |
856 | """ |
|
856 | """ | |
857 | data = ast.literal_eval(self.antenna) |
|
857 | data = ast.literal_eval(self.antenna) | |
858 | up_data = data['antenna_up'] |
|
858 | up_data = data['antenna_up'] | |
859 |
|
859 | |||
860 | return up_data |
|
860 | return up_data | |
861 |
|
861 | |||
862 | @property |
|
862 | @property | |
863 | def antenna_downvalues(self): |
|
863 | def antenna_downvalues(self): | |
864 | """ |
|
864 | """ | |
865 | This function reads antenna pattern and show the down - values of one abs beam |
|
865 | This function reads antenna pattern and show the down - values of one abs beam | |
866 | in a particular order |
|
866 | in a particular order | |
867 | """ |
|
867 | """ | |
868 | data = ast.literal_eval(self.antenna) |
|
868 | data = ast.literal_eval(self.antenna) | |
869 | down_data = data['antenna_down'] |
|
869 | down_data = data['antenna_down'] | |
870 |
|
870 | |||
871 | return down_data |
|
871 | return down_data | |
872 |
|
872 | |||
873 | @property |
|
873 | @property | |
874 | def get_downvalues(self): |
|
874 | def get_downvalues(self): | |
875 | """ |
|
875 | """ | |
876 | This function reads antenna pattern and show the down-value of one abs module |
|
876 | This function reads antenna pattern and show the down-value of one abs module | |
877 | """ |
|
877 | """ | |
878 |
|
878 | |||
879 | data = ast.literal_eval(self.antenna) |
|
879 | data = ast.literal_eval(self.antenna) | |
880 | down_data = data['antenna_down'] |
|
880 | down_data = data['antenna_down'] | |
881 |
|
881 | |||
882 | down_values = [] |
|
882 | down_values = [] | |
883 | for data in down_data: |
|
883 | for data in down_data: | |
884 | for i in range(0,8): |
|
884 | for i in range(0,8): | |
885 | down_values.append(data[i]) |
|
885 | down_values.append(data[i]) | |
886 |
|
886 | |||
887 | return down_values |
|
887 | return down_values | |
888 |
|
888 | |||
889 | @property |
|
889 | @property | |
890 | def get_up_ues(self): |
|
890 | def get_up_ues(self): | |
891 | """ |
|
891 | """ | |
892 | This function shows the up-ues-value of one beam |
|
892 | This function shows the up-ues-value of one beam | |
893 | """ |
|
893 | """ | |
894 | data = ast.literal_eval(self.ues) |
|
894 | data = ast.literal_eval(self.ues) | |
895 | up_ues = data['up'] |
|
895 | up_ues = data['up'] | |
896 |
|
896 | |||
897 | return up_ues |
|
897 | return up_ues | |
898 |
|
898 | |||
899 | @property |
|
899 | @property | |
900 | def get_down_ues(self): |
|
900 | def get_down_ues(self): | |
901 | """ |
|
901 | """ | |
902 | This function shows the down-ues-value of one beam |
|
902 | This function shows the down-ues-value of one beam | |
903 | """ |
|
903 | """ | |
904 | data = ast.literal_eval(self.ues) |
|
904 | data = ast.literal_eval(self.ues) | |
905 | down_ues = data['down'] |
|
905 | down_ues = data['down'] | |
906 |
|
906 | |||
907 | return down_ues |
|
907 | return down_ues | |
908 |
|
908 | |||
909 | @property |
|
909 | @property | |
910 | def get_up_onlyrx(self): |
|
910 | def get_up_onlyrx(self): | |
911 | """ |
|
911 | """ | |
912 | This function shows the up-onlyrx-value of one beam |
|
912 | This function shows the up-onlyrx-value of one beam | |
913 | """ |
|
913 | """ | |
914 | data = json.loads(self.only_rx) |
|
914 | data = json.loads(self.only_rx) | |
915 | up_onlyrx = data['up'] |
|
915 | up_onlyrx = data['up'] | |
916 |
|
916 | |||
917 | return up_onlyrx |
|
917 | return up_onlyrx | |
918 |
|
918 | |||
919 | @property |
|
919 | @property | |
920 | def get_down_onlyrx(self): |
|
920 | def get_down_onlyrx(self): | |
921 | """ |
|
921 | """ | |
922 | This function shows the down-onlyrx-value of one beam |
|
922 | This function shows the down-onlyrx-value of one beam | |
923 | """ |
|
923 | """ | |
924 | data = json.loads(self.only_rx) |
|
924 | data = json.loads(self.only_rx) | |
925 | down_onlyrx = data['down'] |
|
925 | down_onlyrx = data['down'] | |
926 |
|
926 | |||
927 | return down_onlyrx |
|
927 | return down_onlyrx | |
928 |
|
928 | |||
929 | @property |
|
929 | @property | |
930 | def get_tx(self): |
|
930 | def get_tx(self): | |
931 | """ |
|
931 | """ | |
932 | This function shows the tx-values of one beam |
|
932 | This function shows the tx-values of one beam | |
933 | """ |
|
933 | """ | |
934 | data = json.loads(self.tx) |
|
934 | data = json.loads(self.tx) | |
935 |
|
935 | |||
936 | return data |
|
936 | return data | |
937 |
|
937 | |||
938 | @property |
|
938 | @property | |
939 | def get_uptx(self): |
|
939 | def get_uptx(self): | |
940 | """ |
|
940 | """ | |
941 | This function shows the up-tx-values of one beam |
|
941 | This function shows the up-tx-values of one beam | |
942 | """ |
|
942 | """ | |
943 | data = json.loads(self.tx) |
|
943 | data = json.loads(self.tx) | |
944 | up_data = data['up'] |
|
944 | up_data = data['up'] | |
945 |
|
945 | |||
946 | up_values = [] |
|
946 | up_values = [] | |
947 | for data in up_data: |
|
947 | for data in up_data: | |
948 | for i in range(0,8): |
|
948 | for i in range(0,8): | |
949 | up_values.append(data[i]) |
|
949 | up_values.append(data[i]) | |
950 |
|
950 | |||
951 | return up_values |
|
951 | return up_values | |
952 |
|
952 | |||
953 | @property |
|
953 | @property | |
954 | def get_downtx(self): |
|
954 | def get_downtx(self): | |
955 | """ |
|
955 | """ | |
956 | This function shows the down-tx-values of one beam |
|
956 | This function shows the down-tx-values of one beam | |
957 | """ |
|
957 | """ | |
958 | data = json.loads(self.tx) |
|
958 | data = json.loads(self.tx) | |
959 | down_data = data['down'] |
|
959 | down_data = data['down'] | |
960 |
|
960 | |||
961 | down_values = [] |
|
961 | down_values = [] | |
962 | for data in down_data: |
|
962 | for data in down_data: | |
963 | for i in range(0,8): |
|
963 | for i in range(0,8): | |
964 | down_values.append(data[i]) |
|
964 | down_values.append(data[i]) | |
965 |
|
965 | |||
966 | return down_values |
|
966 | return down_values | |
967 |
|
967 | |||
968 |
|
968 | |||
969 |
|
969 | |||
970 | @property |
|
970 | @property | |
971 | def get_rx(self): |
|
971 | def get_rx(self): | |
972 | """ |
|
972 | """ | |
973 | This function shows the rx-values of one beam |
|
973 | This function shows the rx-values of one beam | |
974 | """ |
|
974 | """ | |
975 | data = json.loads(self.rx) |
|
975 | data = json.loads(self.rx) | |
976 |
|
976 | |||
977 | return data |
|
977 | return data | |
978 |
|
978 | |||
979 | @property |
|
979 | @property | |
980 | def get_uprx(self): |
|
980 | def get_uprx(self): | |
981 | """ |
|
981 | """ | |
982 | This function shows the up-rx-values of one beam |
|
982 | This function shows the up-rx-values of one beam | |
983 | """ |
|
983 | """ | |
984 | data = json.loads(self.rx) |
|
984 | data = json.loads(self.rx) | |
985 | up_data = data['up'] |
|
985 | up_data = data['up'] | |
986 |
|
986 | |||
987 | up_values = [] |
|
987 | up_values = [] | |
988 | for data in up_data: |
|
988 | for data in up_data: | |
989 | for i in range(0,8): |
|
989 | for i in range(0,8): | |
990 | up_values.append(data[i]) |
|
990 | up_values.append(data[i]) | |
991 |
|
991 | |||
992 | return up_values |
|
992 | return up_values | |
993 |
|
993 | |||
994 | @property |
|
994 | @property | |
995 | def get_downrx(self): |
|
995 | def get_downrx(self): | |
996 | """ |
|
996 | """ | |
997 | This function shows the down-rx-values of one beam |
|
997 | This function shows the down-rx-values of one beam | |
998 | """ |
|
998 | """ | |
999 | data = json.loads(self.rx) |
|
999 | data = json.loads(self.rx) | |
1000 | down_data = data['down'] |
|
1000 | down_data = data['down'] | |
1001 |
|
1001 | |||
1002 | down_values = [] |
|
1002 | down_values = [] | |
1003 | for data in down_data: |
|
1003 | for data in down_data: | |
1004 | for i in range(0,8): |
|
1004 | for i in range(0,8): | |
1005 | down_values.append(data[i]) |
|
1005 | down_values.append(data[i]) | |
1006 |
|
1006 | |||
1007 | return down_values |
|
1007 | return down_values |
@@ -1,18 +1,18 | |||||
1 | from django.urls import path |
|
1 | from django.urls import path | |
2 |
|
2 | |||
3 | from apps.abs import views |
|
3 | from apps.abs import views | |
4 |
|
4 | |||
5 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
6 | path('<int:id_conf>/', views.abs_conf, name='url_abs_conf'), |
|
6 | path('<int:id_conf>/', views.abs_conf, name='url_abs_conf'), | |
7 | path('<int:id_conf>/edit/', views.abs_conf_edit, name='url_edit_abs_conf'), |
|
7 | path('<int:id_conf>/edit/', views.abs_conf_edit, name='url_edit_abs_conf'), | |
8 | path('alert/', views.abs_conf_alert, name='url_alert_abs_conf'), |
|
8 | path('alert/', views.abs_conf_alert, name='url_alert_abs_conf'), | |
9 | path('<int:id_conf>/import/', views.import_file, name='url_import_abs_conf'), |
|
9 | path('<int:id_conf>/import/', views.import_file, name='url_import_abs_conf'), | |
10 | #url(r'^(?P<id_conf>-?\d+)/status/', views.abs_conf, {'status_request':True},name='url_status_abs_conf'), |
|
10 | #url(r'^(?P<id_conf>-?\d+)/status/', views.abs_conf, {'status_request':True},name='url_status_abs_conf'), | |
11 | path('<int:id_conf>/change_beam/<int:id_beam>/', views.send_beam, name='url_send_beam'), |
|
11 | path('<int:id_conf>/change_beam/<int:id_beam>/', views.send_beam, name='url_send_beam'), | |
12 | path('<int:id_conf>/plot/', views.plot_patterns, name='url_plot_abs_patterns'), |
|
12 | path('<int:id_conf>/plot/', views.plot_patterns, name='url_plot_abs_patterns'), | |
13 | path('<int:id_conf>/plot/<int:id_beam>/', views.plot_patterns, name='url_plot_abs_patterns'), |
|
13 | path('<int:id_conf>/plot/<int:id_beam>/', views.plot_patterns, name='url_plot_abs_patterns'), | |
14 |
path('<int:id_conf>/plot/<int:id_beam>/< |
|
14 | path('<int:id_conf>/plot/<int:id_beam>/<slug:antenna>/pattern.png', views.plot_pattern, name='url_plot_beam'), | |
15 | path('<int:id_conf>/add_beam/', views.add_beam, name='url_add_abs_beam'), |
|
15 | path('<int:id_conf>/add_beam/', views.add_beam, name='url_add_abs_beam'), | |
16 | path('<int:id_conf>/beam/<int:id_beam>/delete/', views.remove_beam, name='url_remove_abs_beam'), |
|
16 | path('<int:id_conf>/beam/<int:id_beam>/delete/', views.remove_beam, name='url_remove_abs_beam'), | |
17 | path('<int:id_conf>/beam/<int:id_beam>/edit/', views.edit_beam, name='url_edit_abs_beam'), |
|
17 | path('<int:id_conf>/beam/<int:id_beam>/edit/', views.edit_beam, name='url_edit_abs_beam'), | |
18 | ) |
|
18 | ) |
@@ -1,1775 +1,1775 | |||||
1 | #!/usr/bin/python |
|
1 | #!/usr/bin/python | |
2 | import sys, os, os.path |
|
2 | import sys, os, os.path | |
3 | import traceback |
|
3 | import traceback | |
4 | import cgi |
|
4 | import cgi | |
5 | from http import cookies |
|
5 | from http import cookies | |
6 |
|
6 | |||
7 | import time, datetime |
|
7 | import time, datetime | |
8 | import types |
|
8 | import types | |
9 | import numpy |
|
9 | import numpy | |
10 | import numpy.fft |
|
10 | import numpy.fft | |
11 | import scipy.linalg |
|
11 | import scipy.linalg | |
12 | import scipy.special |
|
12 | import scipy.special | |
13 | from io import StringIO |
|
13 | from io import StringIO | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | #import Misc_Routines |
|
16 | #import Misc_Routines | |
17 | from .Misc_Routines import CoFactors |
|
17 | from .Misc_Routines import CoFactors | |
18 | #import TimeTools |
|
18 | #import TimeTools | |
19 | from .TimeTools import Time , Julian ,Doy2Date |
|
19 | from .TimeTools import Time , Julian ,Doy2Date | |
20 | #import JroAntSetup |
|
20 | #import JroAntSetup | |
21 | from .JroAntSetup import ReturnSetup |
|
21 | from .JroAntSetup import ReturnSetup | |
22 | #import Graphics_OverJro |
|
22 | #import Graphics_OverJro | |
23 | from .Graphics_OverJro import AntPatternPlot ,BFieldPlot,CelestialObjectsPlot,PatternCutPlot,SkyNoisePlot |
|
23 | from .Graphics_OverJro import AntPatternPlot ,BFieldPlot,CelestialObjectsPlot,PatternCutPlot,SkyNoisePlot | |
24 | #import Astro_Coords |
|
24 | #import Astro_Coords | |
25 | from .Astro_Coords import Geodetic ,AltAz ,CelestialBodies |
|
25 | from .Astro_Coords import Geodetic ,AltAz ,CelestialBodies | |
26 |
|
26 | |||
27 | class JroPattern(): |
|
27 | class JroPattern(): | |
28 | def __init__(self,pattern=0,path=None,filename=None,nptsx=101,nptsy=101,maxphi=5,fftopt=0, \ |
|
28 | def __init__(self,pattern=0,path=None,filename=None,nptsx=101,nptsy=101,maxphi=5,fftopt=0, \ | |
29 | getcut=0,dcosx=None,dcosy=None,eomwl=6,airwl=4, **kwargs): |
|
29 | getcut=0,dcosx=None,dcosy=None,eomwl=6,airwl=4, **kwargs): | |
30 | """ |
|
30 | """ | |
31 | JroPattern class creates an object to represent the useful parameters for beam mode- |
|
31 | JroPattern class creates an object to represent the useful parameters for beam mode- | |
32 | lling of the Jicamarca VHF radar. |
|
32 | lling of the Jicamarca VHF radar. | |
33 |
|
33 | |||
34 | Parameters |
|
34 | Parameters | |
35 | ---------- |
|
35 | ---------- | |
36 | pattern = An integer (See JroAntSetup to know the available values) to load a prede- |
|
36 | pattern = An integer (See JroAntSetup to know the available values) to load a prede- | |
37 | fined configuration. The default value is 0. To use a user-defined configuration |
|
37 | fined configuration. The default value is 0. To use a user-defined configuration | |
38 | pattern must be None. |
|
38 | pattern must be None. | |
39 | path = A string giving the directory that contains the user-configuration file. PATH |
|
39 | path = A string giving the directory that contains the user-configuration file. PATH | |
40 | will work if pattern is None. |
|
40 | will work if pattern is None. | |
41 | filename = A string giving the name of the user-configuration file. FILENAME will |
|
41 | filename = A string giving the name of the user-configuration file. FILENAME will | |
42 | work if pattern is None. |
|
42 | work if pattern is None. | |
43 | nptsx = A scalar to specify the number of points used to define the angular resolu- |
|
43 | nptsx = A scalar to specify the number of points used to define the angular resolu- | |
44 | tion in the "x" axis. The default value is 101. |
|
44 | tion in the "x" axis. The default value is 101. | |
45 | nptsy = A scalar to specify the number of points used to define the angular resolu- |
|
45 | nptsy = A scalar to specify the number of points used to define the angular resolu- | |
46 | tion in the "x" axis. The default value is 101. |
|
46 | tion in the "x" axis. The default value is 101. | |
47 | maxphi = A scalar giving the maximum (absolute) angle (in degree) to model the ante- |
|
47 | maxphi = A scalar giving the maximum (absolute) angle (in degree) to model the ante- | |
48 | nna pattern. The default value is 5 degrees. |
|
48 | nna pattern. The default value is 5 degrees. | |
49 | fftopt = Set this input to 1 to model the beam using FFT. To model using antenna |
|
49 | fftopt = Set this input to 1 to model the beam using FFT. To model using antenna | |
50 | theory set to 0 (default value). |
|
50 | theory set to 0 (default value). | |
51 | getcut = Set to 1 to show an antenna cut instead of a contour plot of itself (set to |
|
51 | getcut = Set to 1 to show an antenna cut instead of a contour plot of itself (set to | |
52 | 0). The defautl value is 0. |
|
52 | 0). The defautl value is 0. | |
53 | dcosx = An array giving the directional cosines for the x-axis. DCOSX will work if |
|
53 | dcosx = An array giving the directional cosines for the x-axis. DCOSX will work if | |
54 | getcut is actived. |
|
54 | getcut is actived. | |
55 | dcosy = An array giving the directional cosines for the y-axis. DCOSY will work if |
|
55 | dcosy = An array giving the directional cosines for the y-axis. DCOSY will work if | |
56 | getcut is actived. |
|
56 | getcut is actived. | |
57 | eomwl = A scalar giving the radar wavelength. The default value is 6m (50 MHZ). |
|
57 | eomwl = A scalar giving the radar wavelength. The default value is 6m (50 MHZ). | |
58 | airwl = Set this input to float (or intger) to specify the wavelength (in meters) of |
|
58 | airwl = Set this input to float (or intger) to specify the wavelength (in meters) of | |
59 | the transmitted EOM wave in the air. The default value is 4m. |
|
59 | the transmitted EOM wave in the air. The default value is 4m. | |
60 |
|
60 | |||
61 | Modification History |
|
61 | Modification History | |
62 | -------------------- |
|
62 | -------------------- | |
63 | Converted to Object-oriented Programming by Freddy Galindo, ROJ, 20 September 2009. |
|
63 | Converted to Object-oriented Programming by Freddy Galindo, ROJ, 20 September 2009. | |
64 | """ |
|
64 | """ | |
65 |
|
65 | |||
66 |
|
66 | |||
67 |
|
67 | |||
68 | # Getting antenna configuration. |
|
68 | # Getting antenna configuration. | |
69 | if filename: |
|
69 | if filename: | |
70 | setup = ReturnSetup(path=path,filename=filename,pattern=pattern) |
|
70 | setup = ReturnSetup(path=path,filename=filename,pattern=pattern) | |
71 |
|
71 | |||
72 | ues = setup["ues"] |
|
72 | ues = setup["ues"] | |
73 | phase = setup["phase"] |
|
73 | phase = setup["phase"] | |
74 | gaintx = setup["gaintx"] |
|
74 | gaintx = setup["gaintx"] | |
75 | gainrx = setup["gainrx"] |
|
75 | gainrx = setup["gainrx"] | |
76 | justrx = setup["justrx"] |
|
76 | justrx = setup["justrx"] | |
77 | self.title = setup["title"] |
|
77 | self.title = setup["title"] | |
78 | else: |
|
78 | else: | |
79 | ues = kwargs["ues"] |
|
79 | ues = kwargs["ues"] | |
80 | phase = kwargs["phases"] |
|
80 | phase = kwargs["phases"] | |
81 | gaintx = kwargs["gain_tx"] |
|
81 | gaintx = kwargs["gain_tx"] | |
82 | gainrx = kwargs["gain_rx"] |
|
82 | gainrx = kwargs["gain_rx"] | |
83 | justrx = kwargs["just_rx"] |
|
83 | justrx = kwargs["just_rx"] | |
84 | self.title = kwargs.get("title", "JRO Pattern") |
|
84 | self.title = kwargs.get("title", "JRO Pattern") | |
85 |
|
85 | |||
86 | # Defining attributes for JroPattern class. |
|
86 | # Defining attributes for JroPattern class. | |
87 | # Antenna configuration |
|
87 | # Antenna configuration | |
88 |
|
88 | |||
89 | self.uestx = ues |
|
89 | self.uestx = ues | |
90 | self.phasetx = phase |
|
90 | self.phasetx = phase | |
91 | self.gaintx = gaintx |
|
91 | self.gaintx = gaintx | |
92 | self.uesrx = ues |
|
92 | self.uesrx = ues | |
93 | self.phaserx = phase |
|
93 | self.phaserx = phase | |
94 | self.gainrx = gainrx |
|
94 | self.gainrx = gainrx | |
95 | self.justrx = justrx |
|
95 | self.justrx = justrx | |
96 |
|
96 | |||
97 | # Pattern resolution & method to model |
|
97 | # Pattern resolution & method to model | |
98 | self.maxphi = maxphi |
|
98 | self.maxphi = maxphi | |
99 | self.nptsx = nptsx |
|
99 | self.nptsx = nptsx | |
100 | self.nptsy = nptsy |
|
100 | self.nptsy = nptsy | |
101 | self.fftopt = fftopt |
|
101 | self.fftopt = fftopt | |
102 |
|
102 | |||
103 | # To get a cut of the pattern. |
|
103 | # To get a cut of the pattern. | |
104 | self.getcut = getcut |
|
104 | self.getcut = getcut | |
105 |
|
105 | |||
106 | maxdcos = numpy.sin(maxphi*CoFactors.d2r) |
|
106 | maxdcos = numpy.sin(maxphi*CoFactors.d2r) | |
107 | if dcosx==None:dcosx = ((numpy.arange(nptsx,dtype=float)/(nptsx-1))-0.5)*2*maxdcos |
|
107 | if dcosx==None:dcosx = ((numpy.arange(nptsx,dtype=float)/(nptsx-1))-0.5)*2*maxdcos | |
108 | if dcosy==None:dcosy = ((numpy.arange(nptsy,dtype=float)/(nptsy-1))-0.5)*2*maxdcos |
|
108 | if dcosy==None:dcosy = ((numpy.arange(nptsy,dtype=float)/(nptsy-1))-0.5)*2*maxdcos | |
109 | self.dcosx = dcosx |
|
109 | self.dcosx = dcosx | |
110 | self.dcosy = dcosy |
|
110 | self.dcosy = dcosy | |
111 | self.nx = dcosx.size |
|
111 | self.nx = dcosx.size | |
112 | self.ny = dcosy.size*(getcut==0) + (getcut==1) |
|
112 | self.ny = dcosy.size*(getcut==0) + (getcut==1) | |
113 |
|
113 | |||
114 | self.eomwl = eomwl |
|
114 | self.eomwl = eomwl | |
115 | self.airwl = airwl |
|
115 | self.airwl = airwl | |
116 |
|
116 | |||
117 | self.kk = 2.*numpy.pi/eomwl |
|
117 | self.kk = 2.*numpy.pi/eomwl | |
118 |
|
118 | |||
119 | self.pattern = None |
|
119 | self.pattern = None | |
120 | self.meanpos = None |
|
120 | self.meanpos = None | |
121 | self.norpattern = None |
|
121 | self.norpattern = None | |
122 | self.maxpattern = None |
|
122 | self.maxpattern = None | |
123 |
|
123 | |||
124 |
|
124 | |||
125 |
|
125 | |||
126 | self.getPattern() |
|
126 | self.getPattern() | |
127 |
|
127 | |||
128 | def getPattern(self): |
|
128 | def getPattern(self): | |
129 | """ |
|
129 | """ | |
130 | getpattern method returns the modeled total antenna pattern and its mean position. |
|
130 | getpattern method returns the modeled total antenna pattern and its mean position. | |
131 |
|
131 | |||
132 | Return |
|
132 | Return | |
133 | ------ |
|
133 | ------ | |
134 | pattern = An array giving the Modelled antenna pattern. |
|
134 | pattern = An array giving the Modelled antenna pattern. | |
135 | mean_pos = A 2-elements array giving the mean position of the main beam. |
|
135 | mean_pos = A 2-elements array giving the mean position of the main beam. | |
136 |
|
136 | |||
137 | Examples |
|
137 | Examples | |
138 | -------- |
|
138 | -------- | |
139 | >> [pattern, mean_pos] = JroPattern(pattern=2).getPattern() |
|
139 | >> [pattern, mean_pos] = JroPattern(pattern=2).getPattern() | |
140 | >> print meanpos |
|
140 | >> print meanpos | |
141 | [ 8.08728085e-14 -4.78193873e-14] |
|
141 | [ 8.08728085e-14 -4.78193873e-14] | |
142 |
|
142 | |||
143 | Modification history |
|
143 | Modification history | |
144 | -------------------- |
|
144 | -------------------- | |
145 | Developed by Jorge L. Chau. |
|
145 | Developed by Jorge L. Chau. | |
146 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
146 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
147 | """ |
|
147 | """ | |
148 |
|
148 | |||
149 | if (self.fftopt>0) and (self.getcut>0): |
|
149 | if (self.fftopt>0) and (self.getcut>0): | |
150 | #print "Conflict bewteen fftopt and getcut" |
|
150 | #print "Conflict bewteen fftopt and getcut" | |
151 | #print "To get a cut of the antenna pattern uses ffopt=0" |
|
151 | #print "To get a cut of the antenna pattern uses ffopt=0" | |
152 | return None, None |
|
152 | return None, None | |
153 |
|
153 | |||
154 | if (self.fftopt==0): |
|
154 | if (self.fftopt==0): | |
155 | # Getting antenna pattern using the array method |
|
155 | # Getting antenna pattern using the array method | |
156 | self.pattern = self.__usingArray(rx=1) |
|
156 | self.pattern = self.__usingArray(rx=1) | |
157 | if (self.justrx==0):self.pattern = self.pattern*self.__usingArray(rx=0) |
|
157 | if (self.justrx==0):self.pattern = self.pattern*self.__usingArray(rx=0) | |
158 |
|
158 | |||
159 | elif (self.fftopt>0): |
|
159 | elif (self.fftopt>0): | |
160 | # Getting antenna pattern using FFT method |
|
160 | # Getting antenna pattern using FFT method | |
161 | self.pattern = self.__usingFFT(rx=1) |
|
161 | self.pattern = self.__usingFFT(rx=1) | |
162 | if (self.justrx==0):self.pattern = self.pattern*self.__usingFFT(rx=0) |
|
162 | if (self.justrx==0):self.pattern = self.pattern*self.__usingFFT(rx=0) | |
163 |
|
163 | |||
164 | self.maxpattern = numpy.nanmax(self.pattern) |
|
164 | self.maxpattern = numpy.nanmax(self.pattern) | |
165 | self.norpattern = self.pattern/self.maxpattern |
|
165 | self.norpattern = self.pattern/self.maxpattern | |
166 | if self.getcut==0:self.__getBeamPars() |
|
166 | if self.getcut==0:self.__getBeamPars() | |
167 |
|
167 | |||
168 | def __usingArray(self,rx): |
|
168 | def __usingArray(self,rx): | |
169 | """ |
|
169 | """ | |
170 | __usingArray method returns the Jicamarca antenna pattern computed using array model |
|
170 | __usingArray method returns the Jicamarca antenna pattern computed using array model | |
171 |
|
171 | |||
172 | pattern = dipolepattern x modulepattern |
|
172 | pattern = dipolepattern x modulepattern | |
173 |
|
173 | |||
174 | Parameters |
|
174 | Parameters | |
175 | ---------- |
|
175 | ---------- | |
176 | rx = Set to 1 to use the Rx information. Otherwise set to 0 for Tx. |
|
176 | rx = Set to 1 to use the Rx information. Otherwise set to 0 for Tx. | |
177 |
|
177 | |||
178 | Return |
|
178 | Return | |
179 | ------ |
|
179 | ------ | |
180 | pattern = An array giving the modelled antenna pattern using the array model. |
|
180 | pattern = An array giving the modelled antenna pattern using the array model. | |
181 |
|
181 | |||
182 | Modification history |
|
182 | Modification history | |
183 | -------------------- |
|
183 | -------------------- | |
184 | Developed by Jorge L. Chau. |
|
184 | Developed by Jorge L. Chau. | |
185 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
185 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
186 | """ |
|
186 | """ | |
187 |
|
187 | |||
188 | if rx==1: |
|
188 | if rx==1: | |
189 | ues = self.uesrx |
|
189 | ues = self.uesrx | |
190 | phase = self.phaserx |
|
190 | phase = self.phaserx | |
191 | gain = self.gainrx |
|
191 | gain = self.gainrx | |
192 | elif rx==0: |
|
192 | elif rx==0: | |
193 | ues = self.uestx |
|
193 | ues = self.uestx | |
194 | phase = self.phasetx |
|
194 | phase = self.phasetx | |
195 | gain = self.gaintx |
|
195 | gain = self.gaintx | |
196 |
|
196 | |||
197 | ues = ues*360./self.airwl |
|
197 | ues = ues*360./self.airwl | |
198 | phase = phase*360./self.airwl |
|
198 | phase = phase*360./self.airwl | |
199 |
|
199 | |||
200 | for ii in range(4): |
|
200 | for ii in range(4): | |
201 | if ii==0:dim = numpy.array([4,0,8,4]) # WEST |
|
201 | if ii==0:dim = numpy.array([4,0,8,4]) # WEST | |
202 | elif ii==1:dim = numpy.array([0,0,4,4]) # NORTH |
|
202 | elif ii==1:dim = numpy.array([0,0,4,4]) # NORTH | |
203 | elif ii==2:dim = numpy.array([0,4,4,8]) # EAST |
|
203 | elif ii==2:dim = numpy.array([0,4,4,8]) # EAST | |
204 | elif ii==3:dim = numpy.array([4,4,8,8]) # SOUTH |
|
204 | elif ii==3:dim = numpy.array([4,4,8,8]) # SOUTH | |
205 | xi = dim[0]; xf = dim[2]; yi = dim[1]; yf = dim[3] |
|
205 | xi = dim[0]; xf = dim[2]; yi = dim[1]; yf = dim[3] | |
206 | phase[xi:xf,yi:yf] = phase[xi:xf,yi:yf] + ues[ii] |
|
206 | phase[xi:xf,yi:yf] = phase[xi:xf,yi:yf] + ues[ii] | |
207 |
|
207 | |||
208 | phase = -phase |
|
208 | phase = -phase | |
209 |
|
209 | |||
210 | ar = self.eomwl*numpy.array([[0.5,6., 24.5],[0.5,6.,24.5]]) |
|
210 | ar = self.eomwl*numpy.array([[0.5,6., 24.5],[0.5,6.,24.5]]) | |
211 | nr = numpy.array([[12.,4.,2.],[12.,4.,2.]]) |
|
211 | nr = numpy.array([[12.,4.,2.],[12.,4.,2.]]) | |
212 | lr = 0.25*self.eomwl*numpy.array([[0,0.,0],[0.,0,0]]) |
|
212 | lr = 0.25*self.eomwl*numpy.array([[0,0.,0],[0.,0,0]]) | |
213 |
|
213 | |||
214 | # Computing module and dipole patterns. |
|
214 | # Computing module and dipole patterns. | |
215 | pattern = (numpy.abs(self.__dipPattern(ar,nr,lr)*self.__modPattern(phase,gain)))**2 |
|
215 | pattern = (numpy.abs(self.__dipPattern(ar,nr,lr)*self.__modPattern(phase,gain)))**2 | |
216 |
|
216 | |||
217 | return pattern |
|
217 | return pattern | |
218 |
|
218 | |||
219 | def __usingFFT(self,rx): |
|
219 | def __usingFFT(self,rx): | |
220 | """ |
|
220 | """ | |
221 | __usingFFT method returns the Jicamarca antenna pattern computed using The Fast Fou- |
|
221 | __usingFFT method returns the Jicamarca antenna pattern computed using The Fast Fou- | |
222 | rier Transform. |
|
222 | rier Transform. | |
223 |
|
223 | |||
224 | pattern = iFFT(FFT(gain*EXP(j*phase))) |
|
224 | pattern = iFFT(FFT(gain*EXP(j*phase))) | |
225 |
|
225 | |||
226 | Parameters |
|
226 | Parameters | |
227 | ---------- |
|
227 | ---------- | |
228 | rx = Set to 1 to use the Rx information. Otherwise set to 0 for Tx. |
|
228 | rx = Set to 1 to use the Rx information. Otherwise set to 0 for Tx. | |
229 |
|
229 | |||
230 | Return |
|
230 | Return | |
231 | ------ |
|
231 | ------ | |
232 | pattern = An array giving the modelled antenna pattern using the array model. |
|
232 | pattern = An array giving the modelled antenna pattern using the array model. | |
233 |
|
233 | |||
234 | Modification history |
|
234 | Modification history | |
235 | -------------------- |
|
235 | -------------------- | |
236 | Developed by Jorge L. Chau. |
|
236 | Developed by Jorge L. Chau. | |
237 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
237 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
238 | """ |
|
238 | """ | |
239 |
|
239 | |||
240 | if rx==1: |
|
240 | if rx==1: | |
241 | ues = self.uesrx |
|
241 | ues = self.uesrx | |
242 | phase = self.phaserx |
|
242 | phase = self.phaserx | |
243 | gain = self.gainrx |
|
243 | gain = self.gainrx | |
244 | elif rx==0: |
|
244 | elif rx==0: | |
245 | ues = self.uestx |
|
245 | ues = self.uestx | |
246 | phase = self.phasetx |
|
246 | phase = self.phasetx | |
247 | gain = self.gaintx |
|
247 | gain = self.gaintx | |
248 |
|
248 | |||
249 | ues = ues*360./self.airwl |
|
249 | ues = ues*360./self.airwl | |
250 | phase = phase*360./self.airwl |
|
250 | phase = phase*360./self.airwl | |
251 |
|
251 | |||
252 | for ii in range(4): |
|
252 | for ii in range(4): | |
253 | if ii==0:dim = numpy.array([4,0,8,4]) # WEST |
|
253 | if ii==0:dim = numpy.array([4,0,8,4]) # WEST | |
254 | elif ii==1:dim = numpy.array([0,0,4,4]) # NORTH |
|
254 | elif ii==1:dim = numpy.array([0,0,4,4]) # NORTH | |
255 | elif ii==2:dim = numpy.array([0,4,4,8]) # EAST |
|
255 | elif ii==2:dim = numpy.array([0,4,4,8]) # EAST | |
256 | elif ii==3:dim = numpy.array([4,4,8,8]) # SOUTH |
|
256 | elif ii==3:dim = numpy.array([4,4,8,8]) # SOUTH | |
257 | xi = dim[0]; xf = dim[2]; yi = dim[1]; yf = dim[3] |
|
257 | xi = dim[0]; xf = dim[2]; yi = dim[1]; yf = dim[3] | |
258 | phase[xi:xf,yi:yf] = phase[xi:xf,yi:yf] + ues[ii] |
|
258 | phase[xi:xf,yi:yf] = phase[xi:xf,yi:yf] + ues[ii] | |
259 |
|
259 | |||
260 | phase = -phase |
|
260 | phase = -phase | |
261 |
|
261 | |||
262 | delta_x = self.eomwl/2. |
|
262 | delta_x = self.eomwl/2. | |
263 | delta_y = self.eomwl/2. |
|
263 | delta_y = self.eomwl/2. | |
264 |
|
264 | |||
265 | nxfft = 2048 |
|
265 | nxfft = 2048 | |
266 | nyfft = 2048 |
|
266 | nyfft = 2048 | |
267 | dcosx = (numpy.arange(nxfft) - (0.5*nxfft))/(nxfft*delta_x)*self.eomwl |
|
267 | dcosx = (numpy.arange(nxfft) - (0.5*nxfft))/(nxfft*delta_x)*self.eomwl | |
268 | dcosy = (numpy.arange(nyfft) - (0.5*nyfft))/(nyfft*delta_y)*self.eomwl |
|
268 | dcosy = (numpy.arange(nyfft) - (0.5*nyfft))/(nyfft*delta_y)*self.eomwl | |
269 |
|
269 | |||
270 | fft_gain = numpy.zeros((nxfft,nyfft)) |
|
270 | fft_gain = numpy.zeros((nxfft,nyfft)) | |
271 | fft_phase = numpy.zeros((nxfft,nyfft)) |
|
271 | fft_phase = numpy.zeros((nxfft,nyfft)) | |
272 |
|
272 | |||
273 | nx = 8 |
|
273 | nx = 8 | |
274 | ny = 8 |
|
274 | ny = 8 | |
275 | ndx =12 |
|
275 | ndx =12 | |
276 | ndy =12 |
|
276 | ndy =12 | |
277 | for iy in numpy.arange(ny): |
|
277 | for iy in numpy.arange(ny): | |
278 | for ix in numpy.arange(nx): |
|
278 | for ix in numpy.arange(nx): | |
279 | ix1 = nxfft/2-self.nx/2*ndx+ix*ndx |
|
279 | ix1 = nxfft/2-self.nx/2*ndx+ix*ndx | |
280 | if ix<(nx/2):ix1 = ix1 - 1 |
|
280 | if ix<(nx/2):ix1 = ix1 - 1 | |
281 | if ix>=(nx/2):ix1 = ix1 + 1 |
|
281 | if ix>=(nx/2):ix1 = ix1 + 1 | |
282 |
|
282 | |||
283 | iy1 = nyfft/2-ny/2*ndx+iy*ndy |
|
283 | iy1 = nyfft/2-ny/2*ndx+iy*ndy | |
284 | if iy<(ny/2):iy1 = iy1 - 1 |
|
284 | if iy<(ny/2):iy1 = iy1 - 1 | |
285 | if iy>=(ny/2):iy1 = iy1 + 1 |
|
285 | if iy>=(ny/2):iy1 = iy1 + 1 | |
286 |
|
286 | |||
287 | fft_gain[ix1:ix1+ndx-1,iy1:iy1+ndy-1] = gain[ix,ny-1-iy] |
|
287 | fft_gain[ix1:ix1+ndx-1,iy1:iy1+ndy-1] = gain[ix,ny-1-iy] | |
288 | fft_phase[ix1:ix1+ndx-1,iy1:iy1+ndy-1] = phase[ix,ny-1-iy] |
|
288 | fft_phase[ix1:ix1+ndx-1,iy1:iy1+ndy-1] = phase[ix,ny-1-iy] | |
289 |
|
289 | |||
290 |
|
290 | |||
291 | fft_phase = fft_phase*CoFactors.d2r |
|
291 | fft_phase = fft_phase*CoFactors.d2r | |
292 |
|
292 | |||
293 | pattern = numpy.abs(numpy.fft.fft2(fft_gain*numpy.exp(numpy.complex(0,1)*fft_phase)))**2 |
|
293 | pattern = numpy.abs(numpy.fft.fft2(fft_gain*numpy.exp(numpy.complex(0,1)*fft_phase)))**2 | |
294 | pattern = numpy.fft.fftshift(pattern) |
|
294 | pattern = numpy.fft.fftshift(pattern) | |
295 |
|
295 | |||
296 | xvals = numpy.where((dcosx>=(numpy.min(self.dcosx))) & (dcosx<=(numpy.max(self.dcosx)))) |
|
296 | xvals = numpy.where((dcosx>=(numpy.min(self.dcosx))) & (dcosx<=(numpy.max(self.dcosx)))) | |
297 | yvals = numpy.where((dcosy>=(numpy.min(self.dcosy))) & (dcosy<=(numpy.max(self.dcosy)))) |
|
297 | yvals = numpy.where((dcosy>=(numpy.min(self.dcosy))) & (dcosy<=(numpy.max(self.dcosy)))) | |
298 |
|
298 | |||
299 | pattern = pattern[xvals[0][0]:xvals[0][-1],yvals[0][0]:yvals[0][-1]] |
|
299 | pattern = pattern[xvals[0][0]:xvals[0][-1],yvals[0][0]:yvals[0][-1]] | |
300 |
|
300 | |||
301 | return pattern |
|
301 | return pattern | |
302 |
|
302 | |||
303 | def __readAttenuation(self): |
|
303 | def __readAttenuation(self): | |
304 | """ |
|
304 | """ | |
305 | _readAttenuation reads the attenuations' file and returns an array giving these va- |
|
305 | _readAttenuation reads the attenuations' file and returns an array giving these va- | |
306 | lues (dB). The ext file must be in the directory "resource". |
|
306 | lues (dB). The ext file must be in the directory "resource". | |
307 |
|
307 | |||
308 | Return |
|
308 | Return | |
309 | ------ |
|
309 | ------ | |
310 | attenuation = An array giving attenuation values read from the text file. |
|
310 | attenuation = An array giving attenuation values read from the text file. | |
311 |
|
311 | |||
312 | Modification history |
|
312 | Modification history | |
313 | -------------------- |
|
313 | -------------------- | |
314 | Developed by Jorge L. Chau. |
|
314 | Developed by Jorge L. Chau. | |
315 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
315 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
316 | """ |
|
316 | """ | |
317 |
|
317 | |||
318 | # attenuation = None |
|
318 | # attenuation = None | |
319 | # # foldr = sys.path[-1] + os.sep + "resource" + os.sep |
|
319 | # # foldr = sys.path[-1] + os.sep + "resource" + os.sep | |
320 | # base_path = os.path.dirname(os.path.abspath(__file__)) |
|
320 | # base_path = os.path.dirname(os.path.abspath(__file__)) | |
321 | # #foldr = './resource' |
|
321 | # #foldr = './resource' | |
322 | # #filen = "attenuation.txt" |
|
322 | # #filen = "attenuation.txt" | |
323 | # attenuationFile = os.path.join(base_path,"resource","attenuation.txt") |
|
323 | # attenuationFile = os.path.join(base_path,"resource","attenuation.txt") | |
324 | # #ff = open(os.path.join(foldr,filen),'r') |
|
324 | # #ff = open(os.path.join(foldr,filen),'r') | |
325 | # ff = open(attenuationFile,'r') |
|
325 | # ff = open(attenuationFile,'r') | |
326 | # print(ff.read()) |
|
326 | # print(ff.read()) | |
327 | # exec(ff.read()) |
|
327 | # exec(ff.read()) | |
328 | # ff.close() |
|
328 | # ff.close() | |
329 | attenuation = numpy.array([[[-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
329 | attenuation = numpy.array([[[-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
330 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
330 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
331 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
331 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
332 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
332 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
333 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
333 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
334 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
334 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
335 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], |
|
335 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25], | |
336 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25]], |
|
336 | [-21.25,-15.25,-9.25,-3.25,03.25,09.25,15.25,21.25]], | |
337 | [[21.25,21.25,21.25,21.25,21.25,21.25,21.25,21.25], |
|
337 | [[21.25,21.25,21.25,21.25,21.25,21.25,21.25,21.25], | |
338 | [15.25,15.25,15.25,15.25,15.25,15.25,15.25,15.25], |
|
338 | [15.25,15.25,15.25,15.25,15.25,15.25,15.25,15.25], | |
339 | [09.25,09.25,09.25,09.25,09.25,09.25,09.25,09.25], |
|
339 | [09.25,09.25,09.25,09.25,09.25,09.25,09.25,09.25], | |
340 | [03.25,03.25,03.25,03.25,03.25,03.25,03.25,03.25], |
|
340 | [03.25,03.25,03.25,03.25,03.25,03.25,03.25,03.25], | |
341 | [-03.25,-03.25,-03.25,-03.25,-03.25,-03.25,-03.25,-03.25], |
|
341 | [-03.25,-03.25,-03.25,-03.25,-03.25,-03.25,-03.25,-03.25], | |
342 | [-09.25,-09.25,-09.25,-09.25,-09.25,-09.25,-09.25,-09.25], |
|
342 | [-09.25,-09.25,-09.25,-09.25,-09.25,-09.25,-09.25,-09.25], | |
343 | [-15.25,-15.25,-15.25,-15.25,-15.25,-15.25,-15.25,-15.25], |
|
343 | [-15.25,-15.25,-15.25,-15.25,-15.25,-15.25,-15.25,-15.25], | |
344 | [-21.25,-21.25,-21.25,-21.25,-21.25,-21.25,-21.25,-21.25]]]) |
|
344 | [-21.25,-21.25,-21.25,-21.25,-21.25,-21.25,-21.25,-21.25]]]) | |
345 |
|
345 | |||
346 | return attenuation |
|
346 | return attenuation | |
347 |
|
347 | |||
348 | def __dipPattern(self,ar,nr,lr): |
|
348 | def __dipPattern(self,ar,nr,lr): | |
349 | """ |
|
349 | """ | |
350 | _dipPattern function computes the dipole's pattern to the Jicamarca radar. The next |
|
350 | _dipPattern function computes the dipole's pattern to the Jicamarca radar. The next | |
351 | equation defines the pattern as a function of the mainlobe direction: |
|
351 | equation defines the pattern as a function of the mainlobe direction: | |
352 |
|
352 | |||
353 | sincx = SIN(k/2*n0x*(a0x*SIN(phi)*COS(alpha)))/SIN(k/2*(a0x*SIN(phi)*COS(alpha))) |
|
353 | sincx = SIN(k/2*n0x*(a0x*SIN(phi)*COS(alpha)))/SIN(k/2*(a0x*SIN(phi)*COS(alpha))) | |
354 | sincy = SIN(k/2*n0y*(a0y*SIN(phi)*SIN(alpha)))/SIN(k/2*(a0y*SIN(phi)*SIN(alpha))) |
|
354 | sincy = SIN(k/2*n0y*(a0y*SIN(phi)*SIN(alpha)))/SIN(k/2*(a0y*SIN(phi)*SIN(alpha))) | |
355 | A0(phi,alpha) = sincx*sincy |
|
355 | A0(phi,alpha) = sincx*sincy | |
356 | Parameters |
|
356 | Parameters | |
357 | ---------- |
|
357 | ---------- | |
358 | ar = ? |
|
358 | ar = ? | |
359 | nr = ? |
|
359 | nr = ? | |
360 | lr = ? |
|
360 | lr = ? | |
361 |
|
361 | |||
362 | Return |
|
362 | Return | |
363 | ------ |
|
363 | ------ | |
364 | dipole = An array giving antenna pattern from the dipole point of view.. |
|
364 | dipole = An array giving antenna pattern from the dipole point of view.. | |
365 |
|
365 | |||
366 | Modification history |
|
366 | Modification history | |
367 | -------------------- |
|
367 | -------------------- | |
368 | Developed by Jorge L. Chau. |
|
368 | Developed by Jorge L. Chau. | |
369 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
369 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
370 | """ |
|
370 | """ | |
371 |
|
371 | |||
372 | dipole = numpy.zeros((self.nx,self.ny),dtype=complex) |
|
372 | dipole = numpy.zeros((self.nx,self.ny),dtype=complex) | |
373 | for iy in range(self.ny): |
|
373 | for iy in range(self.ny): | |
374 | for ix in range(self.nx): |
|
374 | for ix in range(self.nx): | |
375 | yindex = iy*(self.getcut==0) + ix*(self.getcut==1) |
|
375 | yindex = iy*(self.getcut==0) + ix*(self.getcut==1) | |
376 |
|
376 | |||
377 | argx = ar[0,0]*self.dcosx[ix] - lr[0,0] |
|
377 | argx = ar[0,0]*self.dcosx[ix] - lr[0,0] | |
378 | if argx == 0.0: |
|
378 | if argx == 0.0: | |
379 | junkx = nr[0,0] |
|
379 | junkx = nr[0,0] | |
380 | else: |
|
380 | else: | |
381 | junkx = numpy.sin(0.5*self.kk*nr[0,0]*argx)/numpy.sin(0.5*self.kk*argx) |
|
381 | junkx = numpy.sin(0.5*self.kk*nr[0,0]*argx)/numpy.sin(0.5*self.kk*argx) | |
382 |
|
382 | |||
383 |
|
383 | |||
384 | argy = ar[1,0]*self.dcosy[yindex] - lr[1,0] |
|
384 | argy = ar[1,0]*self.dcosy[yindex] - lr[1,0] | |
385 | if argy == 0.0: |
|
385 | if argy == 0.0: | |
386 | junky = nr[1,0] |
|
386 | junky = nr[1,0] | |
387 | else: |
|
387 | else: | |
388 | junky = numpy.sin(0.5*self.kk*nr[1,0]*argy)/numpy.sin(0.5*self.kk*argy) |
|
388 | junky = numpy.sin(0.5*self.kk*nr[1,0]*argy)/numpy.sin(0.5*self.kk*argy) | |
389 |
|
389 | |||
390 |
|
390 | |||
391 | dipole[ix,iy] = junkx*junky |
|
391 | dipole[ix,iy] = junkx*junky | |
392 |
|
392 | |||
393 | return dipole |
|
393 | return dipole | |
394 |
|
394 | |||
395 | def __modPattern(self,phase,gain): |
|
395 | def __modPattern(self,phase,gain): | |
396 | """ |
|
396 | """ | |
397 | ModPattern computes the module's pattern to the Jicamarca radar. The next equation |
|
397 | ModPattern computes the module's pattern to the Jicamarca radar. The next equation | |
398 | defines the pattern as a function mainlobe direction: |
|
398 | defines the pattern as a function mainlobe direction: | |
399 |
|
399 | |||
400 | phasex = pos(x)*SIN(phi)*COS(alpha) |
|
400 | phasex = pos(x)*SIN(phi)*COS(alpha) | |
401 | phasey = pos(y)*SIN(phi)*SIN(alpha) |
|
401 | phasey = pos(y)*SIN(phi)*SIN(alpha) | |
402 |
|
402 | |||
403 | A1(phi,alpha) = TOTAL(gain*EXP(COMPLEX(0,k*(phasex+phasey)+phase))) |
|
403 | A1(phi,alpha) = TOTAL(gain*EXP(COMPLEX(0,k*(phasex+phasey)+phase))) | |
404 |
|
404 | |||
405 | Parameters |
|
405 | Parameters | |
406 | ---------- |
|
406 | ---------- | |
407 | phase = Bidimensional array (8x8) giving the phase (in meters) of each module. |
|
407 | phase = Bidimensional array (8x8) giving the phase (in meters) of each module. | |
408 | gain = Bidimensional array (8x8) giving to define modules will be active (ones) |
|
408 | gain = Bidimensional array (8x8) giving to define modules will be active (ones) | |
409 | and which will not (zeros). |
|
409 | and which will not (zeros). | |
410 |
|
410 | |||
411 | Return |
|
411 | Return | |
412 | ------ |
|
412 | ------ | |
413 | module = An array giving antenna pattern from the module point of view.. |
|
413 | module = An array giving antenna pattern from the module point of view.. | |
414 |
|
414 | |||
415 | Modification history |
|
415 | Modification history | |
416 | -------------------- |
|
416 | -------------------- | |
417 | Developed by Jorge L. Chau. |
|
417 | Developed by Jorge L. Chau. | |
418 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
418 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
419 | """ |
|
419 | """ | |
420 |
|
420 | |||
421 | pos = self.eomwl*self.__readAttenuation() |
|
421 | pos = self.eomwl*self.__readAttenuation() | |
422 | posx = pos[0,:,:] |
|
422 | posx = pos[0,:,:] | |
423 | posy = pos[1,:,:] |
|
423 | posy = pos[1,:,:] | |
424 |
|
424 | |||
425 | phase = phase*CoFactors.d2r |
|
425 | phase = phase*CoFactors.d2r | |
426 | module = numpy.zeros((self.nx,self.ny),dtype=complex) |
|
426 | module = numpy.zeros((self.nx,self.ny),dtype=complex) | |
427 | for iy in range(self.ny): |
|
427 | for iy in range(self.ny): | |
428 | for ix in range(self.nx): |
|
428 | for ix in range(self.nx): | |
429 | yindex = iy*(self.getcut==0) + ix*(self.getcut==1) |
|
429 | yindex = iy*(self.getcut==0) + ix*(self.getcut==1) | |
430 | phasex = posx*self.dcosx[ix] |
|
430 | phasex = posx*self.dcosx[ix] | |
431 | phasey = posy*self.dcosy[yindex] |
|
431 | phasey = posy*self.dcosy[yindex] | |
432 | tmp = gain*numpy.exp(numpy.complex(0,1.)*(self.kk*(phasex+phasey)+phase)) |
|
432 | tmp = gain*numpy.exp(numpy.complex(0,1.)*(self.kk*(phasex+phasey)+phase)) | |
433 | module[ix,iy] = tmp.sum() |
|
433 | module[ix,iy] = tmp.sum() | |
434 |
|
434 | |||
435 | return module |
|
435 | return module | |
436 |
|
436 | |||
437 | def __getBeamPars(self): |
|
437 | def __getBeamPars(self): | |
438 | """ |
|
438 | """ | |
439 | _getBeamPars computes the main-beam parameters of the antenna. |
|
439 | _getBeamPars computes the main-beam parameters of the antenna. | |
440 |
|
440 | |||
441 | Modification history |
|
441 | Modification history | |
442 | -------------------- |
|
442 | -------------------- | |
443 | Developed by Jorge L. Chau. |
|
443 | Developed by Jorge L. Chau. | |
444 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. |
|
444 | Converted to Python by Freddy R. Galindo, ROJ, 20 September 2009. | |
445 | """ |
|
445 | """ | |
446 |
|
446 | |||
447 | dx = self.dcosx[1] - self.dcosx[0] |
|
447 | dx = self.dcosx[1] - self.dcosx[0] | |
448 | dy = self.dcosy[1] - self.dcosy[0] |
|
448 | dy = self.dcosy[1] - self.dcosy[0] | |
449 |
|
449 | |||
450 | amp = self.norpattern |
|
450 | amp = self.norpattern | |
451 |
|
451 | |||
452 | xx = numpy.resize(self.dcosx,(self.nx,self.nx)).transpose() |
|
452 | xx = numpy.resize(self.dcosx,(self.nx,self.nx)).transpose() | |
453 | yy = numpy.resize(self.dcosy,(self.ny,self.ny)) |
|
453 | yy = numpy.resize(self.dcosy,(self.ny,self.ny)) | |
454 |
|
454 | |||
455 | mm0 = amp[numpy.where(amp > 0.5)] |
|
455 | mm0 = amp[numpy.where(amp > 0.5)] | |
456 | xx0 = xx[numpy.where(amp > 0.5)] |
|
456 | xx0 = xx[numpy.where(amp > 0.5)] | |
457 | yy0 = yy[numpy.where(amp > 0.5)] |
|
457 | yy0 = yy[numpy.where(amp > 0.5)] | |
458 |
|
458 | |||
459 | xc = numpy.sum(mm0*xx0)/numpy.sum(mm0) |
|
459 | xc = numpy.sum(mm0*xx0)/numpy.sum(mm0) | |
460 | yc = numpy.sum(mm0*yy0)/numpy.sum(mm0) |
|
460 | yc = numpy.sum(mm0*yy0)/numpy.sum(mm0) | |
461 | rc = numpy.sqrt(mm0.size*dx*dy/numpy.pi) |
|
461 | rc = numpy.sqrt(mm0.size*dx*dy/numpy.pi) | |
462 |
|
462 | |||
463 | nnx = numpy.where(numpy.abs(self.dcosx - xc) < rc) |
|
463 | nnx = numpy.where(numpy.abs(self.dcosx - xc) < rc) | |
464 | nny = numpy.where(numpy.abs(self.dcosy - yc) < rc) |
|
464 | nny = numpy.where(numpy.abs(self.dcosy - yc) < rc) | |
465 |
|
465 | |||
466 | mm1 = amp[numpy.min(nnx):numpy.max(nnx)+1,numpy.min(nny):numpy.max(nny)+1] |
|
466 | mm1 = amp[numpy.min(nnx):numpy.max(nnx)+1,numpy.min(nny):numpy.max(nny)+1] | |
467 | xx1 = self.dcosx[numpy.min(nnx):numpy.max(nnx)+1] |
|
467 | xx1 = self.dcosx[numpy.min(nnx):numpy.max(nnx)+1] | |
468 | yy1 = self.dcosy[numpy.min(nny):numpy.max(nny)+1] |
|
468 | yy1 = self.dcosy[numpy.min(nny):numpy.max(nny)+1] | |
469 |
|
469 | |||
470 | # fitting data into the main beam. |
|
470 | # fitting data into the main beam. | |
471 | import gaussfit |
|
471 | from .gaussfit import fitgaussian | |
472 |
params = |
|
472 | params = fitgaussian(mm1) | |
473 |
|
473 | |||
474 | # Tranforming from indexes to axis' values |
|
474 | # Tranforming from indexes to axis' values | |
475 | xcenter = xx1[0] + (((xx1[xx1.size-1] - xx1[0])/(xx1.size -1))*(params[1])) |
|
475 | xcenter = xx1[0] + (((xx1[xx1.size-1] - xx1[0])/(xx1.size -1))*(params[1])) | |
476 | ycenter = yy1[0] + (((yy1[yy1.size-1] - yy1[0])/(yy1.size -1))*(params[2])) |
|
476 | ycenter = yy1[0] + (((yy1[yy1.size-1] - yy1[0])/(yy1.size -1))*(params[2])) | |
477 | xwidth = ((xx1[xx1.size-1] - xx1[0])/(xx1.size-1))*(params[3])*(1/CoFactors.d2r) |
|
477 | xwidth = ((xx1[xx1.size-1] - xx1[0])/(xx1.size-1))*(params[3])*(1/CoFactors.d2r) | |
478 | ywidth = ((yy1[yy1.size-1] - yy1[0])/(yy1.size-1))*(params[4])*(1/CoFactors.d2r) |
|
478 | ywidth = ((yy1[yy1.size-1] - yy1[0])/(yy1.size-1))*(params[4])*(1/CoFactors.d2r) | |
479 | meanwx = (xwidth*ywidth) |
|
479 | meanwx = (xwidth*ywidth) | |
480 | meanpos = numpy.array([xcenter,ycenter]) |
|
480 | meanpos = numpy.array([xcenter,ycenter]) | |
481 |
|
481 | |||
482 | #print 'Position: %f %f' %(xcenter,ycenter) |
|
482 | #print 'Position: %f %f' %(xcenter,ycenter) | |
483 | #print 'Widths: %f %f' %(xwidth, ywidth) |
|
483 | #print 'Widths: %f %f' %(xwidth, ywidth) | |
484 | #print 'BWHP: %f' %(2*numpy.sqrt(2*meanwx)*numpy.sqrt(-numpy.log(0.5))) |
|
484 | #print 'BWHP: %f' %(2*numpy.sqrt(2*meanwx)*numpy.sqrt(-numpy.log(0.5))) | |
485 |
|
485 | |||
486 | self.meanpos = meanpos |
|
486 | self.meanpos = meanpos | |
487 |
|
487 | |||
488 |
|
488 | |||
489 | class BField(): |
|
489 | class BField(): | |
490 | def __init__(self,year=None,doy=None,site=1,heights=None,alpha_i=90): |
|
490 | def __init__(self,year=None,doy=None,site=1,heights=None,alpha_i=90): | |
491 | """ |
|
491 | """ | |
492 | BField class creates an object to get the Magnetic field for a specific date and |
|
492 | BField class creates an object to get the Magnetic field for a specific date and | |
493 | height(s). |
|
493 | height(s). | |
494 |
|
494 | |||
495 | Parameters |
|
495 | Parameters | |
496 | ---------- |
|
496 | ---------- | |
497 | year = A scalar giving the desired year. If the value is None (default value) then |
|
497 | year = A scalar giving the desired year. If the value is None (default value) then | |
498 | the current year will be used. |
|
498 | the current year will be used. | |
499 | doy = A scalar giving the desired day of the year. If the value is None (default va- |
|
499 | doy = A scalar giving the desired day of the year. If the value is None (default va- | |
500 | lue) then the current doy will be used. |
|
500 | lue) then the current doy will be used. | |
501 | site = An integer to choose the geographic coordinates of the place where the magne- |
|
501 | site = An integer to choose the geographic coordinates of the place where the magne- | |
502 | tic field will be computed. The default value is over Jicamarca (site=1) |
|
502 | tic field will be computed. The default value is over Jicamarca (site=1) | |
503 | heights = An array giving the heights (km) where the magnetic field will be modeled By default the magnetic field will be computed at 100, 500 and 1000km. |
|
503 | heights = An array giving the heights (km) where the magnetic field will be modeled By default the magnetic field will be computed at 100, 500 and 1000km. | |
504 | alpha_i = Angle to interpolate the magnetic field. |
|
504 | alpha_i = Angle to interpolate the magnetic field. | |
505 |
|
505 | |||
506 | Modification History |
|
506 | Modification History | |
507 | -------------------- |
|
507 | -------------------- | |
508 | Converted to Object-oriented Programming by Freddy Galindo, ROJ, 07 October 2009. |
|
508 | Converted to Object-oriented Programming by Freddy Galindo, ROJ, 07 October 2009. | |
509 | """ |
|
509 | """ | |
510 |
|
510 | |||
511 | tmp = time.localtime() |
|
511 | tmp = time.localtime() | |
512 | if year==None: year = tmp[0] |
|
512 | if year==None: year = tmp[0] | |
513 | if doy==None: doy = tmp[7] |
|
513 | if doy==None: doy = tmp[7] | |
514 | self.year = year |
|
514 | self.year = year | |
515 | self.doy = doy |
|
515 | self.doy = doy | |
516 | self.site = site |
|
516 | self.site = site | |
517 | if heights==None:heights = numpy.array([100,500,1000]) |
|
517 | if heights==None:heights = numpy.array([100,500,1000]) | |
518 | self.heights = heights |
|
518 | self.heights = heights | |
519 | self.alpha_i = alpha_i |
|
519 | self.alpha_i = alpha_i | |
520 |
|
520 | |||
521 | def getBField(self,maglimits=numpy.array([-7,-7,7,7])): |
|
521 | def getBField(self,maglimits=numpy.array([-7,-7,7,7])): | |
522 | """ |
|
522 | """ | |
523 | getBField models the magnetic field for a different heights in a specific date. |
|
523 | getBField models the magnetic field for a different heights in a specific date. | |
524 |
|
524 | |||
525 | Parameters |
|
525 | Parameters | |
526 | ---------- |
|
526 | ---------- | |
527 | maglimits = An 4-elements array giving ..... The default value is [-7,-7,7,7]. |
|
527 | maglimits = An 4-elements array giving ..... The default value is [-7,-7,7,7]. | |
528 |
|
528 | |||
529 | Return |
|
529 | Return | |
530 | ------ |
|
530 | ------ | |
531 | dcos = An 4-dimensional array giving the directional cosines of the magnetic field |
|
531 | dcos = An 4-dimensional array giving the directional cosines of the magnetic field | |
532 | over the desired place. |
|
532 | over the desired place. | |
533 | alpha = An 3-dimensional array giving the angle of the magnetic field over the desi- |
|
533 | alpha = An 3-dimensional array giving the angle of the magnetic field over the desi- | |
534 | red place. |
|
534 | red place. | |
535 |
|
535 | |||
536 | Modification History |
|
536 | Modification History | |
537 | -------------------- |
|
537 | -------------------- | |
538 | Converted to Python by Freddy R. Galindo, ROJ, 07 October 2009. |
|
538 | Converted to Python by Freddy R. Galindo, ROJ, 07 October 2009. | |
539 | """ |
|
539 | """ | |
540 |
|
540 | |||
541 | x_ant = numpy.array([1,0,0]) |
|
541 | x_ant = numpy.array([1,0,0]) | |
542 | y_ant = numpy.array([0,1,0]) |
|
542 | y_ant = numpy.array([0,1,0]) | |
543 | z_ant = numpy.array([0,0,1]) |
|
543 | z_ant = numpy.array([0,0,1]) | |
544 |
|
544 | |||
545 | if self.site==0: |
|
545 | if self.site==0: | |
546 | title_site = "Magnetic equator" |
|
546 | title_site = "Magnetic equator" | |
547 | coord_site = numpy.array([-76+52./60.,-11+57/60.,0.5]) |
|
547 | coord_site = numpy.array([-76+52./60.,-11+57/60.,0.5]) | |
548 | elif self.site==1: |
|
548 | elif self.site==1: | |
549 | title_site = 'Jicamarca' |
|
549 | title_site = 'Jicamarca' | |
550 | coord_site = [-76-52./60.,-11-57/60.,0.5] |
|
550 | coord_site = [-76-52./60.,-11-57/60.,0.5] | |
551 | theta = (45+5.35)*numpy.pi/180. # (50.35 and 1.46 from Fleish Thesis) |
|
551 | theta = (45+5.35)*numpy.pi/180. # (50.35 and 1.46 from Fleish Thesis) | |
552 | delta = -1.46*numpy.pi/180 |
|
552 | delta = -1.46*numpy.pi/180 | |
553 |
|
553 | |||
554 | x_ant1 = numpy.roll(self.rotvector(self.rotvector(x_ant,1,delta),3,theta),1) |
|
554 | x_ant1 = numpy.roll(self.rotvector(self.rotvector(x_ant,1,delta),3,theta),1) | |
555 | y_ant1 = numpy.roll(self.rotvector(self.rotvector(y_ant,1,delta),3,theta),1) |
|
555 | y_ant1 = numpy.roll(self.rotvector(self.rotvector(y_ant,1,delta),3,theta),1) | |
556 | z_ant1 = numpy.roll(self.rotvector(self.rotvector(z_ant,1,delta),3,theta),1) |
|
556 | z_ant1 = numpy.roll(self.rotvector(self.rotvector(z_ant,1,delta),3,theta),1) | |
557 |
|
557 | |||
558 | ang0 = -1*coord_site[0]*numpy.pi/180. |
|
558 | ang0 = -1*coord_site[0]*numpy.pi/180. | |
559 | ang1 = coord_site[1]*numpy.pi/180. |
|
559 | ang1 = coord_site[1]*numpy.pi/180. | |
560 | x_ant = self.rotvector(self.rotvector(x_ant1,2,ang1),3,ang0) |
|
560 | x_ant = self.rotvector(self.rotvector(x_ant1,2,ang1),3,ang0) | |
561 | y_ant = self.rotvector(self.rotvector(y_ant1,2,ang1),3,ang0) |
|
561 | y_ant = self.rotvector(self.rotvector(y_ant1,2,ang1),3,ang0) | |
562 | z_ant = self.rotvector(self.rotvector(z_ant1,2,ang1),3,ang0) |
|
562 | z_ant = self.rotvector(self.rotvector(z_ant1,2,ang1),3,ang0) | |
563 | else: |
|
563 | else: | |
564 | # print "No defined Site. Skip..." |
|
564 | # print "No defined Site. Skip..." | |
565 | return None |
|
565 | return None | |
566 |
|
566 | |||
567 | nhei = self.heights.size |
|
567 | nhei = self.heights.size | |
568 | pt_intercep = numpy.zeros((nhei,2)) |
|
568 | pt_intercep = numpy.zeros((nhei,2)) | |
569 | nfields = 1 |
|
569 | nfields = 1 | |
570 |
|
570 | |||
571 | grid_res = 0.5 |
|
571 | grid_res = 0.5 | |
572 | nlon = int(numpy.int(maglimits[2] - maglimits[0])/grid_res + 1) |
|
572 | nlon = int(numpy.int(maglimits[2] - maglimits[0])/grid_res + 1) | |
573 | nlat = int(numpy.int(maglimits[3] - maglimits[1])/grid_res + 1) |
|
573 | nlat = int(numpy.int(maglimits[3] - maglimits[1])/grid_res + 1) | |
574 |
|
574 | |||
575 | location = numpy.zeros((nlon,nlat,2)) |
|
575 | location = numpy.zeros((nlon,nlat,2)) | |
576 | mlon = numpy.atleast_2d(numpy.arange(nlon)*grid_res + maglimits[0]) |
|
576 | mlon = numpy.atleast_2d(numpy.arange(nlon)*grid_res + maglimits[0]) | |
577 | mrep = numpy.atleast_2d(numpy.zeros(nlat) + 1) |
|
577 | mrep = numpy.atleast_2d(numpy.zeros(nlat) + 1) | |
578 | location0 = numpy.dot(mlon.transpose(),mrep) |
|
578 | location0 = numpy.dot(mlon.transpose(),mrep) | |
579 |
|
579 | |||
580 | mlat = numpy.atleast_2d(numpy.arange(nlat)*grid_res + maglimits[1]) |
|
580 | mlat = numpy.atleast_2d(numpy.arange(nlat)*grid_res + maglimits[1]) | |
581 | mrep = numpy.atleast_2d(numpy.zeros(nlon) + 1) |
|
581 | mrep = numpy.atleast_2d(numpy.zeros(nlon) + 1) | |
582 | location1 = numpy.dot(mrep.transpose(),mlat) |
|
582 | location1 = numpy.dot(mrep.transpose(),mlat) | |
583 |
|
583 | |||
584 | location[:,:,0] = location0 |
|
584 | location[:,:,0] = location0 | |
585 | location[:,:,1] = location1 |
|
585 | location[:,:,1] = location1 | |
586 |
|
586 | |||
587 | alpha = numpy.zeros((nlon,nlat,nhei)) |
|
587 | alpha = numpy.zeros((nlon,nlat,nhei)) | |
588 | rr = numpy.zeros((nlon,nlat,nhei,3)) |
|
588 | rr = numpy.zeros((nlon,nlat,nhei,3)) | |
589 | dcos = numpy.zeros((nlon,nlat,nhei,2)) |
|
589 | dcos = numpy.zeros((nlon,nlat,nhei,2)) | |
590 |
|
590 | |||
591 | global first_time |
|
591 | global first_time | |
592 |
|
592 | |||
593 | first_time = None |
|
593 | first_time = None | |
594 | for ilon in numpy.arange(nlon): |
|
594 | for ilon in numpy.arange(nlon): | |
595 | for ilat in numpy.arange(nlat): |
|
595 | for ilat in numpy.arange(nlat): | |
596 | outs = self.__bdotk(self.heights, |
|
596 | outs = self.__bdotk(self.heights, | |
597 | self.year + self.doy/366., |
|
597 | self.year + self.doy/366., | |
598 | coord_site[1], |
|
598 | coord_site[1], | |
599 | coord_site[0], |
|
599 | coord_site[0], | |
600 | coord_site[2], |
|
600 | coord_site[2], | |
601 | coord_site[1]+location[ilon,ilat,1], |
|
601 | coord_site[1]+location[ilon,ilat,1], | |
602 | location[ilon,ilat,0]*720./180.) |
|
602 | location[ilon,ilat,0]*720./180.) | |
603 |
|
603 | |||
604 | alpha[ilon, ilat,:] = outs[1] |
|
604 | alpha[ilon, ilat,:] = outs[1] | |
605 | rr[ilon, ilat,:,:] = outs[3] |
|
605 | rr[ilon, ilat,:,:] = outs[3] | |
606 |
|
606 | |||
607 | mrep = numpy.atleast_2d((numpy.zeros(nhei)+1)).transpose() |
|
607 | mrep = numpy.atleast_2d((numpy.zeros(nhei)+1)).transpose() | |
608 | tmp = outs[3]*numpy.dot(mrep,numpy.atleast_2d(x_ant)) |
|
608 | tmp = outs[3]*numpy.dot(mrep,numpy.atleast_2d(x_ant)) | |
609 | tmp = tmp.sum(axis=1) |
|
609 | tmp = tmp.sum(axis=1) | |
610 | dcos[ilon,ilat,:,0] = tmp/numpy.sqrt((outs[3]**2).sum(axis=1)) |
|
610 | dcos[ilon,ilat,:,0] = tmp/numpy.sqrt((outs[3]**2).sum(axis=1)) | |
611 |
|
611 | |||
612 | mrep = numpy.atleast_2d((numpy.zeros(nhei)+1)).transpose() |
|
612 | mrep = numpy.atleast_2d((numpy.zeros(nhei)+1)).transpose() | |
613 | tmp = outs[3]*numpy.dot(mrep,numpy.atleast_2d(y_ant)) |
|
613 | tmp = outs[3]*numpy.dot(mrep,numpy.atleast_2d(y_ant)) | |
614 | tmp = tmp.sum(axis=1) |
|
614 | tmp = tmp.sum(axis=1) | |
615 | dcos[ilon,ilat,:,1] = tmp/numpy.sqrt((outs[3]**2).sum(axis=1)) |
|
615 | dcos[ilon,ilat,:,1] = tmp/numpy.sqrt((outs[3]**2).sum(axis=1)) | |
616 |
|
616 | |||
617 | return dcos, alpha, nlon, nlat |
|
617 | return dcos, alpha, nlon, nlat | |
618 |
|
618 | |||
619 |
|
619 | |||
620 | def __bdotk(self,heights,tm,gdlat=-11.95,gdlon=-76.8667,gdalt=0.0,decd=-12.88, ham=-4.61666667): |
|
620 | def __bdotk(self,heights,tm,gdlat=-11.95,gdlon=-76.8667,gdalt=0.0,decd=-12.88, ham=-4.61666667): | |
621 |
|
621 | |||
622 | global first_time |
|
622 | global first_time | |
623 | # Mean Earth radius in Km WGS 84 |
|
623 | # Mean Earth radius in Km WGS 84 | |
624 | a_igrf = 6371.2 |
|
624 | a_igrf = 6371.2 | |
625 |
|
625 | |||
626 | bk = numpy.zeros(heights.size) |
|
626 | bk = numpy.zeros(heights.size) | |
627 | alpha = numpy.zeros(heights.size) |
|
627 | alpha = numpy.zeros(heights.size) | |
628 | bfm = numpy.zeros(heights.size) |
|
628 | bfm = numpy.zeros(heights.size) | |
629 | rr = numpy.zeros((heights.size,3)) |
|
629 | rr = numpy.zeros((heights.size,3)) | |
630 | rgc = numpy.zeros((heights.size,3)) |
|
630 | rgc = numpy.zeros((heights.size,3)) | |
631 |
|
631 | |||
632 |
ObjGeodetic = |
|
632 | ObjGeodetic = Geodetic(gdlat,gdalt) | |
633 | [gclat,gcalt] = ObjGeodetic.change2geocentric() |
|
633 | [gclat,gcalt] = ObjGeodetic.change2geocentric() | |
634 |
|
634 | |||
635 | gclat = gclat*numpy.pi/180. |
|
635 | gclat = gclat*numpy.pi/180. | |
636 | gclon = gdlon*numpy.pi/180. |
|
636 | gclon = gdlon*numpy.pi/180. | |
637 |
|
637 | |||
638 | # Antenna position from center of Earth |
|
638 | # Antenna position from center of Earth | |
639 | ca_vector = [numpy.cos(gclat)*numpy.cos(gclon),numpy.cos(gclat)*numpy.sin(gclon),numpy.sin(gclat)] |
|
639 | ca_vector = [numpy.cos(gclat)*numpy.cos(gclon),numpy.cos(gclat)*numpy.sin(gclon),numpy.sin(gclat)] | |
640 | ca_vector = gcalt*numpy.array(ca_vector) |
|
640 | ca_vector = gcalt*numpy.array(ca_vector) | |
641 |
|
641 | |||
642 | dec = decd*numpy.pi/180. |
|
642 | dec = decd*numpy.pi/180. | |
643 |
|
643 | |||
644 | # K vector respect to the center of earth. |
|
644 | # K vector respect to the center of earth. | |
645 | klon = gclon + ham*numpy.pi/720. |
|
645 | klon = gclon + ham*numpy.pi/720. | |
646 | k_vector = [numpy.cos(dec)*numpy.cos(klon),numpy.cos(dec)*numpy.sin(klon),numpy.sin(dec)] |
|
646 | k_vector = [numpy.cos(dec)*numpy.cos(klon),numpy.cos(dec)*numpy.sin(klon),numpy.sin(dec)] | |
647 | k_vector = numpy.array(k_vector) |
|
647 | k_vector = numpy.array(k_vector) | |
648 |
|
648 | |||
649 | for ih in numpy.arange(heights.size): |
|
649 | for ih in numpy.arange(heights.size): | |
650 | # Vector from Earth's center to volume of interest |
|
650 | # Vector from Earth's center to volume of interest | |
651 | rr[ih,:] = k_vector*heights[ih] |
|
651 | rr[ih,:] = k_vector*heights[ih] | |
652 | cv_vector = numpy.squeeze(ca_vector) + rr[ih,:] |
|
652 | cv_vector = numpy.squeeze(ca_vector) + rr[ih,:] | |
653 |
|
653 | |||
654 | cv_gcalt = numpy.sqrt(numpy.sum(cv_vector**2.)) |
|
654 | cv_gcalt = numpy.sqrt(numpy.sum(cv_vector**2.)) | |
655 | cvxy = numpy.sqrt(numpy.sum(cv_vector[0:2]**2.)) |
|
655 | cvxy = numpy.sqrt(numpy.sum(cv_vector[0:2]**2.)) | |
656 |
|
656 | |||
657 | radial = cv_vector/cv_gcalt |
|
657 | radial = cv_vector/cv_gcalt | |
658 | east = numpy.array([-1*cv_vector[1],cv_vector[0],0])/cvxy |
|
658 | east = numpy.array([-1*cv_vector[1],cv_vector[0],0])/cvxy | |
659 | comp1 = east[1]*radial[2] - radial[1]*east[2] |
|
659 | comp1 = east[1]*radial[2] - radial[1]*east[2] | |
660 | comp2 = east[2]*radial[0] - radial[2]*east[0] |
|
660 | comp2 = east[2]*radial[0] - radial[2]*east[0] | |
661 | comp3 = east[0]*radial[1] - radial[0]*east[1] |
|
661 | comp3 = east[0]*radial[1] - radial[0]*east[1] | |
662 | north = -1*numpy.array([comp1, comp2, comp3]) |
|
662 | north = -1*numpy.array([comp1, comp2, comp3]) | |
663 |
|
663 | |||
664 | rr_k = cv_vector - numpy.squeeze(ca_vector) |
|
664 | rr_k = cv_vector - numpy.squeeze(ca_vector) | |
665 | u_rr = rr_k/numpy.sqrt(numpy.sum(rr_k**2.)) |
|
665 | u_rr = rr_k/numpy.sqrt(numpy.sum(rr_k**2.)) | |
666 |
|
666 | |||
667 | cv_gclat = numpy.arctan2(cv_vector[2],cvxy) |
|
667 | cv_gclat = numpy.arctan2(cv_vector[2],cvxy) | |
668 | cv_gclon = numpy.arctan2(cv_vector[1],cv_vector[0]) |
|
668 | cv_gclon = numpy.arctan2(cv_vector[1],cv_vector[0]) | |
669 |
|
669 | |||
670 | bhei = cv_gcalt-a_igrf |
|
670 | bhei = cv_gcalt-a_igrf | |
671 | blat = cv_gclat*180./numpy.pi |
|
671 | blat = cv_gclat*180./numpy.pi | |
672 | blon = cv_gclon*180./numpy.pi |
|
672 | blon = cv_gclon*180./numpy.pi | |
673 | bfield = self.__igrfkudeki(bhei,tm,blat,blon) |
|
673 | bfield = self.__igrfkudeki(bhei,tm,blat,blon) | |
674 |
|
674 | |||
675 | B = (bfield[0]*north + bfield[1]*east - bfield[2]*radial)*1.0e-5 |
|
675 | B = (bfield[0]*north + bfield[1]*east - bfield[2]*radial)*1.0e-5 | |
676 |
|
676 | |||
677 | bfm[ih] = numpy.sqrt(numpy.sum(B**2.)) #module |
|
677 | bfm[ih] = numpy.sqrt(numpy.sum(B**2.)) #module | |
678 | bk[ih] = numpy.sum(u_rr*B) |
|
678 | bk[ih] = numpy.sum(u_rr*B) | |
679 | alpha[ih] = numpy.arccos(bk[ih]/bfm[ih])*180/numpy.pi |
|
679 | alpha[ih] = numpy.arccos(bk[ih]/bfm[ih])*180/numpy.pi | |
680 | rgc[ih,:] = numpy.array([cv_gclon, cv_gclat, cv_gcalt]) |
|
680 | rgc[ih,:] = numpy.array([cv_gclon, cv_gclat, cv_gcalt]) | |
681 |
|
681 | |||
682 | return bk, alpha, bfm, rr, rgc |
|
682 | return bk, alpha, bfm, rr, rgc | |
683 |
|
683 | |||
684 |
|
684 | |||
685 | def __igrfkudeki(self,heights,time,latitude,longitude,ae=6371.2): |
|
685 | def __igrfkudeki(self,heights,time,latitude,longitude,ae=6371.2): | |
686 | """ |
|
686 | """ | |
687 | __igrfkudeki calculates the International Geomagnetic Reference Field for given in- |
|
687 | __igrfkudeki calculates the International Geomagnetic Reference Field for given in- | |
688 | put conditions based on IGRF2005 coefficients. |
|
688 | put conditions based on IGRF2005 coefficients. | |
689 |
|
689 | |||
690 | Parameters |
|
690 | Parameters | |
691 | ---------- |
|
691 | ---------- | |
692 | heights = Scalar or vector giving the height above the Earth of the point in ques- |
|
692 | heights = Scalar or vector giving the height above the Earth of the point in ques- | |
693 | tion in kilometers. |
|
693 | tion in kilometers. | |
694 | time = Scalar or vector giving the decimal year of time in question (e.g. 1991.2). |
|
694 | time = Scalar or vector giving the decimal year of time in question (e.g. 1991.2). | |
695 | latitude = Latitude of point in question in decimal degrees. Scalar or vector. |
|
695 | latitude = Latitude of point in question in decimal degrees. Scalar or vector. | |
696 | longitude = Longitude of point in question in decimal degrees. Scalar or vector. |
|
696 | longitude = Longitude of point in question in decimal degrees. Scalar or vector. | |
697 | ae = |
|
697 | ae = | |
698 | first_time = |
|
698 | first_time = | |
699 |
|
699 | |||
700 | Return |
|
700 | Return | |
701 | ------ |
|
701 | ------ | |
702 | bn = |
|
702 | bn = | |
703 | be = |
|
703 | be = | |
704 | bd = |
|
704 | bd = | |
705 | bmod = |
|
705 | bmod = | |
706 | balpha = |
|
706 | balpha = | |
707 | first_time = |
|
707 | first_time = | |
708 |
|
708 | |||
709 | Modification History |
|
709 | Modification History | |
710 | -------------------- |
|
710 | -------------------- | |
711 | Converted to Python by Freddy R. Galindo, ROJ, 03 October 2009. |
|
711 | Converted to Python by Freddy R. Galindo, ROJ, 03 October 2009. | |
712 | """ |
|
712 | """ | |
713 |
|
713 | |||
714 | global first_time |
|
714 | global first_time | |
715 | global gs, hs, nvec, mvec, maxcoef |
|
715 | global gs, hs, nvec, mvec, maxcoef | |
716 |
|
716 | |||
717 | heights = numpy.atleast_1d(heights) |
|
717 | heights = numpy.atleast_1d(heights) | |
718 | time = numpy.atleast_1d(time) |
|
718 | time = numpy.atleast_1d(time) | |
719 | latitude = numpy.atleast_1d(latitude) |
|
719 | latitude = numpy.atleast_1d(latitude) | |
720 | longitude = numpy.atleast_1d(longitude) |
|
720 | longitude = numpy.atleast_1d(longitude) | |
721 |
|
721 | |||
722 | if numpy.max(latitude)==90: |
|
722 | if numpy.max(latitude)==90: | |
723 | # print "Field calculations are not supported at geographic poles" |
|
723 | # print "Field calculations are not supported at geographic poles" | |
724 | pass |
|
724 | pass | |
725 |
|
725 | |||
726 | # output arrays |
|
726 | # output arrays | |
727 | bn = numpy.zeros(heights.size) |
|
727 | bn = numpy.zeros(heights.size) | |
728 | be = numpy.zeros(heights.size) |
|
728 | be = numpy.zeros(heights.size) | |
729 | bd = numpy.zeros(heights.size) |
|
729 | bd = numpy.zeros(heights.size) | |
730 |
|
730 | |||
731 | if first_time==None:first_time=0 |
|
731 | if first_time==None:first_time=0 | |
732 |
|
732 | |||
733 | time0 = time[0] |
|
733 | time0 = time[0] | |
734 | if time!=first_time: |
|
734 | if time!=first_time: | |
735 | #print "Getting coefficients for", time0 |
|
735 | #print "Getting coefficients for", time0 | |
736 | [periods,g,h ] = self.__readIGRFcoeff() |
|
736 | [periods,g,h ] = self.__readIGRFcoeff() | |
737 | top_year = numpy.max(periods) |
|
737 | top_year = numpy.max(periods) | |
738 | nperiod = (top_year - 1900)/5 + 1 |
|
738 | nperiod = (top_year - 1900)/5 + 1 | |
739 |
|
739 | |||
740 | maxcoef = 10 |
|
740 | maxcoef = 10 | |
741 | if time0>=2000:maxcoef = 12 |
|
741 | if time0>=2000:maxcoef = 12 | |
742 |
|
742 | |||
743 |
|
743 | |||
744 | # Normalization array for Schmidt fucntions |
|
744 | # Normalization array for Schmidt fucntions | |
745 | multer = numpy.zeros((2+maxcoef,1+maxcoef)) + 1 |
|
745 | multer = numpy.zeros((2+maxcoef,1+maxcoef)) + 1 | |
746 | for cn in (numpy.arange(maxcoef)+1): |
|
746 | for cn in (numpy.arange(maxcoef)+1): | |
747 | for rm in (numpy.arange(cn)+1): |
|
747 | for rm in (numpy.arange(cn)+1): | |
748 | tmp = numpy.arange(2*rm) + cn - rm + 1. |
|
748 | tmp = numpy.arange(2*rm) + cn - rm + 1. | |
749 | multer[rm+1,cn] = ((-1.)**rm)*numpy.sqrt(2./tmp.prod()) |
|
749 | multer[rm+1,cn] = ((-1.)**rm)*numpy.sqrt(2./tmp.prod()) | |
750 |
|
750 | |||
751 | schmidt = multer[1:,1:].transpose() |
|
751 | schmidt = multer[1:,1:].transpose() | |
752 |
|
752 | |||
753 | # n and m arrays |
|
753 | # n and m arrays | |
754 | nvec = numpy.atleast_2d(numpy.arange(maxcoef)+2) |
|
754 | nvec = numpy.atleast_2d(numpy.arange(maxcoef)+2) | |
755 | mvec = numpy.atleast_2d(numpy.arange(maxcoef+1)).transpose() |
|
755 | mvec = numpy.atleast_2d(numpy.arange(maxcoef+1)).transpose() | |
756 |
|
756 | |||
757 | # Time adjusted igrf g and h with Schmidt normalization |
|
757 | # Time adjusted igrf g and h with Schmidt normalization | |
758 | # IGRF coefficient arrays: g0(n,m), n=1, maxcoeff,m=0, maxcoeff, ... |
|
758 | # IGRF coefficient arrays: g0(n,m), n=1, maxcoeff,m=0, maxcoeff, ... | |
759 | if time0<top_year: |
|
759 | if time0<top_year: | |
760 | dtime = (time0 - 1900) % 5 |
|
760 | dtime = (time0 - 1900) % 5 | |
761 | ntime = (time0 - 1900 - dtime)/5 |
|
761 | ntime = (time0 - 1900 - dtime)/5 | |
762 | else: |
|
762 | else: | |
763 | # Estimating coefficients for times > top_year |
|
763 | # Estimating coefficients for times > top_year | |
764 | dtime = (time0 - top_year) + 5 |
|
764 | dtime = (time0 - top_year) + 5 | |
765 | ntime = g[:,0,0].size - 2 |
|
765 | ntime = g[:,0,0].size - 2 | |
766 |
|
766 | |||
767 | g0 = g[ntime,1:maxcoef+1,:maxcoef+1] |
|
767 | g0 = g[ntime,1:maxcoef+1,:maxcoef+1] | |
768 | h0 = h[ntime,1:maxcoef+1,:maxcoef+1] |
|
768 | h0 = h[ntime,1:maxcoef+1,:maxcoef+1] | |
769 | gdot = g[ntime+1,1:maxcoef+1,:maxcoef+1]-g[ntime,1:maxcoef+1,:maxcoef+1] |
|
769 | gdot = g[ntime+1,1:maxcoef+1,:maxcoef+1]-g[ntime,1:maxcoef+1,:maxcoef+1] | |
770 | hdot = h[ntime+1,1:maxcoef+1,:maxcoef+1]-h[ntime,1:maxcoef+1,:maxcoef+1] |
|
770 | hdot = h[ntime+1,1:maxcoef+1,:maxcoef+1]-h[ntime,1:maxcoef+1,:maxcoef+1] | |
771 | gs = (g0 + dtime*(gdot/5.))*schmidt[:maxcoef,0:maxcoef+1] |
|
771 | gs = (g0 + dtime*(gdot/5.))*schmidt[:maxcoef,0:maxcoef+1] | |
772 | hs = (h0 + dtime*(hdot/5.))*schmidt[:maxcoef,0:maxcoef+1] |
|
772 | hs = (h0 + dtime*(hdot/5.))*schmidt[:maxcoef,0:maxcoef+1] | |
773 |
|
773 | |||
774 | first_time = time0 |
|
774 | first_time = time0 | |
775 |
|
775 | |||
776 | for ii in numpy.arange(heights.size): |
|
776 | for ii in numpy.arange(heights.size): | |
777 | # Height dependence array rad = (ae/(ae+height))**(n+3) |
|
777 | # Height dependence array rad = (ae/(ae+height))**(n+3) | |
778 | rad = numpy.atleast_2d((ae/(ae + heights[ii]))**(nvec+1)) |
|
778 | rad = numpy.atleast_2d((ae/(ae + heights[ii]))**(nvec+1)) | |
779 |
|
779 | |||
780 | # Sin and Cos of m times longitude phi arrays |
|
780 | # Sin and Cos of m times longitude phi arrays | |
781 | mphi = mvec*longitude[ii]*numpy.pi/180. |
|
781 | mphi = mvec*longitude[ii]*numpy.pi/180. | |
782 | cosmphi = numpy.atleast_2d(numpy.cos(mphi)) |
|
782 | cosmphi = numpy.atleast_2d(numpy.cos(mphi)) | |
783 | sinmphi = numpy.atleast_2d(numpy.sin(mphi)) |
|
783 | sinmphi = numpy.atleast_2d(numpy.sin(mphi)) | |
784 |
|
784 | |||
785 | # Cos of colatitude theta |
|
785 | # Cos of colatitude theta | |
786 | c = numpy.cos((90 - latitude[ii])*numpy.pi/180.) |
|
786 | c = numpy.cos((90 - latitude[ii])*numpy.pi/180.) | |
787 |
|
787 | |||
788 | # Legendre functions p(n,m|c) |
|
788 | # Legendre functions p(n,m|c) | |
789 | [p,dp]= scipy.special.lpmn(maxcoef+1,maxcoef+1,c) |
|
789 | [p,dp]= scipy.special.lpmn(maxcoef+1,maxcoef+1,c) | |
790 | p = p[:,:-1].transpose() |
|
790 | p = p[:,:-1].transpose() | |
791 | s = numpy.sqrt((1. - c)*(1 + c)) |
|
791 | s = numpy.sqrt((1. - c)*(1 + c)) | |
792 |
|
792 | |||
793 | # Generate derivative array dpdtheta = -s*dpdc |
|
793 | # Generate derivative array dpdtheta = -s*dpdc | |
794 | dpdtheta = c*p/s |
|
794 | dpdtheta = c*p/s | |
795 | for m in numpy.arange(maxcoef+2): dpdtheta[:,m] = m*dpdtheta[:,m] |
|
795 | for m in numpy.arange(maxcoef+2): dpdtheta[:,m] = m*dpdtheta[:,m] | |
796 | dpdtheta = dpdtheta + numpy.roll(p,-1,axis=1) |
|
796 | dpdtheta = dpdtheta + numpy.roll(p,-1,axis=1) | |
797 |
|
797 | |||
798 | # Extracting arrays required for field calculations |
|
798 | # Extracting arrays required for field calculations | |
799 | p = p[1:maxcoef+1,:maxcoef+1] |
|
799 | p = p[1:maxcoef+1,:maxcoef+1] | |
800 | dpdtheta = dpdtheta[1:maxcoef+1,:maxcoef+1] |
|
800 | dpdtheta = dpdtheta[1:maxcoef+1,:maxcoef+1] | |
801 |
|
801 | |||
802 | # Weigh p and dpdtheta with gs and hs coefficients. |
|
802 | # Weigh p and dpdtheta with gs and hs coefficients. | |
803 | gp = gs*p |
|
803 | gp = gs*p | |
804 | hp = hs*p |
|
804 | hp = hs*p | |
805 | gdpdtheta = gs*dpdtheta |
|
805 | gdpdtheta = gs*dpdtheta | |
806 | hdpdtheta = hs*dpdtheta |
|
806 | hdpdtheta = hs*dpdtheta | |
807 | # Calcultate field components |
|
807 | # Calcultate field components | |
808 | matrix0 = numpy.dot(gdpdtheta,cosmphi) |
|
808 | matrix0 = numpy.dot(gdpdtheta,cosmphi) | |
809 | matrix1 = numpy.dot(hdpdtheta,sinmphi) |
|
809 | matrix1 = numpy.dot(hdpdtheta,sinmphi) | |
810 | bn[ii] = numpy.dot(rad,(matrix0 + matrix1)) |
|
810 | bn[ii] = numpy.dot(rad,(matrix0 + matrix1)) | |
811 | matrix0 = numpy.dot(hp,(mvec*cosmphi)) |
|
811 | matrix0 = numpy.dot(hp,(mvec*cosmphi)) | |
812 | matrix1 = numpy.dot(gp,(mvec*sinmphi)) |
|
812 | matrix1 = numpy.dot(gp,(mvec*sinmphi)) | |
813 | be[ii] = numpy.dot((-1*rad),((matrix0 - matrix1)/s)) |
|
813 | be[ii] = numpy.dot((-1*rad),((matrix0 - matrix1)/s)) | |
814 | matrix0 = numpy.dot(gp,cosmphi) |
|
814 | matrix0 = numpy.dot(gp,cosmphi) | |
815 | matrix1 = numpy.dot(hp,sinmphi) |
|
815 | matrix1 = numpy.dot(hp,sinmphi) | |
816 | bd[ii] = numpy.dot((-1*nvec*rad),(matrix0 + matrix1)) |
|
816 | bd[ii] = numpy.dot((-1*nvec*rad),(matrix0 + matrix1)) | |
817 |
|
817 | |||
818 | bmod = numpy.sqrt(bn**2. + be**2. + bd**2.) |
|
818 | bmod = numpy.sqrt(bn**2. + be**2. + bd**2.) | |
819 | btheta = numpy.arctan(bd/numpy.sqrt(be**2. + bn**2.))*180/numpy.pi |
|
819 | btheta = numpy.arctan(bd/numpy.sqrt(be**2. + bn**2.))*180/numpy.pi | |
820 | balpha = numpy.arctan(be/bn)*180./numpy.pi |
|
820 | balpha = numpy.arctan(be/bn)*180./numpy.pi | |
821 |
|
821 | |||
822 | #bn : north |
|
822 | #bn : north | |
823 | #be : east |
|
823 | #be : east | |
824 | #bn : radial |
|
824 | #bn : radial | |
825 | #bmod : module |
|
825 | #bmod : module | |
826 |
|
826 | |||
827 |
|
827 | |||
828 | return bn, be, bd, bmod, btheta, balpha |
|
828 | return bn, be, bd, bmod, btheta, balpha | |
829 |
|
829 | |||
830 | def str2num(self, datum): |
|
830 | def str2num(self, datum): | |
831 | try: |
|
831 | try: | |
832 | return int(datum) |
|
832 | return int(datum) | |
833 | except: |
|
833 | except: | |
834 | try: |
|
834 | try: | |
835 | return float(datum) |
|
835 | return float(datum) | |
836 | except: |
|
836 | except: | |
837 | return datum |
|
837 | return datum | |
838 |
|
838 | |||
839 | def __readIGRFfile(self, filename): |
|
839 | def __readIGRFfile(self, filename): | |
840 | list_years=[] |
|
840 | list_years=[] | |
841 | for i in range(1,24): |
|
841 | for i in range(1,24): | |
842 | list_years.append(1895.0 + i*5) |
|
842 | list_years.append(1895.0 + i*5) | |
843 |
|
843 | |||
844 | epochs=list_years |
|
844 | epochs=list_years | |
845 | epochs.append(epochs[-1]+5) |
|
845 | epochs.append(epochs[-1]+5) | |
846 | nepochs = numpy.shape(epochs) |
|
846 | nepochs = numpy.shape(epochs) | |
847 |
|
847 | |||
848 | gg = numpy.zeros((13,14,nepochs[0]),dtype=float) |
|
848 | gg = numpy.zeros((13,14,nepochs[0]),dtype=float) | |
849 | hh = numpy.zeros((13,14,nepochs[0]),dtype=float) |
|
849 | hh = numpy.zeros((13,14,nepochs[0]),dtype=float) | |
850 |
|
850 | |||
851 | coeffs_file=open(filename) |
|
851 | coeffs_file=open(filename) | |
852 | lines=coeffs_file.readlines() |
|
852 | lines=coeffs_file.readlines() | |
853 |
|
853 | |||
854 | coeffs_file.close() |
|
854 | coeffs_file.close() | |
855 |
|
855 | |||
856 | for line in lines: |
|
856 | for line in lines: | |
857 | items = line.split() |
|
857 | items = line.split() | |
858 | g_h = items[0] |
|
858 | g_h = items[0] | |
859 | n = self.str2num(items[1]) |
|
859 | n = self.str2num(items[1]) | |
860 | m = self.str2num(items[2]) |
|
860 | m = self.str2num(items[2]) | |
861 |
|
861 | |||
862 | coeffs = items[3:] |
|
862 | coeffs = items[3:] | |
863 |
|
863 | |||
864 | for i in range(len(coeffs)-1): |
|
864 | for i in range(len(coeffs)-1): | |
865 | coeffs[i] = self.str2num(coeffs[i]) |
|
865 | coeffs[i] = self.str2num(coeffs[i]) | |
866 |
|
866 | |||
867 | #coeffs = numpy.array(coeffs) |
|
867 | #coeffs = numpy.array(coeffs) | |
868 | ncoeffs = numpy.shape(coeffs)[0] |
|
868 | ncoeffs = numpy.shape(coeffs)[0] | |
869 |
|
869 | |||
870 | if g_h == 'g': |
|
870 | if g_h == 'g': | |
871 | # print n," g ",m |
|
871 | # print n," g ",m | |
872 | gg[n-1,m,:]=coeffs |
|
872 | gg[n-1,m,:]=coeffs | |
873 | elif g_h=='h': |
|
873 | elif g_h=='h': | |
874 | # print n," h ",m |
|
874 | # print n," h ",m | |
875 | hh[n-1,m,:]=coeffs |
|
875 | hh[n-1,m,:]=coeffs | |
876 | # else : |
|
876 | # else : | |
877 | # continue |
|
877 | # continue | |
878 |
|
878 | |||
879 | # Ultimo Reordenamiento para almacenar . |
|
879 | # Ultimo Reordenamiento para almacenar . | |
880 | gg[:,:,nepochs[0]-1] = gg[:,:,nepochs[0]-2] + 5*gg[:,:,nepochs[0]-1] |
|
880 | gg[:,:,nepochs[0]-1] = gg[:,:,nepochs[0]-2] + 5*gg[:,:,nepochs[0]-1] | |
881 | hh[:,:,nepochs[0]-1] = hh[:,:,nepochs[0]-2] + 5*hh[:,:,nepochs[0]-1] |
|
881 | hh[:,:,nepochs[0]-1] = hh[:,:,nepochs[0]-2] + 5*hh[:,:,nepochs[0]-1] | |
882 |
|
882 | |||
883 | # return numpy.array([gg,hh]) |
|
883 | # return numpy.array([gg,hh]) | |
884 | periods = numpy.array(epochs) |
|
884 | periods = numpy.array(epochs) | |
885 | g = gg |
|
885 | g = gg | |
886 | h = hh |
|
886 | h = hh | |
887 | return periods, g, h |
|
887 | return periods, g, h | |
888 |
|
888 | |||
889 |
|
889 | |||
890 | def __readIGRFcoeff(self,filename="igrf10coeffs.dat"): |
|
890 | def __readIGRFcoeff(self,filename="igrf10coeffs.dat"): | |
891 | """ |
|
891 | """ | |
892 | __readIGRFcoeff reads the coefficients from a binary file which is located in the |
|
892 | __readIGRFcoeff reads the coefficients from a binary file which is located in the | |
893 | folder "resource." |
|
893 | folder "resource." | |
894 |
|
894 | |||
895 | Parameter |
|
895 | Parameter | |
896 | --------- |
|
896 | --------- | |
897 | filename = A string to specify the name of the file which contains thec coeffs. The |
|
897 | filename = A string to specify the name of the file which contains thec coeffs. The | |
898 | default value is "igrf10coeffs.dat" |
|
898 | default value is "igrf10coeffs.dat" | |
899 |
|
899 | |||
900 | Return |
|
900 | Return | |
901 | ------ |
|
901 | ------ | |
902 | periods = A lineal array giving... |
|
902 | periods = A lineal array giving... | |
903 | g1 = |
|
903 | g1 = | |
904 | h1 = |
|
904 | h1 = | |
905 |
|
905 | |||
906 | Modification History |
|
906 | Modification History | |
907 | -------------------- |
|
907 | -------------------- | |
908 | Converted to Python by Freddy R. Galindo, ROJ, 03 October 2009. |
|
908 | Converted to Python by Freddy R. Galindo, ROJ, 03 October 2009. | |
909 | """ |
|
909 | """ | |
910 |
|
910 | |||
911 | # # igrfile = sys.path[-1] + os.sep + "resource" + os.sep + filename |
|
911 | # # igrfile = sys.path[-1] + os.sep + "resource" + os.sep + filename | |
912 | # igrfile = os.path.join('./resource',filename) |
|
912 | # igrfile = os.path.join('./resource',filename) | |
913 | # f = open(igrfile,'rb') |
|
913 | # f = open(igrfile,'rb') | |
914 | # #f = open(os.getcwd() + os.sep + "resource" + os.sep + filename,'rb') |
|
914 | # #f = open(os.getcwd() + os.sep + "resource" + os.sep + filename,'rb') | |
915 | # |
|
915 | # | |
916 | # # Reading SkyNoise Power (lineal scale) |
|
916 | # # Reading SkyNoise Power (lineal scale) | |
917 | # periods = numpy.fromfile(f,numpy.dtype([('var','<f4')]),23) |
|
917 | # periods = numpy.fromfile(f,numpy.dtype([('var','<f4')]),23) | |
918 | # periods = periods['var'] |
|
918 | # periods = periods['var'] | |
919 | # |
|
919 | # | |
920 | # g = numpy.fromfile(f,numpy.dtype([('var','<f8')]),23*14*14) |
|
920 | # g = numpy.fromfile(f,numpy.dtype([('var','<f8')]),23*14*14) | |
921 | # g = g['var'].reshape((14,14,23)).transpose() |
|
921 | # g = g['var'].reshape((14,14,23)).transpose() | |
922 | # |
|
922 | # | |
923 | # h = numpy.fromfile(f,numpy.dtype([('var','<f8')]),23*14*14) |
|
923 | # h = numpy.fromfile(f,numpy.dtype([('var','<f8')]),23*14*14) | |
924 | # h = h['var'].reshape((14,14,23)).transpose() |
|
924 | # h = h['var'].reshape((14,14,23)).transpose() | |
925 | # |
|
925 | # | |
926 | # f.close() |
|
926 | # f.close() | |
927 | base_path = os.path.dirname(os.path.abspath(__file__)) |
|
927 | base_path = os.path.dirname(os.path.abspath(__file__)) | |
928 | filename = os.path.join(base_path,"resource","igrf11coeffs.txt") |
|
928 | filename = os.path.join(base_path,"resource","igrf11coeffs.txt") | |
929 |
|
929 | |||
930 | period_v, g_v, h_v = self.__readIGRFfile(filename) |
|
930 | period_v, g_v, h_v = self.__readIGRFfile(filename) | |
931 | g2 = numpy.zeros((14,14,24)) |
|
931 | g2 = numpy.zeros((14,14,24)) | |
932 | h2 = numpy.zeros((14,14,24)) |
|
932 | h2 = numpy.zeros((14,14,24)) | |
933 | g2[1:14,:,:] = g_v |
|
933 | g2[1:14,:,:] = g_v | |
934 | h2[1:14,:,:] = h_v |
|
934 | h2[1:14,:,:] = h_v | |
935 |
|
935 | |||
936 | g = numpy.transpose(g2, (2,0,1)) |
|
936 | g = numpy.transpose(g2, (2,0,1)) | |
937 | h = numpy.transpose(h2, (2,0,1)) |
|
937 | h = numpy.transpose(h2, (2,0,1)) | |
938 | periods = period_v.copy() |
|
938 | periods = period_v.copy() | |
939 |
|
939 | |||
940 | return periods, g, h |
|
940 | return periods, g, h | |
941 |
|
941 | |||
942 | def rotvector(self,vector,axis=1,ang=0): |
|
942 | def rotvector(self,vector,axis=1,ang=0): | |
943 | """ |
|
943 | """ | |
944 | rotvector function returns the new vector generated rotating the rectagular coords. |
|
944 | rotvector function returns the new vector generated rotating the rectagular coords. | |
945 |
|
945 | |||
946 | Parameters |
|
946 | Parameters | |
947 | ---------- |
|
947 | ---------- | |
948 | vector = A lineal 3-elements array (x,y,z). |
|
948 | vector = A lineal 3-elements array (x,y,z). | |
949 | axis = A integer to specify the axis used to rotate the coord systems. The default |
|
949 | axis = A integer to specify the axis used to rotate the coord systems. The default | |
950 | value is 1. |
|
950 | value is 1. | |
951 | axis = 1 -> Around "x" |
|
951 | axis = 1 -> Around "x" | |
952 | axis = 2 -> Around "y" |
|
952 | axis = 2 -> Around "y" | |
953 | axis = 3 -> Around "z" |
|
953 | axis = 3 -> Around "z" | |
954 | ang = Angle of rotation (in radians). The default value is zero. |
|
954 | ang = Angle of rotation (in radians). The default value is zero. | |
955 |
|
955 | |||
956 | Return |
|
956 | Return | |
957 | ------ |
|
957 | ------ | |
958 | rotvector = A lineal array of 3 elements giving the new coordinates. |
|
958 | rotvector = A lineal array of 3 elements giving the new coordinates. | |
959 |
|
959 | |||
960 | Modification History |
|
960 | Modification History | |
961 | -------------------- |
|
961 | -------------------- | |
962 | Converted to Python by Freddy R. Galindo, ROJ, 01 October 2009. |
|
962 | Converted to Python by Freddy R. Galindo, ROJ, 01 October 2009. | |
963 | """ |
|
963 | """ | |
964 |
|
964 | |||
965 | if axis==1: |
|
965 | if axis==1: | |
966 | t = [[1,0,0],[0,numpy.cos(ang),numpy.sin(ang)],[0,-numpy.sin(ang),numpy.cos(ang)]] |
|
966 | t = [[1,0,0],[0,numpy.cos(ang),numpy.sin(ang)],[0,-numpy.sin(ang),numpy.cos(ang)]] | |
967 | elif axis==2: |
|
967 | elif axis==2: | |
968 | t = [[numpy.cos(ang),0,-numpy.sin(ang)],[0,1,0],[numpy.sin(ang),0,numpy.cos(ang)]] |
|
968 | t = [[numpy.cos(ang),0,-numpy.sin(ang)],[0,1,0],[numpy.sin(ang),0,numpy.cos(ang)]] | |
969 | elif axis==3: |
|
969 | elif axis==3: | |
970 | t = [[numpy.cos(ang),numpy.sin(ang),0],[-numpy.sin(ang),numpy.cos(ang),0],[0,0,1]] |
|
970 | t = [[numpy.cos(ang),numpy.sin(ang),0],[-numpy.sin(ang),numpy.cos(ang),0],[0,0,1]] | |
971 |
|
971 | |||
972 | rotvector = numpy.array(numpy.dot(numpy.array(t),numpy.array(vector))) |
|
972 | rotvector = numpy.array(numpy.dot(numpy.array(t),numpy.array(vector))) | |
973 |
|
973 | |||
974 | return rotvector |
|
974 | return rotvector | |
975 |
|
975 | |||
976 |
|
976 | |||
977 | class overJroShow: |
|
977 | class overJroShow: | |
978 |
|
978 | |||
979 | # __serverdocspath = '/usr/local/www/htdocs' |
|
979 | # __serverdocspath = '/usr/local/www/htdocs' | |
980 | # __tmpDir = 'overJro/tempReports' |
|
980 | # __tmpDir = 'overJro/tempReports' | |
981 | # __serverdocspath = '/Users/dsuarez/Pictures' |
|
981 | # __serverdocspath = '/Users/dsuarez/Pictures' | |
982 | # __tmpDir = 'overjro' |
|
982 | # __tmpDir = 'overjro' | |
983 | __serverdocspath = '' |
|
983 | __serverdocspath = '' | |
984 | __tmpDir = '' |
|
984 | __tmpDir = '' | |
985 |
|
985 | |||
986 | def __init__(self, title=''): |
|
986 | def __init__(self, title=''): | |
987 | self.year = None |
|
987 | self.year = None | |
988 | self.month = None |
|
988 | self.month = None | |
989 | self.dom = None |
|
989 | self.dom = None | |
990 | self.pattern = None |
|
990 | self.pattern = None | |
991 | self.maxphi = None |
|
991 | self.maxphi = None | |
992 | self.heights = None |
|
992 | self.heights = None | |
993 | self.filename = None |
|
993 | self.filename = None | |
994 | self.showType = None |
|
994 | self.showType = None | |
995 | self.path = None |
|
995 | self.path = None | |
996 | self.objects = None |
|
996 | self.objects = None | |
997 | self.nptsx = 101 |
|
997 | self.nptsx = 101 | |
998 | self.nptsy = 101 |
|
998 | self.nptsy = 101 | |
999 | self.fftopt = 0 |
|
999 | self.fftopt = 0 | |
1000 | self.site = 1 |
|
1000 | self.site = 1 | |
1001 | self.dcosx = 1 |
|
1001 | self.dcosx = 1 | |
1002 | self.dcosy = 1 |
|
1002 | self.dcosy = 1 | |
1003 | self.dcosxrange = None |
|
1003 | self.dcosxrange = None | |
1004 | self.dcosyrange = None |
|
1004 | self.dcosyrange = None | |
1005 | self.maxha_min= 0. |
|
1005 | self.maxha_min= 0. | |
1006 | self.show_object = None |
|
1006 | self.show_object = None | |
1007 | self.dcosx_mag = None |
|
1007 | self.dcosx_mag = None | |
1008 | self.dcosy_mag = None |
|
1008 | self.dcosy_mag = None | |
1009 | self.ha_mag = None |
|
1009 | self.ha_mag = None | |
1010 | self.time_mag = None |
|
1010 | self.time_mag = None | |
1011 | self.main_dec = None |
|
1011 | self.main_dec = None | |
1012 | self.ObjC = None |
|
1012 | self.ObjC = None | |
1013 | self.ptitle = title |
|
1013 | self.ptitle = title | |
1014 | self.path4plotname = None |
|
1014 | self.path4plotname = None | |
1015 | self.plotname0 = None |
|
1015 | self.plotname0 = None | |
1016 | self.plotname1 = None |
|
1016 | self.plotname1 = None | |
1017 | self.plotname2 = None |
|
1017 | self.plotname2 = None | |
1018 | self.scriptHeaders = 0 |
|
1018 | self.scriptHeaders = 0 | |
1019 | self.glat = -11.95 |
|
1019 | self.glat = -11.95 | |
1020 | self.glon = -76.8667 |
|
1020 | self.glon = -76.8667 | |
1021 | self.UT = 5 #timezone |
|
1021 | self.UT = 5 #timezone | |
1022 |
|
1022 | |||
1023 | self.glat = -11.951481 |
|
1023 | self.glat = -11.951481 | |
1024 | self.glon = -76.874383 |
|
1024 | self.glon = -76.874383 | |
1025 | # self.outputHead('Show Plot') |
|
1025 | # self.outputHead('Show Plot') | |
1026 | # self.printBody() |
|
1026 | # self.printBody() | |
1027 |
|
1027 | |||
1028 | def setScriptState(self): |
|
1028 | def setScriptState(self): | |
1029 | self.madForm = cgi.FieldStorage() |
|
1029 | self.madForm = cgi.FieldStorage() | |
1030 |
|
1030 | |||
1031 | if self.madForm.has_key('serverdocspath'): |
|
1031 | if self.madForm.has_key('serverdocspath'): | |
1032 | self.__serverdocspath = self.madForm.getvalue('serverdocspath')#'/usr/local/www/htdocs' |
|
1032 | self.__serverdocspath = self.madForm.getvalue('serverdocspath')#'/usr/local/www/htdocs' | |
1033 |
|
1033 | |||
1034 | if self.madForm.has_key('tmpdir'): |
|
1034 | if self.madForm.has_key('tmpdir'): | |
1035 | self.__tmpDir = self.madForm.getvalue('tmpdir')#'overJro/tempReports' |
|
1035 | self.__tmpDir = self.madForm.getvalue('tmpdir')#'overJro/tempReports' | |
1036 |
|
1036 | |||
1037 | if self.madForm.has_key('showType'): |
|
1037 | if self.madForm.has_key('showType'): | |
1038 | self.showType = int(self.madForm.getvalue('showType')) |
|
1038 | self.showType = int(self.madForm.getvalue('showType')) | |
1039 |
|
1039 | |||
1040 | if self.showType == 0 or self.showType == 1: |
|
1040 | if self.showType == 0 or self.showType == 1: | |
1041 |
|
1041 | |||
1042 | # if self.madForm.has_key('year') and \ |
|
1042 | # if self.madForm.has_key('year') and \ | |
1043 | # self.madForm.has_key('month') and \ |
|
1043 | # self.madForm.has_key('month') and \ | |
1044 | # self.madForm.has_key('dom') and \ |
|
1044 | # self.madForm.has_key('dom') and \ | |
1045 | # self.madForm.has_key('pattern') and \ |
|
1045 | # self.madForm.has_key('pattern') and \ | |
1046 | # self.madForm.has_key('maxphi') and \ |
|
1046 | # self.madForm.has_key('maxphi') and \ | |
1047 | # self.madForm.has_key('objects') and \ |
|
1047 | # self.madForm.has_key('objects') and \ | |
1048 | # self.madForm.has_key('heights'): |
|
1048 | # self.madForm.has_key('heights'): | |
1049 |
|
1049 | |||
1050 | if self.madForm.has_key('year') and \ |
|
1050 | if self.madForm.has_key('year') and \ | |
1051 | self.madForm.has_key('month') and \ |
|
1051 | self.madForm.has_key('month') and \ | |
1052 | self.madForm.has_key('dom') and \ |
|
1052 | self.madForm.has_key('dom') and \ | |
1053 | self.madForm.has_key('maxphi') and \ |
|
1053 | self.madForm.has_key('maxphi') and \ | |
1054 | self.madForm.has_key('objects') and \ |
|
1054 | self.madForm.has_key('objects') and \ | |
1055 | self.madForm.has_key('heights'): |
|
1055 | self.madForm.has_key('heights'): | |
1056 |
|
1056 | |||
1057 | self.year = int(self.madForm.getvalue('year')) |
|
1057 | self.year = int(self.madForm.getvalue('year')) | |
1058 | self.month = int(self.madForm.getvalue('month')) |
|
1058 | self.month = int(self.madForm.getvalue('month')) | |
1059 | self.dom = int(self.madForm.getvalue('dom')) |
|
1059 | self.dom = int(self.madForm.getvalue('dom')) | |
1060 | self.maxphi = float(self.madForm.getvalue('maxphi')) |
|
1060 | self.maxphi = float(self.madForm.getvalue('maxphi')) | |
1061 |
|
1061 | |||
1062 | if self.madForm.has_key('pattern'): |
|
1062 | if self.madForm.has_key('pattern'): | |
1063 |
|
1063 | |||
1064 | tmp_pattern = self.madForm.getvalue('pattern') #pattern es predifinido en listado o definido por el usuario |
|
1064 | tmp_pattern = self.madForm.getvalue('pattern') #pattern es predifinido en listado o definido por el usuario | |
1065 | self.pattern=[] |
|
1065 | self.pattern=[] | |
1066 | if tmp_pattern[0] == '[': |
|
1066 | if tmp_pattern[0] == '[': | |
1067 | tmp_pattern=tmp_pattern[1:] |
|
1067 | tmp_pattern=tmp_pattern[1:] | |
1068 |
|
1068 | |||
1069 | if tmp_pattern[-1] == ']': |
|
1069 | if tmp_pattern[-1] == ']': | |
1070 | tmp_pattern=tmp_pattern[0:len(tmp_pattern)-1] |
|
1070 | tmp_pattern=tmp_pattern[0:len(tmp_pattern)-1] | |
1071 |
|
1071 | |||
1072 | for s in tmp_pattern.split(','): |
|
1072 | for s in tmp_pattern.split(','): | |
1073 | self.pattern.append(float(s)) |
|
1073 | self.pattern.append(float(s)) | |
1074 | elif self.madForm.has_key('filename'): |
|
1074 | elif self.madForm.has_key('filename'): | |
1075 | if self.madForm.has_key('filename'): |
|
1075 | if self.madForm.has_key('filename'): | |
1076 | self.filename = self.madForm.getvalue('filename') # nombre de archivo: patron de radiacion definido por el usuario |
|
1076 | self.filename = self.madForm.getvalue('filename') # nombre de archivo: patron de radiacion definido por el usuario | |
1077 |
|
1077 | |||
1078 | if self.madForm.has_key('path'): |
|
1078 | if self.madForm.has_key('path'): | |
1079 | self.path = self.madForm.getvalue('path') #path donde se encuentra el archivo: patron de radiacion del usuario |
|
1079 | self.path = self.madForm.getvalue('path') #path donde se encuentra el archivo: patron de radiacion del usuario | |
1080 |
|
1080 | |||
1081 | else: |
|
1081 | else: | |
1082 | print ("Content-Type: text/html\n") |
|
1082 | print ("Content-Type: text/html\n") | |
1083 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') |
|
1083 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') | |
1084 | print ('<p> This is a script used to plot Antenna Cuts over Jicamarca Antenna</p>') |
|
1084 | print ('<p> This is a script used to plot Antenna Cuts over Jicamarca Antenna</p>') | |
1085 | print ('<p> Required arguments:</p>') |
|
1085 | print ('<p> Required arguments:</p>') | |
1086 | print ('<p> pattern - chekbox indicating objects over jicamarca antenna</p>') |
|
1086 | print ('<p> pattern - chekbox indicating objects over jicamarca antenna</p>') | |
1087 | print ('<p> or') |
|
1087 | print ('<p> or') | |
1088 | print ('<p> filename - The pattern defined by users is a file text') |
|
1088 | print ('<p> filename - The pattern defined by users is a file text') | |
1089 | print ('<p> path - folder with pattern files') |
|
1089 | print ('<p> path - folder with pattern files') | |
1090 | sys.exit(0) |
|
1090 | sys.exit(0) | |
1091 |
|
1091 | |||
1092 |
|
1092 | |||
1093 | tmp_heights = self.madForm.getvalue('heights') |
|
1093 | tmp_heights = self.madForm.getvalue('heights') | |
1094 | self.heights=[] |
|
1094 | self.heights=[] | |
1095 | if tmp_heights[0] == '[': |
|
1095 | if tmp_heights[0] == '[': | |
1096 | tmp_heights=tmp_heights[1:] |
|
1096 | tmp_heights=tmp_heights[1:] | |
1097 |
|
1097 | |||
1098 | if tmp_heights[-1] == ']': |
|
1098 | if tmp_heights[-1] == ']': | |
1099 | tmp_heights=tmp_heights[0:len(tmp_heights)-1] |
|
1099 | tmp_heights=tmp_heights[0:len(tmp_heights)-1] | |
1100 |
|
1100 | |||
1101 | for s in tmp_heights.split(','): |
|
1101 | for s in tmp_heights.split(','): | |
1102 | self.heights.append(float(s)) |
|
1102 | self.heights.append(float(s)) | |
1103 | self.heights = numpy.array(self.heights) |
|
1103 | self.heights = numpy.array(self.heights) | |
1104 |
|
1104 | |||
1105 | tmp_objects = self.madForm.getvalue('objects') #lista con los objetos a graficar en el patron de radiacion |
|
1105 | tmp_objects = self.madForm.getvalue('objects') #lista con los objetos a graficar en el patron de radiacion | |
1106 | self.objects=[] |
|
1106 | self.objects=[] | |
1107 | if tmp_objects[0] == '[': |
|
1107 | if tmp_objects[0] == '[': | |
1108 | tmp_objects=tmp_objects[1:] |
|
1108 | tmp_objects=tmp_objects[1:] | |
1109 |
|
1109 | |||
1110 | if tmp_objects[-1] == ']': |
|
1110 | if tmp_objects[-1] == ']': | |
1111 | tmp_objects=tmp_objects[0:len(tmp_objects)-1] |
|
1111 | tmp_objects=tmp_objects[0:len(tmp_objects)-1] | |
1112 |
|
1112 | |||
1113 | for s in tmp_objects.split(','): |
|
1113 | for s in tmp_objects.split(','): | |
1114 | self.objects.append(int(s)) |
|
1114 | self.objects.append(int(s)) | |
1115 |
|
1115 | |||
1116 | if self.showType == 1: |
|
1116 | if self.showType == 1: | |
1117 | if numpy.sum(self.objects) == 0: |
|
1117 | if numpy.sum(self.objects) == 0: | |
1118 | if self.scriptHeaders == 0: |
|
1118 | if self.scriptHeaders == 0: | |
1119 | print ("Content-Type: text/html\n") |
|
1119 | print ("Content-Type: text/html\n") | |
1120 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') |
|
1120 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') | |
1121 | print ('<p> This is a script used to plot Antenna Cuts over Jicamarca Antenna</p>') |
|
1121 | print ('<p> This is a script used to plot Antenna Cuts over Jicamarca Antenna</p>') | |
1122 | print ('<p> Required arguments:</p>') |
|
1122 | print ('<p> Required arguments:</p>') | |
1123 | print ('<p> objects - chekbox indicating objects over jicamarca antenna</p>') |
|
1123 | print ('<p> objects - chekbox indicating objects over jicamarca antenna</p>') | |
1124 | print ('<p> Please, options in "Select Object" must be checked') |
|
1124 | print ('<p> Please, options in "Select Object" must be checked') | |
1125 | sys.exit(0) |
|
1125 | sys.exit(0) | |
1126 |
|
1126 | |||
1127 | #considerar para futura implementacion |
|
1127 | #considerar para futura implementacion | |
1128 | if self.madForm.has_key('filename'): |
|
1128 | if self.madForm.has_key('filename'): | |
1129 | self.filename = self.madForm.getvalue('filename') # nombre de archivo: patron de radiacion definido por el usuario |
|
1129 | self.filename = self.madForm.getvalue('filename') # nombre de archivo: patron de radiacion definido por el usuario | |
1130 |
|
1130 | |||
1131 | if self.madForm.has_key('path'): |
|
1131 | if self.madForm.has_key('path'): | |
1132 | self.path = self.madForm.getvalue('path') #path donde se encuentra el archivo: patron de radiacion del usuario |
|
1132 | self.path = self.madForm.getvalue('path') #path donde se encuentra el archivo: patron de radiacion del usuario | |
1133 |
|
1133 | |||
1134 |
|
1134 | |||
1135 | else: |
|
1135 | else: | |
1136 | if self.scriptHeaders == 0: |
|
1136 | if self.scriptHeaders == 0: | |
1137 | print ("Content-Type: text/html\n") |
|
1137 | print ("Content-Type: text/html\n") | |
1138 |
|
1138 | |||
1139 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') |
|
1139 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') | |
1140 | print ('<p> This is a script used to plot Pattern Field and Celestial Objects over Jicamarca Antenna</p>') |
|
1140 | print ('<p> This is a script used to plot Pattern Field and Celestial Objects over Jicamarca Antenna</p>') | |
1141 | print ('<p> Required arguments:</p>') |
|
1141 | print ('<p> Required arguments:</p>') | |
1142 | print ('<p> year - year of event</p>') |
|
1142 | print ('<p> year - year of event</p>') | |
1143 | print ('<p> month - month of event</p>') |
|
1143 | print ('<p> month - month of event</p>') | |
1144 | print ('<p> dom - day of month</p>') |
|
1144 | print ('<p> dom - day of month</p>') | |
1145 | print ('<p> pattern - pattern is defined by "Select an Experiment" list box</p>') |
|
1145 | print ('<p> pattern - pattern is defined by "Select an Experiment" list box</p>') | |
1146 | print ('<p> maxphi - maxphi is defined by "Max Angle" text box</p>') |
|
1146 | print ('<p> maxphi - maxphi is defined by "Max Angle" text box</p>') | |
1147 | print ('<p> objects - objects is a list defined by checkbox in "Select Object"</p>') |
|
1147 | print ('<p> objects - objects is a list defined by checkbox in "Select Object"</p>') | |
1148 | print ('<p> heights - heights is defined by "Heights" text box, for default heights=[100,500,1000]</p>') |
|
1148 | print ('<p> heights - heights is defined by "Heights" text box, for default heights=[100,500,1000]</p>') | |
1149 | print ('<p> showType - showType is a hidden element for show plot of Pattern&Object or Antenna Cuts or Sky Noise</p>') |
|
1149 | print ('<p> showType - showType is a hidden element for show plot of Pattern&Object or Antenna Cuts or Sky Noise</p>') | |
1150 |
|
1150 | |||
1151 | sys.exit(0) |
|
1151 | sys.exit(0) | |
1152 |
|
1152 | |||
1153 | if self.showType == 2: |
|
1153 | if self.showType == 2: | |
1154 | if self.madForm.has_key('year') and \ |
|
1154 | if self.madForm.has_key('year') and \ | |
1155 | self.madForm.has_key('month') and \ |
|
1155 | self.madForm.has_key('month') and \ | |
1156 | self.madForm.has_key('dom'): |
|
1156 | self.madForm.has_key('dom'): | |
1157 |
|
1157 | |||
1158 | self.year = int(self.madForm.getvalue('year')) |
|
1158 | self.year = int(self.madForm.getvalue('year')) | |
1159 | self.month = int(self.madForm.getvalue('month')) |
|
1159 | self.month = int(self.madForm.getvalue('month')) | |
1160 | self.dom = int(self.madForm.getvalue('dom')) |
|
1160 | self.dom = int(self.madForm.getvalue('dom')) | |
1161 |
|
1161 | |||
1162 | else: |
|
1162 | else: | |
1163 | if self.scriptHeaders == 0: |
|
1163 | if self.scriptHeaders == 0: | |
1164 | print ("Content-Type: text/html\n") |
|
1164 | print ("Content-Type: text/html\n") | |
1165 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') |
|
1165 | print ('<h3> This cgi plot script was called without the proper arguments.</h3>') | |
1166 | print ('<p> This is a script used to plot Sky Noise over Jicamarca Antenna</p>') |
|
1166 | print ('<p> This is a script used to plot Sky Noise over Jicamarca Antenna</p>') | |
1167 | print ('<p> Required arguments:</p>') |
|
1167 | print ('<p> Required arguments:</p>') | |
1168 | print ('<p> year - year of event</p>') |
|
1168 | print ('<p> year - year of event</p>') | |
1169 | print ('<p> month - month of event</p>') |
|
1169 | print ('<p> month - month of event</p>') | |
1170 | print ('<p> dom - day of month</p>') |
|
1170 | print ('<p> dom - day of month</p>') | |
1171 |
|
1171 | |||
1172 | sys.exit(0) |
|
1172 | sys.exit(0) | |
1173 |
|
1173 | |||
1174 |
|
1174 | |||
1175 | def initParameters1(self): |
|
1175 | def initParameters1(self): | |
1176 |
|
1176 | |||
1177 | gui=1 |
|
1177 | gui=1 | |
1178 | if self.pattern==None: |
|
1178 | if self.pattern==None: | |
1179 | if gui==1: self.filename = self.filename.split(',') |
|
1179 | if gui==1: self.filename = self.filename.split(',') | |
1180 |
|
1180 | |||
1181 | pattern = numpy.atleast_1d(self.pattern) |
|
1181 | pattern = numpy.atleast_1d(self.pattern) | |
1182 | filename = numpy.atleast_1d(self.filename) |
|
1182 | filename = numpy.atleast_1d(self.filename) | |
1183 |
|
1183 | |||
1184 | npatterns = numpy.max(numpy.array([pattern.size,filename.size])) |
|
1184 | npatterns = numpy.max(numpy.array([pattern.size,filename.size])) | |
1185 |
|
1185 | |||
1186 | self.pattern = numpy.resize(pattern,npatterns) |
|
1186 | self.pattern = numpy.resize(pattern,npatterns) | |
1187 | self.filename = numpy.resize(filename,npatterns) |
|
1187 | self.filename = numpy.resize(filename,npatterns) | |
1188 |
|
1188 | |||
1189 | self.doy = datetime.datetime(self.year,self.month,self.dom).timetuple().tm_yday |
|
1189 | self.doy = datetime.datetime(self.year,self.month,self.dom).timetuple().tm_yday | |
1190 |
|
1190 | |||
1191 |
|
1191 | |||
1192 | if self.objects==None: |
|
1192 | if self.objects==None: | |
1193 | self.objects=numpy.zeros(5) |
|
1193 | self.objects=numpy.zeros(5) | |
1194 | else: |
|
1194 | else: | |
1195 | tmp = numpy.atleast_1d(self.objects) |
|
1195 | tmp = numpy.atleast_1d(self.objects) | |
1196 | self.objects = numpy.zeros(5) |
|
1196 | self.objects = numpy.zeros(5) | |
1197 | self.objects[0:tmp.size] = tmp |
|
1197 | self.objects[0:tmp.size] = tmp | |
1198 |
|
1198 | |||
1199 | self.show_object = self.objects |
|
1199 | self.show_object = self.objects | |
1200 |
|
1200 | |||
1201 | self.maxha_min = 4*self.maxphi*numpy.sqrt(2)*1.25 |
|
1201 | self.maxha_min = 4*self.maxphi*numpy.sqrt(2)*1.25 | |
1202 |
|
1202 | |||
1203 |
|
1203 | |||
1204 | if self.heights==None: |
|
1204 | if self.heights==None: | |
1205 | self.heights = numpy.array([100.,500.,1000.]) |
|
1205 | self.heights = numpy.array([100.,500.,1000.]) | |
1206 |
|
1206 | |||
1207 |
|
1207 | |||
1208 |
|
1208 | |||
1209 | #ROJ geographic coordinates and time zone |
|
1209 | #ROJ geographic coordinates and time zone | |
1210 | self.glat = -11.95 |
|
1210 | self.glat = -11.95 | |
1211 | self.glon = -76.8667 |
|
1211 | self.glon = -76.8667 | |
1212 | self.UT = 5 #timezone |
|
1212 | self.UT = 5 #timezone | |
1213 |
|
1213 | |||
1214 | self.glat = -11.951481 |
|
1214 | self.glat = -11.951481 | |
1215 | self.glon = -76.874383 |
|
1215 | self.glon = -76.874383 | |
1216 |
|
1216 | |||
1217 |
|
1217 | |||
1218 | self.junkjd = Time(self.year,self.month,self.dom).change2julday() |
|
1218 | self.junkjd = Time(self.year,self.month,self.dom).change2julday() | |
1219 | self.junklst = Julian(self.junkjd).change2lst(longitude=self.glon) |
|
1219 | self.junklst = Julian(self.junkjd).change2lst(longitude=self.glon) | |
1220 |
|
1220 | |||
1221 | # Finding RA of observatory for a specific date |
|
1221 | # Finding RA of observatory for a specific date | |
1222 | self.ra_obs = self.junklst*CoFactors.h2d |
|
1222 | self.ra_obs = self.junklst*CoFactors.h2d | |
1223 |
|
1223 | |||
1224 | def initParameters(self): |
|
1224 | def initParameters(self): | |
1225 |
|
1225 | |||
1226 | # Defining plot filenames |
|
1226 | # Defining plot filenames | |
1227 | self.path4plotname = os.path.join(self.__serverdocspath,self.__tmpDir) |
|
1227 | self.path4plotname = os.path.join(self.__serverdocspath,self.__tmpDir) | |
1228 | self.plotname0 = 'over_jro_0_%i.png'% (time.time()) #plot pattern & objects |
|
1228 | self.plotname0 = 'over_jro_0_%i.png'% (time.time()) #plot pattern & objects | |
1229 | self.plotname1 = 'over_jro_1_%i.png'% (time.time()) #plot antenna cuts |
|
1229 | self.plotname1 = 'over_jro_1_%i.png'% (time.time()) #plot antenna cuts | |
1230 | self.plotname2 = 'over_jro_2_%i.png'% (time.time()) #plot sky noise |
|
1230 | self.plotname2 = 'over_jro_2_%i.png'% (time.time()) #plot sky noise | |
1231 |
|
1231 | |||
1232 | # Defining antenna axes respect to geographic coordinates (See Ochs report). |
|
1232 | # Defining antenna axes respect to geographic coordinates (See Ochs report). | |
1233 | # alfa = 1.46*Misc_Routines.CoFactors.d2r |
|
1233 | # alfa = 1.46*Misc_Routines.CoFactors.d2r | |
1234 | # theta = 51.01*Misc_Routines.CoFactors.d2r |
|
1234 | # theta = 51.01*Misc_Routines.CoFactors.d2r | |
1235 |
|
1235 | |||
1236 | alfa = 1.488312*CoFactors.d2r |
|
1236 | alfa = 1.488312*CoFactors.d2r | |
1237 | th = 6.166710 + 45.0 |
|
1237 | th = 6.166710 + 45.0 | |
1238 | theta = th*CoFactors.d2r |
|
1238 | theta = th*CoFactors.d2r | |
1239 |
|
1239 | |||
1240 | sina = numpy.sin(alfa) |
|
1240 | sina = numpy.sin(alfa) | |
1241 | cosa = numpy.cos(alfa) |
|
1241 | cosa = numpy.cos(alfa) | |
1242 | MT1 = numpy.array([[1,0,0],[0,cosa,-sina],[0,sina,cosa]]) |
|
1242 | MT1 = numpy.array([[1,0,0],[0,cosa,-sina],[0,sina,cosa]]) | |
1243 | sinb = numpy.sin(theta) |
|
1243 | sinb = numpy.sin(theta) | |
1244 | cosb = numpy.cos(theta) |
|
1244 | cosb = numpy.cos(theta) | |
1245 | MT2 = numpy.array([[cosb,sinb,0],[-sinb,cosb,0],[0,0,1]]) |
|
1245 | MT2 = numpy.array([[cosb,sinb,0],[-sinb,cosb,0],[0,0,1]]) | |
1246 | self.MT3 = numpy.array(numpy.dot(MT2, MT1)).transpose() |
|
1246 | self.MT3 = numpy.array(numpy.dot(MT2, MT1)).transpose() | |
1247 |
|
1247 | |||
1248 | self.xg = numpy.dot(self.MT3.transpose(),numpy.array([1,0,0])) |
|
1248 | self.xg = numpy.dot(self.MT3.transpose(),numpy.array([1,0,0])) | |
1249 | self.yg = numpy.dot(self.MT3.transpose(),numpy.array([0,1,0])) |
|
1249 | self.yg = numpy.dot(self.MT3.transpose(),numpy.array([0,1,0])) | |
1250 | self.zg = numpy.dot(self.MT3.transpose(),numpy.array([0,0,1])) |
|
1250 | self.zg = numpy.dot(self.MT3.transpose(),numpy.array([0,0,1])) | |
1251 |
|
1251 | |||
1252 | def plotPattern2(self, date, phases, gain_tx, gain_rx, ues, just_rx): |
|
1252 | def plotPattern2(self, date, phases, gain_tx, gain_rx, ues, just_rx): | |
1253 | # Plotting Antenna patterns. |
|
1253 | # Plotting Antenna patterns. | |
1254 |
|
1254 | |||
1255 | self.initParameters() |
|
1255 | self.initParameters() | |
1256 | self.doy = datetime.datetime(date.year,date.month,date.day).timetuple().tm_yday |
|
1256 | self.doy = datetime.datetime(date.year,date.month,date.day).timetuple().tm_yday | |
1257 | self.junkjd = Time(self.year,self.month,self.dom).change2julday() |
|
1257 | self.junkjd = Time(self.year,self.month,self.dom).change2julday() | |
1258 | self.junklst = Julian(self.junkjd).change2lst(longitude=self.glon) |
|
1258 | self.junklst = Julian(self.junkjd).change2lst(longitude=self.glon) | |
1259 | self.ra_obs = self.junklst*CoFactors.h2d |
|
1259 | self.ra_obs = self.junklst*CoFactors.h2d | |
1260 |
|
1260 | |||
1261 | date = Time(date.year,date.month,date.day).change2strdate(mode=2) |
|
1261 | date = Time(date.year,date.month,date.day).change2strdate(mode=2) | |
1262 |
|
1262 | |||
1263 | mesg = 'Over Jicamarca: ' + date[0] |
|
1263 | mesg = 'Over Jicamarca: ' + date[0] | |
1264 |
|
1264 | |||
1265 | ObjAnt = JroPattern(pattern=0, |
|
1265 | ObjAnt = JroPattern(pattern=0, | |
1266 | filename=None, |
|
1266 | filename=None, | |
1267 | path=None, |
|
1267 | path=None, | |
1268 | nptsx=self.nptsx, |
|
1268 | nptsx=self.nptsx, | |
1269 | nptsy=self.nptsy, |
|
1269 | nptsy=self.nptsy, | |
1270 | #maxphi=self.maxphi, |
|
1270 | #maxphi=self.maxphi, | |
1271 | fftopt=self.fftopt, |
|
1271 | fftopt=self.fftopt, | |
1272 | phases=numpy.array(phases), |
|
1272 | phases=numpy.array(phases), | |
1273 | gain_tx=numpy.array(gain_tx), |
|
1273 | gain_tx=numpy.array(gain_tx), | |
1274 | gain_rx=numpy.array(gain_rx), |
|
1274 | gain_rx=numpy.array(gain_rx), | |
1275 | ues=numpy.array(ues), |
|
1275 | ues=numpy.array(ues), | |
1276 | just_rx=just_rx |
|
1276 | just_rx=just_rx | |
1277 | ) |
|
1277 | ) | |
1278 |
|
1278 | |||
1279 | dum = AntPatternPlot() |
|
1279 | dum = AntPatternPlot() | |
1280 |
|
1280 | |||
1281 | dum.contPattern(iplot=0, |
|
1281 | dum.contPattern(iplot=0, | |
1282 | gpath=self.path4plotname, |
|
1282 | gpath=self.path4plotname, | |
1283 | filename=self.plotname0, |
|
1283 | filename=self.plotname0, | |
1284 | mesg=mesg, |
|
1284 | mesg=mesg, | |
1285 | amp=ObjAnt.norpattern, |
|
1285 | amp=ObjAnt.norpattern, | |
1286 | x=ObjAnt.dcosx, |
|
1286 | x=ObjAnt.dcosx, | |
1287 | y=ObjAnt.dcosy, |
|
1287 | y=ObjAnt.dcosy, | |
1288 | getCut=ObjAnt.getcut, |
|
1288 | getCut=ObjAnt.getcut, | |
1289 | title=self.ptitle, |
|
1289 | title=self.ptitle, | |
1290 | save=False) |
|
1290 | save=False) | |
1291 |
|
1291 | |||
1292 |
|
1292 | |||
1293 | dum.plotRaDec(gpath=self.path4plotname, |
|
1293 | dum.plotRaDec(gpath=self.path4plotname, | |
1294 | filename=self.plotname0, |
|
1294 | filename=self.plotname0, | |
1295 | jd=self.junkjd, |
|
1295 | jd=self.junkjd, | |
1296 | ra_obs=self.ra_obs, |
|
1296 | ra_obs=self.ra_obs, | |
1297 | xg=self.xg, |
|
1297 | xg=self.xg, | |
1298 | yg=self.yg, |
|
1298 | yg=self.yg, | |
1299 | x=ObjAnt.dcosx, |
|
1299 | x=ObjAnt.dcosx, | |
1300 | y=ObjAnt.dcosy, |
|
1300 | y=ObjAnt.dcosy, | |
1301 | save=False) |
|
1301 | save=False) | |
1302 |
|
1302 | |||
1303 | ObjB = BField(self.year,self.doy,1,self.heights) |
|
1303 | ObjB = BField(self.year,self.doy,1,self.heights) | |
1304 | [dcos, alpha, nlon, nlat] = ObjB.getBField() |
|
1304 | [dcos, alpha, nlon, nlat] = ObjB.getBField() | |
1305 |
|
1305 | |||
1306 | dum.plotBField('', '',dcos,alpha,nlon,nlat, |
|
1306 | dum.plotBField('', '',dcos,alpha,nlon,nlat, | |
1307 | self.dcosxrange, |
|
1307 | self.dcosxrange, | |
1308 | self.dcosyrange, |
|
1308 | self.dcosyrange, | |
1309 | ObjB.heights, |
|
1309 | ObjB.heights, | |
1310 | ObjB.alpha_i, |
|
1310 | ObjB.alpha_i, | |
1311 | save=False) |
|
1311 | save=False) | |
1312 |
|
1312 | |||
1313 | return dum.fig |
|
1313 | return dum.fig | |
1314 |
|
1314 | |||
1315 |
|
1315 | |||
1316 | def plotPattern(self): |
|
1316 | def plotPattern(self): | |
1317 | # Plotting Antenna patterns. |
|
1317 | # Plotting Antenna patterns. | |
1318 | npatterns = numpy.size(self.pattern) |
|
1318 | npatterns = numpy.size(self.pattern) | |
1319 |
|
1319 | |||
1320 | if npatterns==1: |
|
1320 | if npatterns==1: | |
1321 | if self.pattern[0] == None: npatterns = self.filename.__len__() |
|
1321 | if self.pattern[0] == None: npatterns = self.filename.__len__() | |
1322 |
|
1322 | |||
1323 | date = TimeTools.Time(self.year,self.month,self.dom).change2strdate(mode=2) |
|
1323 | date = TimeTools.Time(self.year,self.month,self.dom).change2strdate(mode=2) | |
1324 |
|
1324 | |||
1325 | mesg = 'Over Jicamarca: ' + date[0] |
|
1325 | mesg = 'Over Jicamarca: ' + date[0] | |
1326 |
|
1326 | |||
1327 | title = '' |
|
1327 | title = '' | |
1328 |
|
1328 | |||
1329 | for ii in numpy.arange(npatterns): |
|
1329 | for ii in numpy.arange(npatterns): | |
1330 | ObjAnt = JroPattern(pattern=self.pattern[ii], |
|
1330 | ObjAnt = JroPattern(pattern=self.pattern[ii], | |
1331 | filename=self.filename[ii], |
|
1331 | filename=self.filename[ii], | |
1332 | path=self.path, |
|
1332 | path=self.path, | |
1333 | nptsx=self.nptsx, |
|
1333 | nptsx=self.nptsx, | |
1334 | nptsy=self.nptsy, |
|
1334 | nptsy=self.nptsy, | |
1335 | maxphi=self.maxphi, |
|
1335 | maxphi=self.maxphi, | |
1336 | fftopt=self.fftopt) |
|
1336 | fftopt=self.fftopt) | |
1337 |
|
1337 | |||
1338 | title += ObjAnt.title |
|
1338 | title += ObjAnt.title | |
1339 | # Plotting Contour Map |
|
1339 | # Plotting Contour Map | |
1340 |
|
1340 | |||
1341 | self.path4plotname = '/home/jespinoza/workspace/radarsys/trunk/webapp/apps/abs/static/images' |
|
1341 | self.path4plotname = '/home/jespinoza/workspace/radarsys/trunk/webapp/apps/abs/static/images' | |
1342 | dum = AntPatternPlot() |
|
1342 | dum = AntPatternPlot() | |
1343 | dum.contPattern(iplot=ii, |
|
1343 | dum.contPattern(iplot=ii, | |
1344 | gpath=self.path4plotname, |
|
1344 | gpath=self.path4plotname, | |
1345 | filename=self.plotname0, |
|
1345 | filename=self.plotname0, | |
1346 | mesg=mesg, |
|
1346 | mesg=mesg, | |
1347 | amp=ObjAnt.norpattern, |
|
1347 | amp=ObjAnt.norpattern, | |
1348 | x=ObjAnt.dcosx, |
|
1348 | x=ObjAnt.dcosx, | |
1349 | y=ObjAnt.dcosy, |
|
1349 | y=ObjAnt.dcosy, | |
1350 | getCut=ObjAnt.getcut, |
|
1350 | getCut=ObjAnt.getcut, | |
1351 | title=title) |
|
1351 | title=title) | |
1352 | # title=ObjAnt.title) |
|
1352 | # title=ObjAnt.title) | |
1353 | # self.ptitle = ObjAnt.title |
|
1353 | # self.ptitle = ObjAnt.title | |
1354 |
|
1354 | |||
1355 | if ii != (npatterns-1): |
|
1355 | if ii != (npatterns-1): | |
1356 | title += '+' |
|
1356 | title += '+' | |
1357 |
|
1357 | |||
1358 |
|
1358 | |||
1359 | vect_ant = numpy.array([ObjAnt.meanpos[0],ObjAnt.meanpos[1],numpy.sqrt(1-numpy.sum(ObjAnt.meanpos**2.))]) |
|
1359 | vect_ant = numpy.array([ObjAnt.meanpos[0],ObjAnt.meanpos[1],numpy.sqrt(1-numpy.sum(ObjAnt.meanpos**2.))]) | |
1360 |
|
1360 | |||
1361 | vect_geo = numpy.dot(scipy.linalg.inv(self.MT3),vect_ant) |
|
1361 | vect_geo = numpy.dot(scipy.linalg.inv(self.MT3),vect_ant) | |
1362 |
|
1362 | |||
1363 | vect_polar = Misc_Routines.Vector(numpy.array(vect_geo),direction=1).Polar2Rect() |
|
1363 | vect_polar = Misc_Routines.Vector(numpy.array(vect_geo),direction=1).Polar2Rect() | |
1364 |
|
1364 | |||
1365 |
[ra,dec,ha] = |
|
1365 | [ra,dec,ha] = AltAz(vect_polar[1],vect_polar[0],self.junkjd).change2equatorial() | |
1366 |
|
1366 | |||
1367 | print('Main beam position (HA(min), DEC(degrees)): %f %f')%(ha*4.,dec) |
|
1367 | print('Main beam position (HA(min), DEC(degrees)): %f %f')%(ha*4.,dec) | |
1368 |
|
1368 | |||
1369 | self.main_dec = dec |
|
1369 | self.main_dec = dec | |
1370 |
|
1370 | |||
1371 | self.ptitle = title |
|
1371 | self.ptitle = title | |
1372 |
|
1372 | |||
1373 | AntPatternPlot().plotRaDec(gpath=self.path4plotname, |
|
1373 | AntPatternPlot().plotRaDec(gpath=self.path4plotname, | |
1374 | filename=self.plotname0, |
|
1374 | filename=self.plotname0, | |
1375 | jd=self.junkjd, |
|
1375 | jd=self.junkjd, | |
1376 | ra_obs=self.ra_obs, |
|
1376 | ra_obs=self.ra_obs, | |
1377 | xg=self.xg, |
|
1377 | xg=self.xg, | |
1378 | yg=self.yg, |
|
1378 | yg=self.yg, | |
1379 | x=ObjAnt.dcosx, |
|
1379 | x=ObjAnt.dcosx, | |
1380 | y=ObjAnt.dcosy) |
|
1380 | y=ObjAnt.dcosy) | |
1381 |
|
1381 | |||
1382 | self.dcosx = ObjAnt.dcosx |
|
1382 | self.dcosx = ObjAnt.dcosx | |
1383 |
|
1383 | |||
1384 | self.dcosy = ObjAnt.dcosy |
|
1384 | self.dcosy = ObjAnt.dcosy | |
1385 |
|
1385 | |||
1386 | self.dcosxrange = [numpy.min(self.dcosx),numpy.max(self.dcosx)] |
|
1386 | self.dcosxrange = [numpy.min(self.dcosx),numpy.max(self.dcosx)] | |
1387 |
|
1387 | |||
1388 | self.dcosyrange = [numpy.min(self.dcosy),numpy.max(self.dcosy)] |
|
1388 | self.dcosyrange = [numpy.min(self.dcosy),numpy.max(self.dcosy)] | |
1389 |
|
1389 | |||
1390 | def plotBfield(self): |
|
1390 | def plotBfield(self): | |
1391 |
|
1391 | |||
1392 | if self.show_object[0]>0: |
|
1392 | if self.show_object[0]>0: | |
1393 | # Getting B field |
|
1393 | # Getting B field | |
1394 | ObjB = BField(self.year,self.doy,self.site,self.heights) |
|
1394 | ObjB = BField(self.year,self.doy,self.site,self.heights) | |
1395 |
|
1395 | |||
1396 |
|
1396 | |||
1397 | [dcos, alpha, nlon, nlat] = ObjB.getBField() |
|
1397 | [dcos, alpha, nlon, nlat] = ObjB.getBField() | |
1398 |
|
1398 | |||
1399 | # Plotting B field. |
|
1399 | # Plotting B field. | |
1400 | # print "Drawing magnetic field over Observatory" |
|
1400 | # print "Drawing magnetic field over Observatory" | |
1401 |
|
1401 | |||
1402 | Obj = BFieldPlot() |
|
1402 | Obj = BFieldPlot() | |
1403 |
|
1403 | |||
1404 | Obj.plotBField(self.path4plotname,self.plotname0,dcos,alpha,nlon,nlat,self.dcosxrange,self.dcosyrange,ObjB.heights,ObjB.alpha_i) |
|
1404 | Obj.plotBField(self.path4plotname,self.plotname0,dcos,alpha,nlon,nlat,self.dcosxrange,self.dcosyrange,ObjB.heights,ObjB.alpha_i) | |
1405 |
|
1405 | |||
1406 | if self.show_object[0]>1: |
|
1406 | if self.show_object[0]>1: | |
1407 |
|
1407 | |||
1408 | Bhei = 0 |
|
1408 | Bhei = 0 | |
1409 |
|
1409 | |||
1410 | dcosx = Obj.alpha_location[:,0,Bhei] |
|
1410 | dcosx = Obj.alpha_location[:,0,Bhei] | |
1411 |
|
1411 | |||
1412 | dcosy = Obj.alpha_location[:,1,Bhei] |
|
1412 | dcosy = Obj.alpha_location[:,1,Bhei] | |
1413 |
|
1413 | |||
1414 | vect_ant = [dcosx,dcosy,numpy.sqrt(1.-(dcosx**2. + dcosy**2.))] |
|
1414 | vect_ant = [dcosx,dcosy,numpy.sqrt(1.-(dcosx**2. + dcosy**2.))] | |
1415 |
|
1415 | |||
1416 | vect_ant = numpy.array(vect_ant) |
|
1416 | vect_ant = numpy.array(vect_ant) | |
1417 |
|
1417 | |||
1418 | vect_geo = numpy.dot(scipy.linalg.inv(self.MT3),vect_ant) |
|
1418 | vect_geo = numpy.dot(scipy.linalg.inv(self.MT3),vect_ant) | |
1419 |
|
1419 | |||
1420 | vect_geo = numpy.array(vect_geo).transpose() |
|
1420 | vect_geo = numpy.array(vect_geo).transpose() | |
1421 |
|
1421 | |||
1422 | vect_polar = Misc_Routines.Vector(vect_geo,direction=1).Polar2Rect() |
|
1422 | vect_polar = Misc_Routines.Vector(vect_geo,direction=1).Polar2Rect() | |
1423 |
|
1423 | |||
1424 |
[ra,dec,ha] = |
|
1424 | [ra,dec,ha] = AltAz(vect_polar[1,:],vect_polar[0,:],self.junkjd).change2equatorial() | |
1425 |
|
1425 | |||
1426 | val = numpy.where(ha>=180) |
|
1426 | val = numpy.where(ha>=180) | |
1427 |
|
1427 | |||
1428 | if val[0].size>0:ha[val] = ha[val] -360. |
|
1428 | if val[0].size>0:ha[val] = ha[val] -360. | |
1429 |
|
1429 | |||
1430 | val = numpy.where(numpy.abs(ha)<=self.maxphi) |
|
1430 | val = numpy.where(numpy.abs(ha)<=self.maxphi) | |
1431 |
|
1431 | |||
1432 | if val[0].size>2: |
|
1432 | if val[0].size>2: | |
1433 |
|
1433 | |||
1434 | self.dcosx_mag = dcosx[val] |
|
1434 | self.dcosx_mag = dcosx[val] | |
1435 |
|
1435 | |||
1436 | self.dcosy_mag = dcosy[val] |
|
1436 | self.dcosy_mag = dcosy[val] | |
1437 |
|
1437 | |||
1438 | self.ha_mag = ha[val] |
|
1438 | self.ha_mag = ha[val] | |
1439 |
|
1439 | |||
1440 | self.time_mag = 0 |
|
1440 | self.time_mag = 0 | |
1441 |
|
1441 | |||
1442 | def plotCelestial(self): |
|
1442 | def plotCelestial(self): | |
1443 |
|
1443 | |||
1444 | ntod = 24.*16. |
|
1444 | ntod = 24.*16. | |
1445 |
|
1445 | |||
1446 | tod = numpy.arange(ntod)/ntod*24. |
|
1446 | tod = numpy.arange(ntod)/ntod*24. | |
1447 |
|
1447 | |||
1448 | [month,dom] = Doy2Date(self.year,self.doy).change2date() |
|
1448 | [month,dom] = Doy2Date(self.year,self.doy).change2date() | |
1449 |
|
1449 | |||
1450 | jd = Time(self.year,month,dom,tod+self.UT).change2julday() |
|
1450 | jd = Time(self.year,month,dom,tod+self.UT).change2julday() | |
1451 |
|
1451 | |||
1452 | if numpy.sum(self.show_object[1:]>0)!=0: |
|
1452 | if numpy.sum(self.show_object[1:]>0)!=0: | |
1453 |
|
1453 | |||
1454 | self.ObjC = CelestialObjectsPlot(jd,self.main_dec,tod,self.maxha_min,self.show_object) |
|
1454 | self.ObjC = CelestialObjectsPlot(jd,self.main_dec,tod,self.maxha_min,self.show_object) | |
1455 |
|
1455 | |||
1456 | self.ObjC.drawObject(self.glat, |
|
1456 | self.ObjC.drawObject(self.glat, | |
1457 | self.glon, |
|
1457 | self.glon, | |
1458 | self.xg, |
|
1458 | self.xg, | |
1459 | self.yg, |
|
1459 | self.yg, | |
1460 | self.dcosxrange, |
|
1460 | self.dcosxrange, | |
1461 | self.dcosyrange, |
|
1461 | self.dcosyrange, | |
1462 | self.path4plotname, |
|
1462 | self.path4plotname, | |
1463 | self.plotname0) |
|
1463 | self.plotname0) | |
1464 |
|
1464 | |||
1465 | def plotAntennaCuts(self): |
|
1465 | def plotAntennaCuts(self): | |
1466 | # print "Drawing antenna cuts" |
|
1466 | # print "Drawing antenna cuts" | |
1467 |
|
1467 | |||
1468 | incha = 0.05 # min |
|
1468 | incha = 0.05 # min | |
1469 | nha = numpy.int32(2*self.maxha_min/incha) + 1. |
|
1469 | nha = numpy.int32(2*self.maxha_min/incha) + 1. | |
1470 | newha = numpy.arange(nha)/nha*2.*self.maxha_min - self.maxha_min |
|
1470 | newha = numpy.arange(nha)/nha*2.*self.maxha_min - self.maxha_min | |
1471 | nha_star = numpy.int32(200./incha) |
|
1471 | nha_star = numpy.int32(200./incha) | |
1472 | star_ha = (numpy.arange(nha_star) - (nha_star/2))*nha_star |
|
1472 | star_ha = (numpy.arange(nha_star) - (nha_star/2))*nha_star | |
1473 |
|
1473 | |||
1474 | #Init ObjCut for PatternCutPlot() |
|
1474 | #Init ObjCut for PatternCutPlot() | |
1475 | view_objects = numpy.where(self.show_object>0) |
|
1475 | view_objects = numpy.where(self.show_object>0) | |
1476 | subplots = len(view_objects[0]) |
|
1476 | subplots = len(view_objects[0]) | |
1477 | ObjCut = PatternCutPlot(subplots) |
|
1477 | ObjCut = PatternCutPlot(subplots) | |
1478 |
|
1478 | |||
1479 | for io in (numpy.arange(5)): |
|
1479 | for io in (numpy.arange(5)): | |
1480 | if self.show_object[io]==2: |
|
1480 | if self.show_object[io]==2: | |
1481 | if io==0: |
|
1481 | if io==0: | |
1482 | if self.dcosx_mag.size!=0: |
|
1482 | if self.dcosx_mag.size!=0: | |
1483 | dcosx = self.dcosx_mag |
|
1483 | dcosx = self.dcosx_mag | |
1484 | dcosy = self.dcosy_mag |
|
1484 | dcosy = self.dcosy_mag | |
1485 | dcosz = 1 - numpy.sqrt(dcosx**2. + dcosy**2.) |
|
1485 | dcosz = 1 - numpy.sqrt(dcosx**2. + dcosy**2.) | |
1486 |
|
1486 | |||
1487 | # Finding rotation of B respec to antenna coords. |
|
1487 | # Finding rotation of B respec to antenna coords. | |
1488 | [mm,bb] = scipy.polyfit(dcosx,dcosy,1) |
|
1488 | [mm,bb] = scipy.polyfit(dcosx,dcosy,1) | |
1489 | alfa = 0.0 |
|
1489 | alfa = 0.0 | |
1490 | theta = -1.*numpy.arctan(mm) |
|
1490 | theta = -1.*numpy.arctan(mm) | |
1491 | sina = numpy.sin(alfa); cosa = numpy.cos(alfa) |
|
1491 | sina = numpy.sin(alfa); cosa = numpy.cos(alfa) | |
1492 | MT1 = [[1,0,0],[0,cosa,-sina],[0,sina,cosa]] |
|
1492 | MT1 = [[1,0,0],[0,cosa,-sina],[0,sina,cosa]] | |
1493 | MT1 = numpy.array(MT1) |
|
1493 | MT1 = numpy.array(MT1) | |
1494 | sinb = numpy.sin(theta); cosb = numpy.cos(theta) |
|
1494 | sinb = numpy.sin(theta); cosb = numpy.cos(theta) | |
1495 | MT2 = [[cosb,sinb,0],[-sinb,cosb,0],[0,0,1]] |
|
1495 | MT2 = [[cosb,sinb,0],[-sinb,cosb,0],[0,0,1]] | |
1496 | MT2 = numpy.array(MT2) |
|
1496 | MT2 = numpy.array(MT2) | |
1497 | MT3_mag = numpy.dot(MT2, MT1) |
|
1497 | MT3_mag = numpy.dot(MT2, MT1) | |
1498 | MT3_mag = numpy.array(MT3_mag).transpose() |
|
1498 | MT3_mag = numpy.array(MT3_mag).transpose() | |
1499 | # Getting dcos respec to B coords |
|
1499 | # Getting dcos respec to B coords | |
1500 | vector = numpy.array([dcosx,dcosy,dcosz]) |
|
1500 | vector = numpy.array([dcosx,dcosy,dcosz]) | |
1501 | nvector = numpy.dot(MT3_mag,vector) |
|
1501 | nvector = numpy.dot(MT3_mag,vector) | |
1502 | nvector = numpy.array(nvector).transpose() |
|
1502 | nvector = numpy.array(nvector).transpose() | |
1503 |
|
1503 | |||
1504 | ## print 'Rotation (deg) %f'%(theta/Misc_Routines.CoFactors.d2r) |
|
1504 | ## print 'Rotation (deg) %f'%(theta/Misc_Routines.CoFactors.d2r) | |
1505 |
|
1505 | |||
1506 | yoffset = numpy.sum(nvector[:,1])/nvector[:,1].size |
|
1506 | yoffset = numpy.sum(nvector[:,1])/nvector[:,1].size | |
1507 | # print 'Dcosyoffset %f'%(yoffset) |
|
1507 | # print 'Dcosyoffset %f'%(yoffset) | |
1508 |
|
1508 | |||
1509 | ha = self.ha_mag*4. |
|
1509 | ha = self.ha_mag*4. | |
1510 | time = self.time_mag |
|
1510 | time = self.time_mag | |
1511 | width_star = 0.1 # half width in minutes |
|
1511 | width_star = 0.1 # half width in minutes | |
1512 | otitle = 'B Perp. cut' |
|
1512 | otitle = 'B Perp. cut' | |
1513 | # else: |
|
1513 | # else: | |
1514 | # print "No B perp. over Observatory" |
|
1514 | # print "No B perp. over Observatory" | |
1515 | # |
|
1515 | # | |
1516 | # |
|
1516 | # | |
1517 | elif io==1: |
|
1517 | elif io==1: | |
1518 | if self.ObjC.dcosx_sun.size!=0: |
|
1518 | if self.ObjC.dcosx_sun.size!=0: | |
1519 | dcosx = self.ObjC.dcosx_sun |
|
1519 | dcosx = self.ObjC.dcosx_sun | |
1520 | dcosy = self.ObjC.dcosy_sun |
|
1520 | dcosy = self.ObjC.dcosy_sun | |
1521 | ha = self.ObjC.ha_sun*4.0 |
|
1521 | ha = self.ObjC.ha_sun*4.0 | |
1522 | time = self.ObjC.time_sun |
|
1522 | time = self.ObjC.time_sun | |
1523 | width_star = 2. # half width in minutes |
|
1523 | width_star = 2. # half width in minutes | |
1524 | otitle = 'Sun cut' |
|
1524 | otitle = 'Sun cut' | |
1525 | # else: |
|
1525 | # else: | |
1526 | # print "Sun is not passing over Observatory" |
|
1526 | # print "Sun is not passing over Observatory" | |
1527 |
|
1527 | |||
1528 | elif io==2: |
|
1528 | elif io==2: | |
1529 | if self.ObjC.dcosx_moon.size!=0: |
|
1529 | if self.ObjC.dcosx_moon.size!=0: | |
1530 | dcosx = self.ObjC.dcosx_moon |
|
1530 | dcosx = self.ObjC.dcosx_moon | |
1531 | dcosy = self.ObjC.dcosy_moon |
|
1531 | dcosy = self.ObjC.dcosy_moon | |
1532 | ha = self.ObjC.ha_moon*4 |
|
1532 | ha = self.ObjC.ha_moon*4 | |
1533 | time = self.ObjC.time_moon |
|
1533 | time = self.ObjC.time_moon | |
1534 | m_distance = 404114.6 # distance to the Earth in km |
|
1534 | m_distance = 404114.6 # distance to the Earth in km | |
1535 | m_diameter = 1734.4 # diameter in km. |
|
1535 | m_diameter = 1734.4 # diameter in km. | |
1536 | width_star = numpy.arctan(m_distance/m_diameter) |
|
1536 | width_star = numpy.arctan(m_distance/m_diameter) | |
1537 | width_star = width_star/2./CoFactors.d2r*4. |
|
1537 | width_star = width_star/2./CoFactors.d2r*4. | |
1538 | otitle = 'Moon cut' |
|
1538 | otitle = 'Moon cut' | |
1539 | # else: |
|
1539 | # else: | |
1540 | # print "Moon is not passing over Observatory" |
|
1540 | # print "Moon is not passing over Observatory" | |
1541 |
|
1541 | |||
1542 | elif io==3: |
|
1542 | elif io==3: | |
1543 | if self.ObjC.dcosx_hydra.size!=0: |
|
1543 | if self.ObjC.dcosx_hydra.size!=0: | |
1544 | dcosx = self.ObjC.dcosx_hydra |
|
1544 | dcosx = self.ObjC.dcosx_hydra | |
1545 | dcosy = self.ObjC.dcosy_hydra |
|
1545 | dcosy = self.ObjC.dcosy_hydra | |
1546 | ha = self.ObjC.ha_hydra*4. |
|
1546 | ha = self.ObjC.ha_hydra*4. | |
1547 | time = self.ObjC.time_hydra |
|
1547 | time = self.ObjC.time_hydra | |
1548 | width_star = 0.25 # half width in minutes |
|
1548 | width_star = 0.25 # half width in minutes | |
1549 | otitle = 'Hydra cut' |
|
1549 | otitle = 'Hydra cut' | |
1550 | # else: |
|
1550 | # else: | |
1551 | # print "Hydra is not passing over Observatory" |
|
1551 | # print "Hydra is not passing over Observatory" | |
1552 |
|
1552 | |||
1553 | elif io==4: |
|
1553 | elif io==4: | |
1554 | if self.ObjC.dcosx_galaxy.size!=0: |
|
1554 | if self.ObjC.dcosx_galaxy.size!=0: | |
1555 | dcosx = self.ObjC.dcosx_galaxy |
|
1555 | dcosx = self.ObjC.dcosx_galaxy | |
1556 | dcosy = self.ObjC.dcosy_galaxy |
|
1556 | dcosy = self.ObjC.dcosy_galaxy | |
1557 | ha = self.ObjC.ha_galaxy*4. |
|
1557 | ha = self.ObjC.ha_galaxy*4. | |
1558 | time = self.ObjC.time_galaxy |
|
1558 | time = self.ObjC.time_galaxy | |
1559 | width_star = 25. # half width in minutes |
|
1559 | width_star = 25. # half width in minutes | |
1560 | otitle = 'Galaxy cut' |
|
1560 | otitle = 'Galaxy cut' | |
1561 | # else: |
|
1561 | # else: | |
1562 | # print "Galaxy center is not passing over Jicamarca" |
|
1562 | # print "Galaxy center is not passing over Jicamarca" | |
1563 | # |
|
1563 | # | |
1564 | # |
|
1564 | # | |
1565 | hour = numpy.int32(time) |
|
1565 | hour = numpy.int32(time) | |
1566 | mins = numpy.int32((time - hour)*60.) |
|
1566 | mins = numpy.int32((time - hour)*60.) | |
1567 | secs = numpy.int32(((time - hour)*60. - mins)*60.) |
|
1567 | secs = numpy.int32(((time - hour)*60. - mins)*60.) | |
1568 |
|
1568 | |||
1569 | ObjT = Time(self.year,self.month,self.dom,hour,mins,secs) |
|
1569 | ObjT = Time(self.year,self.month,self.dom,hour,mins,secs) | |
1570 | subtitle = ObjT.change2strdate() |
|
1570 | subtitle = ObjT.change2strdate() | |
1571 |
|
1571 | |||
1572 | star_cut = numpy.exp(-(star_ha/width_star)**2./2.) |
|
1572 | star_cut = numpy.exp(-(star_ha/width_star)**2./2.) | |
1573 |
|
1573 | |||
1574 | pol = scipy.polyfit(ha,dcosx,3.) |
|
1574 | pol = scipy.polyfit(ha,dcosx,3.) | |
1575 | polx = numpy.poly1d(pol); newdcosx = polx(newha) |
|
1575 | polx = numpy.poly1d(pol); newdcosx = polx(newha) | |
1576 | pol = scipy.polyfit(ha,dcosy,3.) |
|
1576 | pol = scipy.polyfit(ha,dcosy,3.) | |
1577 | poly = numpy.poly1d(pol);newdcosy = poly(newha) |
|
1577 | poly = numpy.poly1d(pol);newdcosy = poly(newha) | |
1578 |
|
1578 | |||
1579 | patterns = [] |
|
1579 | patterns = [] | |
1580 | for icut in numpy.arange(self.pattern.size): |
|
1580 | for icut in numpy.arange(self.pattern.size): | |
1581 | # Getting Antenna cut. |
|
1581 | # Getting Antenna cut. | |
1582 | Obj = JroPattern(dcosx=newdcosx, |
|
1582 | Obj = JroPattern(dcosx=newdcosx, | |
1583 | dcosy=newdcosy, |
|
1583 | dcosy=newdcosy, | |
1584 | getcut=1, |
|
1584 | getcut=1, | |
1585 | pattern=self.pattern[icut], |
|
1585 | pattern=self.pattern[icut], | |
1586 | path=self.path, |
|
1586 | path=self.path, | |
1587 | filename=self.filename[icut]) |
|
1587 | filename=self.filename[icut]) | |
1588 |
|
1588 | |||
1589 | Obj.getPattern() |
|
1589 | Obj.getPattern() | |
1590 |
|
1590 | |||
1591 | patterns.append(Obj.pattern) |
|
1591 | patterns.append(Obj.pattern) | |
1592 |
|
1592 | |||
1593 |
|
1593 | |||
1594 | ObjCut.drawCut(io, |
|
1594 | ObjCut.drawCut(io, | |
1595 | patterns, |
|
1595 | patterns, | |
1596 | self.pattern.size, |
|
1596 | self.pattern.size, | |
1597 | newha, |
|
1597 | newha, | |
1598 | otitle, |
|
1598 | otitle, | |
1599 | subtitle, |
|
1599 | subtitle, | |
1600 | self.ptitle) |
|
1600 | self.ptitle) | |
1601 |
|
1601 | |||
1602 | ObjCut.saveFig(self.path4plotname,self.plotname1) |
|
1602 | ObjCut.saveFig(self.path4plotname,self.plotname1) | |
1603 |
|
1603 | |||
1604 | def plotSkyNoise(self): |
|
1604 | def plotSkyNoise(self): | |
1605 | # print 'Creating SkyNoise map over Jicamarca' |
|
1605 | # print 'Creating SkyNoise map over Jicamarca' | |
1606 | dom = self.dom |
|
1606 | dom = self.dom | |
1607 | month = self.month |
|
1607 | month = self.month | |
1608 | year = self.year |
|
1608 | year = self.year | |
1609 |
|
1609 | |||
1610 | julian = Time(year,month,dom).change2julday() |
|
1610 | julian = Time(year,month,dom).change2julday() | |
1611 |
|
1611 | |||
1612 |
[powr,time, lst] = |
|
1612 | [powr,time, lst] = CelestialBodies().skyNoise(julian) | |
1613 |
|
1613 | |||
1614 | SkyNoisePlot([year,month,dom],powr,time,lst).getPlot(self.path4plotname,self.plotname2) |
|
1614 | SkyNoisePlot([year,month,dom],powr,time,lst).getPlot(self.path4plotname,self.plotname2) | |
1615 |
|
1615 | |||
1616 |
|
1616 | |||
1617 | def outputHead(self,title): |
|
1617 | def outputHead(self,title): | |
1618 | print ("Content-Type: text/html") |
|
1618 | print ("Content-Type: text/html") | |
1619 | print (self).scriptHeaders = 1 |
|
1619 | print (self).scriptHeaders = 1 | |
1620 | print ('<html>') |
|
1620 | print ('<html>') | |
1621 | print ('<head>') |
|
1621 | print ('<head>') | |
1622 | print ('\t<title>' + title + '</title>') |
|
1622 | print ('\t<title>' + title + '</title>') | |
1623 | print ('<style type="text/css">') |
|
1623 | print ('<style type="text/css">') | |
1624 | print ('body') |
|
1624 | print ('body') | |
1625 | print ('{') |
|
1625 | print ('{') | |
1626 | print ('background-color:#ffffff;') |
|
1626 | print ('background-color:#ffffff;') | |
1627 | print ('}') |
|
1627 | print ('}') | |
1628 | print ('h1') |
|
1628 | print ('h1') | |
1629 | print ('{') |
|
1629 | print ('{') | |
1630 | print ('color:black;') |
|
1630 | print ('color:black;') | |
1631 | print ('font-size:18px;') |
|
1631 | print ('font-size:18px;') | |
1632 | print ('text-align:center;') |
|
1632 | print ('text-align:center;') | |
1633 | print ('}') |
|
1633 | print ('}') | |
1634 | print ('p') |
|
1634 | print ('p') | |
1635 | print ('{') |
|
1635 | print ('{') | |
1636 | print ('font-family:"Arial";') |
|
1636 | print ('font-family:"Arial";') | |
1637 | print ('font-size:16px;') |
|
1637 | print ('font-size:16px;') | |
1638 | print ('color:black;') |
|
1638 | print ('color:black;') | |
1639 | print ('}') |
|
1639 | print ('}') | |
1640 | print ('</style>') |
|
1640 | print ('</style>') | |
1641 | # self.printJavaScript() |
|
1641 | # self.printJavaScript() | |
1642 | print ('</head>') |
|
1642 | print ('</head>') | |
1643 |
|
1643 | |||
1644 | def printJavaScript(self): |
|
1644 | def printJavaScript(self): | |
1645 |
|
1645 | |||
1646 |
|
1646 | |||
1647 | def printBody(self): |
|
1647 | def printBody(self): | |
1648 | print ('<body>') |
|
1648 | print ('<body>') | |
1649 | # print '<h1>Test Input Parms</h1>' |
|
1649 | # print '<h1>Test Input Parms</h1>' | |
1650 | # for key in self.madForm.keys(): |
|
1650 | # for key in self.madForm.keys(): | |
1651 | # #print '<p> name=' + str(key) |
|
1651 | # #print '<p> name=' + str(key) | |
1652 | # if type(self.madForm.getvalue(key)) == types.ListType: |
|
1652 | # if type(self.madForm.getvalue(key)) == types.ListType: | |
1653 | # for value in self.madForm.getvalue(key): |
|
1653 | # for value in self.madForm.getvalue(key): | |
1654 | # print '<p> name=' + str(key) + \ |
|
1654 | # print '<p> name=' + str(key) + \ | |
1655 | # ' value=' + value + '' |
|
1655 | # ' value=' + value + '' | |
1656 | # else: |
|
1656 | # else: | |
1657 | # print '<p> name=' + str(key) + \ |
|
1657 | # print '<p> name=' + str(key) + \ | |
1658 | # ' value=' + str(cgi.escape(self.madForm.getvalue(key))) + '' |
|
1658 | # ' value=' + str(cgi.escape(self.madForm.getvalue(key))) + '' | |
1659 |
|
1659 | |||
1660 | print ('<form name="form1" method="post" target="showFrame">') |
|
1660 | print ('<form name="form1" method="post" target="showFrame">') | |
1661 | print (' <div align="center">') |
|
1661 | print (' <div align="center">') | |
1662 | print (' <table width=98% border="1" cellpadding="1">') |
|
1662 | print (' <table width=98% border="1" cellpadding="1">') | |
1663 | print (' <tr>') |
|
1663 | print (' <tr>') | |
1664 | print (' <td colspan="2" align="center">') |
|
1664 | print (' <td colspan="2" align="center">') | |
1665 | if self.showType == 0: |
|
1665 | if self.showType == 0: | |
1666 | print (' <IMG SRC="%s" BORDER="0" >')%(os.path.join(os.sep + self.__tmpDir,self.plotname0)) |
|
1666 | print (' <IMG SRC="%s" BORDER="0" >')%(os.path.join(os.sep + self.__tmpDir,self.plotname0)) | |
1667 | if self.showType == 1: |
|
1667 | if self.showType == 1: | |
1668 | print (' <IMG SRC="%s" BORDER="0" >')%(os.path.join(os.sep + self.__tmpDir,self.plotname1)) |
|
1668 | print (' <IMG SRC="%s" BORDER="0" >')%(os.path.join(os.sep + self.__tmpDir,self.plotname1)) | |
1669 | if self.showType == 2: |
|
1669 | if self.showType == 2: | |
1670 | print (' <IMG SRC="%s" BORDER="0" >')%(os.path.join(os.sep + self.__tmpDir,self.plotname2)) |
|
1670 | print (' <IMG SRC="%s" BORDER="0" >')%(os.path.join(os.sep + self.__tmpDir,self.plotname2)) | |
1671 | print (' </td>') |
|
1671 | print (' </td>') | |
1672 | print (' </tr>') |
|
1672 | print (' </tr>') | |
1673 | print (' </table>') |
|
1673 | print (' </table>') | |
1674 | print (' </div>') |
|
1674 | print (' </div>') | |
1675 | print ('</form>') |
|
1675 | print ('</form>') | |
1676 |
|
1676 | |||
1677 | print ('</body>') |
|
1677 | print ('</body>') | |
1678 | print ('</html>') |
|
1678 | print ('</html>') | |
1679 |
|
1679 | |||
1680 | #def execute(self, serverdocspath, tmpdir, currentdate, finalpath, showType=0, maxphi=5.0, objects="[1,1]", heights="[150,500,1000]"): |
|
1680 | #def execute(self, serverdocspath, tmpdir, currentdate, finalpath, showType=0, maxphi=5.0, objects="[1,1]", heights="[150,500,1000]"): | |
1681 | def setInputParameters(self, serverpath, currentdate, finalpath, showType=0, maxphi=5.0, objects="[1,1]", heights="[150,500,1000]"): |
|
1681 | def setInputParameters(self, serverpath, currentdate, finalpath, showType=0, maxphi=5.0, objects="[1,1]", heights="[150,500,1000]"): | |
1682 | self.objects=[] |
|
1682 | self.objects=[] | |
1683 | self.heights=[] |
|
1683 | self.heights=[] | |
1684 | #self.__serverdocspath = serverdocspath |
|
1684 | #self.__serverdocspath = serverdocspath | |
1685 | self.__serverdocspath = os.path.split(serverpath)[0] |
|
1685 | self.__serverdocspath = os.path.split(serverpath)[0] | |
1686 | #self.__tmpDir = tmpdir |
|
1686 | #self.__tmpDir = tmpdir | |
1687 | self.__tmpDir = os.path.split(serverpath)[1] |
|
1687 | self.__tmpDir = os.path.split(serverpath)[1] | |
1688 | self.showType = int(showType) |
|
1688 | self.showType = int(showType) | |
1689 | self.year = int(currentdate.strftime("%Y")) # Get year of currentdate |
|
1689 | self.year = int(currentdate.strftime("%Y")) # Get year of currentdate | |
1690 | self.month = int(currentdate.strftime("%m")) # Get month of currentdate |
|
1690 | self.month = int(currentdate.strftime("%m")) # Get month of currentdate | |
1691 | self.dom = int(currentdate.strftime("%d")) # Get day of currentdate |
|
1691 | self.dom = int(currentdate.strftime("%d")) # Get day of currentdate | |
1692 | self.filename = os.path.split(finalpath)[1] |
|
1692 | self.filename = os.path.split(finalpath)[1] | |
1693 | self.path = os.path.split(finalpath)[0] |
|
1693 | self.path = os.path.split(finalpath)[0] | |
1694 | self.maxphi = float(maxphi) |
|
1694 | self.maxphi = float(maxphi) | |
1695 |
|
1695 | |||
1696 | tmp_objects = (objects.replace("[","")).replace("]","") |
|
1696 | tmp_objects = (objects.replace("[","")).replace("]","") | |
1697 | for s in tmp_objects.split(','): |
|
1697 | for s in tmp_objects.split(','): | |
1698 | self.objects.append(int(s)) |
|
1698 | self.objects.append(int(s)) | |
1699 |
|
1699 | |||
1700 | tmp_heights = (heights.replace("[","")).replace("]","") |
|
1700 | tmp_heights = (heights.replace("[","")).replace("]","") | |
1701 | for s in tmp_heights.split(','): |
|
1701 | for s in tmp_heights.split(','): | |
1702 | self.heights.append(float(s)) |
|
1702 | self.heights.append(float(s)) | |
1703 | self.heights = numpy.array(self.heights) |
|
1703 | self.heights = numpy.array(self.heights) | |
1704 |
|
1704 | |||
1705 | def setupParameters(self): |
|
1705 | def setupParameters(self): | |
1706 | self.initParameters() |
|
1706 | self.initParameters() | |
1707 |
|
1707 | |||
1708 | def initParametersCGI(self): |
|
1708 | def initParametersCGI(self): | |
1709 | self.setScriptState() |
|
1709 | self.setScriptState() | |
1710 | self.initParameters() |
|
1710 | self.initParameters() | |
1711 |
|
1711 | |||
1712 | def execute(self): |
|
1712 | def execute(self): | |
1713 | if self.showType == 0 or self.showType == 1: |
|
1713 | if self.showType == 0 or self.showType == 1: | |
1714 | self.initParameters1() |
|
1714 | self.initParameters1() | |
1715 | self.plotPattern() |
|
1715 | self.plotPattern() | |
1716 |
|
1716 | |||
1717 | if numpy.sum(self.show_object>0) != 0: |
|
1717 | if numpy.sum(self.show_object>0) != 0: | |
1718 | self.plotBfield() |
|
1718 | self.plotBfield() | |
1719 | self.plotCelestial() |
|
1719 | self.plotCelestial() | |
1720 |
|
1720 | |||
1721 | if numpy.sum(self.show_object>1) != 0: |
|
1721 | if numpy.sum(self.show_object>1) != 0: | |
1722 | self.plotAntennaCuts() |
|
1722 | self.plotAntennaCuts() | |
1723 |
|
1723 | |||
1724 | if self.showType == 2: |
|
1724 | if self.showType == 2: | |
1725 | self.plotSkyNoise() |
|
1725 | self.plotSkyNoise() | |
1726 |
|
1726 | |||
1727 | def getPlot(self): |
|
1727 | def getPlot(self): | |
1728 |
|
1728 | |||
1729 | return os.path.join(self.__serverdocspath,self.__tmpDir,self.plotname0) |
|
1729 | return os.path.join(self.__serverdocspath,self.__tmpDir,self.plotname0) | |
1730 |
|
1730 | |||
1731 |
|
1731 | |||
1732 | if __name__ == '__main__': |
|
1732 | if __name__ == '__main__': | |
1733 |
|
1733 | |||
1734 | # Script overJroShow.py |
|
1734 | # Script overJroShow.py | |
1735 | # This script only calls the init function of the class overJroShow() |
|
1735 | # This script only calls the init function of the class overJroShow() | |
1736 | # All work is done by the init function |
|
1736 | # All work is done by the init function | |
1737 |
|
1737 | |||
1738 | phases = numpy.array([[2.0,0.0,1.5,1.5,1.0,1.0,1.0,0.5], |
|
1738 | phases = numpy.array([[2.0,0.0,1.5,1.5,1.0,1.0,1.0,0.5], | |
1739 | [2.0,2.5,2.5,3.5,0.5,1.0,1.0,1.0], |
|
1739 | [2.0,2.5,2.5,3.5,0.5,1.0,1.0,1.0], | |
1740 | [2.5,2.5,1.0,1.0,0.5,0.5,0.5,0.5], |
|
1740 | [2.5,2.5,1.0,1.0,0.5,0.5,0.5,0.5], | |
1741 | [1.0,1.0,1.0,1.0,0.5,0.5,0.5,1.0], |
|
1741 | [1.0,1.0,1.0,1.0,0.5,0.5,0.5,1.0], | |
1742 | [0.5,0.5,0.5,0.5,0.5,0.0,0.0,0.0], |
|
1742 | [0.5,0.5,0.5,0.5,0.5,0.0,0.0,0.0], | |
1743 | [0.5,0.5,1.0,0.5,0.0,0.0,0.0,0.0], |
|
1743 | [0.5,0.5,1.0,0.5,0.0,0.0,0.0,0.0], | |
1744 | [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0], |
|
1744 | [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0], | |
1745 | [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]]) |
|
1745 | [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]]) | |
1746 |
|
1746 | |||
1747 | gain_tx = numpy.array([[0,0,0,0,0,0,0,0], |
|
1747 | gain_tx = numpy.array([[0,0,0,0,0,0,0,0], | |
1748 | [0,0,0,0,0,0,0,0], |
|
1748 | [0,0,0,0,0,0,0,0], | |
1749 | [0,0,0,0,0,0,0,0], |
|
1749 | [0,0,0,0,0,0,0,0], | |
1750 | [0,0,0,0,0,0,0,0], |
|
1750 | [0,0,0,0,0,0,0,0], | |
1751 | [0,0,0,0,1,1,1,1], |
|
1751 | [0,0,0,0,1,1,1,1], | |
1752 | [0,0,0,0,0,0,0,0], |
|
1752 | [0,0,0,0,0,0,0,0], | |
1753 | [0,0,0,0,0,0,0,0], |
|
1753 | [0,0,0,0,0,0,0,0], | |
1754 | [0,0,0,0,0,0,0,0]]) |
|
1754 | [0,0,0,0,0,0,0,0]]) | |
1755 |
|
1755 | |||
1756 | gain_rx = numpy.array([[0,0,0,0,0,0,0,0], |
|
1756 | gain_rx = numpy.array([[0,0,0,0,0,0,0,0], | |
1757 | [0,0,1,0,0,0,0,0], |
|
1757 | [0,0,1,0,0,0,0,0], | |
1758 | [0,0,1,0,0,0,0,0], |
|
1758 | [0,0,1,0,0,0,0,0], | |
1759 | [0,0,0,0,0,0,0,0], |
|
1759 | [0,0,0,0,0,0,0,0], | |
1760 | [0,0,0,0,0,0,0,0], |
|
1760 | [0,0,0,0,0,0,0,0], | |
1761 | [0,0,0,0,0,0,0,0], |
|
1761 | [0,0,0,0,0,0,0,0], | |
1762 | [0,0,0,0,0,0,0,0], |
|
1762 | [0,0,0,0,0,0,0,0], | |
1763 | [0,0,0,0,0,0,0,0]]) |
|
1763 | [0,0,0,0,0,0,0,0]]) | |
1764 |
|
1764 | |||
1765 | jro = overJroShow() |
|
1765 | jro = overJroShow() | |
1766 |
|
1766 | |||
1767 | fig = jro.plotPattern2(datetime.datetime.today(), |
|
1767 | fig = jro.plotPattern2(datetime.datetime.today(), | |
1768 | phases=phases, |
|
1768 | phases=phases, | |
1769 | gain_tx=gain_tx, |
|
1769 | gain_tx=gain_tx, | |
1770 | gain_rx=gain_rx, |
|
1770 | gain_rx=gain_rx, | |
1771 | ues=numpy.array([0.0,0.0,0.0,0.0]), |
|
1771 | ues=numpy.array([0.0,0.0,0.0,0.0]), | |
1772 | just_rx=0) |
|
1772 | just_rx=0) | |
1773 |
|
1773 | |||
1774 | fig.savefig('./pat.png') |
|
1774 | fig.savefig('./pat.png') | |
1775 |
|
1775 |
@@ -1,1042 +1,1047 | |||||
1 |
|
||||
2 |
|
||||
3 |
|
|
1 | import ast | |
4 | import json |
|
2 | import json | |
5 | import requests |
|
3 | import requests | |
6 | import numpy as np |
|
4 | import numpy as np | |
|
5 | import time | |||
7 | from base64 import b64encode |
|
6 | from base64 import b64encode | |
8 | from struct import pack |
|
7 | from struct import pack | |
9 |
|
8 | |||
10 | from django.db import models |
|
9 | from django.db import models | |
11 | from django.urls import reverse |
|
10 | from django.urls import reverse | |
12 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
11 | from django.core.validators import MinValueValidator, MaxValueValidator | |
13 |
|
12 | |||
14 | from apps.main.models import Configuration |
|
13 | from apps.main.models import Configuration | |
15 | from apps.main.utils import Params |
|
14 | from apps.main.utils import Params | |
16 | from devices.rc import api |
|
15 | from devices.rc import api | |
17 | from apps.rc.utils import RCFile |
|
16 | from apps.rc.utils import RCFile | |
18 |
|
17 | |||
19 |
|
18 | |||
20 | LINE_TYPES = ( |
|
19 | LINE_TYPES = ( | |
21 | ('none', 'Not used'), |
|
20 | ('none', 'Not used'), | |
22 | ('tr', 'Transmission/reception selector signal'), |
|
21 | ('tr', 'Transmission/reception selector signal'), | |
23 | ('tx', 'A modulating signal (Transmission pulse)'), |
|
22 | ('tx', 'A modulating signal (Transmission pulse)'), | |
24 | ('codes', 'BPSK modulating signal'), |
|
23 | ('codes', 'BPSK modulating signal'), | |
25 | ('windows', 'Sample window signal'), |
|
24 | ('windows', 'Sample window signal'), | |
26 | ('sync', 'Synchronizing signal'), |
|
25 | ('sync', 'Synchronizing signal'), | |
27 | ('flip', 'IPP related periodic signal'), |
|
26 | ('flip', 'IPP related periodic signal'), | |
28 | ('prog_pulses', 'Programmable pulse'), |
|
27 | ('prog_pulses', 'Programmable pulse'), | |
29 | ('mix', 'Mixed line'), |
|
28 | ('mix', 'Mixed line'), | |
30 | ) |
|
29 | ) | |
31 |
|
30 | |||
32 |
|
31 | |||
33 | SAMPLING_REFS = ( |
|
32 | SAMPLING_REFS = ( | |
34 | ('none', 'No Reference'), |
|
33 | ('none', 'No Reference'), | |
35 | ('begin_baud', 'Begin of the first baud'), |
|
34 | ('begin_baud', 'Begin of the first baud'), | |
36 | ('first_baud', 'Middle of the first baud'), |
|
35 | ('first_baud', 'Middle of the first baud'), | |
37 | ('sub_baud', 'Middle of the sub-baud') |
|
36 | ('sub_baud', 'Middle of the sub-baud') | |
38 | ) |
|
37 | ) | |
39 |
|
38 | |||
40 | DAT_CMDS = { |
|
39 | DAT_CMDS = { | |
41 | # Pulse Design commands |
|
40 | # Pulse Design commands | |
42 | 'DISABLE' : 0, # Disables pulse generation |
|
41 | 'DISABLE' : 0, # Disables pulse generation | |
43 | 'ENABLE' : 24, # Enables pulse generation |
|
42 | 'ENABLE' : 24, # Enables pulse generation | |
44 | 'DELAY_START' : 40, # Write delay status to memory |
|
43 | 'DELAY_START' : 40, # Write delay status to memory | |
45 | 'FLIP_START' : 48, # Write flip status to memory |
|
44 | 'FLIP_START' : 48, # Write flip status to memory | |
46 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period |
|
45 | 'SAMPLING_PERIOD' : 64, # Establish Sampling Period | |
47 | 'TX_ONE' : 72, # Output '0' in line TX |
|
46 | 'TX_ONE' : 72, # Output '0' in line TX | |
48 | 'TX_ZERO' : 88, # Output '0' in line TX |
|
47 | 'TX_ZERO' : 88, # Output '0' in line TX | |
49 | 'SW_ONE' : 104, # Output '0' in line SW |
|
48 | 'SW_ONE' : 104, # Output '0' in line SW | |
50 | 'SW_ZERO' : 112, # Output '1' in line SW |
|
49 | 'SW_ZERO' : 112, # Output '1' in line SW | |
51 | 'RESTART': 120, # Restarts CR8 Firmware |
|
50 | 'RESTART': 120, # Restarts CR8 Firmware | |
52 | 'CONTINUE' : 253, # Function Unknown |
|
51 | 'CONTINUE' : 253, # Function Unknown | |
53 | # Commands available to new controllers |
|
52 | # Commands available to new controllers | |
54 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. |
|
53 | # In Pulse Design Executable, the clock divisor code is written as 12 at the start, but it should be written as code 22(below) just before the final enable. | |
55 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion |
|
54 | 'CLOCK_DIVISOR_INIT' : 12, # Specifies Clock Divisor. Legacy command, ignored in the actual .dat conversion | |
56 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. |
|
55 | 'CLOCK_DIVISOR_LAST' : 22, # Specifies Clock Divisor (default 60 if not included) syntax: 255,22 254,N-1. | |
57 | 'CLOCK_DIVIDER' : 8, |
|
56 | 'CLOCK_DIVIDER' : 8, | |
58 | } |
|
57 | } | |
59 |
|
58 | |||
60 | MAX_BITS = 8 |
|
59 | MAX_BITS = 8 | |
61 |
|
60 | |||
62 | # Rotate left: 0b1001 --> 0b0011 |
|
61 | # Rotate left: 0b1001 --> 0b0011 | |
63 | rol = lambda val, r_bits: \ |
|
62 | rol = lambda val, r_bits: \ | |
64 | (val << r_bits%MAX_BITS) & (2**MAX_BITS-1) | \ |
|
63 | (val << r_bits%MAX_BITS) & (2**MAX_BITS-1) | \ | |
65 | ((val & (2**MAX_BITS-1)) >> (MAX_BITS-(r_bits%MAX_BITS))) |
|
64 | ((val & (2**MAX_BITS-1)) >> (MAX_BITS-(r_bits%MAX_BITS))) | |
66 |
|
65 | |||
67 | # Rotate right: 0b1001 --> 0b1100 |
|
66 | # Rotate right: 0b1001 --> 0b1100 | |
68 | ror = lambda val, r_bits: \ |
|
67 | ror = lambda val, r_bits: \ | |
69 | ((val & (2**MAX_BITS-1)) >> r_bits%MAX_BITS) | \ |
|
68 | ((val & (2**MAX_BITS-1)) >> r_bits%MAX_BITS) | \ | |
70 | (val << (MAX_BITS-(r_bits%MAX_BITS)) & (2**MAX_BITS-1)) |
|
69 | (val << (MAX_BITS-(r_bits%MAX_BITS)) & (2**MAX_BITS-1)) | |
71 |
|
70 | |||
72 |
|
71 | |||
73 | class RCConfiguration(Configuration): |
|
72 | class RCConfiguration(Configuration): | |
74 |
|
73 | |||
75 | ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1)], default=300) |
|
74 | ipp = models.FloatField(verbose_name='IPP [Km]', validators=[MinValueValidator(1)], default=300) | |
76 | ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1)], default=1) |
|
75 | ntx = models.PositiveIntegerField(verbose_name='Number of TX', validators=[MinValueValidator(1)], default=1) | |
77 | clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) |
|
76 | clock_in = models.FloatField(verbose_name='Clock in [MHz]', validators=[MinValueValidator(1), MaxValueValidator(80)], default=1) | |
78 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) |
|
77 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(1), MaxValueValidator(256)], default=1) | |
79 | clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) |
|
78 | clock = models.FloatField(verbose_name='Clock Master [MHz]', blank=True, default=1) | |
80 | time_before = models.PositiveIntegerField(verbose_name='Time before [μS]', default=12) |
|
79 | time_before = models.PositiveIntegerField(verbose_name='Time before [μS]', default=12) | |
81 | time_after = models.PositiveIntegerField(verbose_name='Time after [μS]', default=1) |
|
80 | time_after = models.PositiveIntegerField(verbose_name='Time after [μS]', default=1) | |
82 | sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0) |
|
81 | sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0) | |
83 | sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40) |
|
82 | sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40) | |
84 | control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False) |
|
83 | control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False) | |
85 | control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False) |
|
84 | control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False) | |
86 | total_units = models.PositiveIntegerField(default=0) |
|
85 | total_units = models.PositiveIntegerField(default=0) | |
87 | mix = models.BooleanField(default=False) |
|
86 | mix = models.BooleanField(default=False) | |
88 |
|
87 | |||
89 | class Meta: |
|
88 | class Meta: | |
90 | db_table = 'rc_configurations' |
|
89 | db_table = 'rc_configurations' | |
91 |
|
90 | |||
92 | def get_absolute_url_plot(self): |
|
91 | def get_absolute_url_plot(self): | |
93 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) |
|
92 | return reverse('url_plot_rc_pulses', args=[str(self.id)]) | |
94 |
|
93 | |||
95 | @property |
|
94 | @property | |
96 | def ipp_unit(self): |
|
95 | def ipp_unit(self): | |
97 |
|
96 | |||
98 | return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit)) |
|
97 | return '{} ({})'.format(self.ipp, int(self.ipp*self.km2unit)) | |
99 |
|
98 | |||
100 | @property |
|
99 | @property | |
101 | def us2unit(self): |
|
100 | def us2unit(self): | |
102 |
|
101 | |||
103 | return self.clock_in/self.clock_divider |
|
102 | return self.clock_in/self.clock_divider | |
104 |
|
103 | |||
105 | @property |
|
104 | @property | |
106 | def km2unit(self): |
|
105 | def km2unit(self): | |
107 |
|
106 | |||
108 | return 20./3*(self.clock_in/self.clock_divider) |
|
107 | return 20./3*(self.clock_in/self.clock_divider) | |
109 |
|
108 | |||
110 | def clone(self, **kwargs): |
|
109 | def clone(self, **kwargs): | |
111 |
|
110 | |||
112 | lines = self.get_lines() |
|
111 | lines = self.get_lines() | |
113 | self.pk = None |
|
112 | self.pk = None | |
114 | self.id = None |
|
113 | self.id = None | |
115 | for attr, value in kwargs.items(): |
|
114 | for attr, value in kwargs.items(): | |
116 | setattr(self, attr, value) |
|
115 | setattr(self, attr, value) | |
117 | self.save() |
|
116 | self.save() | |
118 |
|
117 | |||
119 | for line in lines: |
|
118 | for line in lines: | |
120 | line.clone(rc_configuration=self) |
|
119 | line.clone(rc_configuration=self) | |
121 |
|
120 | |||
122 | new_lines = self.get_lines() |
|
121 | new_lines = self.get_lines() | |
123 | for line in new_lines: |
|
122 | for line in new_lines: | |
124 | line_params = json.loads(line.params) |
|
123 | line_params = json.loads(line.params) | |
125 | if 'TX_ref' in line_params and (line_params['TX_ref'] != '0'): |
|
124 | if 'TX_ref' in line_params and (line_params['TX_ref'] != '0'): | |
126 | ref_line = RCLine.objects.get(pk=line_params['TX_ref']) |
|
125 | ref_line = RCLine.objects.get(pk=line_params['TX_ref']) | |
127 | line_params['TX_ref'] = ['{}'.format(l.pk) for l in new_lines if l.get_name()==ref_line.get_name()][0] |
|
126 | line_params['TX_ref'] = ['{}'.format(l.pk) for l in new_lines if l.get_name()==ref_line.get_name()][0] | |
128 | line.params = json.dumps(line_params) |
|
127 | line.params = json.dumps(line_params) | |
129 | line.save() |
|
128 | line.save() | |
130 |
|
129 | |||
131 | return self |
|
130 | return self | |
132 |
|
131 | |||
133 | def get_lines(self, **kwargs): |
|
132 | def get_lines(self, **kwargs): | |
134 | ''' |
|
133 | ''' | |
135 | Retrieve configuration lines |
|
134 | Retrieve configuration lines | |
136 | ''' |
|
135 | ''' | |
137 |
|
136 | |||
138 | return RCLine.objects.filter(rc_configuration=self.pk, **kwargs) |
|
137 | return RCLine.objects.filter(rc_configuration=self.pk, **kwargs) | |
139 |
|
138 | |||
140 |
|
139 | |||
141 | def clean_lines(self): |
|
140 | def clean_lines(self): | |
142 | ''' |
|
141 | ''' | |
143 | ''' |
|
142 | ''' | |
144 |
|
143 | |||
145 | empty_line = RCLineType.objects.get(name='none') |
|
144 | empty_line = RCLineType.objects.get(name='none') | |
146 |
|
145 | |||
147 | for line in self.get_lines(): |
|
146 | for line in self.get_lines(): | |
148 | line.line_type = empty_line |
|
147 | line.line_type = empty_line | |
149 | line.params = '{}' |
|
148 | line.params = '{}' | |
150 | line.save() |
|
149 | line.save() | |
151 |
|
150 | |||
152 | def dict_to_parms(self, params, id=None): |
|
151 | def dict_to_parms(self, params, id=None): | |
153 | ''' |
|
152 | ''' | |
154 | ''' |
|
153 | ''' | |
155 |
|
154 | |||
156 | if id: |
|
155 | if id: | |
157 | data = Params(params).get_conf(id_conf=id) |
|
156 | data = Params(params).get_conf(id_conf=id) | |
158 | else: |
|
157 | else: | |
159 | data = Params(params).get_conf(dtype='rc') |
|
158 | data = Params(params).get_conf(dtype='rc') | |
160 |
|
159 | |||
161 | #print(data) |
|
160 | #print(data) | |
162 | # self.name = data['name'] |
|
161 | # self.name = data['name'] | |
163 | self.ipp = data['ipp'] |
|
162 | self.ipp = data['ipp'] | |
164 | self.ntx = data['ntx'] |
|
163 | self.ntx = data['ntx'] | |
165 | self.clock_in = data['clock_in'] |
|
164 | self.clock_in = data['clock_in'] | |
166 | self.clock_divider = data['clock_divider'] |
|
165 | self.clock_divider = data['clock_divider'] | |
167 | self.clock = data['clock'] |
|
166 | self.clock = data['clock'] | |
168 | self.time_before = data['time_before'] |
|
167 | self.time_before = data['time_before'] | |
169 | self.time_after = data['time_after'] |
|
168 | self.time_after = data['time_after'] | |
170 | self.sync = data['sync'] |
|
169 | self.sync = data['sync'] | |
171 | self.sampling_reference = data['sampling_reference'] |
|
170 | self.sampling_reference = data['sampling_reference'] | |
172 | self.total_units = self.ipp*self.ntx*self.km2unit |
|
171 | self.total_units = self.ipp*self.ntx*self.km2unit | |
173 | self.save() |
|
172 | self.save() | |
174 | self.clean_lines() |
|
173 | self.clean_lines() | |
175 |
|
174 | |||
176 | #print(params) |
|
175 | #print(params) | |
177 |
|
176 | |||
178 | positions = {'tx':0, 'tr':0} |
|
177 | positions = {'tx':0, 'tr':0} | |
179 | for i, id in enumerate(data['lines']): |
|
178 | for i, id in enumerate(data['lines']): | |
180 | line_data = params['lines']['byId'][id] |
|
179 | line_data = params['lines']['byId'][id] | |
181 | line_type = RCLineType.objects.get(name=line_data['line_type']) |
|
180 | line_type = RCLineType.objects.get(name=line_data['line_type']) | |
182 | if line_type.name == 'codes': |
|
181 | if line_type.name == 'codes': | |
183 | code = RCLineCode.objects.get(name=line_data['params']['code']) |
|
182 | code = RCLineCode.objects.get(name=line_data['params']['code']) | |
184 | line_data['params']['code'] = code.pk |
|
183 | line_data['params']['code'] = code.pk | |
185 | if line_type.name == 'tx': |
|
184 | if line_type.name == 'tx': | |
186 | position = positions['tx'] |
|
185 | position = positions['tx'] | |
187 | positions['tx'] += 1 |
|
186 | positions['tx'] += 1 | |
188 | elif line_type.name == 'tr': |
|
187 | elif line_type.name == 'tr': | |
189 | position = positions['tr'] |
|
188 | position = positions['tr'] | |
190 | positions['tr'] += 1 |
|
189 | positions['tr'] += 1 | |
191 | else: |
|
190 | else: | |
192 | position = 0 |
|
191 | position = 0 | |
193 | line, dum = RCLine.objects.update_or_create( |
|
192 | line, dum = RCLine.objects.update_or_create( | |
194 | rc_configuration=self, |
|
193 | rc_configuration=self, | |
195 | channel=i, |
|
194 | channel=i, | |
196 | position=position, |
|
195 | position=position, | |
197 | defaults={ |
|
196 | defaults={ | |
198 | 'line_type': line_type, |
|
197 | 'line_type': line_type, | |
199 | 'params': json.dumps(line_data['params']) |
|
198 | 'params': json.dumps(line_data['params']) | |
200 | } |
|
199 | } | |
201 | ) |
|
200 | ) | |
202 |
|
201 | |||
203 | for i, line in enumerate(self.get_lines()): |
|
202 | for i, line in enumerate(self.get_lines()): | |
204 | line_params = json.loads(line.params) |
|
203 | line_params = json.loads(line.params) | |
205 | if 'TX_ref' in line_params: |
|
204 | if 'TX_ref' in line_params: | |
206 | if line_params['TX_ref'] in (0, '0'): |
|
205 | if line_params['TX_ref'] in (0, '0'): | |
207 | line_params['TX_ref'] = '0' |
|
206 | line_params['TX_ref'] = '0' | |
208 | else: |
|
207 | else: | |
209 | ref_id = '{}'.format(line_params['TX_ref']) |
|
208 | ref_id = '{}'.format(line_params['TX_ref']) | |
210 | ref_line = params['lines']['byId'][ref_id] |
|
209 | ref_line = params['lines']['byId'][ref_id] | |
211 | line_params['TX_ref'] = RCLine.objects.get( |
|
210 | line_params['TX_ref'] = RCLine.objects.get( | |
212 | rc_configuration=self, |
|
211 | rc_configuration=self, | |
213 | params=json.dumps(ref_line['params']) |
|
212 | params=json.dumps(ref_line['params']) | |
214 | ).pk |
|
213 | ).pk | |
215 | line.params = json.dumps(line_params) |
|
214 | line.params = json.dumps(line_params) | |
216 | print(line.params) |
|
215 | print(line.params) | |
217 | line.save() |
|
216 | line.save() | |
218 | print("Fin de dict to param") |
|
217 | print("Fin de dict to param") | |
219 |
|
218 | |||
220 | def get_delays(self): |
|
219 | def get_delays(self): | |
221 |
|
220 | |||
222 | pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
221 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
223 | points = [tup for tups in pulses for tup in tups] |
|
222 | points = [tup for tups in pulses for tup in tups] | |
224 | points = set([x for tup in points for x in tup]) |
|
223 | points = set([x for tup in points for x in tup]) | |
225 | points = list(points) |
|
224 | points = list(points) | |
226 | points.sort() |
|
225 | points.sort() | |
227 |
|
226 | |||
228 | if points[0]!=0: |
|
227 | if points[0]!=0: | |
229 | points.insert(0, 0) |
|
228 | points.insert(0, 0) | |
230 |
|
229 | |||
231 | return [points[i+1]-points[i] for i in range(len(points)-1)] |
|
230 | return [points[i+1]-points[i] for i in range(len(points)-1)] | |
232 |
|
231 | |||
233 |
|
232 | |||
234 | def get_pulses(self, binary=True): |
|
233 | def get_pulses(self, binary=True): | |
235 |
|
234 | |||
236 | pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
235 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
237 | tuples = [tup for tups in pulses for tup in tups] |
|
236 | tuples = [tup for tups in pulses for tup in tups] | |
238 | points = set([x for tup in tuples for x in tup]) |
|
237 | points = set([x for tup in tuples for x in tup]) | |
239 | points = list(points) |
|
238 | points = list(points) | |
240 | points.sort() |
|
239 | points.sort() | |
241 | states = [] |
|
240 | states = [] | |
242 | last = [0 for x in pulses] |
|
241 | last = [0 for x in pulses] | |
243 |
|
242 | |||
244 | for x in points: |
|
243 | for x in points: | |
245 | dum = [] |
|
244 | dum = [] | |
246 | for i, tups in enumerate(pulses): |
|
245 | for i, tups in enumerate(pulses): | |
247 | ups = [tup[0] for tup in tups if tup!=(0,0)] |
|
246 | ups = [tup[0] for tup in tups if tup!=(0,0)] | |
248 | dws = [tup[1] for tup in tups if tup!=(0,0)] |
|
247 | dws = [tup[1] for tup in tups if tup!=(0,0)] | |
249 | if x in ups: |
|
248 | if x in ups: | |
250 | dum.append(1) |
|
249 | dum.append(1) | |
251 | elif x in dws: |
|
250 | elif x in dws: | |
252 | dum.append(0) |
|
251 | dum.append(0) | |
253 | else: |
|
252 | else: | |
254 | dum.append(last[i]) |
|
253 | dum.append(last[i]) | |
255 | states.append(dum) |
|
254 | states.append(dum) | |
256 | last = dum |
|
255 | last = dum | |
257 |
|
256 | |||
258 | if binary: |
|
257 | if binary: | |
259 | ret = [] |
|
258 | ret = [] | |
260 | for flips in states: |
|
259 | for flips in states: | |
261 | flips.reverse() |
|
260 | flips.reverse() | |
262 | ret.append(int(''.join([str(x) for x in flips]), 2)) |
|
261 | ret.append(int(''.join([str(x) for x in flips]), 2)) | |
263 | states = ret |
|
262 | states = ret | |
264 |
|
263 | |||
265 | return states[:-1] |
|
264 | return states[:-1] | |
266 |
|
265 | |||
267 | def add_cmd(self, cmd): |
|
266 | def add_cmd(self, cmd): | |
268 |
|
267 | |||
269 | if cmd in DAT_CMDS: |
|
268 | if cmd in DAT_CMDS: | |
270 | return (255, DAT_CMDS[cmd]) |
|
269 | return (255, DAT_CMDS[cmd]) | |
271 |
|
270 | |||
272 | def add_data(self, value): |
|
271 | def add_data(self, value): | |
273 |
|
272 | |||
274 | return (254, value-1) |
|
273 | return (254, value-1) | |
275 |
|
274 | |||
276 | def parms_to_binary(self, dat=True): |
|
275 | def parms_to_binary(self, dat=True): | |
277 | ''' |
|
276 | ''' | |
278 | Create "dat" stream to be send to CR |
|
277 | Create "dat" stream to be send to CR | |
279 | ''' |
|
278 | ''' | |
280 |
|
279 | |||
281 | data = bytearray() |
|
280 | data = bytearray() | |
282 | # create header |
|
281 | # create header | |
283 | data.extend(self.add_cmd('DISABLE')) |
|
282 | data.extend(self.add_cmd('DISABLE')) | |
284 | data.extend(self.add_cmd('CONTINUE')) |
|
283 | data.extend(self.add_cmd('CONTINUE')) | |
285 | data.extend(self.add_cmd('RESTART')) |
|
284 | data.extend(self.add_cmd('RESTART')) | |
286 |
|
285 | |||
287 | if self.control_sw: |
|
286 | if self.control_sw: | |
288 | data.extend(self.add_cmd('SW_ONE')) |
|
287 | data.extend(self.add_cmd('SW_ONE')) | |
289 | else: |
|
288 | else: | |
290 | data.extend(self.add_cmd('SW_ZERO')) |
|
289 | data.extend(self.add_cmd('SW_ZERO')) | |
291 |
|
290 | |||
292 | if self.control_tx: |
|
291 | if self.control_tx: | |
293 | data.extend(self.add_cmd('TX_ONE')) |
|
292 | data.extend(self.add_cmd('TX_ONE')) | |
294 | else: |
|
293 | else: | |
295 | data.extend(self.add_cmd('TX_ZERO')) |
|
294 | data.extend(self.add_cmd('TX_ZERO')) | |
296 |
|
295 | |||
297 | # write divider |
|
296 | # write divider | |
298 | data.extend(self.add_cmd('CLOCK_DIVIDER')) |
|
297 | data.extend(self.add_cmd('CLOCK_DIVIDER')) | |
299 | data.extend(self.add_data(self.clock_divider)) |
|
298 | data.extend(self.add_data(self.clock_divider)) | |
300 |
|
299 | |||
301 | # write delays |
|
300 | # write delays | |
302 | data.extend(self.add_cmd('DELAY_START')) |
|
301 | data.extend(self.add_cmd('DELAY_START')) | |
303 | # first delay is always zero |
|
302 | # first delay is always zero | |
304 | data.extend(self.add_data(1)) |
|
303 | data.extend(self.add_data(1)) | |
305 |
|
304 | |||
306 | delays = self.get_delays() |
|
305 | delays = self.get_delays() | |
307 |
|
306 | |||
308 | for delay in delays: |
|
307 | for delay in delays: | |
309 | while delay>252: |
|
308 | while delay>252: | |
310 | data.extend(self.add_data(253)) |
|
309 | data.extend(self.add_data(253)) | |
311 | delay -= 253 |
|
310 | delay -= 253 | |
312 | data.extend(self.add_data(int(delay))) |
|
311 | data.extend(self.add_data(int(delay))) | |
313 |
|
312 | |||
314 | # write flips |
|
313 | # write flips | |
315 | data.extend(self.add_cmd('FLIP_START')) |
|
314 | data.extend(self.add_cmd('FLIP_START')) | |
316 |
|
315 | |||
317 | states = self.get_pulses(binary=True) |
|
316 | states = self.get_pulses(binary=True) | |
318 |
|
317 | |||
319 |
|
318 | |||
320 | last = 0 |
|
319 | last = 0 | |
321 | for flip, delay in zip(states, delays): |
|
320 | for flip, delay in zip(states, delays): | |
322 | data.extend(self.add_data((flip^last)+1)) |
|
321 | data.extend(self.add_data((flip^last)+1)) | |
323 | last = flip |
|
322 | last = flip | |
324 | while delay>252: |
|
323 | while delay>252: | |
325 | data.extend(self.add_data(1)) |
|
324 | data.extend(self.add_data(1)) | |
326 | delay -= 253 |
|
325 | delay -= 253 | |
327 |
|
326 | |||
328 | # write sampling period |
|
327 | # write sampling period | |
329 | data.extend(self.add_cmd('SAMPLING_PERIOD')) |
|
328 | data.extend(self.add_cmd('SAMPLING_PERIOD')) | |
330 | wins = self.get_lines(line_type__name='windows') |
|
329 | wins = self.get_lines(line_type__name='windows') | |
331 | if wins: |
|
330 | if wins: | |
332 | win_params = json.loads(wins[0].params)['params'] |
|
331 | win_params = json.loads(wins[0].params)['params'] | |
333 | if win_params: |
|
332 | if win_params: | |
334 | dh = int(win_params[0]['resolution']*self.km2unit) |
|
333 | dh = int(win_params[0]['resolution']*self.km2unit) | |
335 | else: |
|
334 | else: | |
336 | dh = 1 |
|
335 | dh = 1 | |
337 | else: |
|
336 | else: | |
338 | dh = 1 |
|
337 | dh = 1 | |
339 | data.extend(self.add_data(dh)) |
|
338 | data.extend(self.add_data(dh)) | |
340 |
|
339 | |||
341 | # write enable |
|
340 | # write enable | |
342 | data.extend(self.add_cmd('ENABLE')) |
|
341 | data.extend(self.add_cmd('ENABLE')) | |
343 |
|
342 | |||
344 | if not dat: |
|
343 | if not dat: | |
345 | return data |
|
344 | return data | |
346 |
|
345 | |||
347 | return '\n'.join(['{}'.format(x) for x in data]) |
|
346 | return '\n'.join(['{}'.format(x) for x in data]) | |
348 |
|
347 | |||
349 | def update_pulses(self): |
|
348 | def update_pulses(self): | |
350 | contador = 0 |
|
349 | contador = 0 | |
351 | for line in self.get_lines(): |
|
350 | for line in self.get_lines(): | |
352 | contador=contador+1 |
|
351 | contador=contador+1 | |
353 | print(contador) |
|
352 | print(contador) | |
354 | line.update_pulses() |
|
353 | line.update_pulses() | |
355 |
|
354 | |||
356 | def plot_pulses2(self, km=False): |
|
355 | def plot_pulses2(self, km=False): | |
357 |
|
356 | |||
358 | import matplotlib |
|
357 | import matplotlib | |
359 | matplotlib.use('Agg') |
|
358 | matplotlib.use('Agg') | |
360 | import matplotlib.pyplot as plt |
|
359 | import matplotlib.pyplot as plt | |
361 | from bokeh.resources import CDN |
|
360 | from bokeh.resources import CDN | |
362 | from bokeh.embed import components |
|
361 | from bokeh.embed import components | |
363 | from bokeh.mpl import to_bokeh |
|
362 | from bokeh.mpl import to_bokeh | |
364 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool |
|
363 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool | |
365 |
|
364 | |||
366 | lines = self.get_lines() |
|
365 | lines = self.get_lines() | |
367 |
|
366 | |||
368 | N = len(lines) |
|
367 | N = len(lines) | |
369 | npoints = self.total_units/self.km2unit if km else self.total_units |
|
368 | npoints = self.total_units/self.km2unit if km else self.total_units | |
370 | fig = plt.figure(figsize=(12, 2+N*0.5)) |
|
369 | fig = plt.figure(figsize=(12, 2+N*0.5)) | |
371 | ax = fig.add_subplot(111) |
|
370 | ax = fig.add_subplot(111) | |
372 | labels = ['IPP'] |
|
371 | labels = ['IPP'] | |
373 |
|
372 | |||
374 | for i, line in enumerate(lines): |
|
373 | for i, line in enumerate(lines): | |
375 | labels.append(line.get_name(channel=True)) |
|
374 | labels.append(line.get_name(channel=True)) | |
376 | l = ax.plot((0, npoints),(N-i-1, N-i-1)) |
|
375 | l = ax.plot((0, npoints),(N-i-1, N-i-1)) | |
377 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points(km=km) if tup!=(0,0)] |
|
376 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points(km=km) if tup!=(0,0)] | |
378 | ax.broken_barh(points, (N-i-1, 0.5), |
|
377 | ax.broken_barh(points, (N-i-1, 0.5), | |
379 | edgecolor=l[0].get_color(), facecolor='none') |
|
378 | edgecolor=l[0].get_color(), facecolor='none') | |
380 |
|
379 | |||
381 | n = 0 |
|
380 | n = 0 | |
382 | f = ((self.ntx+50)/100)*5 if ((self.ntx+50)/100)*10>0 else 2 |
|
381 | f = ((self.ntx+50)/100)*5 if ((self.ntx+50)/100)*10>0 else 2 | |
383 | for x in np.arange(0, npoints, self.ipp if km else self.ipp*self.km2unit): |
|
382 | for x in np.arange(0, npoints, self.ipp if km else self.ipp*self.km2unit): | |
384 | if n%f==0: |
|
383 | if n%f==0: | |
385 | ax.text(x, N, '%s' % n, size=10) |
|
384 | ax.text(x, N, '%s' % n, size=10) | |
386 | n += 1 |
|
385 | n += 1 | |
387 |
|
386 | |||
388 | labels.reverse() |
|
387 | labels.reverse() | |
389 | ax.set_yticks(range(len(labels))) |
|
388 | ax.set_yticks(range(len(labels))) | |
390 | ax.set_yticklabels(labels) |
|
389 | ax.set_yticklabels(labels) | |
391 | ax.set_xlabel = 'Units' |
|
390 | ax.set_xlabel = 'Units' | |
392 | plot = to_bokeh(fig, use_pandas=False) |
|
391 | plot = to_bokeh(fig, use_pandas=False) | |
393 | plot.tools = [PanTool(dimensions="width"), WheelZoomTool(dimensions="width"), ResetTool(), SaveTool()] |
|
392 | plot.tools = [PanTool(dimensions="width"), WheelZoomTool(dimensions="width"), ResetTool(), SaveTool()] | |
394 | plot.toolbar_location="above" |
|
393 | plot.toolbar_location="above" | |
395 |
|
394 | |||
396 | return components(plot, CDN) |
|
395 | return components(plot, CDN) | |
397 |
|
396 | |||
398 | def plot_pulses(self, km=False): |
|
397 | def plot_pulses(self, km=False): | |
399 |
|
398 | |||
400 | from bokeh.plotting import figure |
|
399 | from bokeh.plotting import figure | |
401 | from bokeh.resources import CDN |
|
400 | from bokeh.resources import CDN | |
402 | from bokeh.embed import components |
|
401 | from bokeh.embed import components | |
403 | from bokeh.models import FixedTicker, PrintfTickFormatter |
|
402 | from bokeh.models import FixedTicker, PrintfTickFormatter | |
404 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool |
|
403 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, HoverTool, SaveTool | |
405 | from bokeh.models.sources import ColumnDataSource |
|
404 | from bokeh.models.sources import ColumnDataSource | |
406 |
|
405 | |||
407 | lines = self.get_lines().reverse() |
|
406 | lines = self.get_lines().reverse() | |
408 |
|
407 | |||
409 | N = len(lines) |
|
408 | N = len(lines) | |
410 | npoints = self.total_units/self.km2unit if km else self.total_units |
|
409 | npoints = self.total_units/self.km2unit if km else self.total_units | |
411 | ipp = self.ipp if km else self.ipp*self.km2unit |
|
410 | ipp = self.ipp if km else self.ipp*self.km2unit | |
412 |
|
411 | |||
413 | hover = HoverTool(tooltips=[("Line", "@name"), |
|
412 | hover = HoverTool(tooltips=[("Line", "@name"), | |
414 | ("IPP", "@ipp"), |
|
413 | ("IPP", "@ipp"), | |
415 | ("X", "@left")]) |
|
414 | ("X", "@left")]) | |
416 |
|
415 | |||
417 | tools = [PanTool(dimensions="width"), |
|
416 | tools = [PanTool(dimensions="width"), | |
418 | WheelZoomTool(dimensions="width"), |
|
417 | WheelZoomTool(dimensions="width"), | |
419 | hover, SaveTool()] |
|
418 | hover, SaveTool()] | |
420 |
|
419 | |||
421 | plot = figure(width=1000, |
|
420 | plot = figure(width=1000, | |
422 | height=40+N*50, |
|
421 | height=40+N*50, | |
423 | y_range = (0, N), |
|
422 | y_range = (0, N), | |
424 | tools=tools, |
|
423 | tools=tools, | |
425 | toolbar_location='above', |
|
424 | toolbar_location='above', | |
426 | toolbar_sticky=False,) |
|
425 | toolbar_sticky=False,) | |
427 |
|
426 | |||
428 | plot.xaxis.axis_label = 'Km' if km else 'Units' |
|
427 | plot.xaxis.axis_label = 'Km' if km else 'Units' | |
429 | plot.xaxis[0].formatter = PrintfTickFormatter(format='%d') |
|
428 | plot.xaxis[0].formatter = PrintfTickFormatter(format='%d') | |
430 | plot.yaxis.axis_label = 'Pulses' |
|
429 | plot.yaxis.axis_label = 'Pulses' | |
431 | plot.yaxis[0].ticker=FixedTicker(ticks=list(range(N))) |
|
430 | plot.yaxis[0].ticker=FixedTicker(ticks=list(range(N))) | |
432 | plot.yaxis[0].formatter = PrintfTickFormatter(format='Line %d') |
|
431 | plot.yaxis[0].formatter = PrintfTickFormatter(format='Line %d') | |
433 |
|
432 | |||
434 | for i, line in enumerate(lines): |
|
433 | for i, line in enumerate(lines): | |
435 |
|
434 | |||
436 | points = [tup for tup in line.pulses_as_points(km=km) if tup!=(0,0)] |
|
435 | points = [tup for tup in line.pulses_as_points(km=km) if tup!=(0,0)] | |
437 |
|
436 | |||
438 | source = ColumnDataSource(data = dict( |
|
437 | source = ColumnDataSource(data = dict( | |
439 | bottom = [i for tup in points], |
|
438 | bottom = [i for tup in points], | |
440 | top = [i+0.5 for tup in points], |
|
439 | top = [i+0.5 for tup in points], | |
441 | left = [tup[0] for tup in points], |
|
440 | left = [tup[0] for tup in points], | |
442 | right = [tup[1] for tup in points], |
|
441 | right = [tup[1] for tup in points], | |
443 | ipp = [int(tup[0]/ipp) for tup in points], |
|
442 | ipp = [int(tup[0]/ipp) for tup in points], | |
444 | name = [line.get_name() for tup in points] |
|
443 | name = [line.get_name() for tup in points] | |
445 | )) |
|
444 | )) | |
446 |
|
445 | |||
447 | plot.quad( |
|
446 | plot.quad( | |
448 | bottom = 'bottom', |
|
447 | bottom = 'bottom', | |
449 | top = 'top', |
|
448 | top = 'top', | |
450 | left = 'left', |
|
449 | left = 'left', | |
451 | right = 'right', |
|
450 | right = 'right', | |
452 | source = source, |
|
451 | source = source, | |
453 | fill_alpha = 0, |
|
452 | fill_alpha = 0, | |
454 | #line_color = 'blue', |
|
453 | #line_color = 'blue', | |
455 | ) |
|
454 | ) | |
456 |
|
455 | |||
457 | plot.line([0, npoints], [i, i])#, color='blue') |
|
456 | plot.line([0, npoints], [i, i])#, color='blue') | |
458 |
|
457 | |||
459 | return components(plot, CDN) |
|
458 | return components(plot, CDN) | |
460 |
|
459 | |||
461 | def request(self, cmd, method='get', **kwargs): |
|
460 | def request(self, cmd, method='get', **kwargs): | |
462 |
|
461 | |||
463 | req = getattr(requests, method)(self.device.url(cmd), **kwargs) |
|
462 | req = getattr(requests, method)(self.device.url(cmd), **kwargs) | |
464 | payload = req.json() |
|
463 | payload = req.json() | |
465 |
|
464 | |||
466 | return payload |
|
465 | return payload | |
467 |
|
466 | |||
468 | def status_device(self): |
|
467 | def status_device(self): | |
469 |
|
468 | |||
470 | try: |
|
469 | try: | |
471 | self.device.status = 0 |
|
470 | self.device.status = 0 | |
472 | payload = self.request('status') |
|
471 | payload = self.request('status') | |
473 | if payload['status']=='enable': |
|
472 | if payload['status']=='enable': | |
474 | self.device.status = 3 |
|
473 | self.device.status = 3 | |
475 | elif payload['status']=='disable': |
|
474 | elif payload['status']=='disable': | |
476 | self.device.status = 2 |
|
475 | self.device.status = 2 | |
477 | else: |
|
476 | else: | |
478 | self.device.status = 1 |
|
477 | self.device.status = 1 | |
479 | self.device.save() |
|
478 | self.device.save() | |
480 | self.message = 'RC status: {}'.format(payload['status']) |
|
479 | self.message = 'RC status: {}'.format(payload['status']) | |
481 | return False |
|
480 | return False | |
482 | except Exception as e: |
|
481 | except Exception as e: | |
483 | if 'No route to host' not in str(e): |
|
482 | if 'No route to host' not in str(e): | |
484 | self.device.status = 4 |
|
483 | self.device.status = 4 | |
485 | self.device.save() |
|
484 | self.device.save() | |
486 | self.message = 'RC status: {}'.format(str(e)) |
|
485 | self.message = 'RC status: {}'.format(str(e)) | |
487 | return False |
|
486 | return False | |
488 |
|
487 | |||
489 | self.device.save() |
|
488 | self.device.save() | |
490 | return True |
|
489 | return True | |
491 |
|
490 | |||
492 | def reset_device(self): |
|
491 | def reset_device(self): | |
493 |
|
492 | |||
494 | try: |
|
493 | try: | |
495 | payload = self.request('reset', 'post') |
|
494 | payload = self.request('reset', 'post') | |
496 | if payload['reset']=='ok': |
|
495 | if payload['reset']=='ok': | |
497 | self.message = 'RC restarted OK' |
|
496 | self.message = 'RC restarted OK' | |
498 | self.device.status = 2 |
|
497 | self.device.status = 2 | |
499 | self.device.save() |
|
498 | self.device.save() | |
500 | else: |
|
499 | else: | |
501 | self.message = 'RC restart fail' |
|
500 | self.message = 'RC restart fail' | |
502 | self.device.status = 4 |
|
501 | self.device.status = 4 | |
503 | self.device.save() |
|
502 | self.device.save() | |
504 | except Exception as e: |
|
503 | except Exception as e: | |
505 | self.message = 'RC reset: {}'.format(str(e)) |
|
504 | self.message = 'RC reset: {}'.format(str(e)) | |
506 | return False |
|
505 | return False | |
507 |
|
506 | |||
508 | return True |
|
507 | return True | |
509 |
|
508 | |||
510 | def stop_device(self): |
|
509 | def stop_device(self): | |
511 |
|
510 | |||
512 | try: |
|
511 | try: | |
513 | payload = self.request('stop', 'post') |
|
512 | payload = self.request('stop', 'post') | |
514 | self.message = 'RC stop: {}'.format(payload['stop']) |
|
513 | self.message = 'RC stop: {}'.format(payload['stop']) | |
515 | if payload['stop']=='ok': |
|
514 | if payload['stop']=='ok': | |
516 | self.device.status = 2 |
|
515 | self.device.status = 2 | |
517 | self.device.save() |
|
516 | self.device.save() | |
518 | else: |
|
517 | else: | |
519 | self.device.status = 4 |
|
518 | self.device.status = 4 | |
520 | self.device.save() |
|
519 | self.device.save() | |
521 | return False |
|
520 | return False | |
522 | except Exception as e: |
|
521 | except Exception as e: | |
523 | if 'No route to host' not in str(e): |
|
522 | if 'No route to host' not in str(e): | |
524 | self.device.status = 4 |
|
523 | self.device.status = 4 | |
525 | else: |
|
524 | else: | |
526 | self.device.status = 0 |
|
525 | self.device.status = 0 | |
527 | self.message = 'RC stop: {}'.format(str(e)) |
|
526 | self.message = 'RC stop: {}'.format(str(e)) | |
528 | self.device.save() |
|
527 | self.device.save() | |
529 | return False |
|
528 | return False | |
530 |
|
529 | |||
531 | return True |
|
530 | return True | |
532 |
|
531 | |||
533 | def start_device(self): |
|
532 | def start_device(self): | |
534 |
|
533 | |||
535 | try: |
|
534 | try: | |
536 | payload = self.request('start', 'post') |
|
535 | payload = self.request('start', 'post') | |
537 | self.message = 'RC start: {}'.format(payload['start']) |
|
536 | self.message = 'RC start: {}'.format(payload['start']) | |
538 | if payload['start']=='ok': |
|
537 | if payload['start']=='ok': | |
539 | self.device.status = 3 |
|
538 | self.device.status = 3 | |
540 | self.device.save() |
|
539 | self.device.save() | |
541 | else: |
|
540 | else: | |
542 | return False |
|
541 | return False | |
543 | except Exception as e: |
|
542 | except Exception as e: | |
544 | if 'No route to host' not in str(e): |
|
543 | if 'No route to host' not in str(e): | |
545 | self.device.status = 4 |
|
544 | self.device.status = 4 | |
546 | else: |
|
545 | else: | |
547 | self.device.status = 0 |
|
546 | self.device.status = 0 | |
548 | self.message = 'RC start: {}'.format(str(e)) |
|
547 | self.message = 'RC start: {}'.format(str(e)) | |
549 | self.device.save() |
|
548 | self.device.save() | |
550 | return False |
|
549 | return False | |
551 |
|
550 | |||
552 | return True |
|
551 | return True | |
553 |
|
552 | |||
554 | def write_device(self, raw=False): |
|
553 | def write_device(self, raw=False): | |
555 | print("write device") |
|
554 | print("write device") | |
556 |
|
555 | |||
557 | if not raw: |
|
556 | if not raw: | |
|
557 | pass | |||
|
558 | ''' | |||
558 | clock = RCClock.objects.get(rc_configuration=self) |
|
559 | clock = RCClock.objects.get(rc_configuration=self) | |
559 | if clock.mode: |
|
560 | if clock.mode: | |
560 | data = {'default': clock.frequency} |
|
561 | data = {'default': clock.frequency} | |
561 | else: |
|
562 | else: | |
562 | data = {'manual': [clock.multiplier, clock.divisor, clock.reference]} |
|
563 | data = {'manual': [clock.multiplier, clock.divisor, clock.reference]} | |
563 | payload = self.request('setfreq', 'post', data=json.dumps(data)) |
|
564 | payload = self.request('setfreq', 'post', data=json.dumps(data)) | |
564 | if payload['setfreq'] != 'ok': |
|
565 | if payload['setfreq'] != 'ok': | |
565 | self.message = 'RC write: {}'.format(payload['setfreq']) |
|
566 | self.message = 'RC write: {}'.format(payload['setfreq']) | |
566 | else: |
|
567 | else: | |
567 | self.message = payload['setfreq'] |
|
568 | self.message = payload['setfreq'] | |
568 | if payload['setfreq'] == 'fail': |
|
569 | if payload['setfreq'] == 'fail': | |
569 | self.message = 'RC write: error programming CGS chip' |
|
570 | self.message = 'RC write: error programming CGS chip' | |
|
571 | ''' | |||
570 |
|
572 | |||
571 | values = [] |
|
573 | values = [] | |
|
574 | print('ok') | |||
572 | for pulse, delay in zip(self.get_pulses(), self.get_delays()): |
|
575 | for pulse, delay in zip(self.get_pulses(), self.get_delays()): | |
573 | while delay > 65536: |
|
576 | while delay > 65536: | |
574 | values.append((pulse, 65535)) |
|
577 | values.append((pulse, 65535)) | |
575 | delay -= 65536 |
|
578 | delay -= 65536 | |
576 | values.append((pulse, delay-1)) |
|
579 | values.append((pulse, delay-1)) | |
577 | data = bytearray() |
|
580 | data = bytearray() | |
578 | #reset |
|
581 | #reset | |
579 | data.extend((128, 0)) |
|
582 | data.extend((128, 0)) | |
580 | #disable |
|
583 | #disable | |
581 | data.extend((129, 0)) |
|
584 | data.extend((129, 0)) | |
582 | #SW switch |
|
585 | #SW switch | |
583 | if self.control_sw: |
|
586 | if self.control_sw: | |
584 | data.extend((130, 2)) |
|
587 | data.extend((130, 2)) | |
585 | else: |
|
588 | else: | |
586 | data.extend((130, 0)) |
|
589 | data.extend((130, 0)) | |
587 | #divider |
|
590 | #divider | |
588 | data.extend((131, self.clock_divider-1)) |
|
591 | data.extend((131, self.clock_divider-1)) | |
589 | #enable writing |
|
592 | #enable writing | |
590 | data.extend((139, 62)) |
|
593 | data.extend((139, 62)) | |
591 |
|
594 | |||
592 | last = 0 |
|
595 | last = 0 | |
593 | for tup in values: |
|
596 | for tup in values: | |
594 | vals = pack('<HH', last^tup[0], tup[1]) |
|
597 | vals = pack('<HH', last^tup[0], tup[1]) | |
595 | last = tup[0] |
|
598 | last = tup[0] | |
596 | data.extend((133, vals[1], 132, vals[0], 133, vals[3], 132, vals[2])) |
|
599 | data.extend((133, vals[1], 132, vals[0], 133, vals[3], 132, vals[2])) | |
597 |
|
600 | |||
598 | #enable |
|
601 | #enable | |
599 | data.extend((129, 1)) |
|
602 | data.extend((129, 1)) | |
600 |
|
603 | |||
601 | if raw: |
|
604 | if raw: | |
602 | return b64encode(data) |
|
605 | return b64encode(data) | |
603 |
|
606 | |||
604 | #try: |
|
607 | #try: | |
605 | payload = self.request('stop', 'post') |
|
608 | payload = self.request('stop', 'post') | |
606 | payload = self.request('reset', 'post') |
|
609 | payload = self.request('reset', 'post') | |
607 | #payload = self.request('divider', 'post', data={'divider': self.clock_divider-1}) |
|
610 | #payload = self.request('divider', 'post', data={'divider': self.clock_divider-1}) | |
608 | #payload = self.request('write', 'post', data=b64encode(bytearray((139, 62))), timeout=20) |
|
611 | #payload = self.request('write', 'post', data=b64encode(bytearray((139, 62))), timeout=20) | |
609 | n = len(data) |
|
612 | n = len(data) | |
610 | x = 0 |
|
613 | x = 0 | |
611 |
|
|
614 | while x < n: | |
612 | payload = self.request('write', 'post', data=b64encode(data)) |
|
615 | payload = self.request('write', 'post', data=b64encode(data[x:x+1024])) | |
613 |
|
|
616 | x += 1024 | |
|
617 | time.sleep(1) | |||
|
618 | print('writing... ', x) | |||
614 |
|
619 | |||
615 | if payload['write']=='ok': |
|
620 | if payload['write']=='ok': | |
616 | self.device.status = 3 |
|
621 | self.device.status = 3 | |
617 | self.device.save() |
|
622 | self.device.save() | |
618 | self.message = 'RC configured and started' |
|
623 | self.message = 'RC configured and started' | |
619 | else: |
|
624 | else: | |
620 | self.device.status = 1 |
|
625 | self.device.status = 1 | |
621 | self.device.save() |
|
626 | self.device.save() | |
622 | self.message = 'RC write: {}'.format(payload['write']) |
|
627 | self.message = 'RC write: {}'.format(payload['write']) | |
623 | return False |
|
628 | return False | |
624 |
|
629 | |||
625 | #payload = self.request('start', 'post') |
|
630 | #payload = self.request('start', 'post') | |
626 |
|
631 | |||
627 | #except Exception as e: |
|
632 | #except Exception as e: | |
628 | # if 'No route to host' not in str(e): |
|
633 | # if 'No route to host' not in str(e): | |
629 | # self.device.status = 4 |
|
634 | # self.device.status = 4 | |
630 | # else: |
|
635 | # else: | |
631 | # self.device.status = 0 |
|
636 | # self.device.status = 0 | |
632 | # self.message = 'RC write: {}'.format(str(e)) |
|
637 | # self.message = 'RC write: {}'.format(str(e)) | |
633 | # self.device.save() |
|
638 | # self.device.save() | |
634 | # return False |
|
639 | # return False | |
635 |
|
640 | |||
636 | return True |
|
641 | return True | |
637 |
|
642 | |||
638 |
|
643 | |||
639 | def get_absolute_url_import(self): |
|
644 | def get_absolute_url_import(self): | |
640 | return reverse('url_import_rc_conf', args=[str(self.id)]) |
|
645 | return reverse('url_import_rc_conf', args=[str(self.id)]) | |
641 |
|
646 | |||
642 |
|
647 | |||
643 | class RCLineCode(models.Model): |
|
648 | class RCLineCode(models.Model): | |
644 |
|
649 | |||
645 | name = models.CharField(max_length=40) |
|
650 | name = models.CharField(max_length=40) | |
646 | bits_per_code = models.PositiveIntegerField(default=0) |
|
651 | bits_per_code = models.PositiveIntegerField(default=0) | |
647 | number_of_codes = models.PositiveIntegerField(default=0) |
|
652 | number_of_codes = models.PositiveIntegerField(default=0) | |
648 | codes = models.TextField(blank=True, null=True) |
|
653 | codes = models.TextField(blank=True, null=True) | |
649 |
|
654 | |||
650 | class Meta: |
|
655 | class Meta: | |
651 | db_table = 'rc_line_codes' |
|
656 | db_table = 'rc_line_codes' | |
652 | ordering = ('name',) |
|
657 | ordering = ('name',) | |
653 |
|
658 | |||
654 | def __str__(self): |
|
659 | def __str__(self): | |
655 | return u'%s' % self.name |
|
660 | return u'%s' % self.name | |
656 |
|
661 | |||
657 |
|
662 | |||
658 | class RCLineType(models.Model): |
|
663 | class RCLineType(models.Model): | |
659 |
|
664 | |||
660 | name = models.CharField(choices=LINE_TYPES, max_length=40) |
|
665 | name = models.CharField(choices=LINE_TYPES, max_length=40) | |
661 | description = models.TextField(blank=True, null=True) |
|
666 | description = models.TextField(blank=True, null=True) | |
662 | params = models.TextField(default='[]') |
|
667 | params = models.TextField(default='[]') | |
663 |
|
668 | |||
664 | class Meta: |
|
669 | class Meta: | |
665 | db_table = 'rc_line_types' |
|
670 | db_table = 'rc_line_types' | |
666 |
|
671 | |||
667 | def __str__(self): |
|
672 | def __str__(self): | |
668 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) |
|
673 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) | |
669 |
|
674 | |||
670 |
|
675 | |||
671 | class RCLine(models.Model): |
|
676 | class RCLine(models.Model): | |
672 |
|
677 | |||
673 | rc_configuration = models.ForeignKey('RCConfiguration', on_delete=models.CASCADE) |
|
678 | rc_configuration = models.ForeignKey('RCConfiguration', on_delete=models.CASCADE) | |
674 | line_type = models.ForeignKey('RCLineType',on_delete=models.CASCADE) |
|
679 | line_type = models.ForeignKey('RCLineType',on_delete=models.CASCADE) | |
675 | channel = models.PositiveIntegerField(default=0) |
|
680 | channel = models.PositiveIntegerField(default=0) | |
676 | position = models.PositiveIntegerField(default=0) |
|
681 | position = models.PositiveIntegerField(default=0) | |
677 | params = models.TextField(default='{}') |
|
682 | params = models.TextField(default='{}') | |
678 | pulses = models.TextField(default='') |
|
683 | pulses = models.TextField(default='') | |
679 |
|
684 | |||
680 | class Meta: |
|
685 | class Meta: | |
681 | db_table = 'rc_lines' |
|
686 | db_table = 'rc_lines' | |
682 | ordering = ['channel'] |
|
687 | ordering = ['channel'] | |
683 |
|
688 | |||
684 | def __str__(self): |
|
689 | def __str__(self): | |
685 | if self.rc_configuration: |
|
690 | if self.rc_configuration: | |
686 | return u'{}|{} - {}'.format(self.pk, self.get_name(), self.rc_configuration.name) |
|
691 | return u'{}|{} - {}'.format(self.pk, self.get_name(), self.rc_configuration.name) | |
687 |
|
692 | |||
688 | def jsonify(self): |
|
693 | def jsonify(self): | |
689 |
|
694 | |||
690 | data = {} |
|
695 | data = {} | |
691 | data['params'] = json.loads(self.params) |
|
696 | data['params'] = json.loads(self.params) | |
692 | data['id'] = '{}'.format(self.pk) |
|
697 | data['id'] = '{}'.format(self.pk) | |
693 | data['line_type'] = self.line_type.name |
|
698 | data['line_type'] = self.line_type.name | |
694 | data['name'] = self.get_name() |
|
699 | data['name'] = self.get_name() | |
695 | if data['line_type']=='codes': |
|
700 | if data['line_type']=='codes': | |
696 | data['params']['code'] = RCLineCode.objects.get(pk=data['params']['code']).name |
|
701 | data['params']['code'] = RCLineCode.objects.get(pk=data['params']['code']).name | |
697 |
|
702 | |||
698 | return data |
|
703 | return data | |
699 |
|
704 | |||
700 |
|
705 | |||
701 | def clone(self, **kwargs): |
|
706 | def clone(self, **kwargs): | |
702 |
|
707 | |||
703 | self.pk = None |
|
708 | self.pk = None | |
704 | self.id = None |
|
709 | self.id = None | |
705 |
|
710 | |||
706 | for attr, value in kwargs.items(): |
|
711 | for attr, value in kwargs.items(): | |
707 | setattr(self, attr, value) |
|
712 | setattr(self, attr, value) | |
708 |
|
713 | |||
709 | self.save() |
|
714 | self.save() | |
710 |
|
715 | |||
711 | return self |
|
716 | return self | |
712 |
|
717 | |||
713 | def get_name(self, channel=False): |
|
718 | def get_name(self, channel=False): | |
714 |
|
719 | |||
715 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
720 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
716 | s = '' |
|
721 | s = '' | |
717 |
|
722 | |||
718 | if self.line_type.name in ('tx',): |
|
723 | if self.line_type.name in ('tx',): | |
719 | s = chars[self.position] |
|
724 | s = chars[self.position] | |
720 | elif self.line_type.name in ('codes', 'windows', 'tr'): |
|
725 | elif self.line_type.name in ('codes', 'windows', 'tr'): | |
721 | if 'TX_ref' in json.loads(self.params): |
|
726 | if 'TX_ref' in json.loads(self.params): | |
722 | pk = json.loads(self.params)['TX_ref'] |
|
727 | pk = json.loads(self.params)['TX_ref'] | |
723 | if pk in (0, '0'): |
|
728 | if pk in (0, '0'): | |
724 | s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx')) |
|
729 | s = ','.join(chars[l.position] for l in self.rc_configuration.get_lines(line_type__name='tx')) | |
725 | else: |
|
730 | else: | |
726 | ref = RCLine.objects.get(pk=pk) |
|
731 | ref = RCLine.objects.get(pk=pk) | |
727 | s = chars[ref.position] |
|
732 | s = chars[ref.position] | |
728 | s = '({})'.format(s) |
|
733 | s = '({})'.format(s) | |
729 |
|
734 | |||
730 | s = '{}{}'.format(self.line_type.name.upper(), s) |
|
735 | s = '{}{}'.format(self.line_type.name.upper(), s) | |
731 |
|
736 | |||
732 | if channel: |
|
737 | if channel: | |
733 | return '{} {}'.format(s, self.channel) |
|
738 | return '{} {}'.format(s, self.channel) | |
734 | else: |
|
739 | else: | |
735 | return s |
|
740 | return s | |
736 |
|
741 | |||
737 | def get_lines(self, **kwargs): |
|
742 | def get_lines(self, **kwargs): | |
738 |
|
743 | |||
739 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs) |
|
744 | return RCLine.objects.filter(rc_configuration=self.rc_configuration, **kwargs) | |
740 |
|
745 | |||
741 | def pulses_as_array(self): |
|
746 | def pulses_as_array(self): | |
742 |
|
747 | |||
743 | y = np.zeros(self.rc_configuration.total_units) |
|
748 | y = np.zeros(self.rc_configuration.total_units) | |
744 |
|
749 | |||
745 | for tup in ast.literal_eval(self.pulses): |
|
750 | for tup in ast.literal_eval(self.pulses): | |
746 | y[tup[0]:tup[1]] = 1 |
|
751 | y[tup[0]:tup[1]] = 1 | |
747 |
|
752 | |||
748 | return y.astype(np.int8) |
|
753 | return y.astype(np.int8) | |
749 |
|
754 | |||
750 | def pulses_as_points(self, km=False): |
|
755 | def pulses_as_points(self, km=False): | |
751 |
|
756 | |||
752 | if km: |
|
757 | if km: | |
753 | unit2km = 1/self.rc_configuration.km2unit |
|
758 | unit2km = 1/self.rc_configuration.km2unit | |
754 | return [(tup[0]*unit2km, tup[1]*unit2km) for tup in ast.literal_eval(self.pulses)] |
|
759 | return [(tup[0]*unit2km, tup[1]*unit2km) for tup in ast.literal_eval(self.pulses)] | |
755 | else: |
|
760 | else: | |
756 | return ast.literal_eval(self.pulses) |
|
761 | return ast.literal_eval(self.pulses) | |
757 |
|
762 | |||
758 | def get_win_ref(self, params, tx_id, km2unit): |
|
763 | def get_win_ref(self, params, tx_id, km2unit): | |
759 |
|
764 | |||
760 | ref = self.rc_configuration.sampling_reference |
|
765 | ref = self.rc_configuration.sampling_reference | |
761 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] |
|
766 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] | |
762 |
|
767 | |||
763 | if codes: |
|
768 | if codes: | |
764 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) |
|
769 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) | |
765 | else: |
|
770 | else: | |
766 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit |
|
771 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit | |
767 |
|
772 | |||
768 | if ref=='first_baud': |
|
773 | if ref=='first_baud': | |
769 | return int(1 + round((tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit)) |
|
774 | return int(1 + round((tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit)) | |
770 | elif ref=='sub_baud': |
|
775 | elif ref=='sub_baud': | |
771 | return np.ceil(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) |
|
776 | return np.ceil(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) | |
772 | else: |
|
777 | else: | |
773 | return 0 |
|
778 | return 0 | |
774 |
|
779 | |||
775 | def update_pulses(self): |
|
780 | def update_pulses(self): | |
776 | ''' |
|
781 | ''' | |
777 | Update pulses field |
|
782 | Update pulses field | |
778 | ''' |
|
783 | ''' | |
779 |
|
784 | |||
780 | km2unit = self.rc_configuration.km2unit |
|
785 | km2unit = self.rc_configuration.km2unit | |
781 | us2unit = self.rc_configuration.us2unit |
|
786 | us2unit = self.rc_configuration.us2unit | |
782 | ipp = self.rc_configuration.ipp |
|
787 | ipp = self.rc_configuration.ipp | |
783 | ntx = int(self.rc_configuration.ntx) |
|
788 | ntx = int(self.rc_configuration.ntx) | |
784 | ipp_u = int(ipp*km2unit) |
|
789 | ipp_u = int(ipp*km2unit) | |
785 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units |
|
790 | total = ipp_u*ntx if self.rc_configuration.total_units==0 else self.rc_configuration.total_units | |
786 | y = [] |
|
791 | y = [] | |
787 |
|
792 | |||
788 | if self.line_type.name=='tr': |
|
793 | if self.line_type.name=='tr': | |
789 | tr_params = json.loads(self.params) |
|
794 | tr_params = json.loads(self.params) | |
790 | #print(tr_params) |
|
795 | #print(tr_params) | |
791 | #print(tr_params['TX_ref']) |
|
796 | #print(tr_params['TX_ref']) | |
792 | if tr_params['TX_ref'] in ('0', 0): |
|
797 | if tr_params['TX_ref'] in ('0', 0): | |
793 | txs = self.get_lines(line_type__name='tx') |
|
798 | txs = self.get_lines(line_type__name='tx') | |
794 | else: |
|
799 | else: | |
795 | txs = RCLine.objects.filter(pk=tr_params['TX_ref']) |
|
800 | txs = RCLine.objects.filter(pk=tr_params['TX_ref']) | |
796 |
|
801 | |||
797 | for tx in txs: |
|
802 | for tx in txs: | |
798 | params = json.loads(tx.params) |
|
803 | params = json.loads(tx.params) | |
799 |
|
804 | |||
800 | if float(params['pulse_width'])==0: |
|
805 | if float(params['pulse_width'])==0: | |
801 | continue |
|
806 | continue | |
802 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
807 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
803 | width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit) |
|
808 | width = float(params['pulse_width'])*km2unit+int(self.rc_configuration.time_before*us2unit) | |
804 | before = 0 |
|
809 | before = 0 | |
805 | after = int(self.rc_configuration.time_after*us2unit) |
|
810 | after = int(self.rc_configuration.time_after*us2unit) | |
806 |
|
811 | |||
807 | y_tx = self.points(ntx, ipp_u, width, |
|
812 | y_tx = self.points(ntx, ipp_u, width, | |
808 | delay=delays, |
|
813 | delay=delays, | |
809 | before=before, |
|
814 | before=before, | |
810 | after=after, |
|
815 | after=after, | |
811 | sync=self.rc_configuration.sync) |
|
816 | sync=self.rc_configuration.sync) | |
812 |
|
817 | |||
813 | ranges = params['range'].split(',') |
|
818 | ranges = params['range'].split(',') | |
814 |
|
819 | |||
815 | if len(ranges)>0 and ranges[0]!='0': |
|
820 | if len(ranges)>0 and ranges[0]!='0': | |
816 | y_tx = self.mask_ranges(y_tx, ranges) |
|
821 | y_tx = self.mask_ranges(y_tx, ranges) | |
817 |
|
822 | |||
818 | tr_ranges = tr_params['range'].split(',') |
|
823 | tr_ranges = tr_params['range'].split(',') | |
819 |
|
824 | |||
820 | if len(tr_ranges)>0 and tr_ranges[0]!='0': |
|
825 | if len(tr_ranges)>0 and tr_ranges[0]!='0': | |
821 | y_tx = self.mask_ranges(y_tx, tr_ranges) |
|
826 | y_tx = self.mask_ranges(y_tx, tr_ranges) | |
822 |
|
827 | |||
823 | y.extend(y_tx) |
|
828 | y.extend(y_tx) | |
824 |
|
829 | |||
825 | self.pulses = str(y) |
|
830 | self.pulses = str(y) | |
826 | y = self.array_to_points(self.pulses_as_array()) |
|
831 | y = self.array_to_points(self.pulses_as_array()) | |
827 |
|
832 | |||
828 | elif self.line_type.name=='tx': |
|
833 | elif self.line_type.name=='tx': | |
829 | params = json.loads(self.params) |
|
834 | params = json.loads(self.params) | |
830 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] |
|
835 | delays = [float(d)*km2unit for d in params['delays'].split(',') if d] | |
831 | width = float(params['pulse_width'])*km2unit |
|
836 | width = float(params['pulse_width'])*km2unit | |
832 |
|
837 | |||
833 | if width>0: |
|
838 | if width>0: | |
834 | before = int(self.rc_configuration.time_before*us2unit) |
|
839 | before = int(self.rc_configuration.time_before*us2unit) | |
835 | after = 0 |
|
840 | after = 0 | |
836 |
|
841 | |||
837 | y = self.points(ntx, ipp_u, width, |
|
842 | y = self.points(ntx, ipp_u, width, | |
838 | delay=delays, |
|
843 | delay=delays, | |
839 | before=before, |
|
844 | before=before, | |
840 | after=after, |
|
845 | after=after, | |
841 | sync=self.rc_configuration.sync) |
|
846 | sync=self.rc_configuration.sync) | |
842 |
|
847 | |||
843 | ranges = params['range'].split(',') |
|
848 | ranges = params['range'].split(',') | |
844 |
|
849 | |||
845 | if len(ranges)>0 and ranges[0]!='0': |
|
850 | if len(ranges)>0 and ranges[0]!='0': | |
846 | y = self.mask_ranges(y, ranges) |
|
851 | y = self.mask_ranges(y, ranges) | |
847 |
|
852 | |||
848 | elif self.line_type.name=='flip': |
|
853 | elif self.line_type.name=='flip': | |
849 | n = float(json.loads(self.params)['number_of_flips']) |
|
854 | n = float(json.loads(self.params)['number_of_flips']) | |
850 | width = n*ipp*km2unit |
|
855 | width = n*ipp*km2unit | |
851 | y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width) |
|
856 | y = self.points(int((ntx+1)/(2*n)), ipp_u*n*2, width) | |
852 |
|
857 | |||
853 | elif self.line_type.name=='codes': |
|
858 | elif self.line_type.name=='codes': | |
854 | params = json.loads(self.params) |
|
859 | params = json.loads(self.params) | |
855 | tx = RCLine.objects.get(pk=params['TX_ref']) |
|
860 | tx = RCLine.objects.get(pk=params['TX_ref']) | |
856 | tx_params = json.loads(tx.params) |
|
861 | tx_params = json.loads(tx.params) | |
857 | delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] |
|
862 | delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] | |
858 | f = int(float(tx_params['pulse_width'])*km2unit/len(params['codes'][0])) |
|
863 | f = int(float(tx_params['pulse_width'])*km2unit/len(params['codes'][0])) | |
859 | codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] |
|
864 | codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] | |
860 | codes = [self.array_to_points(code) for code in codes] |
|
865 | codes = [self.array_to_points(code) for code in codes] | |
861 | n = len(codes) |
|
866 | n = len(codes) | |
862 |
|
867 | |||
863 | ranges = tx_params['range'].split(',') |
|
868 | ranges = tx_params['range'].split(',') | |
864 | if len(ranges)>0 and ranges[0]!='0': |
|
869 | if len(ranges)>0 and ranges[0]!='0': | |
865 | dum = self.mask_ranges(tx.pulses_as_points(), ranges) |
|
870 | dum = self.mask_ranges(tx.pulses_as_points(), ranges) | |
866 | else: |
|
871 | else: | |
867 | dum = tx.pulses_as_points() |
|
872 | dum = tx.pulses_as_points() | |
868 |
|
873 | |||
869 | for i, tup in enumerate(dum): |
|
874 | for i, tup in enumerate(dum): | |
870 | if tup==(0,0): continue |
|
875 | if tup==(0,0): continue | |
871 | code = codes[i%n] |
|
876 | code = codes[i%n] | |
872 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) |
|
877 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) | |
873 |
|
878 | |||
874 | elif self.line_type.name=='sync': |
|
879 | elif self.line_type.name=='sync': | |
875 | params = json.loads(self.params) |
|
880 | params = json.loads(self.params) | |
876 | n = ipp_u*ntx |
|
881 | n = ipp_u*ntx | |
877 | if params['invert'] in ('1', 1): |
|
882 | if params['invert'] in ('1', 1): | |
878 | y = [(n-1, n)] |
|
883 | y = [(n-1, n)] | |
879 | else: |
|
884 | else: | |
880 | y = [(0, 1)] |
|
885 | y = [(0, 1)] | |
881 |
|
886 | |||
882 | elif self.line_type.name=='prog_pulses': |
|
887 | elif self.line_type.name=='prog_pulses': | |
883 | params = json.loads(self.params) |
|
888 | params = json.loads(self.params) | |
884 | if int(params['periodic'])==0: |
|
889 | if int(params['periodic'])==0: | |
885 | nntx = 1 |
|
890 | nntx = 1 | |
886 | nipp = ipp_u*ntx |
|
891 | nipp = ipp_u*ntx | |
887 | else: |
|
892 | else: | |
888 | nntx = ntx |
|
893 | nntx = ntx | |
889 | nipp = ipp_u |
|
894 | nipp = ipp_u | |
890 |
|
895 | |||
891 | if 'params' in params and len(params['params'])>0: |
|
896 | if 'params' in params and len(params['params'])>0: | |
892 | for p in params['params']: |
|
897 | for p in params['params']: | |
893 | y_pp = self.points(nntx, nipp, |
|
898 | y_pp = self.points(nntx, nipp, | |
894 | p['end']-p['begin'], |
|
899 | p['end']-p['begin'], | |
895 | before=p['begin']) |
|
900 | before=p['begin']) | |
896 |
|
901 | |||
897 | y.extend(y_pp) |
|
902 | y.extend(y_pp) | |
898 |
|
903 | |||
899 | elif self.line_type.name=='windows': |
|
904 | elif self.line_type.name=='windows': | |
900 | params = json.loads(self.params) |
|
905 | params = json.loads(self.params) | |
901 | if 'params' in params and len(params['params'])>0: |
|
906 | if 'params' in params and len(params['params'])>0: | |
902 | tx = RCLine.objects.get(pk=params['TX_ref']) |
|
907 | tx = RCLine.objects.get(pk=params['TX_ref']) | |
903 | tx_params = json.loads(tx.params) |
|
908 | tx_params = json.loads(tx.params) | |
904 | ranges = tx_params['range'].split(',') |
|
909 | ranges = tx_params['range'].split(',') | |
905 | for p in params['params']: |
|
910 | for p in params['params']: | |
906 | y_win = self.points(ntx, ipp_u, |
|
911 | y_win = self.points(ntx, ipp_u, | |
907 | p['resolution']*p['number_of_samples']*km2unit, |
|
912 | p['resolution']*p['number_of_samples']*km2unit, | |
908 | before=int(self.rc_configuration.time_before*us2unit)+p['first_height']*km2unit, |
|
913 | before=int(self.rc_configuration.time_before*us2unit)+p['first_height']*km2unit, | |
909 | sync=self.rc_configuration.sync+self.get_win_ref(p, params['TX_ref'], km2unit)) |
|
914 | sync=self.rc_configuration.sync+self.get_win_ref(p, params['TX_ref'], km2unit)) | |
910 |
|
915 | |||
911 |
|
916 | |||
912 | if len(ranges)>0 and ranges[0]!='0': |
|
917 | if len(ranges)>0 and ranges[0]!='0': | |
913 | y_win = self.mask_ranges(y_win, ranges) |
|
918 | y_win = self.mask_ranges(y_win, ranges) | |
914 |
|
919 | |||
915 | y.extend(y_win) |
|
920 | y.extend(y_win) | |
916 |
|
921 | |||
917 | elif self.line_type.name=='mix': |
|
922 | elif self.line_type.name=='mix': | |
918 | values = self.rc_configuration.parameters.split('-') |
|
923 | values = self.rc_configuration.parameters.split('-') | |
919 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] |
|
924 | confs = [RCConfiguration.objects.get(pk=value.split('|')[0]) for value in values] | |
920 | modes = [value.split('|')[1] for value in values] |
|
925 | modes = [value.split('|')[1] for value in values] | |
921 | ops = [value.split('|')[2] for value in values] |
|
926 | ops = [value.split('|')[2] for value in values] | |
922 | delays = [value.split('|')[3] for value in values] |
|
927 | delays = [value.split('|')[3] for value in values] | |
923 | masks = [value.split('|')[4] for value in values] |
|
928 | masks = [value.split('|')[4] for value in values] | |
924 | print("masks") |
|
929 | print("masks") | |
925 | print(masks) |
|
930 | print(masks) | |
926 | print('{:8b}'.format(int(masks[0]))) |
|
931 | print('{:8b}'.format(int(masks[0]))) | |
927 | mask = list('{:8b}'.format(int(masks[0]))) |
|
932 | mask = list('{:8b}'.format(int(masks[0]))) | |
928 | print("mask") |
|
933 | print("mask") | |
929 | print(mask) |
|
934 | print(mask) | |
930 | mask.reverse() |
|
935 | mask.reverse() | |
931 | print("mask reverse") |
|
936 | print("mask reverse") | |
932 | print(mask) |
|
937 | print(mask) | |
933 | if mask[self.channel] in ('0', '', ' '): |
|
938 | if mask[self.channel] in ('0', '', ' '): | |
934 | y = np.zeros(confs[0].total_units, dtype=np.int8) |
|
939 | y = np.zeros(confs[0].total_units, dtype=np.int8) | |
935 | else: |
|
940 | else: | |
936 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() |
|
941 | y = confs[0].get_lines(channel=self.channel)[0].pulses_as_array() | |
937 |
|
942 | |||
938 | for i in range(1, len(values)): |
|
943 | for i in range(1, len(values)): | |
939 | mask = list('{:8b}'.format(int(masks[i]))) |
|
944 | mask = list('{:8b}'.format(int(masks[i]))) | |
940 | mask.reverse() |
|
945 | mask.reverse() | |
941 |
|
946 | |||
942 | if mask[self.channel] in ('0', '', ' '): |
|
947 | if mask[self.channel] in ('0', '', ' '): | |
943 | continue |
|
948 | continue | |
944 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() |
|
949 | Y = confs[i].get_lines(channel=self.channel)[0].pulses_as_array() | |
945 | delay = float(delays[i])*km2unit |
|
950 | delay = float(delays[i])*km2unit | |
946 |
|
951 | |||
947 | if modes[i]=='P': |
|
952 | if modes[i]=='P': | |
948 | if delay>0: |
|
953 | if delay>0: | |
949 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): |
|
954 | if delay<self.rc_configuration.ipp*km2unit and len(Y)==len(y): | |
950 | y_temp = np.empty_like(Y) |
|
955 | y_temp = np.empty_like(Y) | |
951 | y_temp[:delay] = 0 |
|
956 | y_temp[:delay] = 0 | |
952 | y_temp[delay:] = Y[:-delay] |
|
957 | y_temp[delay:] = Y[:-delay] | |
953 | elif delay+len(Y)>len(y): |
|
958 | elif delay+len(Y)>len(y): | |
954 | y_new = np.zeros(delay+len(Y), dtype=np.int8) |
|
959 | y_new = np.zeros(delay+len(Y), dtype=np.int8) | |
955 | y_new[:len(y)] = y |
|
960 | y_new[:len(y)] = y | |
956 | y = y_new |
|
961 | y = y_new | |
957 | y_temp = np.zeros(delay+len(Y), dtype=np.int8) |
|
962 | y_temp = np.zeros(delay+len(Y), dtype=np.int8) | |
958 | y_temp[-len(Y):] = Y |
|
963 | y_temp[-len(Y):] = Y | |
959 | elif delay+len(Y)==len(y): |
|
964 | elif delay+len(Y)==len(y): | |
960 | y_temp = np.zeros(delay+len(Y)) |
|
965 | y_temp = np.zeros(delay+len(Y)) | |
961 | y_temp[-len(Y):] = Y |
|
966 | y_temp[-len(Y):] = Y | |
962 | elif delay+len(Y)<len(y): |
|
967 | elif delay+len(Y)<len(y): | |
963 | y_temp = np.zeros(len(y), dtype=np.int8) |
|
968 | y_temp = np.zeros(len(y), dtype=np.int8) | |
964 | y_temp[delay:delay+len(Y)] = Y |
|
969 | y_temp[delay:delay+len(Y)] = Y | |
965 | else: |
|
970 | else: | |
966 | y_temp = Y.copy() |
|
971 | y_temp = Y.copy() | |
967 |
|
972 | |||
968 | if ops[i]=='OR': |
|
973 | if ops[i]=='OR': | |
969 | y = y | y_temp |
|
974 | y = y | y_temp | |
970 | elif ops[i]=='XOR': |
|
975 | elif ops[i]=='XOR': | |
971 | y = y ^ y_temp |
|
976 | y = y ^ y_temp | |
972 | elif ops[i]=='AND': |
|
977 | elif ops[i]=='AND': | |
973 | y = y & y_temp |
|
978 | y = y & y_temp | |
974 | elif ops[i]=='NAND': |
|
979 | elif ops[i]=='NAND': | |
975 | y = y & ~y_temp |
|
980 | y = y & ~y_temp | |
976 | else: |
|
981 | else: | |
977 | y = np.concatenate([y, Y]) |
|
982 | y = np.concatenate([y, Y]) | |
978 |
|
983 | |||
979 | total = len(y) |
|
984 | total = len(y) | |
980 | y = self.array_to_points(y) |
|
985 | y = self.array_to_points(y) | |
981 |
|
986 | |||
982 | else: |
|
987 | else: | |
983 | y = [] |
|
988 | y = [] | |
984 |
|
989 | |||
985 | if self.rc_configuration.total_units != total: |
|
990 | if self.rc_configuration.total_units != total: | |
986 | self.rc_configuration.total_units = total |
|
991 | self.rc_configuration.total_units = total | |
987 | self.rc_configuration.save() |
|
992 | self.rc_configuration.save() | |
988 |
|
993 | |||
989 | self.pulses = str(y) |
|
994 | self.pulses = str(y) | |
990 | self.save() |
|
995 | self.save() | |
991 |
|
996 | |||
992 | @staticmethod |
|
997 | @staticmethod | |
993 | def array_to_points(X): |
|
998 | def array_to_points(X): | |
994 |
|
999 | |||
995 | if X.size==0: |
|
1000 | if X.size==0: | |
996 | return [] |
|
1001 | return [] | |
997 |
|
1002 | |||
998 | d = X[1:]-X[:-1] |
|
1003 | d = X[1:]-X[:-1] | |
999 |
|
1004 | |||
1000 | up = np.where(d==1)[0] |
|
1005 | up = np.where(d==1)[0] | |
1001 | if X[0]==1: |
|
1006 | if X[0]==1: | |
1002 | up = np.concatenate((np.array([-1]), up)) |
|
1007 | up = np.concatenate((np.array([-1]), up)) | |
1003 | up += 1 |
|
1008 | up += 1 | |
1004 |
|
1009 | |||
1005 | dw = np.where(d==-1)[0] |
|
1010 | dw = np.where(d==-1)[0] | |
1006 | if X[-1]==1: |
|
1011 | if X[-1]==1: | |
1007 | dw = np.concatenate((dw, np.array([len(X)-1]))) |
|
1012 | dw = np.concatenate((dw, np.array([len(X)-1]))) | |
1008 | dw += 1 |
|
1013 | dw += 1 | |
1009 |
|
1014 | |||
1010 | return [(tup[0], tup[1]) for tup in zip(up, dw)] |
|
1015 | return [(tup[0], tup[1]) for tup in zip(up, dw)] | |
1011 |
|
1016 | |||
1012 | @staticmethod |
|
1017 | @staticmethod | |
1013 | def mask_ranges(Y, ranges): |
|
1018 | def mask_ranges(Y, ranges): | |
1014 |
|
1019 | |||
1015 | y = [(0, 0) for __ in Y] |
|
1020 | y = [(0, 0) for __ in Y] | |
1016 |
|
1021 | |||
1017 | for index in ranges: |
|
1022 | for index in ranges: | |
1018 | if '-' in index: |
|
1023 | if '-' in index: | |
1019 | args = [int(a) for a in index.split('-')] |
|
1024 | args = [int(a) for a in index.split('-')] | |
1020 | y[args[0]-1:args[1]] = Y[args[0]-1:args[1]] |
|
1025 | y[args[0]-1:args[1]] = Y[args[0]-1:args[1]] | |
1021 | else: |
|
1026 | else: | |
1022 | y[int(index)-1] = Y[int(index)-1] |
|
1027 | y[int(index)-1] = Y[int(index)-1] | |
1023 |
|
1028 | |||
1024 | return y |
|
1029 | return y | |
1025 |
|
1030 | |||
1026 | @staticmethod |
|
1031 | @staticmethod | |
1027 | def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0): |
|
1032 | def points(ntx, ipp, width, delay=[0], before=0, after=0, sync=0): | |
1028 |
|
1033 | |||
1029 | delays = len(delay) |
|
1034 | delays = len(delay) | |
1030 |
|
1035 | |||
1031 | Y = [(int(ipp*x+before+delay[x%delays]+sync), int(ipp*x+width+before+delay[x%delays]+after+sync)) for x in range(ntx)] |
|
1036 | Y = [(int(ipp*x+before+delay[x%delays]+sync), int(ipp*x+width+before+delay[x%delays]+after+sync)) for x in range(ntx)] | |
1032 |
|
1037 | |||
1033 | return Y |
|
1038 | return Y | |
1034 |
|
1039 | |||
1035 | class RCClock(models.Model): |
|
1040 | class RCClock(models.Model): | |
1036 |
|
1041 | |||
1037 | rc_configuration = models.ForeignKey('RCConfiguration', on_delete=models.CASCADE) |
|
1042 | rc_configuration = models.ForeignKey('RCConfiguration', on_delete=models.CASCADE) | |
1038 | mode = models.BooleanField(default=True, choices=((True, 'Auto'), (False, 'Manual'))) |
|
1043 | mode = models.BooleanField(default=True, choices=((True, 'Auto'), (False, 'Manual'))) | |
1039 | multiplier = models.PositiveIntegerField(default=60) |
|
1044 | multiplier = models.PositiveIntegerField(default=60) | |
1040 | divisor = models.PositiveIntegerField(default=10) |
|
1045 | divisor = models.PositiveIntegerField(default=10) | |
1041 | reference = models.PositiveSmallIntegerField(default=1, choices=((0, 'Internal (25MHz)'), (1, 'External (10MHz)'))) |
|
1046 | reference = models.PositiveSmallIntegerField(default=1, choices=((0, 'Internal (25MHz)'), (1, 'External (10MHz)'))) | |
1042 | frequency = models.FloatField(default=60.0) No newline at end of file |
|
1047 | frequency = models.FloatField(default=60.0) |
@@ -1,436 +1,435 | |||||
1 |
|
||||
2 |
|
|
1 | import json | |
3 |
|
2 | |||
4 | from django.contrib import messages |
|
3 | from django.contrib import messages | |
5 | from django.utils.safestring import mark_safe |
|
4 | from django.utils.safestring import mark_safe | |
6 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
5 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
7 | from django.contrib.auth.decorators import login_required |
|
6 | from django.contrib.auth.decorators import login_required | |
8 |
|
7 | |||
9 | from apps.main.models import Experiment, Device |
|
8 | from apps.main.models import Experiment, Device | |
10 | from apps.main.views import sidebar |
|
9 | from apps.main.views import sidebar | |
11 |
|
10 | |||
12 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode, RCClock |
|
11 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode, RCClock | |
13 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm, RCImportForm, RCLineCodesForm, RCClockForm |
|
12 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm, RCImportForm, RCLineCodesForm, RCClockForm | |
14 |
|
13 | |||
15 |
|
14 | |||
16 | def conf(request, conf_id): |
|
15 | def conf(request, conf_id): | |
17 |
|
16 | |||
18 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
17 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
19 |
|
18 | |||
20 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
19 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
21 | clk = RCClock.objects.filter(rc_configuration=conf).first() |
|
20 | clk = RCClock.objects.filter(rc_configuration=conf).first() | |
22 | if clk is None: |
|
21 | if clk is None: | |
23 | clk = RCClock(rc_configuration=conf) |
|
22 | clk = RCClock(rc_configuration=conf) | |
24 | clk.save() |
|
23 | clk.save() | |
25 |
|
24 | |||
26 | for line in lines: |
|
25 | for line in lines: | |
27 | params = json.loads(line.params) |
|
26 | params = json.loads(line.params) | |
28 | line.form = RCLineViewForm(extra_fields=params, line=line) |
|
27 | line.form = RCLineViewForm(extra_fields=params, line=line) | |
29 | if 'params' in params: |
|
28 | if 'params' in params: | |
30 | line.subforms = [RCLineViewForm(extra_fields=fields, line=line, subform=True) for fields in params['params']] |
|
29 | line.subforms = [RCLineViewForm(extra_fields=fields, line=line, subform=True) for fields in params['params']] | |
31 |
|
30 | |||
32 | kwargs = {} |
|
31 | kwargs = {} | |
33 | kwargs['clock'] = clk |
|
32 | kwargs['clock'] = clk | |
34 | kwargs['dev_conf'] = conf |
|
33 | kwargs['dev_conf'] = conf | |
35 | kwargs['rc_lines'] = lines |
|
34 | kwargs['rc_lines'] = lines | |
36 | kwargs['dev_conf_keys'] = ['ipp_unit', 'ntx', 'clock_divider', 'clock', |
|
35 | kwargs['dev_conf_keys'] = ['ipp_unit', 'ntx', 'clock_divider', 'clock', | |
37 | 'time_before', 'time_after', 'sync', 'sampling_reference', |
|
36 | 'time_before', 'time_after', 'sync', 'sampling_reference', | |
38 | 'control_tx', 'control_sw'] |
|
37 | 'control_tx', 'control_sw'] | |
39 |
|
38 | |||
40 | kwargs['title'] = 'Configuration' |
|
39 | kwargs['title'] = 'Configuration' | |
41 | kwargs['suptitle'] = 'Detail' |
|
40 | kwargs['suptitle'] = 'Detail' | |
42 |
|
41 | |||
43 | kwargs['button'] = 'Edit Configuration' |
|
42 | kwargs['button'] = 'Edit Configuration' | |
44 | ###### SIDEBAR ###### |
|
43 | ###### SIDEBAR ###### | |
45 | kwargs.update(sidebar(conf=conf)) |
|
44 | kwargs.update(sidebar(conf=conf)) | |
46 |
|
45 | |||
47 | return render(request, 'rc_conf.html', kwargs) |
|
46 | return render(request, 'rc_conf.html', kwargs) | |
48 |
|
47 | |||
49 | @login_required |
|
48 | @login_required | |
50 | def conf_edit(request, conf_id): |
|
49 | def conf_edit(request, conf_id): | |
51 |
|
50 | |||
52 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
51 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
53 | clock = RCClock.objects.get(rc_configuration=conf) |
|
52 | clock = RCClock.objects.get(rc_configuration=conf) | |
54 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
53 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
55 |
|
54 | |||
56 | for line in lines: |
|
55 | for line in lines: | |
57 | params = json.loads(line.params) |
|
56 | params = json.loads(line.params) | |
58 | #print(params) |
|
57 | #print(params) | |
59 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) |
|
58 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) | |
60 | line.subform = False |
|
59 | line.subform = False | |
61 |
|
60 | |||
62 | if 'params' in params: |
|
61 | if 'params' in params: | |
63 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] |
|
62 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] | |
64 | line.subform = True |
|
63 | line.subform = True | |
65 | print(params) |
|
64 | print(params) | |
66 | print("fin de sub carga de params") |
|
65 | print("fin de sub carga de params") | |
67 | #print("fin de carga de params") |
|
66 | #print("fin de carga de params") | |
68 | if request.method=='GET': |
|
67 | if request.method=='GET': | |
69 | print("GET case") |
|
68 | print("GET case") | |
70 | form = RCConfigurationForm(instance=conf) |
|
69 | form = RCConfigurationForm(instance=conf) | |
71 | form_clock = RCClockForm(instance=clock) |
|
70 | form_clock = RCClockForm(instance=clock) | |
72 |
|
71 | |||
73 | elif request.method=='POST': |
|
72 | elif request.method=='POST': | |
74 | #print("ingreso a post conf edit") |
|
73 | #print("ingreso a post conf edit") | |
75 | line_data = {} |
|
74 | line_data = {} | |
76 | conf_data = {} |
|
75 | conf_data = {} | |
77 | clock_data = {} |
|
76 | clock_data = {} | |
78 | extras = [] |
|
77 | extras = [] | |
79 | print("Inicio impresion POST#####") |
|
78 | print("Inicio impresion POST#####") | |
80 | print(request.POST.items) |
|
79 | print(request.POST.items) | |
81 | print("Fin impresion de POST items#####") |
|
80 | print("Fin impresion de POST items#####") | |
82 | #classified post fields |
|
81 | #classified post fields | |
83 | for label,value in request.POST.items(): |
|
82 | for label,value in request.POST.items(): | |
84 | if label=='csrfmiddlewaretoken': |
|
83 | if label=='csrfmiddlewaretoken': | |
85 | continue |
|
84 | continue | |
86 |
|
85 | |||
87 | if label.count('|')==0: |
|
86 | if label.count('|')==0: | |
88 | if label in ('mode', 'multiplier', 'divisor', 'reference', 'frequency'): |
|
87 | if label in ('mode', 'multiplier', 'divisor', 'reference', 'frequency'): | |
89 | clock_data[label] = value |
|
88 | clock_data[label] = value | |
90 | else: |
|
89 | else: | |
91 | conf_data[label] = value |
|
90 | conf_data[label] = value | |
92 | continue |
|
91 | continue | |
93 |
|
92 | |||
94 | elif label.split('|')[0]!='-1': |
|
93 | elif label.split('|')[0]!='-1': | |
95 | extras.append(label) |
|
94 | extras.append(label) | |
96 | continue |
|
95 | continue | |
97 |
|
96 | |||
98 | #print(label) |
|
97 | #print(label) | |
99 | x, pk, name = label.split('|') |
|
98 | x, pk, name = label.split('|') | |
100 |
|
99 | |||
101 | if name=='codes': |
|
100 | if name=='codes': | |
102 | value = [s for s in value.split('\r\n') if s] |
|
101 | value = [s for s in value.split('\r\n') if s] | |
103 |
|
102 | |||
104 | if pk in line_data: |
|
103 | if pk in line_data: | |
105 | line_data[pk][name] = value |
|
104 | line_data[pk][name] = value | |
106 | else: |
|
105 | else: | |
107 | line_data[pk] = {name:value} |
|
106 | line_data[pk] = {name:value} | |
108 | #print(line_data[pk]) |
|
107 | #print(line_data[pk]) | |
109 | #update conf |
|
108 | #update conf | |
110 |
|
109 | |||
111 | form_clock = RCClockForm(clock_data, instance=clock) |
|
110 | form_clock = RCClockForm(clock_data, instance=clock) | |
112 | form = RCConfigurationForm(conf_data, instance=conf) |
|
111 | form = RCConfigurationForm(conf_data, instance=conf) | |
113 |
|
112 | |||
114 | #print(request.POST.items()) |
|
113 | #print(request.POST.items()) | |
115 |
|
114 | |||
116 | if form_clock.is_valid() and form.is_valid(): |
|
115 | if form_clock.is_valid() and form.is_valid(): | |
117 | form_clock.save() |
|
116 | form_clock.save() | |
118 | form.save() |
|
117 | form.save() | |
119 |
|
118 | |||
120 | #update lines fields |
|
119 | #update lines fields | |
121 | extras.sort() |
|
120 | extras.sort(key=lambda x: int(x.split('|')[0])) | |
122 | #print("Inicio extras") |
|
121 | #print("Inicio extras") | |
123 | #print(extras) |
|
122 | #print(extras) | |
124 | #print("Fin extras") |
|
123 | #print("Fin extras") | |
125 | for label in extras: |
|
124 | for label in extras: | |
126 | x, pk, name = label.split('|') |
|
125 | x, pk, name = label.split('|') | |
127 | if pk not in line_data: |
|
126 | if pk not in line_data: | |
128 | line_data[pk] = {} |
|
127 | line_data[pk] = {} | |
129 | if 'params' not in line_data[pk]: |
|
128 | if 'params' not in line_data[pk]: | |
130 | line_data[pk]['params'] = [] |
|
129 | line_data[pk]['params'] = [] | |
131 | if len(line_data[pk]['params'])<int(x)+1: |
|
130 | if len(line_data[pk]['params'])<int(x)+1: | |
132 | line_data[pk]['params'].append({}) |
|
131 | line_data[pk]['params'].append({}) | |
133 | line_data[pk]['params'][int(x)][name] = float(request.POST[label]) |
|
132 | line_data[pk]['params'][int(x)][name] = float(request.POST[label]) | |
134 |
|
133 | |||
135 | for pk, params in line_data.items(): |
|
134 | for pk, params in line_data.items(): | |
136 | line = RCLine.objects.get(pk=pk) |
|
135 | line = RCLine.objects.get(pk=pk) | |
137 | if line.line_type.name in ('windows', 'prog_pulses'): |
|
136 | if line.line_type.name in ('windows', 'prog_pulses'): | |
138 | if 'params' not in params: |
|
137 | if 'params' not in params: | |
139 | params['params'] = [] |
|
138 | params['params'] = [] | |
140 | line.params = json.dumps(params) |
|
139 | line.params = json.dumps(params) | |
141 | #print(line.params) |
|
140 | #print(line.params) | |
142 | line.save() |
|
141 | line.save() | |
143 |
|
142 | |||
144 |
|
143 | |||
145 | #update pulses field |
|
144 | #update pulses field | |
146 | conf.update_pulses() |
|
145 | conf.update_pulses() | |
147 |
|
146 | |||
148 | messages.success(request, 'RC Configuration successfully updated') |
|
147 | messages.success(request, 'RC Configuration successfully updated') | |
149 |
|
148 | |||
150 | return redirect(conf.get_absolute_url()) |
|
149 | return redirect(conf.get_absolute_url()) | |
151 |
|
150 | |||
152 | kwargs = {} |
|
151 | kwargs = {} | |
153 | kwargs['dev_conf'] = conf |
|
152 | kwargs['dev_conf'] = conf | |
154 | kwargs['form'] = form |
|
153 | kwargs['form'] = form | |
155 | kwargs['form_clock'] = form_clock |
|
154 | kwargs['form_clock'] = form_clock | |
156 | kwargs['rc_lines'] = lines |
|
155 | kwargs['rc_lines'] = lines | |
157 | kwargs['edit'] = True |
|
156 | kwargs['edit'] = True | |
158 |
|
157 | |||
159 | kwargs['title'] = 'RC Configuration' |
|
158 | kwargs['title'] = 'RC Configuration' | |
160 | kwargs['suptitle'] = 'Edit' |
|
159 | kwargs['suptitle'] = 'Edit' | |
161 | kwargs['button'] = 'Update' |
|
160 | kwargs['button'] = 'Update' | |
162 |
|
161 | |||
163 | return render(request, 'rc_conf_edit.html', kwargs) |
|
162 | return render(request, 'rc_conf_edit.html', kwargs) | |
164 |
|
163 | |||
165 |
|
164 | |||
166 | def add_line(request, conf_id, line_type_id=None, code_id=None): |
|
165 | def add_line(request, conf_id, line_type_id=None, code_id=None): | |
167 |
|
166 | |||
168 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
167 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
169 |
|
168 | |||
170 | if request.method=='GET': |
|
169 | if request.method=='GET': | |
171 | if line_type_id: |
|
170 | if line_type_id: | |
172 | line_type = get_object_or_404(RCLineType, pk=line_type_id) |
|
171 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
173 |
|
172 | |||
174 | if code_id: |
|
173 | if code_id: | |
175 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id, 'code_id': code_id}, |
|
174 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id, 'code_id': code_id}, | |
176 | extra_fields=json.loads(line_type.params)) |
|
175 | extra_fields=json.loads(line_type.params)) | |
177 | else: |
|
176 | else: | |
178 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id}, |
|
177 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id}, | |
179 | extra_fields=json.loads(line_type.params)) |
|
178 | extra_fields=json.loads(line_type.params)) | |
180 | else: |
|
179 | else: | |
181 | line_type = {'id':0} |
|
180 | line_type = {'id':0} | |
182 | form = RCLineForm(initial={'rc_configuration':conf_id}) |
|
181 | form = RCLineForm(initial={'rc_configuration':conf_id}) | |
183 |
|
182 | |||
184 | if request.method=='POST': |
|
183 | if request.method=='POST': | |
185 |
|
184 | |||
186 | line_type = get_object_or_404(RCLineType, pk=line_type_id) |
|
185 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
187 | form = RCLineForm(request.POST, |
|
186 | form = RCLineForm(request.POST, | |
188 | extra_fields=json.loads(line_type.params)) |
|
187 | extra_fields=json.loads(line_type.params)) | |
189 |
|
188 | |||
190 | if form.is_valid(): |
|
189 | if form.is_valid(): | |
191 | form.save() |
|
190 | form.save() | |
192 | form.instance.update_pulses() |
|
191 | form.instance.update_pulses() | |
193 | return redirect('url_edit_rc_conf', conf.id) |
|
192 | return redirect('url_edit_rc_conf', conf.id) | |
194 |
|
193 | |||
195 | kwargs = {} |
|
194 | kwargs = {} | |
196 | kwargs['form'] = form |
|
195 | kwargs['form'] = form | |
197 | kwargs['title'] = 'RC Configuration' |
|
196 | kwargs['title'] = 'RC Configuration' | |
198 | kwargs['suptitle'] = 'Add Line' |
|
197 | kwargs['suptitle'] = 'Add Line' | |
199 | kwargs['button'] = 'Add' |
|
198 | kwargs['button'] = 'Add' | |
200 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
199 | kwargs['previous'] = conf.get_absolute_url_edit() | |
201 | kwargs['dev_conf'] = conf |
|
200 | kwargs['dev_conf'] = conf | |
202 | kwargs['line_type'] = line_type |
|
201 | kwargs['line_type'] = line_type | |
203 |
|
202 | |||
204 | return render(request, 'rc_add_line.html', kwargs) |
|
203 | return render(request, 'rc_add_line.html', kwargs) | |
205 |
|
204 | |||
206 | def edit_codes(request, conf_id, line_id, code_id=None): |
|
205 | def edit_codes(request, conf_id, line_id, code_id=None): | |
207 |
|
206 | |||
208 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
207 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
209 | line = get_object_or_404(RCLine, pk=line_id) |
|
208 | line = get_object_or_404(RCLine, pk=line_id) | |
210 | params = json.loads(line.params) |
|
209 | params = json.loads(line.params) | |
211 |
|
210 | |||
212 | if request.method=='GET': |
|
211 | if request.method=='GET': | |
213 | if code_id: |
|
212 | if code_id: | |
214 | code = get_object_or_404(RCLineCode, pk=code_id) |
|
213 | code = get_object_or_404(RCLineCode, pk=code_id) | |
215 | form = RCLineCodesForm(instance=code) |
|
214 | form = RCLineCodesForm(instance=code) | |
216 | else: |
|
215 | else: | |
217 | initial = {'code': params['code'], |
|
216 | initial = {'code': params['code'], | |
218 | 'codes': params['codes'] if 'codes' in params else [], |
|
217 | 'codes': params['codes'] if 'codes' in params else [], | |
219 | 'number_of_codes': len(params['codes']) if 'codes' in params else 0, |
|
218 | 'number_of_codes': len(params['codes']) if 'codes' in params else 0, | |
220 | 'bits_per_code': len(params['codes'][0]) if 'codes' in params else 0, |
|
219 | 'bits_per_code': len(params['codes'][0]) if 'codes' in params else 0, | |
221 | } |
|
220 | } | |
222 | form = RCLineCodesForm(initial=initial) |
|
221 | form = RCLineCodesForm(initial=initial) | |
223 |
|
222 | |||
224 | if request.method=='POST': |
|
223 | if request.method=='POST': | |
225 | form = RCLineCodesForm(request.POST) |
|
224 | form = RCLineCodesForm(request.POST) | |
226 | if form.is_valid(): |
|
225 | if form.is_valid(): | |
227 | params['code'] = request.POST['code'] |
|
226 | params['code'] = request.POST['code'] | |
228 | params['codes'] = [s for s in request.POST['codes'].split('\r\n') if s] |
|
227 | params['codes'] = [s for s in request.POST['codes'].split('\r\n') if s] | |
229 | line.params = json.dumps(params) |
|
228 | line.params = json.dumps(params) | |
230 | line.save() |
|
229 | line.save() | |
231 | messages.success(request, 'Line: "%s" has been updated.' % line) |
|
230 | messages.success(request, 'Line: "%s" has been updated.' % line) | |
232 | return redirect('url_edit_rc_conf', conf.id) |
|
231 | return redirect('url_edit_rc_conf', conf.id) | |
233 |
|
232 | |||
234 | kwargs = {} |
|
233 | kwargs = {} | |
235 | kwargs['form'] = form |
|
234 | kwargs['form'] = form | |
236 | kwargs['title'] = line |
|
235 | kwargs['title'] = line | |
237 | kwargs['suptitle'] = 'Edit' |
|
236 | kwargs['suptitle'] = 'Edit' | |
238 | kwargs['button'] = 'Update' |
|
237 | kwargs['button'] = 'Update' | |
239 | kwargs['dev_conf'] = conf |
|
238 | kwargs['dev_conf'] = conf | |
240 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
239 | kwargs['previous'] = conf.get_absolute_url_edit() | |
241 | kwargs['line'] = line |
|
240 | kwargs['line'] = line | |
242 |
|
241 | |||
243 | return render(request, 'rc_edit_codes.html', kwargs) |
|
242 | return render(request, 'rc_edit_codes.html', kwargs) | |
244 |
|
243 | |||
245 | def add_subline(request, conf_id, line_id): |
|
244 | def add_subline(request, conf_id, line_id): | |
246 |
|
245 | |||
247 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
246 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
248 | line = get_object_or_404(RCLine, pk=line_id) |
|
247 | line = get_object_or_404(RCLine, pk=line_id) | |
249 |
|
248 | |||
250 | if request.method == 'POST': |
|
249 | if request.method == 'POST': | |
251 | if line: |
|
250 | if line: | |
252 | params = json.loads(line.params) |
|
251 | params = json.loads(line.params) | |
253 | subparams = json.loads(line.line_type.params) |
|
252 | subparams = json.loads(line.line_type.params) | |
254 | if 'params' in subparams: |
|
253 | if 'params' in subparams: | |
255 | dum = {} |
|
254 | dum = {} | |
256 | for key, value in subparams['params'].items(): |
|
255 | for key, value in subparams['params'].items(): | |
257 | dum[key] = value['value'] |
|
256 | dum[key] = value['value'] | |
258 | params['params'].append(dum) |
|
257 | params['params'].append(dum) | |
259 | line.params = json.dumps(params) |
|
258 | line.params = json.dumps(params) | |
260 | line.save() |
|
259 | line.save() | |
261 | return redirect('url_edit_rc_conf', conf.id) |
|
260 | return redirect('url_edit_rc_conf', conf.id) | |
262 |
|
261 | |||
263 | kwargs = {} |
|
262 | kwargs = {} | |
264 |
|
263 | |||
265 | kwargs['title'] = 'Add new' |
|
264 | kwargs['title'] = 'Add new' | |
266 | kwargs['suptitle'] = '%s to %s' % (line.line_type.name, line) |
|
265 | kwargs['suptitle'] = '%s to %s' % (line.line_type.name, line) | |
267 |
|
266 | |||
268 | return render(request, 'confirm.html', kwargs) |
|
267 | return render(request, 'confirm.html', kwargs) | |
269 |
|
268 | |||
270 | def remove_line(request, conf_id, line_id): |
|
269 | def remove_line(request, conf_id, line_id): | |
271 |
|
270 | |||
272 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
271 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
273 | line = get_object_or_404(RCLine, pk=line_id) |
|
272 | line = get_object_or_404(RCLine, pk=line_id) | |
274 |
|
273 | |||
275 | if request.method == 'POST': |
|
274 | if request.method == 'POST': | |
276 | if line: |
|
275 | if line: | |
277 | try: |
|
276 | try: | |
278 | channel = line.channel |
|
277 | channel = line.channel | |
279 | line.delete() |
|
278 | line.delete() | |
280 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): |
|
279 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): | |
281 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) |
|
280 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) | |
282 | l.channel = l.channel-1 |
|
281 | l.channel = l.channel-1 | |
283 | l.save() |
|
282 | l.save() | |
284 | messages.success(request, 'Line: "%s" has been deleted.' % line) |
|
283 | messages.success(request, 'Line: "%s" has been deleted.' % line) | |
285 | except: |
|
284 | except: | |
286 | messages.error(request, 'Unable to delete line: "%s".' % line) |
|
285 | messages.error(request, 'Unable to delete line: "%s".' % line) | |
287 |
|
286 | |||
288 | return redirect('url_edit_rc_conf', conf.id) |
|
287 | return redirect('url_edit_rc_conf', conf.id) | |
289 |
|
288 | |||
290 | kwargs = {} |
|
289 | kwargs = {} | |
291 |
|
290 | |||
292 | kwargs['object'] = line |
|
291 | kwargs['object'] = line | |
293 | kwargs['delete'] = True |
|
292 | kwargs['delete'] = True | |
294 | kwargs['title'] = 'Delete' |
|
293 | kwargs['title'] = 'Delete' | |
295 | kwargs['suptitle'] = 'Line' |
|
294 | kwargs['suptitle'] = 'Line' | |
296 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
295 | kwargs['previous'] = conf.get_absolute_url_edit() | |
297 | return render(request, 'confirm.html', kwargs) |
|
296 | return render(request, 'confirm.html', kwargs) | |
298 |
|
297 | |||
299 |
|
298 | |||
300 | def remove_subline(request, conf_id, line_id, subline_id): |
|
299 | def remove_subline(request, conf_id, line_id, subline_id): | |
301 |
|
300 | |||
302 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
301 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
303 | line = get_object_or_404(RCLine, pk=line_id) |
|
302 | line = get_object_or_404(RCLine, pk=line_id) | |
304 |
|
303 | |||
305 | if request.method == 'POST': |
|
304 | if request.method == 'POST': | |
306 | if line: |
|
305 | if line: | |
307 | params = json.loads(line.params) |
|
306 | params = json.loads(line.params) | |
308 | params['params'].remove(params['params'][int(subline_id)-1]) |
|
307 | params['params'].remove(params['params'][int(subline_id)-1]) | |
309 | line.params = json.dumps(params) |
|
308 | line.params = json.dumps(params) | |
310 | line.save() |
|
309 | line.save() | |
311 |
|
310 | |||
312 | return redirect('url_edit_rc_conf', conf.id) |
|
311 | return redirect('url_edit_rc_conf', conf.id) | |
313 |
|
312 | |||
314 | kwargs = {} |
|
313 | kwargs = {} | |
315 |
|
314 | |||
316 | kwargs['object'] = line |
|
315 | kwargs['object'] = line | |
317 | kwargs['object_name'] = line.line_type.name |
|
316 | kwargs['object_name'] = line.line_type.name | |
318 | kwargs['delete_view'] = True |
|
317 | kwargs['delete_view'] = True | |
319 | kwargs['title'] = 'Confirm delete' |
|
318 | kwargs['title'] = 'Confirm delete' | |
320 |
|
319 | |||
321 | return render(request, 'confirm.html', kwargs) |
|
320 | return render(request, 'confirm.html', kwargs) | |
322 |
|
321 | |||
323 |
|
322 | |||
324 | def update_lines_position(request, conf_id): |
|
323 | def update_lines_position(request, conf_id): | |
325 |
|
324 | |||
326 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
325 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
327 | print("ingreso a update_lines_position") |
|
326 | print("ingreso a update_lines_position") | |
328 | if request.method=='POST': |
|
327 | if request.method=='POST': | |
329 | ch = 0 |
|
328 | ch = 0 | |
330 | for item in request.POST['items'].split('&'): |
|
329 | for item in request.POST['items'].split('&'): | |
331 | line = RCLine.objects.get(pk=item.split('=')[-1]) |
|
330 | line = RCLine.objects.get(pk=item.split('=')[-1]) | |
332 | line.channel = ch |
|
331 | line.channel = ch | |
333 | line.save() |
|
332 | line.save() | |
334 | ch += 1 |
|
333 | ch += 1 | |
335 |
|
334 | |||
336 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
335 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
337 |
|
336 | |||
338 | for line in lines: |
|
337 | for line in lines: | |
339 |
|
338 | |||
340 | params = json.loads(line.params) |
|
339 | params = json.loads(line.params) | |
341 | print(params) |
|
340 | print(params) | |
342 | print("Fin de impresion_lines_position") |
|
341 | print("Fin de impresion_lines_position") | |
343 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) |
|
342 | line.form = RCLineEditForm(conf=conf, line=line, extra_fields=params) | |
344 |
|
343 | |||
345 | if 'params' in params: |
|
344 | if 'params' in params: | |
346 | line.subform = True |
|
345 | line.subform = True | |
347 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] |
|
346 | line.subforms = [RCLineEditForm(extra_fields=fields, line=line, subform=i) for i, fields in enumerate(params['params'])] | |
348 |
|
347 | |||
349 | html = render(request, 'rc_lines.html', {'dev_conf':conf, 'rc_lines':lines, 'edit':True}) |
|
348 | html = render(request, 'rc_lines.html', {'dev_conf':conf, 'rc_lines':lines, 'edit':True}) | |
350 | data = {'html': html.content.decode('utf8')} |
|
349 | data = {'html': html.content.decode('utf8')} | |
351 |
|
350 | |||
352 | return HttpResponse(json.dumps(data), content_type="application/json") |
|
351 | return HttpResponse(json.dumps(data), content_type="application/json") | |
353 | return redirect('url_edit_rc_conf', conf.id) |
|
352 | return redirect('url_edit_rc_conf', conf.id) | |
354 |
|
353 | |||
355 |
|
354 | |||
356 | def import_file(request, conf_id): |
|
355 | def import_file(request, conf_id): | |
357 |
|
356 | |||
358 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
357 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
359 | if request.method=='POST': |
|
358 | if request.method=='POST': | |
360 | form = RCImportForm(request.POST, request.FILES) |
|
359 | form = RCImportForm(request.POST, request.FILES) | |
361 | if form.is_valid(): |
|
360 | if form.is_valid(): | |
362 | try: |
|
361 | try: | |
363 | data = conf.import_from_file(request.FILES['file_name']) |
|
362 | data = conf.import_from_file(request.FILES['file_name']) | |
364 | conf.dict_to_parms(data) |
|
363 | conf.dict_to_parms(data) | |
365 | conf.update_pulses() |
|
364 | conf.update_pulses() | |
366 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
365 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) | |
367 | return redirect(conf.get_absolute_url_edit()) |
|
366 | return redirect(conf.get_absolute_url_edit()) | |
368 |
|
367 | |||
369 | except Exception as e: |
|
368 | except Exception as e: | |
370 | messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], repr(e))) |
|
369 | messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], repr(e))) | |
371 | else: |
|
370 | else: | |
372 | messages.warning(request, 'Your current configuration will be replaced') |
|
371 | messages.warning(request, 'Your current configuration will be replaced') | |
373 | form = RCImportForm() |
|
372 | form = RCImportForm() | |
374 |
|
373 | |||
375 | kwargs = {} |
|
374 | kwargs = {} | |
376 | kwargs['form'] = form |
|
375 | kwargs['form'] = form | |
377 | kwargs['title'] = 'RC Configuration' |
|
376 | kwargs['title'] = 'RC Configuration' | |
378 | kwargs['suptitle'] = 'Import file' |
|
377 | kwargs['suptitle'] = 'Import file' | |
379 | kwargs['button'] = 'Upload' |
|
378 | kwargs['button'] = 'Upload' | |
380 | kwargs['previous'] = conf.get_absolute_url() |
|
379 | kwargs['previous'] = conf.get_absolute_url() | |
381 |
|
380 | |||
382 | return render(request, 'rc_import.html', kwargs) |
|
381 | return render(request, 'rc_import.html', kwargs) | |
383 |
|
382 | |||
384 |
|
383 | |||
385 | def plot_pulses(request, conf_id): |
|
384 | def plot_pulses(request, conf_id): | |
386 |
|
385 | |||
387 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
386 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
388 | km = True if 'km' in request.GET else False |
|
387 | km = True if 'km' in request.GET else False | |
389 |
|
388 | |||
390 | script, div = conf.plot_pulses(km=km) |
|
389 | script, div = conf.plot_pulses(km=km) | |
391 |
|
390 | |||
392 | kwargs = {} |
|
391 | kwargs = {} | |
393 | kwargs['no_sidebar'] = True |
|
392 | kwargs['no_sidebar'] = True | |
394 | kwargs['title'] = 'RC Pulses' |
|
393 | kwargs['title'] = 'RC Pulses' | |
395 | kwargs['suptitle'] = conf.name |
|
394 | kwargs['suptitle'] = conf.name | |
396 | kwargs['div'] = mark_safe(div) |
|
395 | kwargs['div'] = mark_safe(div) | |
397 | kwargs['script'] = mark_safe(script) |
|
396 | kwargs['script'] = mark_safe(script) | |
398 | kwargs['units'] = conf.km2unit |
|
397 | kwargs['units'] = conf.km2unit | |
399 | kwargs['kms'] = 1/conf.km2unit |
|
398 | kwargs['kms'] = 1/conf.km2unit | |
400 |
|
399 | |||
401 | if km: |
|
400 | if km: | |
402 | kwargs['km_selected'] = True |
|
401 | kwargs['km_selected'] = True | |
403 |
|
402 | |||
404 | if 'json' in request.GET: |
|
403 | if 'json' in request.GET: | |
405 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") |
|
404 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") | |
406 | else: |
|
405 | else: | |
407 | return render(request, 'rc_pulses.html', kwargs) |
|
406 | return render(request, 'rc_pulses.html', kwargs) | |
408 |
|
407 | |||
409 | def plot_pulses2(request, conf_id): |
|
408 | def plot_pulses2(request, conf_id): | |
410 |
|
409 | |||
411 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
410 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
412 | km = True if 'km' in request.GET else False |
|
411 | km = True if 'km' in request.GET else False | |
413 |
|
412 | |||
414 | script, div = conf.plot_pulses2(km=km) |
|
413 | script, div = conf.plot_pulses2(km=km) | |
415 |
|
414 | |||
416 | kwargs = {} |
|
415 | kwargs = {} | |
417 | kwargs['no_sidebar'] = True |
|
416 | kwargs['no_sidebar'] = True | |
418 | kwargs['title'] = 'RC Pulses' |
|
417 | kwargs['title'] = 'RC Pulses' | |
419 | kwargs['suptitle'] = conf.name |
|
418 | kwargs['suptitle'] = conf.name | |
420 | kwargs['div'] = mark_safe(div) |
|
419 | kwargs['div'] = mark_safe(div) | |
421 | kwargs['script'] = mark_safe(script) |
|
420 | kwargs['script'] = mark_safe(script) | |
422 | kwargs['units'] = conf.km2unit |
|
421 | kwargs['units'] = conf.km2unit | |
423 | kwargs['kms'] = 1/conf.km2unit |
|
422 | kwargs['kms'] = 1/conf.km2unit | |
424 |
|
423 | |||
425 | if km: |
|
424 | if km: | |
426 | kwargs['km_selected'] = True |
|
425 | kwargs['km_selected'] = True | |
427 |
|
426 | |||
428 | if 'json' in request.GET: |
|
427 | if 'json' in request.GET: | |
429 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") |
|
428 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") | |
430 | else: |
|
429 | else: | |
431 | return render(request, 'rc_pulses.html', kwargs) |
|
430 | return render(request, 'rc_pulses.html', kwargs) | |
432 |
|
431 | |||
433 | def conf_raw(request, conf_id): |
|
432 | def conf_raw(request, conf_id): | |
434 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
433 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
435 | raw = conf.write_device(raw=True) |
|
434 | raw = conf.write_device(raw=True) | |
436 | return HttpResponse(raw, content_type='application/json') No newline at end of file |
|
435 | return HttpResponse(raw, content_type='application/json') |
@@ -1,68 +1,70 | |||||
1 | version: '2' |
|
1 | version: '2' | |
2 | services: |
|
2 | services: | |
3 | # Django app |
|
3 | # Django app | |
4 | web: |
|
4 | # web: | |
5 |
|
|
5 | # container_name: 'radarsys' | |
6 |
|
|
6 | # build: . | |
7 |
|
|
7 | # restart: always | |
8 |
|
|
8 | # image: radarsys | |
9 |
|
|
9 | # command: gunicorn radarsys.wsgi:application -w 2 -b :8000 | |
10 | # command: python manage.py runserver 0.0.0.0:8030 |
|
10 | # # command: python manage.py runserver 0.0.0.0:8030 | |
11 | # ports: |
|
11 | # # ports: | |
12 | # - 8030:8030 |
|
12 | # # - 8030:8030 | |
13 |
|
|
13 | # env_file: .env | |
14 |
|
14 | |||
15 | links: |
|
15 | # links: | |
16 |
|
|
16 | # - redis | |
17 |
|
|
17 | # - postgres | |
18 | volumes: |
|
18 | # volumes: | |
19 |
|
|
19 | # - './:/radarsys' | |
20 |
|
|
20 | # - '${DOCKER_DATA}/static:/radarsys/static' | |
21 | depends_on: |
|
21 | # depends_on: | |
22 |
|
|
22 | # - redis | |
23 |
|
|
23 | # - postgres | |
24 |
|
24 | |||
25 | redis: |
|
25 | redis: | |
26 | container_name: 'radarsys-redis' |
|
26 | container_name: 'radarsys-redis' | |
27 | image: 'redis:3.2-alpine' |
|
27 | image: 'redis:3.2-alpine' | |
28 | volumes: |
|
28 | volumes: | |
29 | - '${DOCKER_DATA}/redis:/data' |
|
29 | - '${DOCKER_DATA}/redis:/data' | |
|
30 | ports: | |||
|
31 | - 6300:6379 | |||
30 |
|
32 | |||
31 | celery_worker: |
|
33 | celery_worker: | |
32 | container_name: 'radarsys-celery' |
|
34 | container_name: 'radarsys-celery' | |
33 | image: radarsys |
|
35 | image: radarsys | |
34 | env_file: .env |
|
36 | env_file: .env | |
35 | command: celery -A radarsys worker -l info |
|
37 | command: celery -A radarsys worker -l info | |
36 | volumes_from: |
|
38 | # volumes_from: | |
37 | - web |
|
39 | # - web | |
38 | depends_on: |
|
40 | # depends_on: | |
39 | - web |
|
41 | # - web | |
40 |
|
42 | |||
41 | # PostgreSQL |
|
43 | # PostgreSQL | |
42 | postgres: |
|
44 | postgres: | |
43 | container_name: 'radarsys-postgres' |
|
45 | container_name: 'radarsys-postgres' | |
44 | build: ./postgres/ |
|
46 | build: ./postgres/ | |
45 | volumes: |
|
47 | volumes: | |
46 | - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d |
|
48 | - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d | |
47 |
- |
|
49 | - /data/dockers/radarsys/postgres:/var/lib/postgresql/data | |
48 |
|
|
50 | ports: | |
49 |
|
|
51 | - 5400:5432 | |
50 | env_file: .env |
|
52 | env_file: .env | |
51 |
|
53 | |||
52 | # Web Server |
|
54 | # Web Server | |
53 | nginx: |
|
55 | # nginx: | |
54 | container_name: 'radarsys-nginx' |
|
56 | # container_name: 'radarsys-nginx' | |
55 | restart: always |
|
57 | # restart: always | |
56 | build: ./nginx/ |
|
58 | # build: ./nginx/ | |
57 | ports: |
|
59 | # ports: | |
58 | - '8030:8030' |
|
60 | # - '8030:8030' | |
59 | volumes_from: |
|
61 | # volumes_from: | |
60 | - web |
|
62 | # - web | |
61 | links: |
|
63 | # links: | |
62 | - web:web |
|
64 | # - web:web | |
63 | depends_on: |
|
65 | # depends_on: | |
64 | - web |
|
66 | # - web | |
65 |
|
67 | |||
66 | volumes: |
|
68 | # volumes: | |
67 | pgdata: |
|
69 | # pgdata: | |
68 | driver: local |
|
70 | # driver: local |
@@ -1,146 +1,140 | |||||
1 | """ |
|
1 | """ | |
2 | Django settings for radarsys project. |
|
2 | Django settings for radarsys project. | |
3 |
|
3 | |||
4 | Generated by 'django-admin startproject' using Django 1.8.6. |
|
4 | Generated by 'django-admin startproject' using Django 1.8.6. | |
5 |
|
5 | |||
6 | For more information on this file, see |
|
6 | For more information on this file, see | |
7 | https://docs.djangoproject.com/en/1.8/topics/settings/ |
|
7 | https://docs.djangoproject.com/en/1.8/topics/settings/ | |
8 |
|
8 | |||
9 | For the full list of settings and their values, see |
|
9 | For the full list of settings and their values, see | |
10 | https://docs.djangoproject.com/en/1.8/ref/settings/ |
|
10 | https://docs.djangoproject.com/en/1.8/ref/settings/ | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
|
13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | |
14 | import os |
|
14 | import os | |
15 |
|
15 | |||
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
17 |
|
17 | |||
18 | # Quick-start development settings - unsuitable for production |
|
18 | # Quick-start development settings - unsuitable for production | |
19 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ |
|
19 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ | |
20 |
|
20 | |||
21 | # SECURITY WARNING: keep the secret key used in production secret! |
|
21 | # SECURITY WARNING: keep the secret key used in production secret! | |
22 | SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0' |
|
22 | SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0' | |
23 |
|
23 | |||
24 | # SECURITY WARNING: don't run with debug turned on in production! |
|
24 | # SECURITY WARNING: don't run with debug turned on in production! | |
25 | DEBUG = True |
|
25 | DEBUG = True | |
26 |
|
26 | |||
27 | ALLOWED_HOSTS = ['*'] |
|
27 | ALLOWED_HOSTS = ['*'] | |
28 |
|
28 | |||
29 | # Application definition |
|
29 | # Application definition | |
30 |
|
30 | |||
31 |
INSTALLED_APPS = |
|
31 | INSTALLED_APPS = ( | |
32 | 'django.contrib.admin', |
|
32 | 'django.contrib.admin', | |
33 | 'django.contrib.auth', |
|
33 | 'django.contrib.auth', | |
34 | 'django.contrib.contenttypes', |
|
34 | 'django.contrib.contenttypes', | |
35 | 'django.contrib.sessions', |
|
35 | 'django.contrib.sessions', | |
36 | 'django.contrib.messages', |
|
36 | 'django.contrib.messages', | |
37 | 'django.contrib.staticfiles', |
|
37 | 'django.contrib.staticfiles', | |
38 | 'bootstrap4', |
|
38 | 'bootstrap4', | |
39 | 'polymorphic', |
|
39 | 'polymorphic', | |
40 | 'apps.accounts', |
|
40 | 'apps.accounts', | |
41 | 'apps.main', |
|
41 | 'apps.main', | |
42 | 'apps.misc', |
|
42 | 'apps.misc', | |
43 | 'apps.rc', |
|
43 | 'apps.rc', | |
44 | 'apps.dds', |
|
44 | 'apps.dds', | |
|
45 | 'apps.dds_rest', | |||
45 | 'apps.jars', |
|
46 | 'apps.jars', | |
46 | 'apps.usrp', |
|
47 | 'apps.usrp', | |
47 | 'apps.abs', |
|
48 | 'apps.abs', | |
48 | 'apps.cgs', |
|
49 | 'apps.cgs', | |
49 | 'apps.dds_rest', |
|
50 | ) | |
50 | ] |
|
|||
51 |
|
51 | |||
52 | MIDDLEWARE = [ |
|
52 | MIDDLEWARE = [ | |
53 | 'django.middleware.security.SecurityMiddleware', |
|
53 | 'django.middleware.security.SecurityMiddleware', | |
54 | 'django.contrib.sessions.middleware.SessionMiddleware', |
|
54 | 'django.contrib.sessions.middleware.SessionMiddleware', | |
55 | 'django.middleware.common.CommonMiddleware', |
|
55 | 'django.middleware.common.CommonMiddleware', | |
56 | 'django.middleware.csrf.CsrfViewMiddleware', |
|
56 | 'django.middleware.csrf.CsrfViewMiddleware', | |
57 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
57 | 'django.contrib.auth.middleware.AuthenticationMiddleware', | |
58 | 'django.contrib.messages.middleware.MessageMiddleware', |
|
58 | 'django.contrib.messages.middleware.MessageMiddleware', | |
59 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
|
59 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
60 |
|
60 | |||
61 | ] |
|
61 | ] | |
62 |
|
62 | |||
63 | ROOT_URLCONF = 'radarsys.urls' |
|
63 | ROOT_URLCONF = 'radarsys.urls' | |
64 |
|
64 | |||
65 | TEMPLATES = [ |
|
65 | TEMPLATES = [ | |
66 | { |
|
66 | { | |
67 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
|
67 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
68 | 'DIRS': [os.path.join(BASE_DIR, "templates")], |
|
68 | 'DIRS': [os.path.join(BASE_DIR, "templates").replace('\\', '/'),], | |
69 | 'APP_DIRS': True, |
|
69 | 'APP_DIRS': True, | |
70 | 'OPTIONS': { |
|
70 | 'OPTIONS': { | |
71 | 'context_processors': [ |
|
71 | 'context_processors': [ | |
72 | 'django.template.context_processors.debug', |
|
72 | 'django.template.context_processors.debug', | |
73 | 'django.template.context_processors.request', |
|
73 | 'django.template.context_processors.request', | |
74 | 'django.contrib.auth.context_processors.auth', |
|
74 | 'django.contrib.auth.context_processors.auth', | |
75 | 'django.contrib.messages.context_processors.messages', |
|
75 | 'django.contrib.messages.context_processors.messages', | |
76 | 'apps.main.processors.radarsys_globals', |
|
76 | 'apps.main.processors.radarsys_globals', | |
77 | ], |
|
77 | ], | |
78 | }, |
|
78 | }, | |
79 | }, |
|
79 | }, | |
80 | ] |
|
80 | ] | |
81 |
|
81 | |||
82 | WSGI_APPLICATION = 'radarsys.wsgi.application' |
|
82 | WSGI_APPLICATION = 'radarsys.wsgi.application' | |
83 |
|
83 | |||
84 |
|
84 | |||
85 | # Database |
|
85 | # Database | |
86 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases |
|
86 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases | |
87 |
|
87 | |||
88 | DATABASES = { |
|
88 | DATABASES = { | |
89 | 'default': { |
|
89 | 'default': { | |
90 | 'ENGINE': 'django.db.backends.sqlite3', |
|
90 | 'ENGINE': 'django.db.backends.sqlite3', | |
91 | 'NAME': 'radarsys.sqlite', |
|
91 | 'NAME': 'radarsys.sqlite', | |
|
92 | # 'ENGINE': 'django.db.backends.postgresql_psycopg2', | |||
|
93 | # 'NAME': os.environ.get('DB_NAME', 'radarsys'), | |||
|
94 | # 'USER': os.environ.get('DB_USER', 'docker'), | |||
|
95 | # 'PASSWORD': os.environ.get('DB_PASSWORD', 'docker'), | |||
|
96 | # 'HOST': os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', 'localhost'), | |||
|
97 | # 'PORT': os.environ.get('POSTGRES_PORT_5432_TCP_PORT', '5400'), | |||
|
98 | } | |||
92 | } |
|
99 | } | |
93 | # 'default': { |
|
|||
94 | # 'ENGINE': 'django.db.backends.postgresql_psycopg2', |
|
|||
95 | # 'NAME': os.environ.get('DB_NAME', 'radarsys'), |
|
|||
96 | # 'USER': os.environ.get('DB_USER', 'docker'), |
|
|||
97 | # 'PASSWORD': os.environ.get('DB_PASSWORD', 'docker'), |
|
|||
98 | # 'HOST': os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', 'localhost'), |
|
|||
99 | # 'PORT': os.environ.get('POSTGRES_PORT_5432_TCP_PORT', '5400'), |
|
|||
100 | #} |
|
|||
101 | } |
|
|||
102 |
|
100 | |||
103 | # Internationalization |
|
101 | # Internationalization | |
104 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ |
|
102 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ | |
105 |
|
103 | |||
106 | LANGUAGE_CODE = 'en-us' |
|
104 | LANGUAGE_CODE = 'en-us' | |
107 |
|
105 | |||
108 | USE_TZ = False #True |
|
|||
109 |
|
||||
110 | TIME_ZONE = os.environ.get('TZ', 'America/Lima') |
|
106 | TIME_ZONE = os.environ.get('TZ', 'America/Lima') | |
111 |
|
107 | |||
112 | USE_I18N = True |
|
108 | USE_I18N = True | |
113 |
|
109 | |||
114 | USE_L10N = True |
|
110 | USE_L10N = True | |
115 |
|
111 | |||
|
112 | USE_TZ = False | |||
|
113 | ||||
116 | # Static files (CSS, JavaScript, Images) |
|
114 | # Static files (CSS, JavaScript, Images) | |
117 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ |
|
115 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ | |
118 |
|
116 | |||
119 | MEDIA_URL = '/media/' |
|
117 | MEDIA_URL = '/media/' | |
120 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') |
|
118 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') | |
121 |
|
119 | |||
122 | STATIC_URL = '/static/' |
|
120 | STATIC_URL = '/static/' | |
123 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') |
|
121 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') | |
124 |
|
122 | |||
125 | STATICFILES_FINDERS = ( |
|
123 | STATICFILES_FINDERS = ( | |
126 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
|
124 | 'django.contrib.staticfiles.finders.FileSystemFinder', | |
127 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', |
|
125 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', | |
128 | ) |
|
126 | ) | |
129 |
|
127 | |||
130 | # Celery stuff |
|
128 | # Celery stuff | |
131 |
|
129 | REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') | ||
132 |
REDIS_ |
|
130 | REDIS_PORT = os.environ.get('REDIS_PORT', 6300) | |
133 | #REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') |
|
|||
134 | REDIS_PORT = os.environ.get('REDIS_PORT', 6379) |
|
|||
135 |
|
131 | |||
136 | BROKER_TRANSPORT = 'redis' |
|
132 | BROKER_TRANSPORT = 'redis' | |
137 |
|
|
133 | BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) | |
138 | BROKER_URL = 'redis://{}:{}'.format(REDIS_HOST, REDIS_PORT) |
|
|||
139 |
|
134 | |||
140 |
CELERY_RESULT_BACKEND |
|
135 | CELERY_RESULT_BACKEND = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) | |
141 |
CELERY_BROKER_TRANSPORT |
|
136 | CELERY_BROKER_TRANSPORT = BROKER_URL | |
142 |
CELERY_ACCEPT_CONTENT |
|
137 | CELERY_ACCEPT_CONTENT = ['application/json'] | |
143 |
CELERY_TASK_SERIALIZER |
|
138 | CELERY_TASK_SERIALIZER = 'json' | |
144 | CELERY_RESULT_SERIALIZER = 'json' |
|
139 | CELERY_RESULT_SERIALIZER = 'json' | |
145 |
CELERY_ENABLE_UTC |
|
140 | CELERY_ENABLE_UTC = False | |
146 | CELERY_TIMEZONE = 'America/Lima' No newline at end of file |
|
General Comments 0
You need to be logged in to leave comments.
Login now