Skip to content
Snippets Groups Projects
Commit eed1dfc2 authored by Carlo Guidi's avatar Carlo Guidi
Browse files

Update acoustics.py

parent e6209a49
No related branches found
No related tags found
3 merge requests!21Resolve "Integrate Online Acoustic Monitoring script for ORCA site and ARCA site",!17Update Acoustic Monitoring Program,!10Fix acoustics route
...@@ -16,6 +16,8 @@ Options: ...@@ -16,6 +16,8 @@ Options:
from datetime import datetime from datetime import datetime
import os import os
import time import time
import http
import ssl
import matplotlib import matplotlib
matplotlib.use("Agg") matplotlib.use("Agg")
...@@ -68,7 +70,7 @@ while check: ...@@ -68,7 +70,7 @@ while check:
mintime = mintime1.values mintime = mintime1.values
maxrun = table["RUN"][len(table["RUN"]) - 1] maxrun = table["RUN"][len(table["RUN"]) - 1]
now = time.time() now = time.time()
now = now - 600 now = now - TIT
if (now - mintime / 1000) < TIT: if (now - mintime / 1000) < TIT:
minrun = table["RUN"][len(table["RUN"]) - 1] - 1 minrun = table["RUN"][len(table["RUN"]) - 1] - 1
print(now) print(now)
...@@ -280,9 +282,13 @@ while check: ...@@ -280,9 +282,13 @@ while check:
N_Pulses_Indicator_DU.append(-1.5) N_Pulses_Indicator_DU.append(-1.5)
except ( except (
TypeError, ValueError TypeError, ValueError, http.client.RemoteDisconnected, ssl.SSLError
): # TypeError if no data found for a certain piezo, ValueError if there are zero data for a certain piezo ): # TypeError if no data found for a certain piezo, ValueError if there are zero data for a certain piezo
N_Pulses_Indicator_DU.append(-1.5) N_Pulses_Indicator_DU.append(-1.5)
except (
http.client.RemoteDisconnected, ssl.SSLError
): # Bad connection to the DB
N_Pulses_Indicator_DU.append(-2.5)
# To avoid to take wrong beacon signals # To avoid to take wrong beacon signals
...@@ -309,8 +315,7 @@ while check: ...@@ -309,8 +315,7 @@ while check:
N_Pulses_Indicator.append(N_Pulses_Indicator_DU) N_Pulses_Indicator.append(N_Pulses_Indicator_DU)
fig = plt.figure() fig, ax = plt.subplots(figsize=(9, 7))
ax = fig.add_subplot(111)
duab = [] duab = []
DUs = [] DUs = []
...@@ -333,9 +338,9 @@ while check: ...@@ -333,9 +338,9 @@ while check:
iAB2.append(3 * i + 1) iAB2.append(3 * i + 1)
iAB3.append(3 * i + 2) iAB3.append(3 * i + 2)
colorsList = [(0, 0, 0), (1, 0.3, 0), (1, 1, 0), (0.2, 0.9, 0)] colorsList = [(0.6, 0, 1), (0, 0, 0), (1, 0.3, 0), (1, 1, 0), (0.2, 0.9, 0)]
CustomCmap = matplotlib.colors.ListedColormap(colorsList) CustomCmap = matplotlib.colors.ListedColormap(colorsList)
bounds = [-2, -1, 0, 1, 2] bounds = [-3, -2, -1, 0, 1, 2]
norma = colors.BoundaryNorm(bounds, CustomCmap.N) norma = colors.BoundaryNorm(bounds, CustomCmap.N)
for du in DUS: for du in DUS:
color = ax.scatter(duab[du - 1][0], color = ax.scatter(duab[du - 1][0],
...@@ -363,16 +368,16 @@ while check: ...@@ -363,16 +368,16 @@ while check:
cbar = plt.colorbar(color) cbar = plt.colorbar(color)
cbar.ax.get_yaxis().set_ticks([]) cbar.ax.get_yaxis().set_ticks([])
for j, lab in enumerate( for j, lab in enumerate(
['$0. pings$', '$1-3 pings$', '$4-7 pings$', '$>7. pings$']): ['$No DB conn.$','$0. pings$', '$1-3 pings$', '$4-7 pings$', '$>7. pings$']):
cbar.ax.text(3.5, (2 * j + 1) / 8.0, lab, ha='center', va='center') cbar.ax.text(4, (1.5 * j + 1) / 8.0, lab, ha='center', va='center')
cbar.ax.get_yaxis().labelpad = 18 cbar.ax.get_yaxis().labelpad = 18
matplotlib.pyplot.xticks(np.arange(1, max(DUS) + 1, step=1)) ax.set_xticks(np.arange(1, max(DUS) + 1, step=1))
matplotlib.pyplot.yticks(np.arange(0, 19, step=1)) ax.set_yticks(np.arange(0, 19, step=1))
matplotlib.pyplot.grid(color='k', linestyle='-', linewidth=0.2) ax.grid(color='k', linestyle='-', linewidth=0.2)
ax.set_xlabel('DUs', fontsize=18) ax.set_xlabel('DUs', fontsize=18)
ax.set_ylabel('Floors', fontsize=18) ax.set_ylabel('Floors', fontsize=18)
ts = now + 3600 ts = now
DATE = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') DATE = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
ax.set_title( ax.set_title(
r' %.16s Detection of the pings emitted by autonomous beacons' % DATE, r' %.16s Detection of the pings emitted by autonomous beacons' % DATE,
...@@ -382,12 +387,13 @@ while check: ...@@ -382,12 +387,13 @@ while check:
my_file = 'Online_Acoustic_Monitoring.png' my_file = 'Online_Acoustic_Monitoring.png'
fig.savefig(os.path.join(my_path, my_file)) fig.savefig(os.path.join(my_path, my_file))
plt.close('all')
print(time.time()) print(time.time())
check = False check = False
check_time = time.time() - now check_time = time.time() - now - TIT
print(check_time) print(check_time)
time.sleep(abs(2 * TIT - check_time)) time.sleep(abs(TIT - check_time))
check = True check = True
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment