File setting is created to store global variables used all along tabs. Acoustic data tab is re-write with global variables.

dev-brahim
brahim 2023-08-08 15:40:35 +02:00
parent 2905226f2a
commit 58138d0e4e
3 changed files with 405 additions and 226 deletions

View File

@ -5,10 +5,10 @@ import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm from matplotlib.colors import LogNorm
path_BS_raw_data = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \ # path_BS_raw_data = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \
"Data/Acoustic_data/20180107123500.aqa" # "Data/Acoustic_data/20180107123500.aqa"
path_noise_data = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \ # path_noise_data = "/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/" \
"Data/AcousticNoise_data/20180107121600.aqa" # "Data/AcousticNoise_data/20180107121600.aqa"
class AcousticDataLoader(): class AcousticDataLoader():
@ -39,29 +39,32 @@ class AcousticDataLoader():
self._gain_rx = self._data_BS.RxGain self._gain_rx = self._data_BS.RxGain
self._gain_tx = self._data_BS.TxGain self._gain_tx = self._data_BS.TxGain
self._snr = np.array([]) # self._snr = np.array([])
self._snr_reshape = np.array([]) # self._snr_reshape = np.array([])
self._time_snr = np.array([]) # self._time_snr = np.array([])
# print(type(self._gain_tx))
# print(["BS - " + f for f in self._freq_text]) # print(["BS - " + f for f in self._freq_text])
# print(self._time.shape[0]*self._r.shape[0]*4) # print(self._time.shape[0]*self._r.shape[0]*4)
# fig, ax = plt.subplots(nrows=1, ncols=1) # fig, ax = plt.subplots(nrows=1, ncols=1)
# ax.pcolormesh(self._time, self._r, np.flipud(self._BS_raw_data[:, 1, :]), # ax.pcolormesh(self._time, self._r, (self._BS_raw_data[:, 1, :]),
# cmap='viridis', # cmap='viridis',
# norm=LogNorm(vmin=1e-5, vmax=np.max(self._BS_raw_data[:, 0, :]))) # , shading='gouraud') # norm=LogNorm(vmin=1e-5, vmax=np.max(self._BS_raw_data[:, 0, :]))) # , shading='gouraud')
# ax.pcolormesh(range(self._BS_raw_data.shape[2]), range(self._BS_raw_data.shape[0]), self._BS_raw_data[:, 1, :], cmap='viridis', # # ax.pcolormesh(range(self._BS_raw_data.shape[2]), range(self._BS_raw_data.shape[0]), self._BS_raw_data[:, 1, :], cmap='viridis',
# norm=LogNorm(vmin=1e-5, vmax=np.max(self._BS_raw_data[:, 0, :]))) # , shading='gouraud') # # norm=LogNorm(vmin=1e-5, vmax=np.max(self._BS_raw_data[:, 0, :]))) # , shading='gouraud')
# plt.show() # plt.show()
# fig, ax = plt.subplots(nrows=1, ncols=1)
# ax.plot(self._BS_raw_data[:, 0, 100] , self._r)
# ax.set_ylim(2, 20)
# plt.show()
# print(self.reshape_BS_raw_cross_section()[0, 0]) # print(self.reshape_BS_raw_cross_section()[0, 0])
# self.reshape_r() # self.reshape_r()
# self.reshape_t() # self.reshape_t()
# dataframe = self.concatenate_data()
# print(dataframe)
def reshape_BS_raw_cross_section(self): def reshape_BS_raw_cross_section(self):
BS_raw_cross_section = np.reshape(self._BS_raw_data, BS_raw_cross_section = np.reshape(self._BS_raw_data,
(self._r.shape[0]*len(self._time), self._freq.shape[0]), (self._r.shape[0]*len(self._time), self._freq.shape[0]),
@ -78,14 +81,14 @@ class AcousticDataLoader():
t = np.reshape(np.repeat(self._time, self._r.shape[0]), (self._time.shape[0]*self._r.shape[0], 1)) t = np.reshape(np.repeat(self._time, self._r.shape[0]), (self._time.shape[0]*self._r.shape[0], 1))
return t return t
def concatenate_data(self): # def concatenate_data(self):
self.reshape_t() # self.reshape_t()
self.reshape_BS_raw_cross_section() # self.reshape_BS_raw_cross_section()
# print(self.reshape_t().shape) # # print(self.reshape_t().shape)
# print(se.lf.reshape_BS_raw_cross_section().shape) # # print(se.lf.reshape_BS_raw_cross_section().shape)
df = pd.DataFrame(np.concatenate((self.reshape_t(), self.reshape_BS_raw_cross_section()), axis=1), # df = pd.DataFrame(np.concatenate((self.reshape_t(), self.reshape_BS_raw_cross_section()), axis=1),
columns=["time"] + self._freq_text) # columns=["time"] + self._freq_text)
return df # return df
# if __name__ == "__main__": # if __name__ == "__main__":

View File

@ -1,8 +1,9 @@
import sys import sys
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QPushButton, QComboBox, QLineEdit, QLabel, \ from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QPushButton, QComboBox, QLineEdit, QLabel, \
QGridLayout, QSpinBox, QDoubleSpinBox, QTableView, QTableWidget, QSpacerItem, QSizePolicy, \ QGridLayout, QSpinBox, QDoubleSpinBox, QTableView, QTableWidget, QSpacerItem, QSizePolicy, \
QAbstractScrollArea, QFileDialog, QTableWidgetItem, QMessageBox, QScrollBar, QScrollArea QAbstractScrollArea, QFileDialog, QTableWidgetItem, QMessageBox, QScrollBar, QScrollArea,
QProgressBar)
from PyQt5.QtGui import QPixmap, QIcon from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtCore import Qt, QCoreApplication, pyqtSignal, pyqtSlot, QEvent from PyQt5.QtCore import Qt, QCoreApplication, pyqtSignal, pyqtSlot, QEvent
@ -31,6 +32,8 @@ from View.window_noise_level_averaged_profile import WindowNoiseLevelTailAverage
from View.sample_data_tab import SampleDataTab from View.sample_data_tab import SampleDataTab
import settings as stg
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
@ -336,7 +339,7 @@ class AcousticDataTab(QWidget):
self.spinbox_tmin.setRange(0, 9999) self.spinbox_tmin.setRange(0, 9999)
self.gridLayout_groupbox_xaxis_time.addWidget(self.spinbox_tmin, 0, 2, 1, 1) 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.update_xaxis_transect_with_BS_raw_data)
self.spinbox_tmin.valueChanged.connect(self.update_xaxis_transect_with_SNR_data) # self.spinbox_tmin.valueChanged.connect(self.plot_transect_with_BS_raw_data)
self.label_tmin_unit = QLabel() self.label_tmin_unit = QLabel()
self.label_tmin_unit.setText("sec") self.label_tmin_unit.setText("sec")
@ -354,7 +357,7 @@ class AcousticDataTab(QWidget):
self.spinbox_tmax.setRange(0, 9999) self.spinbox_tmax.setRange(0, 9999)
self.gridLayout_groupbox_xaxis_time.addWidget(self.spinbox_tmax, 0, 6, 1, 1) 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_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 = QLabel()
self.label_tmax_unit.setText("sec") self.label_tmax_unit.setText("sec")
@ -405,7 +408,7 @@ class AcousticDataTab(QWidget):
self.gridlayout_compute_bathymetry = QGridLayout(self.groupbox_compute_bathymetry) self.gridlayout_compute_bathymetry = QGridLayout(self.groupbox_compute_bathymetry)
self.combobox_freq_choice = QComboBox() self.combobox_freq_choice = QComboBox()
self.combobox_freq_choice.addItems(['', '0.3 MHz', '0.5 Mhz', '1 MHz', '5 MHz']) # self.combobox_freq_choice.addItems(['', '0.3 MHz', '0.5 Mhz', '1 MHz', '5 MHz'])
self.gridlayout_compute_bathymetry.addWidget(self.combobox_freq_choice, 0, 0, 2, 1) self.gridlayout_compute_bathymetry.addWidget(self.combobox_freq_choice, 0, 0, 2, 1)
self.gridlayout_compute_bathymetry.addWidget(self.label_from, 0, 1, 1, 1) self.gridlayout_compute_bathymetry.addWidget(self.label_from, 0, 1, 1, 1)
self.spinbox_depth_min = QSpinBox() self.spinbox_depth_min = QSpinBox()
@ -631,6 +634,7 @@ class AcousticDataTab(QWidget):
self.WindowNoiseLevelTailAveragedProfile().show() self.WindowNoiseLevelTailAveragedProfile().show()
def open_dialog_box(self): def open_dialog_box(self):
# --- Open dialog box + choice directory and select file ---
if self.combobox_ABS_system_choice.currentIndex() == 0: if self.combobox_ABS_system_choice.currentIndex() == 0:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Download Error") msgBox.setWindowTitle("Download Error")
@ -648,100 +652,109 @@ class AcousticDataTab(QWidget):
filename = QFileDialog.getOpenFileName(self, "Open file", "", "UBSediFlow file (*.udt)") filename = QFileDialog.getOpenFileName(self, "Open file", "", "UBSediFlow file (*.udt)")
dir_name = path.dirname(filename[0]) dir_name = path.dirname(filename[0])
name = path.basename(filename[0]) name = path.basename(filename[0])
# --- Fill lineEdit with path and file names + load acoustic data ---
# --- fill date, hour and measurements information + fill frequency combobox for bottom detection ---
if self.combobox_ABS_system_choice.currentIndex() != 0: if self.combobox_ABS_system_choice.currentIndex() != 0:
if self.sender().objectName() == "pushbutton_acoustic_file": if self.sender().objectName() == "pushbutton_acoustic_file":
self.lineEdit_acoustic_file.setText(name) stg.path_BS_raw_data = dir_name
self.lineEdit_acoustic_file.setToolTip(dir_name) stg.filename_BS_raw_data = name
acoustic_data = self.load_BS_acoustic_raw_data() self.load_BS_acoustic_raw_data()
self.lineEdit_acoustic_file.setText(stg.filename_BS_raw_data)
self.lineEdit_acoustic_file.setToolTip(stg.path_BS_raw_data)
self.label_date_groupbox_acoustic_file.setText( self.label_date_groupbox_acoustic_file.setText(
_translate("CONSTANT_STRING", cs.DATE) + ": " + str(acoustic_data._date)) _translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date))
self.label_hour_groupbox_acoustic_file.setText( self.label_hour_groupbox_acoustic_file.setText(
_translate("CONSTANT_STRING", cs.HOUR) + ": " + str(acoustic_data._hour)) _translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour))
self.fill_measurements_information_groupbox() self.fill_measurements_information_groupbox()
self.combobox_freq_choice.addItems([f for f in stg.freq_text])
if self.sender().objectName() == "pushbutton_noise_file": if self.sender().objectName() == "pushbutton_noise_file":
self.lineEdit_noise_file.setText(name) stg.path_BS_noise_data = dir_name
self.lineEdit_noise_file.setToolTip(dir_name) stg.filename_BS_noise_data = name
noise_data = self.load_noise_data() self.load_noise_data_and_compute_SNR()
self.lineEdit_noise_file.setText(stg.filename_BS_noise_data)
self.lineEdit_noise_file.setToolTip(stg.path_BS_noise_data)
self.label_date_groupbox_noise_file.setText( self.label_date_groupbox_noise_file.setText(
_translate("CONSTANT_STRING", cs.DATE) + ": " + str(noise_data._date)) _translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date_noise))
self.label_hour_groupbox_noise_file.setText( self.label_hour_groupbox_noise_file.setText(
_translate("CONSTANT_STRING", cs.HOUR) + ": " + str(noise_data._hour)) _translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour_noise))
# return filename[0]
def load_BS_acoustic_raw_data(self): def load_BS_acoustic_raw_data(self):
acoustic_data = \ acoustic_data = AcousticDataLoader(stg.path_BS_raw_data + "/" + stg.filename_BS_raw_data)
AcousticDataLoader(self.lineEdit_acoustic_file.toolTip() + "/" + self.lineEdit_acoustic_file.text()) stg.BS_raw_data = acoustic_data._BS_raw_data
return acoustic_data stg.BS_raw_data_reshape = acoustic_data.reshape_BS_raw_cross_section()
stg.r = acoustic_data._r
stg.r_reshape = acoustic_data.reshape_r()
stg.time = acoustic_data._time
stg.time_reshape = acoustic_data.reshape_t()
stg.freq = acoustic_data._freq
stg.freq_text = acoustic_data._freq_text
stg.date = acoustic_data._date
stg.hour = acoustic_data._hour
stg.nb_profiles = acoustic_data._nb_profiles
stg.nb_profiles_per_sec = acoustic_data._nb_profiles_per_sec
stg.nb_cells = acoustic_data._nb_cells
stg.cell_size = acoustic_data._cell_size
stg.pulse_length = acoustic_data._cell_size
stg.nb_pings_per_sec = acoustic_data._nb_pings_per_sec
stg.nb_pings_averaged_per_profile = acoustic_data._nb_pings_averaged_per_profile
stg.kt = acoustic_data._kt
stg.gain_rx = acoustic_data._gain_rx
stg.gain_tx = acoustic_data._gain_tx
def load_noise_data(self): def load_noise_data_and_compute_SNR(self):
noise_data = AcousticDataLoader(self.lineEdit_noise_file.toolTip() + "/" + self.lineEdit_noise_file.text()) noise_data = AcousticDataLoader(stg.path_BS_noise_data + "/" + stg.filename_BS_noise_data)
return noise_data stg.BS_noise_data = noise_data._BS_raw_data
stg.date_noise = noise_data._date
def compute_SNR(self): stg.hour_noise = noise_data._hour
acoustic_data = self.load_BS_acoustic_raw_data() stg.time_snr = noise_data._time
noise_data = self.load_noise_data() noise = np.zeros(stg.BS_raw_data.shape)
noise = np.zeros(acoustic_data._BS_raw_data.shape)
for f in range(noise_data._freq.shape[0]): for f in range(noise_data._freq.shape[0]):
# print(np.mean(self.V_noise[:, f, :], axis=(0, 1))) noise[:, f, :] = np.mean(stg.BS_noise_data[:, f, :], axis=(0, 1))
# BS_noise_section[0:BS_noise_section.shape[0], f, 0:BS_noise_section.shape[2]] = \ stg.snr = np.divide((stg.BS_raw_data - noise) ** 2, noise ** 2)
noise[:, f, :] = np.mean(noise_data._BS_raw_data[:, f, :], axis=(0, 1)) stg.snr_reshape = np.reshape(stg.snr, (stg.r.shape[0] * stg.time.shape[0], stg.freq.shape[0]), order="F")
noise_data._time_snr = acoustic_data._time
noise_data._snr = np.divide((acoustic_data._BS_raw_data - noise)**2, noise**2)
noise_data._snr_reshape = np.reshape(noise_data._snr,
(acoustic_data._r.shape[0] * acoustic_data._time.shape[0],
noise_data._freq.shape[0]),
order="F")
return noise_data
def fill_measurements_information_groupbox(self): def fill_measurements_information_groupbox(self):
acoustic_data = self.load_BS_acoustic_raw_data() # acoustic_data = self.load_BS_acoustic_raw_data()
self.label_profiles.setText( self.label_profiles.setText(
_translate("CONSTANT_STRING", cs.NB_PROFILES) + ": " + str(acoustic_data._nb_profiles)) _translate("CONSTANT_STRING", cs.NB_PROFILES) + ": " + str(stg.nb_profiles))
self.label_profiles_per_sec.setText( self.label_profiles_per_sec.setText(
_translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC) + ": " + _translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC) + ": " +
str(acoustic_data._nb_profiles_per_sec) + " Hz") str(stg.nb_profiles_per_sec) + " Hz")
self.label_freq.setText( self.label_freq.setText(
_translate("CONSTANT_STRING", cs.FREQUENCY) + ": " + ', '.join(acoustic_data._freq_text)) _translate("CONSTANT_STRING", cs.FREQUENCY) + ": " + ', '.join(stg.freq_text))
self.label_cells.setText( self.label_cells.setText(
_translate("CONSTANT_STRING", cs.NB_CELLS) + ": " + str(acoustic_data._nb_cells)) _translate("CONSTANT_STRING", cs.NB_CELLS) + ": " + str(stg.nb_cells))
self.label_cell_size.setText( self.label_cell_size.setText(
_translate("CONSTANT_STRING", cs.CELL_SIZE) + ": " + str(100*round(acoustic_data._cell_size, 3)) + " cm") _translate("CONSTANT_STRING", cs.CELL_SIZE) + ": " + str(100*round(stg.cell_size, 3)) + " cm")
self.label_pulse_length.setText( self.label_pulse_length.setText(
_translate("CONSTANT_STRING", cs.PULSE_LENGHT) + ": " + str(round(acoustic_data._pulse_length,6)) + "sec") _translate("CONSTANT_STRING", cs.PULSE_LENGHT) + ": " + str(round(stg.pulse_length,6)) + "sec")
self.label_pings_per_sec.setText( self.label_pings_per_sec.setText(
_translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC) + ": " + str(acoustic_data._nb_pings_per_sec) + " Hz") _translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC) + ": " + str(stg.nb_pings_per_sec) + " Hz")
self.label_pings_per_profile.setText( self.label_pings_per_profile.setText(
_translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE) + ": " + _translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE) + ": " +
str(acoustic_data._nb_pings_averaged_per_profile)) str(stg.nb_pings_averaged_per_profile))
self.label_kt.setText( self.label_kt.setText(
_translate("CONSTANT_STRING", cs.KT) + ": " + ', '.join(map(str, acoustic_data._kt))) _translate("CONSTANT_STRING", cs.KT) + ": " + ', '.join(map(str, stg.kt)))
self.label_rx.setText( self.label_rx.setText(
_translate("CONSTANT_STRING", cs.GAIN_RX) + ": " + ', '.join(map(str, acoustic_data._gain_rx))) _translate("CONSTANT_STRING", cs.GAIN_RX) + ": " + ', '.join(map(str, stg.gain_rx)))
self.label_tx.setText( self.label_tx.setText(
_translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, acoustic_data._gain_tx))) _translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, stg.gain_tx)))
def fill_table(self): def fill_table(self):
if ((self.lineEdit_acoustic_file.text()) and (self.lineEdit_noise_file.text())): if ((self.lineEdit_acoustic_file.text()) and (self.lineEdit_noise_file.text())):
# --- Load data --- stg.DataFrame_acoustic = pd.DataFrame(
acoustic_data = self.load_BS_acoustic_raw_data() np.concatenate((stg.time_reshape, stg.BS_raw_data_reshape, stg.snr_reshape), axis=1),
noise_data = self.compute_SNR() columns=list(map(str, ["Time"] + ["BS - " + f for f in stg.freq_text] +
# --- Fill table with data --- ["SNR - " + f for f in stg.freq_text])))
data = pd.DataFrame( self.tableModel = TableModel(stg.DataFrame_acoustic)
np.concatenate((acoustic_data.reshape_t(), acoustic_data.reshape_BS_raw_cross_section(),
noise_data._snr_reshape), axis=1),
columns=list(map(str, ["Time"] + ["BS - " + f for f in acoustic_data._freq_text] +
["SNR - " + f for f in acoustic_data._freq_text])))
self.tableModel = TableModel(data)
self.tableView.setModel(self.tableModel) self.tableView.setModel(self.tableModel)
elif self.lineEdit_acoustic_file.text(): elif self.lineEdit_acoustic_file.text():
# --- Load data --- stg.DataFrame_acoustic = pd.DataFrame(
acoustic_data = self.load_BS_acoustic_raw_data() np.concatenate((stg.time_reshape, stg.BS_raw_data_reshape), axis=1),
# --- Fill table with data --- columns=list(map(str, ["Time"] + ["BS - " + f for f in stg.freq_text])))
data = pd.DataFrame( self.tableModel = TableModel(stg.DataFrame_acoustic)
np.concatenate((acoustic_data.reshape_t(), acoustic_data.reshape_BS_raw_cross_section()), axis=1),
columns=list(map(str, ["Time"] + ["BS - " + f for f in acoustic_data._freq_text])))
self.tableModel = TableModel(data)
self.tableView.setModel(self.tableModel) self.tableView.setModel(self.tableModel)
else: else:
msgBox = QMessageBox() msgBox = QMessageBox()
@ -773,16 +786,21 @@ class AcousticDataTab(QWidget):
# self.groupbox_xaxis_space.setDisabled(True) # self.groupbox_xaxis_space.setDisabled(True)
def plot_transect_with_BS_raw_data(self): def plot_transect_with_BS_raw_data(self):
if self.tableModel.rowCount(1) > 11: # --- Condition if table is not filled ---
acoustic_data = self.load_BS_acoustic_raw_data()
# print(np.max(acoustic_data._time))
# print("tmin value ", self.spinbox_tmin.value()) if self.tableModel.rowCount(1) == 10:
# print("tmin index ", np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]) msgBox = QMessageBox()
msgBox.setWindowTitle("Plot transect Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Fill table before plot transect 2D field")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
# print("tmax value ", self.spinbox_tmax.value()) # --- Condition if table is filled and figure is not plotted ---
# print("tmax index ", np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]) # --- => Then plot transect for each frequency by pressing the button "Plot transect"
self.fig_BS, self.axis_BS = plt.subplots(nrows=acoustic_data._freq.shape[0], ncols=1, sharex=True, sharey=False, layout="constrained")
elif (self.tableModel.rowCount(1) > 10) and (self.canvas_BS == None):
self.fig_BS, self.axis_BS = plt.subplots(nrows=stg.freq.shape[0], ncols=1, sharex=True, sharey=False, layout="constrained")
self.canvas_BS = FigureCanvas(self.fig_BS) self.canvas_BS = FigureCanvas(self.fig_BS)
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.canvas_BS) # self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.canvas_BS)
@ -794,57 +812,76 @@ class AcousticDataTab(QWidget):
self.scroll_BS.setAlignment(Qt.AlignCenter) self.scroll_BS.setAlignment(Qt.AlignCenter)
self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.scroll_BS) self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.scroll_BS)
self.spinbox_tmin.setValue(np.min(acoustic_data._time)) self.spinbox_tmin.setValue(np.min(stg.time))
self.spinbox_tmax.setValue(np.round(np.max(acoustic_data._time), 2)) self.spinbox_tmax.setValue(np.round(np.max(stg.time), 2))
for f in range(acoustic_data._freq.shape[0]): for f in range(stg.freq.shape[0]):
# self.ax = self.fig.add_subplot((4, 1, f+1), sharex=True, sharey=False)
# val_min = np.min(self.model.V[:, f, :2300]) val_min = np.nanmin(stg.BS_raw_data[:, f, :])
val_min = np.min(acoustic_data._BS_raw_data[:, f, :]) val_max = np.nanmax(stg.BS_raw_data[:, f, :])
# val_max = np.max(self.model.V[:, f, :2300])
val_max = np.max(acoustic_data._BS_raw_data[:, f, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
# if val_min == 0:
# val_min = 1e-5
# self.ax[f].imshow(np.asarray(np.array(self.model.BS_raw_cross_section.V[:, f, :], dtype=float)), aspect='auto',
# extent=[0, 1912, self.model.depth[-1][0], self.model.depth[0][0]],
# cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
# self.ax[f].plot(self.model.r_bottom_cross_section, color='red', linewidth=2)
pcm = self.axis_BS[f].pcolormesh( pcm = self.axis_BS[f].pcolormesh(
acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: stg.time[np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]], np.where(np.round(stg.time, 2) == self.spinbox_tmax.value())[0][0]],
acoustic_data._r , -stg.r,
np.flipud(acoustic_data._BS_raw_data[:, f, stg.BS_raw_data[:, f,
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: np.where(np.round(stg.time, 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.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))#, shading='gouraud') cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
# self.axis_BS[f].plot(self._model.dist_BS_section,
# np.max(self._model.r_bottom_cross_section) - self._model.r_bottom_cross_section + np.min(self._model.r_bottom_cross_section), self.axis_BS[f].text(1, .70, stg.freq_text[f],
# color='red', linewidth=2) fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
# x, y = np.meshgrid(self.model.dist_BS_section, self.model.BS_raw_cross_section.r) horizontalalignment='right', verticalalignment='bottom',
# z = np.cos(x) + np.sin(y) transform=self.axis_BS[f].transAxes)
# self.ax[f].contour(x, y, z, levels = 0, colors='k')
# self.ax[f].plot([25, 200], [5, 5], '-k')
self.axis_BS[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.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_BS.supylabel('Depth (m)', fontsize=10) self.fig_BS.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_BS.colorbar(pcm, ax=self.axis_BS[:], shrink=1, location='right') 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) cbar.set_label(label='Backscatter acoustic signal (V)', rotation=270, labelpad=10)
self.fig_BS.canvas.draw_idle() self.fig_BS.canvas.draw_idle()
else:
def update_xaxis_transect_with_BS_raw_data(self):
# --- Condition if table is filled but transect is not plotted
# --- => Error message if spin box values of tmin or tmax is change
if self.canvas_BS == None:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Plot transect Error") msgBox.setWindowTitle("Plot transect Error")
msgBox.setIcon(QMessageBox.Warning) msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Fill table before plot transect 2D field") msgBox.setText("Plot transect before change x-axis value")
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
else:
for f in range(stg.freq.shape[0]):
self.axis_BS[f].cla()
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(
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].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.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_BS.supylabel('Depth (m)', fontsize=10)
self.fig_BS.canvas.draw_idle()
def plot_transect_with_SNR_data(self): def plot_transect_with_SNR_data(self):
if self.tableModel.rowCount(1) == 10: if self.tableModel.rowCount(1) == 10:
msgBox = QMessageBox() msgBox = QMessageBox()
@ -895,10 +932,10 @@ class AcousticDataTab(QWidget):
bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2] bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
norm = BoundaryNorm(boundaries=bounds, ncolors=300) norm = BoundaryNorm(boundaries=bounds, ncolors=300)
cf = self.axis_SNR[f].contourf(x, y, cf = self.axis_SNR[f].contourf(x, -y,
np.flipud(noise_data._snr[:, f, 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_tmin.value())[0][0]:
np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.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') levels, cmap='gist_rainbow', norm=norm)#, shading='gouraud')
self.axis_SNR[f].text(1, .70, noise_data._freq_text[f], self.axis_SNR[f].text(1, .70, noise_data._freq_text[f],
@ -914,93 +951,51 @@ class AcousticDataTab(QWidget):
cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$']) cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$'])
self.fig_SNR.canvas.draw_idle() self.fig_SNR.canvas.draw_idle()
def update_xaxis_transect_with_BS_raw_data(self):
if self.canvas_BS == 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()
else:
# print(self.axis_BS.cla())
# self.fig_BS.clf()
acoustic_data = self.load_BS_acoustic_raw_data()
# self.fig_BS, self.axis_BS = plt.subplots(nrows=acoustic_data._freq.shape[0], ncols=1, sharex=True,
# sharey=False, layout="constrained")
# self.canvas_BS = FigureCanvas(self.fig_BS)
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.canvas_BS)
for f in range(acoustic_data._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, :])
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 ,
np.flipud(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')
self.axis_BS[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)
# 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()
def update_xaxis_transect_with_SNR_data(self): def update_xaxis_transect_with_SNR_data(self):
noise_data = self.compute_SNR() if self.lineEdit_noise_file.text():
if ((self.canvas_BS != None) and (self.canvas_SNR != None)): noise_data = self.compute_SNR()
if ((self.canvas_BS != None) and (self.canvas_SNR != None)):
x, y = np.meshgrid( x, y = np.meshgrid(
noise_data._time_snr[np.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmin.value())[0][0]: 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.where(np.round(noise_data._time_snr, 2) == self.spinbox_tmax.value())[0][0]],
noise_data._r) noise_data._r)
for f in range(noise_data._freq.shape[0]): for f in range(noise_data._freq.shape[0]):
self.axis_SNR[f].cla() self.axis_SNR[f].cla()
val_min = np.min(noise_data._snr[:, f, :]) val_min = np.min(noise_data._snr[:, f, :])
val_max = np.max(noise_data._snr[:, f, :]) val_max = np.max(noise_data._snr[:, f, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
if val_max > 1000: if val_max > 1000:
levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6]) levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
else: else:
levels = np.array([00.1, 1, 2, 10, 100, val_max]) 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] bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
norm = BoundaryNorm(boundaries=bounds, ncolors=300) norm = BoundaryNorm(boundaries=bounds, ncolors=300)
cf = self.axis_SNR[f].contourf(x, y, cf = self.axis_SNR[f].contourf(x, -y,
np.flipud(noise_data._snr[:, f, noise_data._snr[:, f,
np.where(np.round(noise_data._time_snr, np.where(np.round(noise_data._time_snr,
2) == self.spinbox_tmin.value())[0][0]: 2) == self.spinbox_tmin.value())[0][0]:
np.where(np.round(noise_data._time_snr, np.where(np.round(noise_data._time_snr,
2) == self.spinbox_tmax.value())[0][0]]), 2) == self.spinbox_tmax.value())[0][0]],
levels, cmap='gist_rainbow', norm=norm) # , shading='gouraud') levels, cmap='gist_rainbow', norm=norm) # , shading='gouraud')
self.axis_SNR[f].text(1, .70, noise_data._freq_text[f], self.axis_SNR[f].text(1, .70, noise_data._freq_text[f],
fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
horizontalalignment='right', verticalalignment='bottom', horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_SNR[f].transAxes) transform=self.axis_SNR[f].transAxes)
self.fig_SNR.supxlabel('Distance from left bank (m)', fontsize=10) self.fig_SNR.supxlabel('Distance from left bank (m)', fontsize=10)
self.fig_SNR.supylabel('Depth (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) # plt.subplots_adjust(bottom=0.125, top=0.98, right=1.03, left=0.08, hspace=0.1)
# self.fig.tight_layout() # self.fig.tight_layout()
# cbar = self.fig_SNR.colorbar(cf, ax=self.axis_SNR[:], shrink=1, location='right') # 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_label(label='Signal to Noise Ratio', rotation=270, labelpad=10)
# cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$']) # cbar.set_ticklabels(['0', '1', '2', '10', '100', r'10$^3$', r'10$^6$'])
self.fig_SNR.canvas.draw_idle() self.fig_SNR.canvas.draw_idle()
def detect_bottom(self): def detect_bottom(self):
if self.lineEdit_acoustic_file.text() == "": if self.lineEdit_acoustic_file.text() == "":
@ -1024,6 +1019,14 @@ class AcousticDataTab(QWidget):
msgBox.setText("Plot transect before compute bathymety algorithm") msgBox.setText("Plot transect before compute bathymety algorithm")
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
# elif self.canvas_SNR == None:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Detect bottom Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Plot transect before compute bathymety algorithm")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# elif (self.canvas_BS) and (self.canvas_SNR == None):
else: else:
acoustic_data = self.load_BS_acoustic_raw_data() acoustic_data = self.load_BS_acoustic_raw_data()
# Selecting the range in which we look for the bottom reflection # Selecting the range in which we look for the bottom reflection
@ -1035,16 +1038,18 @@ class AcousticDataTab(QWidget):
val_bottom = np.zeros(acoustic_data._nb_profiles) val_bottom = np.zeros(acoustic_data._nb_profiles)
r_bottom_ind = [] r_bottom_ind = []
# ----------- Detecting the bottom ------------- # ----------- Detecting the bottom -------------
progessBar = QProgressBar()
for d in range(acoustic_data._nb_profiles): for d in range(acoustic_data._nb_profiles):
progessBar.setValue(d)
# Index of the range where we look for the peak # Index of the range where we look for the peak
ind_min = np.where(acoustic_data._r >= rmin)[0][0] ind_min = np.where(acoustic_data._r >= rmin)[0][0]
ind_max = np.where(acoustic_data._r <= rmax)[0][-1] ind_max = np.where(acoustic_data._r <= rmax)[0][-1]
# Getting the peak # Getting the peak
val_bottom[d] = np.nanmax(acoustic_data._BS_raw_data[ind_min:ind_max, val_bottom[d] = np.nanmax(acoustic_data._BS_raw_data[ind_min:ind_max,
self.combobox_freq_choice.currentIndex() - 1, d]) self.combobox_freq_choice.currentIndex(), d])
# Getting the range cell of the peak # Getting the range cell of the peak
ind_bottom = np.where(acoustic_data._BS_raw_data[ind_min:ind_max, ind_bottom = np.where(acoustic_data._BS_raw_data[ind_min:ind_max,
self.combobox_freq_choice.currentIndex() - 1, d] == val_bottom[d])[0][0] self.combobox_freq_choice.currentIndex(), d] == val_bottom[d])[0][0]
r_bottom[d] = acoustic_data._r[ind_bottom + ind_min] r_bottom[d] = acoustic_data._r[ind_bottom + ind_min]
r_bottom_ind.append(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) # Updating the range where we will look for the peak (in the next cell)
@ -1059,7 +1064,7 @@ class AcousticDataTab(QWidget):
BS_section_bottom[r_bottom_ind[i]][i] = 1 BS_section_bottom[r_bottom_ind[i]][i] = 1
# print(BS_section_bottom[r_bottom_temp_ind[i]][i]) # print(BS_section_bottom[r_bottom_temp_ind[i]][i])
# --- Plot transect with bathymetry --- # --- Plot transect BS with bathymetry ---
for f in range(acoustic_data._freq.shape[0]): for f in range(acoustic_data._freq.shape[0]):
self.axis_BS[f].cla() self.axis_BS[f].cla()
@ -1071,8 +1076,8 @@ class AcousticDataTab(QWidget):
pcm = self.axis_BS[f].pcolormesh( pcm = self.axis_BS[f].pcolormesh(
acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: 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.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.value())[0][0]],
acoustic_data._r , -acoustic_data._r ,
np.flipud(acoustic_data._BS_raw_data[:, f, (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_tmin.value())[0][0]:
np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmax.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') cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))#, shading='gouraud')
@ -1080,18 +1085,143 @@ class AcousticDataTab(QWidget):
self.axis_BS[f].plot( self.axis_BS[f].plot(
acoustic_data._time[np.where(np.round(acoustic_data._time, 2) == self.spinbox_tmin.value())[0][0]: 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.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.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]]) # 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]: - 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.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.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.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), # 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") 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, acoustic_data._freq_text[f],
# fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5, fontsize=14, fontweight='bold', fontname="Ubuntu", c="black", alpha=0.5,
# horizontalalignment='right', verticalalignment='bottom', transform=self.axis_BS[f].transAxes) horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_BS[f].transAxes)
# 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
#
# # empty result arrays
# r_bottom = np.zeros(acoustic_data._nb_profiles)
# val_bottom = np.zeros(acoustic_data._nb_profiles)
# r_bottom_ind = []
# # ----------- Detecting the bottom -------------
# for d in range(acoustic_data._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]
# # Getting the peak
# val_bottom[d] = np.nanmax(acoustic_data._BS_raw_data[ind_min:ind_max,
# self.combobox_freq_choice.currentIndex() - 1, 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() - 1, d] == val_bottom[d])[0][0]
# r_bottom[d] = acoustic_data._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
#
# BS_section_bottom = np.zeros((acoustic_data._BS_raw_data.shape[0], acoustic_data._BS_raw_data.shape[2]))
#
# for i in range(BS_section_bottom.shape[0]):
# # print(r_bottom_temp_ind[i])
# # print(i)
# BS_section_bottom[r_bottom_ind[i]][i] = 1
# # print(BS_section_bottom[r_bottom_temp_ind[i]][i])
#
# # --- Plot transect BS with bathymetry ---
# for f in range(acoustic_data._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, :])
# 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')
#
# 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),
# color='black', linewidth=1, linestyle="solid")
#
# self.axis_BS[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)
#
#
# # --- 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.supxlabel('Distance from left bank (m)', fontsize=10)
# self.fig_BS.supylabel('Depth (m)', fontsize=10) # self.fig_BS.supylabel('Depth (m)', fontsize=10)
@ -1100,4 +1230,5 @@ class AcousticDataTab(QWidget):
# cbar = self.fig_BS.colorbar(pcm, ax=self.axis_BS[:], shrink=1, location='right') # 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) # cbar.set_label(label='Backscatter acoustic signal (V)', rotation=270, labelpad=10)
self.fig_BS.canvas.draw_idle() 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

45
settings.py Normal file
View File

@ -0,0 +1,45 @@
""" this file includs global variables shared between tab """
import numpy as np
import pandas as pd
import datetime
path_BS_raw_data = ""
filename_BS_raw_data = ""
BS_raw_data = np.array([])
r = np.array([])
freq = np.array([])
freq_text = list()
time = np.array([])
path_BS_noise_data = ""
filename_BS_noise_data = ""
BS_noise_data = np.array([])
snr = np.array([])
date = []
date_noise = []
hour = []
hour_noise = []
nb_profiles = 0
nb_profiles_per_sec = 0.0
nb_cells = 0
cell_size = 0.0
pulse_length = 0.0
nb_pings_per_sec = 0
nb_pings_averaged_per_profile = 0.0
kt = np.array([])
gain_rx = np.array([])
gain_tx = np.array([])
snr = np.array([])
snr_reshape = np.array([])
time_snr = np.array([])
time_reshape = np.array([])
r_reshape = np.array([])
BS_raw_data_reshape = np.array([])
snr_reshape = np.array([])
DataFrame_acoustic = pd.DataFrame()