@@ -0,0 +1,77 | |||
|
1 | #!/usr/bin/env python | |
|
2 | ||
|
3 | import os, sys | |
|
4 | import signal | |
|
5 | import time | |
|
6 | import json | |
|
7 | import paho.mqtt.client as paho | |
|
8 | from watchdog.events import FileSystemEventHandler | |
|
9 | from watchdog.observers.polling import PollingObserver | |
|
10 | import platform | |
|
11 | ||
|
12 | MQTTHOST = os.getenv('BROKER_URL', '192.168.1.130') | |
|
13 | PROCSITE = os.getenv('PROC_SITE', 'sophy-proc') | |
|
14 | MQTTPORT = int(os.getenv('MQTTPORT', 1883)) | |
|
15 | MQTTUSERNAME = os.getenv('MQTTUSERNAME', None) | |
|
16 | MQTTPASSWORD = os.getenv('MQTTPASSWORD', None) | |
|
17 | MQTTWATCHDIR = '/data' | |
|
18 | MQTTQOS = int(os.getenv('MQTTQOS', 0)) | |
|
19 | MQTTRETAIN = int(os.getenv('MQTTRETAIN', 0)) | |
|
20 | ||
|
21 | MQTTFIXEDTOPIC = os.getenv('MQTTFIXEDTOPIC', 'sophy/acq') | |
|
22 | ||
|
23 | WATCHDEBUG = os.getenv('WATCHDEBUG', 1) | |
|
24 | ||
|
25 | # Publish with retain (True or False) | |
|
26 | if MQTTRETAIN == 1: | |
|
27 | MQTTRETAIN=True | |
|
28 | else: | |
|
29 | MQTTRETAIN=False | |
|
30 | ||
|
31 | OS = platform.system() | |
|
32 | ||
|
33 | clientid = 'sophy-acq-%s' % os.getpid() | |
|
34 | mqtt = paho.Client(clientid, clean_session=True) | |
|
35 | ||
|
36 | if MQTTUSERNAME is not None or MQTTPASSWORD is not None: | |
|
37 | mqtt.username_pw_set(MQTTUSERNAME, MQTTPASSWORD) | |
|
38 | ||
|
39 | def on_publish(mosq, userdata, mid): | |
|
40 | pass | |
|
41 | ||
|
42 | def on_disconnect(mosq, userdata, rc): | |
|
43 | print ("disconnected") | |
|
44 | time.sleep(1) | |
|
45 | ||
|
46 | def on_message(client, userdata, msg): | |
|
47 | payload = msg.payload.decode() | |
|
48 | print(f"Received `{payload}` from `{msg.topic}` topic", flush=True) | |
|
49 | ||
|
50 | def signal_handler(signal, frame): | |
|
51 | """ Bail out at the top level """ | |
|
52 | ||
|
53 | mqtt.loop_stop() | |
|
54 | mqtt.disconnect() | |
|
55 | ||
|
56 | sys.exit(0) | |
|
57 | ||
|
58 | def main(): | |
|
59 | print('Sophy acquisition monitor will publish messages to {}'.format(MQTTFIXEDTOPIC), flush=True) | |
|
60 | mqtt.on_disconnect = on_disconnect | |
|
61 | mqtt.on_publish = on_publish | |
|
62 | mqtt.connect(MQTTHOST, MQTTPORT) | |
|
63 | mqtt.subscribe('sophy/control') | |
|
64 | mqtt.on_message = on_message | |
|
65 | ||
|
66 | mqtt.loop_start() | |
|
67 | ||
|
68 | signal.signal(signal.SIGINT, signal_handler) | |
|
69 | ||
|
70 | test = json.dumps({'file': '', 'size': ''}) | |
|
71 | ||
|
72 | while 1: | |
|
73 | mqtt.publish(MQTTFIXEDTOPIC, test, qos=MQTTQOS, retain=MQTTRETAIN) | |
|
74 | time.sleep(1) | |
|
75 | ||
|
76 | if __name__ == '__main__': | |
|
77 | main() No newline at end of file |
@@ -0,0 +1,63 | |||
|
1 | {% extends "bootstrap/base.html" %} | |
|
2 | {% block title %}SOPHY monitor{% endblock %} | |
|
3 | ||
|
4 | {% block styles %} | |
|
5 | {{ super() }} | |
|
6 | {% endblock %} | |
|
7 | ||
|
8 | {% block scripts %} | |
|
9 | {{ super() }} | |
|
10 | <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script> | |
|
11 | <script type="text/javascript" charset="utf-8"> | |
|
12 | $(document).ready(function() { | |
|
13 | var socket = io.connect('http://' + document.domain + ':' + location.port); | |
|
14 | ||
|
15 | socket.on('connect', function(data) { | |
|
16 | console.log('Connecting... OK'); | |
|
17 | }) | |
|
18 | socket.on('mqtt_message', function(data) { | |
|
19 | console.log(data.topic); | |
|
20 | if (data['topic'].includes('acq')) { | |
|
21 | var payload = JSON.parse(data.payload); | |
|
22 | console.log(payload); | |
|
23 | } | |
|
24 | }) | |
|
25 | }); | |
|
26 | ||
|
27 | </script> | |
|
28 | {% endblock %} | |
|
29 | ||
|
30 | {% block content %} | |
|
31 | <div class="container-fluid"> | |
|
32 | <div class="row"> | |
|
33 | <div class="col-xs-12"> | |
|
34 | <h1>SOPHy monitor</h1> | |
|
35 | </div> | |
|
36 | </div> | |
|
37 | <div class="row"> | |
|
38 | <!--Messages--> | |
|
39 | <div class="col-xs-12"> | |
|
40 | <div class="panel panel-default"> | |
|
41 | <div class="panel-heading"> | |
|
42 | <h3 class="panel-title">MQTT</h3> | |
|
43 | </div> | |
|
44 | <div class="panel-body"> | |
|
45 | <div class="col-xs-12"> | |
|
46 | <div class="row"> | |
|
47 | <div class="form-horizontal"> | |
|
48 | <div class="form-group"> | |
|
49 | <div class="col-xs-12"> | |
|
50 | <label for="mqtt_acq">Log Message</label> | |
|
51 | <textarea id="mqtt_acq" class="form-control" rows=10></textarea> | |
|
52 | </div> | |
|
53 | </div> | |
|
54 | </div> | |
|
55 | </div>` | |
|
56 | </div> | |
|
57 | </div> | |
|
58 | </div> | |
|
59 | </div> | |
|
60 | </div> | |
|
61 | </div> | |
|
62 | {{debug}} | |
|
63 | {% endblock %} No newline at end of file |
@@ -0,0 +1,40 | |||
|
1 | from django.core.management.base import BaseCommand | |
|
2 | from apps.main.models import Experiment | |
|
3 | from django.shortcuts import get_object_or_404 | |
|
4 | import os | |
|
5 | import time | |
|
6 | import requests | |
|
7 | ||
|
8 | class Command(BaseCommand): | |
|
9 | """ | |
|
10 | Create a superuser if none exist | |
|
11 | Example: | |
|
12 | manage.py reset_exp --pk=1 | |
|
13 | """ | |
|
14 | ||
|
15 | def handle(self, *args, **options): | |
|
16 | if check_experiment(): | |
|
17 | #value = 36 | |
|
18 | #experiment = get_object_or_404(Experiment, pk=value) | |
|
19 | ##time.sleep(15) | |
|
20 | #experiment.stop() | |
|
21 | #self.stdout.write(f'Experiment "{value}" was stoped') | |
|
22 | #time.sleep(15) | |
|
23 | #experiment.start() | |
|
24 | #self.stdout.write(f'Experiment "{value}" is running') | |
|
25 | value = 36 | |
|
26 | self.stdout.write(f'Experiment "{value}" is running') | |
|
27 | else: | |
|
28 | pass | |
|
29 | ||
|
30 | def check_experiment(): | |
|
31 | try: | |
|
32 | url = 'http://{}/status'.format(os.environ.get('PROC_SITE', 'sophy-proc')) | |
|
33 | response = requests.get(url, timeout=0.4) | |
|
34 | if response.status_code == 200: | |
|
35 | data = response.json() | |
|
36 | return data['status'] | |
|
37 | else: | |
|
38 | return False | |
|
39 | except: | |
|
40 | return False No newline at end of file |
@@ -0,0 +1,41 | |||
|
1 | #!/usr/local/bin/python | |
|
2 | ||
|
3 | import os | |
|
4 | import sys | |
|
5 | from datetime import datetime, timedelta | |
|
6 | from time import sleep | |
|
7 | import django | |
|
8 | ||
|
9 | sys.path.append('/workspace/sirm') | |
|
10 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "radarsys.settings") | |
|
11 | django.setup() | |
|
12 | ||
|
13 | from apps.main.models import Experiment | |
|
14 | ||
|
15 | exp = Experiment.objects.get(pk=36) | |
|
16 | ||
|
17 | N = 0 | |
|
18 | ok = True | |
|
19 | ||
|
20 | while True: | |
|
21 | if N >=3: | |
|
22 | ok = False | |
|
23 | print('Stopping Experiment {}'.format(exp.name)) | |
|
24 | exp.stop() | |
|
25 | sleep(30) | |
|
26 | print('Starting Experiment {}'.format(exp.name)) | |
|
27 | exp.start() | |
|
28 | dt = datetime.utcnow() | |
|
29 | sleep(30) | |
|
30 | path = os.path.join(exp.reception_rx.datadir, 'ch0', dt.strftime('%Y-%m-%dT%H-00-00')) | |
|
31 | path = path.replace('DATA_RM/DATA', 'data') | |
|
32 | if not os.path.exists(path): | |
|
33 | N += 1 | |
|
34 | continue | |
|
35 | else: | |
|
36 | break | |
|
37 | ||
|
38 | if ok: | |
|
39 | print('Experiment started ok in {} try at {}!!!'.format(N+1, dt-timedelta(hours=5))) | |
|
40 | else: | |
|
41 | print('Error starting Experiment') No newline at end of file |
@@ -11,6 +11,9 TXA_SITE=<IP TXA> | |||
|
11 | 11 | TXB_SITE=<IP TXB> |
|
12 | 12 | SIRM_MAX_UPLOAD_SIZE_MB=20 |
|
13 | 13 | |
|
14 | #PEDESTAL - AZ OFFSET | |
|
15 | AZ_OFFSET=26.27 | |
|
16 | ||
|
14 | 17 | #Postgres settings |
|
15 | 18 | POSTGRES_PORT_5432_TCP_ADDR=sirm-postgres |
|
16 | 19 | POSTGRES_PORT_5432_TCP_PORT=5432 |
@@ -4,7 +4,10 volumes/certs | |||
|
4 | 4 | volumes/sirm/static_files/* |
|
5 | 5 | volumes/cam |
|
6 | 6 | volumes/sirm/.gitkeep |
|
7 | volumes/sirm/log.log | |
|
8 | volumes/schain/schain | |
|
7 | 9 | migrations |
|
8 | 10 | *.pyc |
|
9 | 11 | *initial.py |
|
10 | .DS_Store No newline at end of file | |
|
12 | .DS_Store | |
|
13 | .env No newline at end of file |
@@ -101,14 +101,39 services: | |||
|
101 | 101 | - SIRM_USER=${SIRM_USER} |
|
102 | 102 | - SIRM_PASSWORD=${SIRM_PASSWORD} |
|
103 | 103 | - SIRM_EMAIL=${SIRM_EMAIL} |
|
104 | - AZ_OFFSET=${AZ_OFFSET} | |
|
104 | 105 | - VIRTUAL_HOST=${SIRM_SITE} |
|
105 | 106 | volumes: |
|
106 | 107 | - 'sirm_web:/workspace/sirm' |
|
108 | - 'sirm_nas:/data' | |
|
107 | 109 | depends_on: |
|
108 | 110 | - sirm-postgres |
|
109 | 111 | networks: |
|
110 | 112 | - frontend_sirm |
|
111 | 113 | - backend_sirm |
|
114 | labels: | |
|
115 | ofelia.enabled: "true" | |
|
116 | ofelia.job-exec.datecron.schedule: "@every 5s" | |
|
117 | ofelia.job-exec.datecron.command: "python manage.py reset_exp" | |
|
118 | logging: | |
|
119 | driver: "json-file" | |
|
120 | options: | |
|
121 | max-size: "12m" | |
|
122 | ||
|
123 | sirm-job: | |
|
124 | container_name: 'sirm-job' | |
|
125 | image: mcuadros/ofelia:latest | |
|
126 | depends_on: | |
|
127 | - sirm-web | |
|
128 | networks: | |
|
129 | - frontend_sirm | |
|
130 | - backend_sirm | |
|
131 | command: daemon --docker | |
|
132 | volumes: | |
|
133 | - /var/run/docker.sock:/var/run/docker.sock:ro | |
|
134 | labels: | |
|
135 | ofelia.job-local.my-test-job.schedule: "@every 5s" | |
|
136 | ofelia.job-local.my-test-job.command: "date" | |
|
112 | 137 | logging: |
|
113 | 138 | driver: "json-file" |
|
114 | 139 | options: |
@@ -148,6 +173,7 services: | |||
|
148 | 173 | - SOPHY_TOPIC=${SOPHY_TOPIC} |
|
149 | 174 | - TXA_SITE=${TXA_SITE} |
|
150 | 175 | - TXB_SITE=${TXB_SITE} |
|
176 | - SCHAIN_SITE=${SCHAIN_SITE} | |
|
151 | 177 | - VIRTUAL_HOST=${PROC_SITE} |
|
152 | 178 | volumes: |
|
153 | 179 | - 'sirm_proc:/app' |
@@ -106,9 +106,24 class HDF5File(): | |||
|
106 | 106 | |
|
107 | 107 | if self.first: |
|
108 | 108 | self.pos_time = int(data['timestamp']) |
|
109 | self.timestamp = int(data['timestamp']) | |
|
109 | 110 | self.first = False |
|
110 | 111 | |
|
111 | 112 | self.raw = data |
|
113 | if True: | |
|
114 | date_folder = datetime.fromtimestamp(self.timestamp).strftime('%Y-%m-%dT%H-00-00') | |
|
115 | filelog = os.path.join(DATA_PATH, EXPERIMENT['name'], 'position', date_folder, "pos@%10.3f.txt" % (self.timestamp)) | |
|
116 | if not os.path.exists(os.path.dirname(filelog)): | |
|
117 | path = os.path.dirname(filelog) | |
|
118 | os.makedirs(path) | |
|
119 | f = open(filelog, 'w') | |
|
120 | f.write(json.dumps(self.raw, cls=NumpyArrayEncoder)) | |
|
121 | f.close() | |
|
122 | ||
|
123 | if int(data['timestamp'])<= self.timestamp: | |
|
124 | print('Bad time') | |
|
125 | return | |
|
126 | ||
|
112 | 127 | self.update(data) |
|
113 | 128 | |
|
114 | 129 | if self.pos_ready: |
@@ -137,12 +152,7 class HDF5File(): | |||
|
137 | 152 | self.data_pos['timestamp'] = [] |
|
138 | 153 | self.pos_ready = True |
|
139 | 154 | |
|
140 |
|
|
|
141 | date_folder = datetime.fromtimestamp(self.timestamp).strftime('%Y-%m-%dT%H-00-00') | |
|
142 | filelog = os.path.join(DATA_PATH, EXPERIMENT['name'], 'position', date_folder, "pos@%10.3f.txt" % (self.timestamp)) | |
|
143 | f = open(filelog, 'w') | |
|
144 | f.write(json.dumps(self.raw, cls=NumpyArrayEncoder)) | |
|
145 | f.close() | |
|
155 | ||
|
146 | 156 | |
|
147 | 157 | |
|
148 | 158 | HDF = HDF5File() |
@@ -272,6 +282,8 def start_proc(): | |||
|
272 | 282 | |
|
273 | 283 | mqtt.publish('sophy/control', json.dumps(EXPERIMENT)) |
|
274 | 284 | socketio.emit('mqtt_message', data={'topic':'monitor', 'status': 'Running', 'name': EXPERIMENT['name']}) |
|
285 | r = requests.post('http://sirm-schain/start', data=EXPERIMENT) | |
|
286 | print('Starting schain: {}'.format(r)) | |
|
275 | 287 | |
|
276 | 288 | return jsonify({'start': 'ok'}) |
|
277 | 289 | |
@@ -285,6 +297,8 def stop_proc(): | |||
|
285 | 297 | HDF.reset() |
|
286 | 298 | socketio.emit('mqtt_message', data={'topic':'monitor', 'status': 'Not Running'}) |
|
287 | 299 | mqtt.publish('sophy/control', json.dumps({'stop': 'ok'})) |
|
300 | r = requests.get('http://sirm-schain/stop') | |
|
301 | print('Stopping schain: {}'.format(r)) | |
|
288 | 302 | |
|
289 | 303 | return jsonify({'stop': 'ok'}) |
|
290 | 304 | |
@@ -315,12 +329,10 def run_proc(): | |||
|
315 | 329 | |
|
316 | 330 | @app.route('/mqtt') |
|
317 | 331 | def mqtt_log(): |
|
318 | ||
|
319 | 332 | return render_template('mqtt.html') |
|
320 | 333 | |
|
321 | 334 | @app.route('/acq') |
|
322 | 335 | def acq_log(): |
|
323 | ||
|
324 | 336 | return render_template('acq.html') |
|
325 | 337 | |
|
326 | 338 | @socketio.on('publish') |
@@ -374,5 +386,4 def handle_logging(client, userdata, level, buf): | |||
|
374 | 386 | pass |
|
375 | 387 | |
|
376 | 388 | if __name__ == '__main__': |
|
377 |
socketio.run(app, host='0.0.0.0', port=5000, use_reloader=False, debug=True) |
|
|
378 | ||
|
389 | socketio.run(app, host='0.0.0.0', port=5000, use_reloader=False, debug=True) No newline at end of file |
@@ -80,7 +80,7 | |||
|
80 | 80 | for (let i = 0; i < n; i++) { |
|
81 | 81 | traces.push({x: [], y: [], name: names[i]}); |
|
82 | 82 | } |
|
83 |
var yrange = [0, |
|
|
83 | var yrange = [0, 50]; | |
|
84 | 84 | if (div == "plot-pos"){yrange = [0, 360];} |
|
85 | 85 | if (div == "plot-speed"){yrange = [-15, 15];} |
|
86 | 86 | var layout = { |
@@ -13,11 +13,14 from watchdog.events import FileSystemEventHandler | |||
|
13 | 13 | EXP = sys.argv[1] |
|
14 | 14 | main_path = '/DATA_RM/DATA/{}/plots'.format(EXP) |
|
15 | 15 | |
|
16 | print(main_path) | |
|
16 | if not os.path.exists(main_path): | |
|
17 | os.makedirs(main_path) | |
|
17 | 18 | |
|
18 | 19 | CODES = { |
|
19 | 20 | 'V': 'Velocity', |
|
20 | 21 | 'P': 'Power', |
|
22 | 'Z': 'Reflectivity', | |
|
23 | 'W': 'Spectral Width' | |
|
21 | 24 | |
|
22 | 25 | } |
|
23 | 26 | |
@@ -27,7 +30,7 DATA = { | |||
|
27 | 30 | 'localtime': True, |
|
28 | 31 | 'type': 'image', |
|
29 | 32 | 'interval': 150, |
|
30 |
'tag' : ' |
|
|
33 | 'tag' : 'Huancayo' | |
|
31 | 34 | }, |
|
32 | 35 | 'data': '', |
|
33 | 36 | 'plot': '', |
@@ -39,7 +42,8 class FileHandler(FileSystemEventHandler): | |||
|
39 | 42 | last = { |
|
40 | 43 | 'V': 0, |
|
41 | 44 | 'P': 0, |
|
42 | ||
|
45 | 'Z': 0, | |
|
46 | 'W': 0, | |
|
43 | 47 | } |
|
44 | 48 | |
|
45 | 49 | def on_modified(self, event): |
@@ -91,7 +95,7 if __name__ == "__main__": | |||
|
91 | 95 | print ("Connecting to server...") |
|
92 | 96 | event.socket = event.context.socket(zmq.REQ) |
|
93 | 97 | #event.socket.connect ("tcp://10.10.20.128:4444") |
|
94 |
event.socket.connect ("tcp://1 |
|
|
98 | event.socket.connect ("tcp://190.187.237.239:4444") | |
|
95 | 99 | |
|
96 | 100 | observer = Observer() |
|
97 | 101 | observer.schedule(event, main_path, recursive=True) |
@@ -1,96 +1,116 | |||
|
1 | #!/opt/conda/bin/python | |
|
1 | # SOPHY PROC script | |
|
2 | 2 | import os, sys, json, argparse |
|
3 | 3 | import datetime |
|
4 | 4 | import time |
|
5 | 5 | |
|
6 | ||
|
7 | PATH = '/data' | |
|
6 | PATH = '/DATA_RM/DATA' | |
|
7 | #PATH = '/data' | |
|
8 | # PATH = '/Users/jespinoza/workspace/data/' | |
|
8 | 9 | |
|
9 | 10 | PARAM = { |
|
10 |
'P': {'name': 'dataPP_POWER', 'zmin': 3 |
|
|
11 | 'V': {'name': 'dataPP_DOP', 'zmin': -20, 'zmax': 20, 'colormap': 'seismic', 'label': 'Velocity', 'cb_label': 'm/s'} | |
|
12 | } | |
|
11 | 'P': {'name': 'dataPP_POWER', 'zmin': 30, 'zmax': 60, 'colormap': 'jet', 'label': 'Power', 'wrname': 'Pow','cb_label': 'dB', 'ch':0}, | |
|
12 | 'V': {'name': 'dataPP_DOP', 'zmin': -20, 'zmax': 20, 'colormap': 'seismic', 'label': 'Velocity', 'wrname': 'Vel', 'cb_label': 'm/s', 'ch':0}, | |
|
13 | 'RH': {'name': 'RhoHV_R', 'zmin': 0, 'zmax': 1, 'colormap': 'jet', 'label': 'Coef.Correlacion', 'wrname':'R', 'cb_label': '*', 'ch':0}, | |
|
14 | 'FD': {'name': 'PhiD_P', 'zmin': -180,'zmax': 180,'colormap': 'RdBu_r', 'label': 'Fase Diferencial', 'wrname':'P' , 'cb_label': 'º', 'ch':0}, | |
|
15 | 'ZD': {'name': 'Zdb_D', 'zmin': -20, 'zmax': 80, 'colormap': 'viridis','label': 'Reflect.Diferencial','wrname':'D' , 'cb_label': 'dBz','ch':0}, | |
|
16 | 'Z': {'name': 'Zdb', 'zmin': -40, 'zmax': 80, 'colormap': 'viridis','label': 'Reflectividad', 'wrname':'Z', 'cb_label': 'dBz','ch':1}, | |
|
17 | 'W': {'name': 'Sigmav_W', 'zmin': -20, 'zmax': 60, 'colormap': 'viridis','label': 'Spectral Width', 'wrname':'S', 'cb_label': 'hz', 'ch':1} | |
|
18 | } | |
|
19 | ||
|
20 | def max_index(r, sample_rate, ipp): | |
|
21 | ||
|
22 | return int(sample_rate*ipp*1e6 * r / 60) + int(sample_rate*ipp*1e6 * 1.2 / 60) | |
|
13 | 23 | |
|
14 | 24 | def main(args): |
|
15 | 25 | |
|
16 | 26 | experiment = args.experiment |
|
17 |
fp = open(os.path.join(PATH, experiment, 'experiment.conf')) |
|
|
27 | fp = open(os.path.join(PATH, experiment, 'experiment.conf')) | |
|
18 | 28 | conf = json.loads(fp.read()) |
|
19 | 29 | |
|
20 | 30 | ipp_km = conf['usrp_tx']['ipp'] |
|
21 | 31 | ipp = ipp_km * 2 /300000 |
|
22 | samp_rate = conf['usrp_rx']['sample_rate'] | |
|
32 | sample_rate = conf['usrp_rx']['sample_rate'] | |
|
23 | 33 | axis = ['0' if x=='elevation' else '1' for x in conf['pedestal']['axis']] # AZIMUTH 1 ELEVACION 0 |
|
24 | 34 | speed_axis = conf['pedestal']['speed'] |
|
25 |
ste |
|
|
35 | steps = conf['pedestal']['table'] | |
|
26 | 36 | time_offset = args.time_offset |
|
27 | 37 | parameters = args.parameters |
|
28 | 38 | start_date = experiment.split('@')[1].split('T')[0].replace('-', '/') |
|
29 | 39 | end_date = start_date |
|
30 | start_time = experiment.split('@')[1].split('T')[1].replace('-', ':') | |
|
40 | if args.start_time: | |
|
41 | start_time = args.start_time | |
|
42 | else: | |
|
43 | start_time = experiment.split('@')[1].split('T')[1].replace('-', ':') | |
|
44 | #start_time = '13:00:00' | |
|
31 | 45 | end_time = '23:59:59' |
|
32 | max_index = int(samp_rate*ipp*1e6 * args.range / 60) + int(samp_rate*ipp*1e6 * 1.2 / 60) | |
|
33 | 46 | N = int(1/(speed_axis[0]*ipp)) # 1 GRADO DE RESOLUCION |
|
34 | 47 | path = os.path.join(PATH, experiment, 'rawdata') |
|
35 | 48 | path_ped = os.path.join(PATH, experiment, 'position') |
|
36 | 49 | path_plots = os.path.join(PATH, experiment, 'plots') |
|
37 | 50 | path_save = os.path.join(PATH, experiment, 'param') |
|
51 | RMIX = 5 | |
|
38 | 52 | |
|
39 | dBmin = 35 | |
|
40 | dBmax = 60 | |
|
41 | Vmin = -20 | |
|
42 | Vmax = 20 | |
|
43 | ||
|
44 | 53 | from schainpy.controller import Project |
|
45 | ||
|
54 | ||
|
46 | 55 | project = Project() |
|
47 | 56 | project.setup(id='1', name='Sophy', description='sophy proc') |
|
48 | ||
|
57 | print(start_time) | |
|
49 | 58 | reader = project.addReadUnit(datatype='DigitalRFReader', |
|
50 | 59 | path=path, |
|
51 | 60 | startDate=start_date, |
|
52 | 61 | endDate=end_date, |
|
53 |
start |
|
|
62 | start_time=start_time, | |
|
54 | 63 | endTime=end_time, |
|
55 | delay=0, | |
|
56 |
online= |
|
|
64 | delay=30, | |
|
65 | online=args.online, | |
|
57 | 66 | walk=1, |
|
58 | 67 | ippKm = ipp_km, |
|
59 | 68 | getByBlock = 1, |
|
60 | 69 | nProfileBlocks = N, |
|
61 | 70 | ) |
|
62 | 71 | |
|
63 | voltage = project.addProcUnit(datatype='VoltageProc', inputId=reader.getId()) | |
|
64 | op = voltage.addOperation(name='setH0') | |
|
65 | op.addParameter(name='h0', value='-1.2') | |
|
72 | if not conf['usrp_tx']['enable_2']: # One Pulse | |
|
73 | voltage = project.addProcUnit(datatype='VoltageProc', inputId=reader.getId()) | |
|
66 | 74 | |
|
67 | if args.range > 0: | |
|
68 | op = voltage.addOperation(name='selectHeights') | |
|
69 | op.addParameter(name='minIndex', value='0', format='int') | |
|
70 |
op.addParameter(name=' |
|
|
75 | if conf['usrp_tx']['code_type_1']: | |
|
76 | code = [c.split() for c in conf['usrp']['code_1']] | |
|
77 | op = voltage.addOperation(name='Decoder', optype='other') | |
|
78 | op.addParameter(name='code', value=code) | |
|
79 | op.addParameter(name='nCode', value=len(code), format='int') | |
|
80 | op.addParameter(name='nBaud', value=len(code[0]), format='int') | |
|
71 | 81 | |
|
72 |
op = voltage.addOperation(name=' |
|
|
73 |
op.addParameter(name=' |
|
|
82 | op = voltage.addOperation(name='setH0') | |
|
83 | op.addParameter(name='h0', value='-1.2') | |
|
74 | 84 | |
|
75 | proc = project.addProcUnit(datatype='ParametersProc', inputId=voltage.getId()) | |
|
76 | ||
|
77 | op = proc.addOperation(name='PedestalInformation') | |
|
78 |
op.addParameter(name=' |
|
|
79 | op.addParameter(name='interval', value='0.04', format='float') | |
|
80 | op.addParameter(name='time_offset', value=time_offset) | |
|
81 |
op.addParameter(name=' |
|
|
82 | ||
|
83 | for param in parameters: | |
|
84 | ||
|
85 |
op = proc.addOperation(name= |
|
|
86 | op.addParameter(name='axis', value=','.join(axis)) | |
|
87 | op.addParameter(name='attr_data', value=PARAM[param]['name']) | |
|
88 | op.addParameter(name='runNextOp', value=True) | |
|
89 | ||
|
90 | if axis[0] == '1': | |
|
91 | path_fig = '/PPI-{}km'.format(args.range) | |
|
92 | op= proc.addOperation(name='Weather_vRF_Plot') | |
|
93 | if args.save: op.addParameter(name='save', value=path_plots+path_fig, format='str') | |
|
85 | if args.range > 0: | |
|
86 | op = voltage.addOperation(name='selectHeights') | |
|
87 | op.addParameter(name='minIndex', value='0', format='int') | |
|
88 | op.addParameter(name='maxIndex', value=max_index(RMIX, sample_rate, ipp), format='int') | |
|
89 | ||
|
90 | op = voltage.addOperation(name='PulsePair_vRF', optype='other') | |
|
91 | op.addParameter(name='n', value=int(N), format='int') | |
|
92 | ||
|
93 | proc = project.addProcUnit(datatype='ParametersProc', inputId=voltage.getId()) | |
|
94 | ||
|
95 | opObj10 = proc.addOperation(name="WeatherRadar") | |
|
96 | opObj10.addParameter(name='variableList',value='Reflectividad,VelocidadRadial,AnchoEspectral') | |
|
97 | ||
|
98 | # {"latitude": -12.0404828587, "longitude": -75.2147483647, "altitude": 3379.2147483647} | |
|
99 | ||
|
100 | op = proc.addOperation(name='PedestalInformation') | |
|
101 | op.addParameter(name='path', value=path_ped, format='str') | |
|
102 | op.addParameter(name='interval', value='0.04') | |
|
103 | op.addParameter(name='time_offset', value=time_offset) | |
|
104 | op.addParameter(name='az_offset', value=-26.2) | |
|
105 | ||
|
106 | for param in parameters: | |
|
107 | op = proc.addOperation(name='Block360_vRF4') | |
|
108 | #op.addParameter(name='axis', value=','.join(axis)) | |
|
109 | op.addParameter(name='attr_data', value=PARAM[param]['name']) | |
|
110 | op.addParameter(name='runNextOp', value=True) | |
|
111 | ||
|
112 | op= proc.addOperation(name='WeatherParamsPlot') | |
|
113 | if args.save: op.addParameter(name='save', value=path_plots, format='str') | |
|
94 | 114 | op.addParameter(name='save_period', value=-1) |
|
95 | 115 | op.addParameter(name='show', value=args.show) |
|
96 | 116 | op.addParameter(name='channels', value='1,') |
@@ -101,13 +121,134 def main(args): | |||
|
101 | 121 | op.addParameter(name='save_code', value=param) |
|
102 | 122 | op.addParameter(name='cb_label', value=PARAM[param]['cb_label']) |
|
103 | 123 | op.addParameter(name='colormap', value=PARAM[param]['colormap']) |
|
104 | if axis[0] == '0': | |
|
105 | path_fig = '/RHI{}km'.format(args.range) | |
|
106 | op= proc.addOperation(name='WeatherRHI_vRF4_Plot') | |
|
107 | if args.save: op.addParameter(name='save', value=path_plots+path_fig, format='str') | |
|
124 | ||
|
125 | desc = { | |
|
126 | 'Data': { | |
|
127 | PARAM[param]['name']: PARAM[param]['label'], | |
|
128 | 'utctime': 'time' | |
|
129 | }, | |
|
130 | 'Metadata': { | |
|
131 | 'heightList': 'range', | |
|
132 | 'data_azi': 'azimuth', | |
|
133 | 'data_ele': 'elevation', | |
|
134 | } | |
|
135 | } | |
|
136 | ||
|
137 | if args.save: | |
|
138 | opObj10 = proc.addOperation(name='HDFWriter') | |
|
139 | opObj10.addParameter(name='path',value=path_save+'-{}'.format(param), format='str') | |
|
140 | opObj10.addParameter(name='Reset',value=True) | |
|
141 | opObj10.addParameter(name='setType',value='weather') | |
|
142 | opObj10.addParameter(name='description',value='desc') | |
|
143 | opObj10.addParameter(name='blocksPerFile',value='1',format='int') | |
|
144 | opObj10.addParameter(name='metadataList',value='heightList,data_azi,data_ele') | |
|
145 | opObj10.addParameter(name='dataList',value='{},utctime'.format(PARAM[param]['name'])) | |
|
146 | ||
|
147 | else: #Two pulses | |
|
148 | ||
|
149 | voltage1 = project.addProcUnit(datatype='VoltageProc', inputId=reader.getId()) | |
|
150 | ||
|
151 | op = voltage1.addOperation(name='ProfileSelector') | |
|
152 | op.addParameter(name='profileRangeList', value='0,{}'.format(conf['usrp_tx']['repetitions_1']-1)) | |
|
153 | ||
|
154 | if conf['usrp_tx']['code_type_1'] != 'None': | |
|
155 | code = [c.split() for c in conf['usrp_tx']['code_1']] | |
|
156 | op = voltage1.addOperation(name='Decoder', optype='other') | |
|
157 | op.addParameter(name='code', value=code) | |
|
158 | op.addParameter(name='nCode', value=len(code), format='int') | |
|
159 | op.addParameter(name='nBaud', value=len(code[0]), format='int') | |
|
160 | ||
|
161 | op = voltage1.addOperation(name='setH0') | |
|
162 | op.addParameter(name='h0', value='-1.2') | |
|
163 | ||
|
164 | if args.range > 0: | |
|
165 | op = voltage1.addOperation(name='selectHeights') | |
|
166 | op.addParameter(name='minIndex', value='0', format='int') | |
|
167 | op.addParameter(name='maxIndex', value=max_index(RMIX, sample_rate, ipp), format='int') | |
|
168 | ||
|
169 | op = voltage1.addOperation(name='PulsePair_vRF', optype='other') | |
|
170 | op.addParameter(name='n', value=int(N), format='int') | |
|
171 | ||
|
172 | proc1 = project.addProcUnit(datatype='ParametersProc', inputId=voltage1.getId()) | |
|
173 | proc1.addParameter(name='runNextUnit', value=True) | |
|
174 | ||
|
175 | opObj10 = proc1.addOperation(name="WeatherRadar") | |
|
176 | opObj10.addParameter(name='variableList',value='Reflectividad,VelocidadRadial,AnchoEspectral') | |
|
177 | ||
|
178 | # {"latitude": -12.0404828587, "longitude": -75.2147483647, "altitude": 3379.2147483647} | |
|
179 | ||
|
180 | op = proc1.addOperation(name='PedestalInformation') | |
|
181 | op.addParameter(name='path', value=path_ped, format='str') | |
|
182 | op.addParameter(name='interval', value='0.04') | |
|
183 | op.addParameter(name='time_offset', value=time_offset) | |
|
184 | op.addParameter(name='az_offset', value=-26.2) | |
|
185 | ||
|
186 | for param in parameters: | |
|
187 | op = proc1.addOperation(name='Block360_vRF4') | |
|
188 | op.addParameter(name='attr_data', value=PARAM[param]['name']) | |
|
189 | op.addParameter(name='runNextOp', value=True) | |
|
190 | ||
|
191 | voltage2 = project.addProcUnit(datatype='VoltageProc', inputId=reader.getId()) | |
|
192 | ||
|
193 | op = voltage2.addOperation(name='ProfileSelector') | |
|
194 | op.addParameter(name='profileRangeList', value='{},{}'.format(conf['usrp_tx']['repetitions_1'], conf['usrp_tx']['repetitions_1']+conf['usrp_tx']['repetitions_2']-1)) | |
|
195 | ||
|
196 | ||
|
197 | if conf['usrp_tx']['code_type_2']: | |
|
198 | codes = [ c.strip() for c in conf['usrp_tx']['code_2'].split(',')] | |
|
199 | code = [] | |
|
200 | for c in codes: | |
|
201 | code.append([int(x) for x in c]) | |
|
202 | op = voltage2.addOperation(name='Decoder', optype='other') | |
|
203 | op.addParameter(name='code', value=code) | |
|
204 | op.addParameter(name='nCode', value=len(code), format='int') | |
|
205 | op.addParameter(name='nBaud', value=len(code[0]), format='int') | |
|
206 | ||
|
207 | op = voltage2.addOperation(name='CohInt', optype='other') #Minimo integrar 2 perfiles por ser codigo complementario | |
|
208 | op.addParameter(name='n', value=len(code), format='int') | |
|
209 | ncode = len(code) | |
|
210 | else: | |
|
211 | ncode = 1 | |
|
212 | ||
|
213 | op = voltage2.addOperation(name='setH0') | |
|
214 | op.addParameter(name='h0', value='-1.2') | |
|
215 | ||
|
216 | if args.range > 0: | |
|
217 | op = voltage2.addOperation(name='selectHeights') | |
|
218 | op.addParameter(name='minIndex', value=max_index(RMIX, sample_rate, ipp), format='int') | |
|
219 | op.addParameter(name='maxIndex', value=max_index(args.range, sample_rate, ipp), format='int') | |
|
220 | ||
|
221 | op = voltage2.addOperation(name='PulsePair_vRF', optype='other') | |
|
222 | op.addParameter(name='n', value=int(N)/ncode, format='int') | |
|
223 | ||
|
224 | proc2 = project.addProcUnit(datatype='ParametersProc', inputId=voltage2.getId()) | |
|
225 | ||
|
226 | opObj10 = proc2.addOperation(name="WeatherRadar") | |
|
227 | opObj10.addParameter(name='variableList',value='Reflectividad,AnchoEspectral') | |
|
228 | ||
|
229 | # {"latitude": -12.0404828587, "longitude": -75.2147483647, "altitude": 3379.2147483647} | |
|
230 | ||
|
231 | op = proc2.addOperation(name='PedestalInformation') | |
|
232 | op.addParameter(name='path', value=path_ped, format='str') | |
|
233 | op.addParameter(name='interval', value='0.04') | |
|
234 | op.addParameter(name='time_offset', value=time_offset) | |
|
235 | op.addParameter(name='az_offset', value=-26.2) | |
|
236 | ||
|
237 | for param in parameters: | |
|
238 | op = proc2.addOperation(name='Block360_vRF4') | |
|
239 | #op.addParameter(name='axis', value=','.join(axis)) | |
|
240 | op.addParameter(name='attr_data', value=PARAM[param]['name']) | |
|
241 | op.addParameter(name='runNextOp', value=True) | |
|
242 | ||
|
243 | merge = project.addProcUnit(datatype='MergeProc', inputId=[proc1.getId(), proc2.getId()]) | |
|
244 | merge.addParameter(name='attr_data', value=PARAM[param]['name']) | |
|
245 | merge.addParameter(name='mode', value='7') #RM | |
|
246 | ||
|
247 | op= merge.addOperation(name='WeatherParamsPlot') | |
|
248 | if args.save: op.addParameter(name='save', value=path_plots, format='str') | |
|
108 | 249 | op.addParameter(name='save_period', value=-1) |
|
109 | 250 | op.addParameter(name='show', value=args.show) |
|
110 |
op.addParameter(name='channels', value=' |
|
|
251 | op.addParameter(name='channels', value='1,') | |
|
111 | 252 | op.addParameter(name='zmin', value=PARAM[param]['zmin']) |
|
112 | 253 | op.addParameter(name='zmax', value=PARAM[param]['zmax']) |
|
113 | 254 | op.addParameter(name='attr_data', value=PARAM[param]['name'], format='str') |
@@ -115,14 +256,28 def main(args): | |||
|
115 | 256 | op.addParameter(name='save_code', value=param) |
|
116 | 257 | op.addParameter(name='cb_label', value=PARAM[param]['cb_label']) |
|
117 | 258 | op.addParameter(name='colormap', value=PARAM[param]['colormap']) |
|
118 | ||
|
119 | if args.save: | |
|
120 | opObj10 = proc.addOperation(name='HDFWriter') | |
|
121 | opObj10.addParameter(name='path',value=path_save, format='str') | |
|
122 | opObj10.addParameter(name='Reset',value=True) | |
|
123 | opObj10.addParameter(name='blocksPerFile',value='1',format='int') | |
|
124 | opObj10.addParameter(name='metadataList',value='heightList,data_azi,data_ele') | |
|
125 | opObj10.addParameter(name='dataList',value='dataPP_POWER,utctime') | |
|
259 | ||
|
260 | desc = { | |
|
261 | 'Data': { | |
|
262 | PARAM[param]['name']: PARAM[param]['label'], | |
|
263 | 'utctime': 'time' | |
|
264 | }, | |
|
265 | 'Metadata': { | |
|
266 | 'heightList': 'range', | |
|
267 | 'data_azi': 'azimuth', | |
|
268 | 'data_ele': 'elevation', | |
|
269 | } | |
|
270 | } | |
|
271 | ||
|
272 | if args.save: | |
|
273 | opObj10 = merge.addOperation(name='HDFWriter') | |
|
274 | opObj10.addParameter(name='path',value=path_save, format='str') | |
|
275 | opObj10.addParameter(name='Reset',value=True) | |
|
276 | opObj10.addParameter(name='setType',value='weather') | |
|
277 | opObj10.addParameter(name='description',value='desc') | |
|
278 | opObj10.addParameter(name='blocksPerFile',value='1',format='int') | |
|
279 | opObj10.addParameter(name='metadataList',value='heightList,data_azi,data_ele') | |
|
280 | opObj10.addParameter(name='dataList',value='{},utctime'.format(PARAM[param]['name'])) | |
|
126 | 281 | |
|
127 | 282 | project.start() |
|
128 | 283 | |
@@ -143,9 +298,10 if __name__ == '__main__': | |||
|
143 | 298 | help='Show matplotlib plot.') |
|
144 | 299 | parser.add_argument('--online', action='store_true', |
|
145 | 300 | help='Set online mode.') |
|
146 |
parser.add_argument('--rti', |
|
|
147 |
help='Set |
|
|
301 | parser.add_argument('--start_time', default='', | |
|
302 | help='Set start time.') | |
|
148 | 303 | |
|
149 | args = parser.parse_args() | |
|
150 | 304 | |
|
151 | main(args) | |
|
305 | args = parser.parse_args() | |
|
306 | print(args) | |
|
307 | main(args) No newline at end of file |
@@ -1,4 +1,4 | |||
|
1 |
import |
|
|
1 | import os | |
|
2 | 2 | from datetime import datetime |
|
3 | 3 | import json |
|
4 | 4 | import requests |
@@ -127,7 +127,10 class PedestalConfiguration(Configuration): | |||
|
127 | 127 | payload_az = {'axis': 'azimuth'} |
|
128 | 128 | |
|
129 | 129 | if axi == 'elevation': |
|
130 | payload_az['position'] = angle | |
|
130 | # CORRECT AZ OFFSET | |
|
131 | azi = angle - float(os.environ.get('AZ_OFFSET', 26.27)) | |
|
132 | if azi<0: azi += 360 | |
|
133 | payload_az['position'] = round(azi, 2) | |
|
131 | 134 | payload_el['position'] = 0 |
|
132 | 135 | elif axi == 'azimuth': |
|
133 | 136 | payload_el['position'] = angle |
@@ -222,6 +225,14 class PedestalConfiguration(Configuration): | |||
|
222 | 225 | elif self.mode == 'table': |
|
223 | 226 | url = self.device.url() + "combinedtable?params=" |
|
224 | 227 | list_of_floats = [float(x.strip()) for x in self.angle.split(",")] |
|
228 | ||
|
229 | # CORRECT AZ OFFSET | |
|
230 | for i, ax in enumerate(axis): | |
|
231 | if ax == 'elevation': | |
|
232 | azi = list_of_floats[i] - float(os.environ.get('AZ_OFFSET', 26.27)) | |
|
233 | if azi<0: azi += 360 | |
|
234 | list_of_floats[i] = round(azi, 2) | |
|
235 | ||
|
225 | 236 | byte_table = [] |
|
226 | 237 | for x in list_of_floats: |
|
227 | 238 | temp = bytearray(struct.pack("f", x)) |
@@ -282,4 +293,4 class PedestalConfiguration(Configuration): | |||
|
282 | 293 | return payload |
|
283 | 294 | |
|
284 | 295 | def get_absolute_url_import(self): |
|
285 |
return reverse('url_import_pedestal_conf', args=[str(self.id)]) |
|
|
296 | return reverse('url_import_pedestal_conf', args=[str(self.id)]) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now