Acoustic data tab is all updated with global variables from settings.py file

dev-brahim
brahim 2023-08-08 16:51:53 +02:00
parent 58138d0e4e
commit 89fc888797
1 changed files with 129 additions and 136 deletions

View File

@ -339,7 +339,7 @@ class AcousticDataTab(QWidget):
self.spinbox_tmin.setRange(0, 9999)
self.gridLayout_groupbox_xaxis_time.addWidget(self.spinbox_tmin, 0, 2, 1, 1)
self.spinbox_tmin.valueChanged.connect(self.update_xaxis_transect_with_BS_raw_data)
# self.spinbox_tmin.valueChanged.connect(self.plot_transect_with_BS_raw_data)
self.spinbox_tmin.valueChanged.connect(self.update_xaxis_transect_with_SNR_data)
self.label_tmin_unit = QLabel()
self.label_tmin_unit.setText("sec")
@ -357,7 +357,7 @@ class AcousticDataTab(QWidget):
self.spinbox_tmax.setRange(0, 9999)
self.gridLayout_groupbox_xaxis_time.addWidget(self.spinbox_tmax, 0, 6, 1, 1)
self.spinbox_tmax.valueChanged.connect(self.update_xaxis_transect_with_BS_raw_data)
# self.spinbox_tmax.valueChanged.connect(self.update_xaxis_transect_with_SNR_data)
self.spinbox_tmax.valueChanged.connect(self.update_xaxis_transect_with_SNR_data)
self.label_tmax_unit = QLabel()
self.label_tmax_unit.setText("sec")
@ -836,7 +836,7 @@ class AcousticDataTab(QWidget):
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_BS[f].transAxes)
self.fig_BS.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_BS.supxlabel('Time (sec)', fontsize=10)
self.fig_BS.supylabel('Depth (m)', fontsize=10)
cbar = self.fig_BS.colorbar(pcm, ax=self.axis_BS[:], shrink=1, location='right')
cbar.set_label(label='Backscatter acoustic signal (V)', rotation=270, labelpad=10)
@ -878,7 +878,7 @@ class AcousticDataTab(QWidget):
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_BS[f].transAxes)
self.fig_BS.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_BS.supxlabel('Time (sec)', fontsize=10)
self.fig_BS.supylabel('Depth (m)', fontsize=10)
self.fig_BS.canvas.draw_idle()
@ -897,10 +897,9 @@ class AcousticDataTab(QWidget):
msgBox.setText("Plot backscatter acoustic raw data 2D field before plot SNR 2D field")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
elif self.tableModel.rowCount(1) > 11:
noise_data = self.compute_SNR()
elif (self.lineEdit_noise_file.text()) and (self.tableModel.rowCount(1) > 11):
self.fig_SNR, self.axis_SNR = plt.subplots(nrows=noise_data._freq.shape[0] , ncols=1,
self.fig_SNR, self.axis_SNR = plt.subplots(nrows=stg.freq.shape[0] , ncols=1,
sharex=True, sharey=False, layout="constrained")
self.canvas_SNR = FigureCanvas(self.fig_SNR)
self.verticalLayout_groupbox_transect_2Dplot_snr_data.addWidget(self.canvas_SNR)
@ -915,14 +914,14 @@ class AcousticDataTab(QWidget):
# self.spinbox_tmax.setValue(np.round(np.max(noise_data._time_snr), 2))
x, y = np.meshgrid(
noise_data._time_snr[np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
noise_data._r)
stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
stg.r)
for f in range(noise_data._freq.shape[0]):
for f in range(stg.freq.shape[0]):
val_min = np.min(noise_data._snr[:, f, :])
val_max = np.max(noise_data._snr[:, f, :])
val_min = np.min(stg.snr[:, f, :])
val_max = np.max(stg.snr[:, f, :])
if val_min == 0:
val_min = 1e-5
if val_max > 1000:
@ -932,40 +931,47 @@ class AcousticDataTab(QWidget):
bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
norm = BoundaryNorm(boundaries=bounds, ncolors=300)
cf = self.axis_SNR[f].contourf(x, -y,
noise_data._snr[:, f,
np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
levels, cmap='gist_rainbow', norm=norm)#, shading='gouraud')
cf = (self.axis_SNR[f].
contourf(x, -y,
stg.snr[:, f,
np.where(np.round(stg.snr, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
levels, cmap='gist_rainbow', norm=norm))
self.axis_SNR[f].text(1, .70, noise_data._freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom', transform=self.axis_SNR[f].transAxes)
self.axis_SNR[f].text(1, .70, stg.freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_SNR[f].transAxes)
self.fig_SNR.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_SNR.supxlabel('Time (sec)', fontsize=10)
self.fig_SNR.supylabel('Depth (m)', fontsize=10)
# plt.subplots_adjust(bottom=0.125, top=0.98, right=1.03, left=0.08, hspace=0.1)
# self.fig.tight_layout()
cbar = self.fig_SNR.colorbar(cf, ax=self.axis_SNR[:], shrink=1, location='right')
cbar.set_label(label='Signal to Noise Ratio', rotation=270, labelpad=10)
cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$'])
self.fig_SNR.canvas.draw_idle()
def update_xaxis_transect_with_SNR_data(self):
if self.lineEdit_noise_file.text():
noise_data = self.compute_SNR()
if ((self.canvas_BS != None) and (self.canvas_SNR != None)):
# if self.canvas_SNR == None:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Plot transect Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Plot transect before change x-axis value")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
if ((self.canvas_BS != None) and (self.canvas_SNR != None)):
x, y = np.meshgrid(
noise_data._time_snr[np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
noise_data._r)
stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
stg.r)
for f in range(noise_data._freq.shape[0]):
for f in range(stg.freq.shape[0]):
self.axis_SNR[f].cla()
val_min = np.min(noise_data._snr[:, f, :])
val_max = np.max(noise_data._snr[:, f, :])
val_min = np.min(stg.snr[:, f, :])
val_max = np.max(stg.snr[:, f, :])
if val_min == 0:
val_min = 1e-5
if val_max > 1000:
@ -976,25 +982,18 @@ class AcousticDataTab(QWidget):
norm = BoundaryNorm(boundaries=bounds, ncolors=300)
cf = self.axis_SNR[f].contourf(x, -y,
noise_data._snr[:, f,
np.where(np.round(noise_data._time_snr,
2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(noise_data._time_snr,
2) == self.spinbox_tmax.value())[0][0]],
levels, cmap='gist_rainbow', norm=norm) # , shading='gouraud')
stg.snr[:, f,
np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
levels, cmap='gist_rainbow', norm=norm)
self.axis_SNR[f].text(1, .70, noise_data._freq_text[f],
self.axis_SNR[f].text(1, .70, stg.freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_SNR[f].transAxes)
self.fig_SNR.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_SNR.supylabel('Depth (m)', fontsize=10)
# plt.subplots_adjust(bottom=0.125, top=0.98, right=1.03, left=0.08, hspace=0.1)
# self.fig.tight_layout()
# cbar = self.fig_SNR.colorbar(cf, ax=self.axis_SNR[:], shrink=1, location='right')
# cbar.set_label(label='Signal to Noise Ratio', rotation=270, labelpad=10)
# cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$'])
self.fig_SNR.canvas.draw_idle()
def detect_bottom(self):
@ -1028,35 +1027,31 @@ class AcousticDataTab(QWidget):
# msgBox.exec()
# elif (self.canvas_BS) and (self.canvas_SNR == None):
else:
acoustic_data = self.load_BS_acoustic_raw_data()
# Selecting the range in which we look for the bottom reflection
rmin = np.int(self.spinbox_depth_min.text()) # 4
rmax = np.int(self.spinbox_depth_max.text()) # 8
rmin = np.int(self.spinbox_depth_min.text())
rmax = np.int(self.spinbox_depth_max.text())
# empty result arrays
r_bottom = np.zeros(acoustic_data._nb_profiles)
val_bottom = np.zeros(acoustic_data._nb_profiles)
r_bottom = np.zeros(stg.nb_profiles)
val_bottom = np.zeros(stg.nb_profiles)
r_bottom_ind = []
# ----------- Detecting the bottom -------------
progessBar = QProgressBar()
for d in range(acoustic_data._nb_profiles):
progessBar.setValue(d)
for d in range(stg.nb_profiles):
# Index of the range where we look for the peak
ind_min = np.where(acoustic_data._r >= rmin)[0][0]
ind_max = np.where(acoustic_data._r <= rmax)[0][-1]
ind_min = np.where(stg.r >= rmin)[0][0]
ind_max = np.where(stg.r <= rmax)[0][-1]
# Getting the peak
val_bottom[d] = np.nanmax(acoustic_data._BS_raw_data[ind_min:ind_max,
self.combobox_freq_choice.currentIndex(), d])
val_bottom[d] = np.nanmax(stg.BS_raw_data[ind_min:ind_max, self.combobox_freq_choice.currentIndex(), d])
# Getting the range cell of the peak
ind_bottom = np.where(acoustic_data._BS_raw_data[ind_min:ind_max,
self.combobox_freq_choice.currentIndex(), d] == val_bottom[d])[0][0]
r_bottom[d] = acoustic_data._r[ind_bottom + ind_min]
ind_bottom = np.where(stg.BS_raw_data[ind_min:ind_max, self.combobox_freq_choice.currentIndex(), d]
== val_bottom[d])[0][0]
r_bottom[d] = stg.r[ind_bottom + ind_min]
r_bottom_ind.append(ind_bottom + ind_min)
# Updating the range where we will look for the peak (in the next cell)
rmin = r_bottom[d] - locale.atof(self.doublespinbox_next_cell.text()) # 0.75
rmax = r_bottom[d] + locale.atof(self.doublespinbox_next_cell.text()) # 0.75
rmin = r_bottom[d] - locale.atof(self.doublespinbox_next_cell.text())
rmax = r_bottom[d] + locale.atof(self.doublespinbox_next_cell.text())
BS_section_bottom = np.zeros((acoustic_data._BS_raw_data.shape[0], acoustic_data._BS_raw_data.shape[2]))
BS_section_bottom = np.zeros((stg.r.shape[0], stg.time.shape[0]))
for i in range(BS_section_bottom.shape[0]):
# print(r_bottom_temp_ind[i])
@ -1065,40 +1060,88 @@ class AcousticDataTab(QWidget):
# print(BS_section_bottom[r_bottom_temp_ind[i]][i])
# --- Plot transect BS with bathymetry ---
for f in range(acoustic_data._freq.shape[0]):
for f in range(stg.freq.shape[0]):
self.axis_BS[f].cla()
val_min = np.min(acoustic_data._BS_raw_data[:, f, :])
val_max = np.max(acoustic_data._BS_raw_data[:, f, :])
val_min = np.min(stg.BS_raw_data[:, f, :])
val_max = np.max(stg.BS_raw_data[:, f, :])
if val_min == 0:
val_min = 1e-5
pcm = self.axis_BS[f].pcolormesh(
acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]],
-acoustic_data._r ,
(acoustic_data._BS_raw_data[:, f,
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]]),
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))#, shading='gouraud')
stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
-stg.r,
(stg.BS_raw_data[:, f,
np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]]),
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
self.axis_BS[f].plot(
acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]],
# np.max(r_bottom[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]]),
- r_bottom[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]],
# + np.min(r_bottom[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]]),
# np.max(self._model.r_bottom_cross_section) - self._model.r_bottom_cross_section + np.min(self._model.r_bottom_cross_section),
stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
- r_bottom[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
color='black', linewidth=1, linestyle="solid")
self.axis_BS[f].text(1, .70, acoustic_data._freq_text[f],
self.axis_BS[f].text(1, .70, stg.freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_BS[f].transAxes)
self.fig_BS.canvas.draw_idle()
# --- Plot transect SNR with bathymetry ---
x, y = np.meshgrid(
stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
stg.r)
for f in range(stg.freq.shape[0]):
self.axis_SNR[f].cla()
val_min = np.min(stg.snr[:, f, :])
val_max = np.max(stg.snr[:, f, :])
if val_min == 0:
val_min = 1e-5
if val_max > 1000:
levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
else:
levels = np.array([00.1, 1, 2, 10, 100, val_max])
bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
norm = BoundaryNorm(boundaries=bounds, ncolors=300)
cf = self.axis_SNR[f].contourf(x, -y,
stg.snr[:, f,
np.where(np.round(stg.time,
2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time,
2) == self.spinbox_tmax.value())[0][0]],
levels, cmap='gist_rainbow', norm=norm) # , shading='gouraud')
self.axis_SNR[f].text(1, .70, stg.freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_SNR[f].transAxes)
self.axis_SNR[f].plot(
stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
- r_bottom[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
# + np.min(r_bottom[np.where(np.round(noise_data._time, 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(noise_data._time, 2) == self.spinbox_tmax.value())[0][0]]),
# np.max(self._model.r_bottom_cross_section) - self._model.r_bottom_cross_section + np.min(self._model.r_bottom_cross_section),
color='black', linewidth=1, linestyle="solid")
self.axis_SNR[f].text(1, .70, stg.freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_BS[f].transAxes)
self.fig_SNR.canvas.draw_idle()
# else:
#
# acoustic_data = self.load_BS_acoustic_raw_data()
@ -1171,57 +1214,7 @@ class AcousticDataTab(QWidget):
# transform=self.axis_BS[f].transAxes)
#
#
# # --- Plot transect SNR with bathymetry ---
#
# noise_data = self.compute_SNR()
#
# x, y = np.meshgrid(
# noise_data._time_snr[np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
# noise_data._r)
#
# for f in range(noise_data._freq.shape[0]):
# self.axis_SNR[f].cla()
#
# val_min = np.min(noise_data._snr[:, f, :])
# val_max = np.max(noise_data._snr[:, f, :])
# if val_min == 0:
# val_min = 1e-5
# if val_max > 1000:
# levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
# else:
# levels = np.array([00.1, 1, 2, 10, 100, val_max])
# bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
# norm = BoundaryNorm(boundaries=bounds, ncolors=300)
#
# cf = self.axis_SNR[f].contourf(x, -y,
# noise_data._snr[:, f,
# np.where(np.round(noise_data._time_snr,
# 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(noise_data._time_snr,
# 2) == self.spinbox_tmax.value())[0][0]],
# levels, cmap='gist_rainbow', norm=norm) # , shading='gouraud')
#
# self.axis_SNR[f].text(1, .70, noise_data._freq_text[f],
# fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
# horizontalalignment='right', verticalalignment='bottom',
# transform=self.axis_SNR[f].transAxes)
#
# self.axis_SNR[f].plot(
# noise_data._time_snr[np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
# # np.max(r_bottom[np.where(np.round(noise_data._time, 2) == self.spinbox_tmin.value())[0][0]:
# # np.where(np.round(noise_data._time, 2) == self.spinbox_tmax.value())[0][0]])
# - r_bottom[np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]:
# np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
# # + np.min(r_bottom[np.where(np.round(noise_data._time, 2) == self.spinbox_tmin.value())[0][0]:
# # np.where(np.round(noise_data._time, 2) == self.spinbox_tmax.value())[0][0]]),
# # np.max(self._model.r_bottom_cross_section) - self._model.r_bottom_cross_section + np.min(self._model.r_bottom_cross_section),
# color='black', linewidth=1, linestyle="solid")
#
# self.axis_SNR[f].text(1, .70, acoustic_data._freq_text[f],
# fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
# horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes)
# self.fig_BS.supxlabel('Distance from left bank (m)', fontsize=10)
# self.fig_BS.supylabel('Depth (m)', fontsize=10)
@ -1229,6 +1222,6 @@ class AcousticDataTab(QWidget):
# # self.fig.tight_layout()
# cbar = self.fig_BS.colorbar(pcm, ax=self.axis_BS[:], shrink=1, location='right')
# cbar.set_label(label='Backscatter acoustic signal (V)', rotation=270, labelpad=10)
self.fig_BS.canvas.draw_idle()
# self.fig_SNR.canvas.draw_idle()
return r_bottom, val_bottom, r_bottom_ind, BS_section_bottom
# return r_bottom, val_bottom, r_bottom_ind, BS_section_bottom