acoused/View/acoustic_data_tab.py

2031 lines
110 KiB
Python

import sys
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QPushButton, QComboBox, QLineEdit, QLabel,
QGridLayout, QSpinBox, QDoubleSpinBox, QTableView, QTableWidget, QSpacerItem, QSizePolicy,
QAbstractScrollArea, QFileDialog, QTableWidgetItem, QMessageBox, QScrollBar, QScrollArea,
QProgressBar, QRadioButton, QFormLayout, QSlider)
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtCore import Qt, QCoreApplication, pyqtSignal, pyqtSlot, QEvent
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# import matplotlib
# matplotlib.use("Qt5Agg")
from matplotlib.colors import LogNorm, CSS4_COLORS, BoundaryNorm
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolBar
from os import path
from copy import deepcopy
import locale
locale.setlocale(locale.LC_ALL, '')
from scipy.signal import savgol_filter
from pyqt_top_left_right_file_list_widget.topLeftRightFileListWidget import TopLeftRightFileListWidget
# import Translation.biblio_string as bs
import Translation.constant_string as cs
from Model.TableModel import TableModel
from Model.AquascatDataLoader import RawAquascatData
from Model.acoustic_data_loader import AcousticDataLoader
from Model.acoustic_data_loader_UBSediFlow import AcousticDataLoaderUBSediFlow
# from View.window_noise_level_averaged_profile import WindowNoiseLevelTailAveragedProfile
from View.sample_data_tab import SampleDataTab
import settings as stg
_translate = QCoreApplication.translate
class AcousticDataTab(QWidget):
''' This class generates the Acoustic Data Tab '''
def __init__(self, tab_widget):
super().__init__()
self.path_icon = "./icons/"
self.icon_folder = QIcon(self.path_icon + "folder.png")
self.icon_triangle_left = QIcon(self.path_icon + "triangle_left.png")
self.icon_triangle_right = QIcon(self.path_icon + "triangle_right.png")
### --- General layout of widgets ---
self.verticalLayoutMain = QVBoxLayout(tab_widget)
self.horizontalLayoutTop = QHBoxLayout()
self.verticalLayoutMain.addLayout(self.horizontalLayoutTop, 4) # 1O units is 100% , 1 units is 10%
self.horizontalLayoutBottom = QHBoxLayout()
self.verticalLayoutMain.addLayout(self.horizontalLayoutBottom, 6)
### --- Layout of groupbox in the Top horizontal layout box
# Download | Measurement information | Table of values | Display options
self.groupbox_download = QGroupBox()
self.horizontalLayoutTop.addWidget(self.groupbox_download, 3)
self.groupbox_info = QGroupBox()
self.horizontalLayoutTop.addWidget(self.groupbox_info, 3)
# self.groupbox_table = QGroupBox()
# self.horizontalLayoutTop.addWidget(self.groupbox_table, 4)
self.groupbox_display_option = QGroupBox()
self.horizontalLayoutTop.addWidget(self.groupbox_display_option, 4)
### --- Layout of groupbox in the Bottom horizontal layout box
# 2D field of raw acoustic backscatter data | 2D field of Signal to Noise ratio
self.groupbox_transect_2Dplot_raw_BS_data = QGroupBox()
self.horizontalLayoutBottom.addWidget(self.groupbox_transect_2Dplot_raw_BS_data, 6)
self.groupbox_plot_profile = QGroupBox()
self.horizontalLayoutBottom.addWidget(self.groupbox_plot_profile, 4)
# self.groupbox_transect_2Dplot_snr_data = QGroupBox()
# self.horizontalLayoutBottom.addWidget(self.groupbox_transect_2Dplot_snr_data)
# =====================================================
# TOP HORIZONTAL BOX LAYOUT
# =====================================================
# +++++++++++++++++++++++++++
# | Group box Download file |
# +++++++++++++++++++++++++++
self.verticalLayout_groupbox_download = QVBoxLayout(self.groupbox_download)
# --- Group box Download multiple file ---
# self.groupbox_multiple_acoustic_file = QGroupBox()
# self.verticalLayout_groupbox_download_multiple_file = QVBoxLayout(self.groupbox_multiple_acoustic_file)
#
# self.groupbox_multiple_acoustic_file.setTitle("Multiple files")
# self.topLeftRightFileListWidget = TopLeftRightFileListWidget()
# # self.topLeftRightFileListWidget.show()
# # self.verticalLayout_groupbox_download_multiple_file.addWidget(self.topLeftRightFileListWidget)
# self.topLeftRightFileListWidget.setLayout(self.verticalLayout_groupbox_download_multiple_file)
# --- Group box acoustic file ---
self.groupbox_acoustic_file = QGroupBox()
self.gridLayout_groupbox_acoustic_file = QGridLayout(self.groupbox_acoustic_file)
self.combobox_ABS_system_choice = QComboBox()
self.combobox_ABS_system_choice.addItems([" ", "Aquascat 1000R", "UB-SediFlow"])
self.gridLayout_groupbox_acoustic_file.addWidget(self.combobox_ABS_system_choice, 0, 0, 1, 1)
self.pushbutton_acoustic_file = QPushButton()
self.pushbutton_acoustic_file.setObjectName("pushbutton_acoustic_file")
self.pushbutton_acoustic_file.setIcon(self.icon_folder)
self.gridLayout_groupbox_acoustic_file.addWidget(self.pushbutton_acoustic_file, 0, 1, 1, 1)
self.lineEdit_acoustic_file = QLineEdit()
self.gridLayout_groupbox_acoustic_file.addWidget(self.lineEdit_acoustic_file, 0, 2, 1, 1)
self.label_date_groupbox_acoustic_file = QLabel()
self.gridLayout_groupbox_acoustic_file.addWidget(self.label_date_groupbox_acoustic_file, 1, 0, 1, 2)
self.label_hour_groupbox_acoustic_file = QLabel()
self.gridLayout_groupbox_acoustic_file.addWidget(self.label_hour_groupbox_acoustic_file, 1, 2, 1, 1)
# Download Push Button event : connect button clicked signal to open file slot
self.pushbutton_acoustic_file.clicked.connect(self.open_dialog_box)
self.verticalLayout_groupbox_download.addWidget(self.groupbox_acoustic_file)
# --- Group box noise file --- (move to signal processing tab)
# self.groupbox_noise_file = QGroupBox()
# self.gridLayout_groupbox_noise_file = QGridLayout(self.groupbox_noise_file)
#
# self.pushbutton_noise_level_with_tail_of_mean_profile = QPushButton()
# self.gridLayout_groupbox_noise_file.addWidget(self.pushbutton_noise_level_with_tail_of_mean_profile, 0, 0, 1, 1)
# self.pushbutton_noise_file = QPushButton()
# self.pushbutton_noise_file.setObjectName("pushbutton_noise_file")
# self.pushbutton_noise_file.setIcon(icon_folder)
# self.gridLayout_groupbox_noise_file.addWidget(self.pushbutton_noise_file, 0, 1, 1, 1)
# self.lineEdit_noise_file = QLineEdit()
# self.gridLayout_groupbox_noise_file.addWidget(self.lineEdit_noise_file, 0, 2, 1, 1)
#
# self.label_date_groupbox_noise_file = QLabel()
# self.gridLayout_groupbox_noise_file.addWidget(self.label_date_groupbox_noise_file, 1, 0, 1, 2)
# self.label_hour_groupbox_noise_file = QLabel()
# self.gridLayout_groupbox_noise_file.addWidget(self.label_hour_groupbox_noise_file, 1, 2, 1, 1)
#
# # Download Push Button event : connect button clicked signal to open file slot
# self.pushbutton_noise_file.clicked.connect(self.open_dialog_box)
#
# self.verticalLayout_groupbox_download.addWidget(self.groupbox_noise_file)
# --- Group box GPS file ---
self.groupbox_gps = QGroupBox()
self.verticalLayout_gps_input_data = QVBoxLayout(self.groupbox_gps)
self.horizontalLayout_radiobutton_gps = QHBoxLayout()
self.verticalLayout_gps_input_data.addLayout(self.horizontalLayout_radiobutton_gps)
self.radiobutton_value = QRadioButton("Value")
self.radiobutton_value.setChecked(True)
self.radiobutton_value.toggled.connect(self.onClicked_radiobutton_gps)
self.horizontalLayout_radiobutton_gps.addWidget(self.radiobutton_value)
self.radiobutton_file = QRadioButton("File")
# self.radiobutton_file.setChecked(False)
self.radiobutton_file.toggled.connect(self.onClicked_radiobutton_gps)
self.horizontalLayout_radiobutton_gps.addWidget(self.radiobutton_file)
self.groupbox_gps_value = QGroupBox()
self.formLayout_gps_value = QFormLayout(self.groupbox_gps_value)
self.label_distance_value = QLabel()
self.label_distance_value.setText("Distance : ")
self.lineEdit_gps_value = QLineEdit()
self.formLayout_gps_value.addRow(self.label_distance_value, self.lineEdit_gps_value)
self.verticalLayout_gps_input_data.addWidget(self.groupbox_gps_value)
self.groupbox_gps_file = QGroupBox()
self.groupbox_gps_file.setEnabled(False)
self.gridLayout_groupbox_gps_file = QGridLayout(self.groupbox_gps_file)
self.combobox_gps_system_choice = QComboBox()
self.combobox_gps_system_choice.addItems([" ", "GPS1", "GPS2", "no GPS"])
self.gridLayout_groupbox_gps_file.addWidget(self.combobox_gps_system_choice, 0, 0, 1, 1)
self.pushbutton_gps_file = QPushButton()
self.pushbutton_gps_file.setIcon(self.icon_folder)
self.gridLayout_groupbox_gps_file.addWidget(self.pushbutton_gps_file, 0, 1, 1, 1)
self.lineEdit_gps_file = QLineEdit()
self.gridLayout_groupbox_gps_file.addWidget(self.lineEdit_gps_file, 0, 2, 1, 1)
self.label_date_groupbox_gps_file = QLabel()
self.gridLayout_groupbox_gps_file.addWidget(self.label_date_groupbox_gps_file, 1, 0, 1, 2)
self.label_hour_groupbox_gps_file = QLabel()
self.gridLayout_groupbox_gps_file.addWidget(self.label_hour_groupbox_gps_file, 1, 2, 1, 1)
# Download Push Button event : connect button clicked signal to open file slot
# self.pushButton_gpsfile.clicked.connect(self.open_dialog_box)
self.verticalLayout_gps_input_data.addWidget(self.groupbox_gps_file)
self.verticalLayout_groupbox_download.addWidget(self.groupbox_gps)
# # --- Time offset line between ABS system time and GPS time ---
self.gridLayout_time_offset = QGridLayout()
self.label_time_offset = QLabel()
self.gridLayout_time_offset.addWidget(self.label_time_offset, 0, 0, 1, 1)
self.label_acoustic_gps_time = QLabel()
self.label_acoustic_gps_time.setText(
"T<span style= vertical-align:sub>acoustic</span> =" + " T<span style= vertical-align:sub>gps</span>")
self.gridLayout_time_offset.addWidget(self.label_acoustic_gps_time, 0, 1, 1, 1)
self.combobox_plus_minus = QComboBox()
self.combobox_plus_minus.addItem("+")
self.combobox_plus_minus.addItem("-")
self.gridLayout_time_offset.addWidget(self.combobox_plus_minus, 0, 2, 1, 1)
self.spinbox_time_offset_value = QSpinBox()
self.gridLayout_time_offset.addWidget(self.spinbox_time_offset_value, 0, 3, 1, 1)
self.label_seconds = QLabel()
self.label_seconds.setText("sec")
self.gridLayout_time_offset.addWidget(self.label_seconds, 0, 4, 1, 1)
self.verticalLayout_groupbox_download.addLayout(self.gridLayout_time_offset)
# ++++++++++++++++++++++++++++++++++++++
# | Group Box Measurements information |
# ++++++++++++++++++++++++++++++++++++++
self.verticalLayout_groupbox_info = QVBoxLayout(self.groupbox_info)
self.formLayout_temperature = QFormLayout()
self.label_temperature = QLabel("Temperature : ")
self.lineEdit_temperature = QLineEdit()
self.formLayout_temperature.addRow(self.label_temperature, self.lineEdit_temperature)
self.verticalLayout_groupbox_info.addLayout(self.formLayout_temperature)
self.gridLayout_goupbox_info = QGridLayout()
self.verticalLayout_groupbox_info.addLayout(self.gridLayout_goupbox_info)
# --- Information for Aquascat ---
self.label_profiles = QLabel()
self.label_profiles_per_sec = QLabel()
self.label_cells = QLabel() # n_cell in UBSediFlow parameters
self.label_cell_size = QLabel() # r_em in UBSediFlow parameters
self.label_pulse_length = QLabel() # n_p / PRF with n_p = n_ech, nb of pulses to calculate one instantaneous profile
self.label_pings_per_sec = QLabel() # PRF in UBSediFlow parameters
self.label_pings_per_profile = QLabel() # n_profile/n_avg in UBSediFlow parameters
self.label_freq = QLabel()
self.label_kt = QLabel()
self.label_rx = QLabel() # a0 in UBSediFlow parameters
self.label_tx = QLabel() # a1 in UBSediFlow parameters
# --- Information for UBSediFlow ---
self.label_tr_out = QLabel()
self.label_tr_out.setText("Channel : ")
self.label_r_cell1 = QLabel()
self.label_r_cell1.setText("1st cell size : ")
self.label_r_dcell = QLabel()
self.label_r_dcell.setText("Inter-cell distance : ")
# self.groupbox_measurement_information_Aquascat()
self.combobox_ABS_system_choice.currentTextChanged.connect(self.ABS_system_choice)
# +++++++++++++++++++++++++++++
# | Group Box Table of values |
# +++++++++++++++++++++++++++++
# self.verticalLayout_groupbox_table = QVBoxLayout(self.groupbox_table)
#
# self.horizontalLayout_pushbutton_fill_export_table = QHBoxLayout()
# self.pushbutton_fill_table = QPushButton()
# self.horizontalLayout_pushbutton_fill_export_table.addWidget(self.pushbutton_fill_table)
#
# self.pushbutton_fill_table.clicked.connect(self.fill_table)
#
# self.horizontalSpacerItem_between_pushbutton_fill_export_table = QSpacerItem(50, 10,
# QSizePolicy.Expanding, QSizePolicy.Minimum)
# self.horizontalLayout_pushbutton_fill_export_table.addItem(
# self.horizontalSpacerItem_between_pushbutton_fill_export_table)
#
# self.pushbutton_export_table = QPushButton()
# self.horizontalLayout_pushbutton_fill_export_table.addWidget(self.pushbutton_export_table)
#
# self.pushbutton_export_table.clicked.connect(self.export_table)
#
# self.verticalLayout_groupbox_table.addLayout(self.horizontalLayout_pushbutton_fill_export_table)
#
# # self.tableWidget = QTableWidget()
# # self.tableWidget.setRowCount(10)
# # self.tableWidget.setColumnCount(10)
#
# self.tableView = QTableView()
# data = pd.DataFrame(np.zeros((10, 10)))
# self.tableModel = TableModel(data)
# self.tableView.setModel(self.tableModel)
# self.verticalLayout_groupbox_table.addWidget(self.tableView)
# #------------------------------------
# # self.tableView = QTableView()
# # self.tableView.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContentsOnFirstShow)
# # self.tableView.horizontalHeader().setStretchLastSection(True)
# #
# # df, tension, freq, depth = self._model.acoustic_data()
# # print(np.zeros(len(tension), dtype=int))
# # print("dimension", list(tension))
# # self.data = pd.DataFrame({'Time (sec)': np.zeros(10, dtype=int),
# # 'y (m)': np.zeros(10, dtype=int),
# # 'z (m)': np.zeros(10, dtype=int),
# # 'Frequency (MHz)': np.zeros(10, dtype=int),
# # 'Voltage (V)': np.zeros(10, dtype=int),
# # 'SNR': np.zeros(10, dtype=int)})
# # self.data = pd.DataFrame({'Time (sec)': np.zeros(len(tension), dtype=int),
# # 'y (m)': np.zeros(len(tension), dtype=int),
# # 'z (m)': np.zeros(len(tension), dtype=int),
# # 'Frequency (Hz)': df['freq'],
# # 'Voltage (V)': df['tension'],
# # 'SNR': np.zeros(len(tension), dtype=int)})
# # self.data.reset_index(drop=True, inplace=True)
# # self.data = self._model.acoustic_data_table
# #
# # self.tableModel = TableModel(self.data)
# # self.tableView.setModel(self.tableModel)
# # self.verticalLayout_groupboxtable.addWidget(self.tableView)
# # ------------------------------------
#
# self.tableWidget = QTableWidget()
# self.tableWidget.setRowCount(10)
# self.tableWidget.setColumnCount(10)
# #
# # print("tablewidget = ", self.tableWidget)
# #
# # self.tableWidget2 = TableWidget(3, 3)
# # print("tablewidget2 = ", self.tableWidget2)
#
# # for i in range(10):
# # for j in range(10):
# # item_v = QTableWidgetItem()
# # self.tableWidget.setVerticalHeaderItem(i, item_v)
# # item_h = QTableWidgetItem()
# # self.tableWidget.setHorizontalHeaderItem(j, item_h)
#
# # Fill table Push Button event
# # 1st : connect widgets to controllers = fill table
# self.pushbutton_fill_table_acousic.clicked.connect(self.fill_table) # self.on_pushButtonFillTable_clicked
# # 2nd : listen for model event signals = table is filled
# # self._model.BS_data_updated.connect(self.on_BS_data_updated)
#
# self.verticalLayout_groupboxtable.addWidget(self.tableWidget)
# # self.verticalLayout_groupboxtable.addWidget(self.tableView)
# ++++++++++++++++++++++++++++
# | Group Box Display option |
# ++++++++++++++++++++++++++++
self.verticalLayout_display_option = QVBoxLayout(self.groupbox_display_option)
# --- Push buttons to trigger plot of transect with Backscatter acoustic raw data and SNR ---
self.gridLayout_plot_transect_frequency_profile = QGridLayout()
self.verticalLayout_display_option.addLayout(self.gridLayout_plot_transect_frequency_profile)
# self.horizontalLayout_pushbutton_plot_BS_SNR_data = QHBoxLayout()
# self.verticalLayout_display_option.addLayout(self.horizontalLayout_pushbutton_plot_BS_SNR_data)
self.pushbutton_plot_transect_with_BS_raw_data = QPushButton()
self.gridLayout_plot_transect_frequency_profile.addWidget(self.pushbutton_plot_transect_with_BS_raw_data, 0, 0, 1, 3)
# self.horizontalLayout_pushbutton_plot_BS_SNR_data.addWidget(self.pushbutton_plot_transect_with_BS_raw_data)
self.pushbutton_plot_transect_with_BS_raw_data.clicked.connect(self.plot_transect_with_BS_raw_data)
self.label_profile_frequency = QLabel()
self.label_profile_frequency.setText("Profile frequency : ")
self.gridLayout_plot_transect_frequency_profile.addWidget(self.label_profile_frequency, 0, 4, 1, 1)
self.combobox_frequency_profile = QComboBox()
self.gridLayout_plot_transect_frequency_profile.addWidget(self.combobox_frequency_profile, 0, 5, 1, 1)
# self.pushbutton_plot_transect_with_SNR_data = QPushButton()
# self.horizontalLayout_pushbutton_plot_BS_SNR_data.addWidget(self.pushbutton_plot_transect_with_SNR_data)
# self.pushbutton_plot_transect_with_SNR_data.clicked.connect(self.plot_transect_with_SNR_data)
# --- Group Box Plot x-axis in time ---
self.groupbox_xaxis_time = QGroupBox()
# self.groupbox_xaxis_time.setCheckable(True)
# self.groupbox_xaxis_time.setChecked(True)
# self.groupbox_xaxis_time.clicked.connect(self.transect_xaxis_choice)
self.verticalLayout_display_option.addWidget(self.groupbox_xaxis_time)
self.gridLayout_groupbox_xaxis_time = QGridLayout(self.groupbox_xaxis_time)
self.label_from_time = QLabel()
self.label_from_time.setText("From")
self.gridLayout_groupbox_xaxis_time.addWidget(self.label_from_time, 0, 0, 1, 1)
self.label_tmin = QLabel()
self.label_tmin.setText("t<span style= vertical-align:sub>min</span> = ")
self.gridLayout_groupbox_xaxis_time.addWidget(self.label_tmin, 0, 1, 1, 1)
self.spinbox_tmin = QDoubleSpinBox()
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.update_xaxis_transect_with_SNR_data)
self.label_tmin_unit = QLabel()
self.label_tmin_unit.setText("sec")
self.gridLayout_groupbox_xaxis_time.addWidget(self.label_tmin_unit, 0, 3, 1, 1)
self.label_to_time = QLabel()
self.label_to_time.setText("to")
self.gridLayout_groupbox_xaxis_time.addWidget(self.label_to_time, 0, 4, 1, 1)
self.label_tmax = QLabel()
self.label_tmax.setText("t<span style= vertical-align:sub>max</span> = ")
self.gridLayout_groupbox_xaxis_time.addWidget(self.label_tmax, 0, 5, 1, 1)
self.spinbox_tmax = QDoubleSpinBox()
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.label_tmax_unit = QLabel()
self.label_tmax_unit.setText("sec")
self.gridLayout_groupbox_xaxis_time.addWidget(self.label_tmax_unit, 0, 7, 1, 1)
self.pushbutton_apply_transect_boundaries_in_time = QPushButton()
self.pushbutton_apply_transect_boundaries_in_time.setText("Apply")
self.gridLayout_groupbox_xaxis_time.addWidget(self.pushbutton_apply_transect_boundaries_in_time, 0, 7, 1, 1)
self.pushbutton_apply_transect_boundaries_in_time.clicked.connect(self.update_xaxis_transect_with_BS_raw_data)
# self.pushbutton_apply_transect_boundaries_in_time.clicked.connect(self.update_xaxis_transect_with_SNR_data)
self.pushbutton_apply_transect_boundaries_in_time.clicked.connect(self.update_plot_profile)
# --- Group Box Plot x-axis in space ---
self.groupbox_xaxis_space = QGroupBox()
# self.groupbox_xaxis_space.setCheckable(True)
# self.groupbox_xaxis_space.setChecked(False)
# self.groupbox_xaxis_space.clicked.connect(self.transect_xaxis_choice)
self.verticalLayout_display_option.addWidget(self.groupbox_xaxis_space)
self.gridLayout_groupbox_xaxis_space = QGridLayout(self.groupbox_xaxis_space)
self.label_from_space = QLabel()
self.label_from_space.setText("From ")
self.gridLayout_groupbox_xaxis_space.addWidget(self.label_from_space, 0, 0, 1, 1)
self.label_xmin = QLabel()
self.label_xmin.setText("x<span style= vertical-align:sub>min</span> = ")
self.gridLayout_groupbox_xaxis_space.addWidget(self.label_xmin, 0, 1, 1, 1)
self.spinbox_xmin = QSpinBox()
self.spinbox_xmin.setRange(0, 9999)
self.gridLayout_groupbox_xaxis_space.addWidget(self.spinbox_xmin, 0, 2, 1, 1)
self.label_xmin_m = QLabel()
self.label_xmin_m.setText("m")
self.gridLayout_groupbox_xaxis_space.addWidget(self.label_xmin_m, 0, 3, 1, 1)
self.label_to_space = QLabel()
self.label_to_space.setText("to")
self.gridLayout_groupbox_xaxis_space.addWidget(self.label_to_space, 0, 4, 1, 1)
self.label_xmax = QLabel()
self.label_xmax.setText("x<span style= vertical-align:sub>max</span> = ")
self.gridLayout_groupbox_xaxis_space.addWidget(self.label_xmax, 0, 5, 1, 1)
self.spinbox_xmax = QSpinBox()
self.spinbox_xmax.setRange(0, 9999)
self.gridLayout_groupbox_xaxis_space.addWidget(self.spinbox_xmax, 0, 6, 1, 1)
self.label_xmax_m = QLabel()
self.label_xmax_m.setText("m")
self.gridLayout_groupbox_xaxis_space.addWidget(self.label_xmax_m, 0, 7, 1, 1)
self.pushbutton_apply_transect_boundaries_in_space = QPushButton()
self.pushbutton_apply_transect_boundaries_in_space.setText("Apply")
self.gridLayout_groupbox_xaxis_space.addWidget(self.pushbutton_apply_transect_boundaries_in_space, 0, 8, 1, 1)
self.pushbutton_apply_transect_boundaries_in_space.clicked.connect(self.update_xaxis_transect_with_BS_raw_data)
# self.pushbutton_apply_transect_boundaries_in_space.clicked.connect(self.update_xaxis_transect_with_SNR_data)
# --- Group Box bathymetry computation algorithm to detect and plot bottom of transect---
self.groupbox_compute_bathymetry = QGroupBox()
# # self.groupbox_crosssectionbottom.setTitle("Plot bottom of cross section")
# self.groupbox_crosssectionbottom.setCheckable(True)
# self.groupbox_crosssectionbottom.setChecked(False)
self.verticalLayout_display_option.addWidget(self.groupbox_compute_bathymetry)
self.gridlayout_compute_bathymetry = QGridLayout(self.groupbox_compute_bathymetry)
self.combobox_freq_choice = QComboBox()
# 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.label_from_bathy = QLabel()
self.label_from_bathy.setText("From - ")
self.gridlayout_compute_bathymetry.addWidget(self.label_from_bathy, 0, 1, 1, 1)
# self.spinbox_depth_min = QSpinBox()
self.spinbox_depth_min = QDoubleSpinBox()
self.spinbox_depth_min.setRange(0, 9999)
self.spinbox_depth_min.setDecimals(2)
self.gridlayout_compute_bathymetry.addWidget(self.spinbox_depth_min, 0, 2, 1, 1)
self.label_depth_min_unit = QLabel()
self.label_depth_min_unit.setText("m")
self.gridlayout_compute_bathymetry.addWidget(self.label_depth_min_unit, 0, 3, 1, 1)
self.label_to_bathy = QLabel()
self.label_to_bathy.setText("to - ")
self.gridlayout_compute_bathymetry.addWidget(self.label_to_bathy, 0, 4, 1, 1)
# self.spinbox_depth_max = QSpinBox()
self.spinbox_depth_max = QDoubleSpinBox()
self.spinbox_depth_max.setRange(0, 99999)
self.spinbox_depth_max.setDecimals(2)
self.gridlayout_compute_bathymetry.addWidget(self.spinbox_depth_max, 0, 5, 1, 1)
self.label_depth_max_unit = QLabel()
self.label_depth_max_unit.setText("m")
self.gridlayout_compute_bathymetry.addWidget(self.label_depth_max_unit, 0, 6, 1, 1)
self.label_next_cell = QLabel()
self.label_next_cell.setText("Next cell : +/-")
self.gridlayout_compute_bathymetry.addWidget(self.label_next_cell, 1, 1, 1, 1)
self.doublespinbox_next_cell = QDoubleSpinBox()
self.doublespinbox_next_cell.setRange(0, 99999)
self.doublespinbox_next_cell.setDecimals(2)
self.gridlayout_compute_bathymetry.addWidget(self.doublespinbox_next_cell, 1, 2, 1, 1)
self.label_next_cell_unit = QLabel()
self.label_next_cell_unit.setText("m")
self.gridlayout_compute_bathymetry.addWidget(self.label_next_cell_unit, 1, 3, 1, 1)
self.pushbutton_compute_bathymetry_algorithm = QPushButton()
self.pushbutton_compute_bathymetry_algorithm.setText("Compute \n&& \nPlot")
self.gridlayout_compute_bathymetry.addWidget(self.pushbutton_compute_bathymetry_algorithm, 0, 7, 2, 1)
self.pushbutton_compute_bathymetry_algorithm.clicked.connect(self.detect_bottom)
# =====================================================
# BOTTOM HORIZONTAL BOX LAYOUT
# =====================================================
# +++++++++++++++++++++++++++++++++++++************+++
# | Group Box Backscatter Acoustic Raw Data 2D field |
# ++++++++++++++++++++++++++************++++++++++++++
self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data = QVBoxLayout(self.groupbox_transect_2Dplot_raw_BS_data)
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.setContentsMargins(0, 0, 0, 0)
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.setSpacing(0)
self.canvas_BS = None
self.scroll_BS = None
# self.fig_BS, self.axis_BS = plt.subplots(nrows=4, ncols=1, sharex=True, sharey=False, layout="constrained")
# self.fig, self.ax = plt.subplots(4, 1)
# self.canvas_BS = FigureCanvas(self.fig_BS)
# self.canvas_BS = FigureCanvas()
# self.plotToolbar_rawdata = NavigationToolBar(self.canvas_rawdata, self)
# self.plot_acoustic_raw_data()
# self.verticalLayout_plotrawdata.addWidget(self.plotToolbar_rawdata)
# self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.canvas_BS)
# ++++++++++++++++++++++++++++++++++++++++++++
# | Group Box Signal to Noise ratio 2D field |
# ++++++++++++++++++++++++++++++++++++++++++++
# self.verticalLayout_groupbox_transect_2Dplot_snr_data = QVBoxLayout(self.groupbox_transect_2Dplot_snr_data)
#
# self.canvas_SNR = None
# self.scroll_SNR = None
#
# # self.figure, self.axis = plt.subplots(nrows=4, ncols=1, sharex=True, sharey=False, layout="constrained")
# # # self.canvas_snrdata = FigureCanvas(self.figure)
# #
# # self.canvas_snrdata = FigureCanvas()
# # # self.plotToolbar_snrdata = NavigationToolBar(self.canvas_snrdata, self)
# # # self.plot_snr_data()
# # # self.verticalLayout_plotsnrdata.addWidget(self.plotToolbar_snrdata)
# # self.verticalLayout_plotsnrdata.addWidget(self.canvas_snrdata)
# #
# # self.horizontalLayoutBottom.addWidget(self.groupbox_transect_2Dplot_snr_data)
# +++++++++++++++++++++++++++++++++++++++++++
# | Group Box Plot profile from BS 2D field |
# +++++++++++++++++++++++++++++++++++++++++++
self.verticalLayout_groupbox_plot_profile = QVBoxLayout(self.groupbox_plot_profile)
self.groupbox_plot_profile.setTitle("Profiles")
self.canvas_plot_profile = None
self.retranslate_acoustic_data_tab()
# -------------------- Functions for Acoustic dataTab --------------------
def retranslate_acoustic_data_tab(self):
self.groupbox_download.setTitle(_translate("CONSTANT_STRING", cs.DOWNLOAD))
self.groupbox_acoustic_file.setTitle(_translate("CONSTANT_STRING", cs.ACOUSTIC_FILE))
self.label_date_groupbox_acoustic_file.setText(_translate("CONSTANT_STRING", cs.DATE) + ":")
self.label_hour_groupbox_acoustic_file.setText(_translate("CONSTANT_STRING", cs.HOUR) + ":")
# self.groupbox_noise_file.setTitle(_translate("CONSTANT_STRING", cs.NOISE_FILE))
# self.pushbutton_noise_level_with_tail_of_mean_profile.setText(_translate("CONSTANT_STRING", cs.NOISE_LEVEL))
# self.label_date_groupbox_noise_file.setText(_translate("CONSTANT_STRING", cs.DATE) + ":")
# self.label_hour_groupbox_noise_file.setText(_translate("CONSTANT_STRING", cs.HOUR) + ":")
self.groupbox_gps.setTitle(_translate("CONSTANT_STRING", cs.GPS_FILE))
self.label_date_groupbox_gps_file.setText(_translate("CONSTANT_STRING", cs.DATE) + ":")
self.label_hour_groupbox_gps_file.setText(_translate("CONSTANT_STRING", cs.HOUR) + ":")
self.label_time_offset.setText(_translate("CONSTANT_STRING", cs.TIME_OFFSET))
self.groupbox_info.setTitle(_translate("CONSTANT_STRING", cs.MEASUREMENTS_INFORMATION))
self.label_profiles.setText(_translate("CONSTANT_STRING", cs.NB_PROFILES) + ":")
self.label_profiles.setToolTip(_translate("CONSTANT_STRING", cs.NB_PROFILES_TOOLTIP))
self.label_profiles_per_sec.setText(_translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC) + ":")
self.label_profiles_per_sec.setToolTip(_translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC_TOOLTIP))
self.label_cells.setText(_translate("CONSTANT_STRING", cs.NB_CELLS) + ":")
self.label_cells.setToolTip(_translate("CONSTANT_STRING", cs.NB_CELLS_TOOLTIP))
self.label_cell_size.setText(_translate("CONSTANT_STRING", cs.CELL_SIZE) + ":")
self.label_cell_size.setToolTip(_translate("CONSTANT_STRING", cs.CELL_SIZE_TOOLTIP))
self.label_pulse_length.setText(_translate("CONSTANT_STRING", cs.PULSE_LENGHT) + ":")
self.label_pulse_length.setToolTip(_translate("CONSTANT_STRING", cs.PULSE_LENGHT_TOOLTIP))
self.label_pings_per_sec.setText(_translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC))
self.label_pings_per_sec.setToolTip(_translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC_TOOLTIP))
self.label_pings_per_profile.setText(_translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE) + ":")
self.label_pings_per_profile.setToolTip(_translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE_TOOLTIP))
self.label_freq.setText(_translate("CONSTANT_STRING", cs.FREQUENCY) + ":")
self.label_freq.setToolTip(_translate("CONSTANT_STRING", cs.FREQUENCY_TOOLTIP))
self.label_kt.setText(_translate("CONSTANT_STRING", cs.KT) + ":")
self.label_kt.setToolTip(_translate("CONSTANT_STRING", cs.KT_TOOLTIP))
self.label_rx.setText(_translate("CONSTANT_STRING", cs.GAIN_RX) + ":")
self.label_rx.setToolTip(_translate("CONSTANT_STRING", cs.GAIN_RX_TOOLTIP))
self.label_tx.setText(_translate("CONSTANT_STRING", cs.GAIN_TX) + ":")
self.label_tx.setToolTip(_translate("CONSTANT_STRING", cs.GAIN_TX_TOOLTIP))
# self.groupbox_table.setTitle(_translate("CONSTANT_STRING", cs.TABLE_VALUES))
# self.pushbutton_fill_table.setText(_translate("CONSTANT_STRING", cs.SYNCHRONIZE_AND_FILL_TABLE))
# self.pushbutton_export_table.setText(_translate("CONSTANT_STRING", cs.EXPORT_TABLE))
self.groupbox_display_option.setTitle(_translate("CONSTANT_STRING", cs.DISPLAY_OPTIONS))
self.pushbutton_plot_transect_with_BS_raw_data.setText(_translate("CONSTANT_STRING", cs.PLOT_TRANSECT))
# self.pushbutton_plot_transect_with_SNR_data.setText(_translate("CONSTANT_STRING", cs.PLOT_SNR))
self.groupbox_xaxis_time.setTitle(_translate("CONSTANT_STRING", cs.PLOT_XAXIS_IN_TIME))
# self.label_tmin.setText(_translate("CONSTANT_STRING", cs.FROM) + " t<span style= vertical-align:sub>min</span> = ")
# self.label_tmax.setText(_translate("CONSTANT_STRING", cs.TO) + " t<span style= vertical-align:sub>max</span> = ")
# self.pushButton_plot_acoustic_transect_in_time.setText(_translate("CONSTANT_STRING", cs.PLOT_TRANSECT))
self.groupbox_xaxis_space.setTitle(_translate("CONSTANT_STRING", cs.PLOT_XAXIS_IN_SPACE))
# self.label_zmin.setText(_translate("CONSTANT_STRING", cs.FROM) + " z<span style= vertical-align:sub>min</span> = ")
# self.label_zmax.setText(_translate("CONSTANT_STRING", cs.TO) + " z<span style= vertical-align:sub>max</span> = ")
# self.pushButton_plot_acoustic_transect_in_space.setText(_translate("CONSTANT_STRING", cs.PLOT_TRANSECT))
self.groupbox_compute_bathymetry.setTitle(_translate("CONSTANT_STRING", cs.PLOT_BOTTOM_CROSS_SECTION))
# self.label_depthmin.setText(_translate("CONSTANT_STRING", cs.INITIAL_DEPTH_RANGE) + ":")
# self.label_depthmin.setText(_translate("CONSTANT_STRING", cs.FROM))
# self.label_to.setText(_translate("CONSTANT_STRING", cs.TO))
# self.pushButton_bottom_transect.setText(_translate("CONSTANT_STRING", cs.PLOT_BOTTOM))
self.groupbox_transect_2Dplot_raw_BS_data.setTitle(_translate("CONSTANT_STRING", cs.RAW_ACOUSTIC_DATA_2D_FIELD))
# self.groupbox_transect_2Dplot_snr_data.setTitle(_translate("CONSTANT_STRING", cs.SIGNAL_TO_NOISE_RATIO_2D_FIELD))
def onClicked_radiobutton_gps(self):
radiobutton = self.sender()
if radiobutton.isChecked():
if self.radiobutton_value.isChecked():
self.groupbox_gps_value.setEnabled(True)
self.groupbox_gps_file.setDisabled(True)
elif self.radiobutton_file.isChecked():
self.groupbox_gps_value.setDisabled(True)
self.groupbox_gps_file.setEnabled(True)
def ABS_system_choice(self):
if self.combobox_ABS_system_choice.currentText() == "Aquascat 1000R":
self.groupbox_measurement_information_Aquascat()
self.lineEdit_acoustic_file.clear()
self.label_date_groupbox_acoustic_file.clear()
self.label_date_groupbox_acoustic_file.setText(_translate("CONSTANT_STRING", cs.DATE) + ": ")
self.label_hour_groupbox_acoustic_file.clear()
self.label_hour_groupbox_acoustic_file.setText(_translate("CONSTANT_STRING", cs.HOUR) + ": ")
elif self.combobox_ABS_system_choice.currentText() == "UB-SediFlow":
self.groupbox_measurement_information_UBSediFlow()
self.lineEdit_acoustic_file.clear()
self.label_date_groupbox_acoustic_file.clear()
self.label_date_groupbox_acoustic_file.setText(_translate("CONSTANT_STRING", cs.DATE) + ": ")
self.label_hour_groupbox_acoustic_file.clear()
self.label_hour_groupbox_acoustic_file.setText(_translate("CONSTANT_STRING", cs.HOUR) + ": ")
def groupbox_measurement_information_Aquascat(self):
# self.gridLayout_goupbox_info.itemAt(0).widget().deleteLater()
# self.label_to_do.hide()
self.label_freq.hide()
self.label_profiles.show()
self.label_profiles_per_sec.show()
self.label_cells.show()
self.label_cell_size.show()
self.label_pulse_length.show()
self.label_pings_per_sec.show()
self.label_pings_per_profile.show()
self.label_freq.show()
self.label_kt.show()
self.label_rx.show()
self.label_tx.show()
self.gridLayout_goupbox_info.addWidget(self.label_profiles, 0, 0, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_profiles_per_sec, 0, 1, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_cells, 1, 0, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_cell_size, 1, 1, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_pulse_length, 2, 0, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_pings_per_sec, 3, 0, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_pings_per_profile, 3, 1, 1, 1)
self.gridLayout_goupbox_info.addWidget(self.label_freq, 4, 0, 1, 2)
self.gridLayout_goupbox_info.addWidget(self.label_kt, 5, 0, 1, 2)
self.gridLayout_goupbox_info.addWidget(self.label_rx, 6, 0, 1, 2)
self.gridLayout_goupbox_info.addWidget(self.label_tx, 7, 0, 1, 2)
def groupbox_measurement_information_UBSediFlow(self):
# self.gridLayout_goupbox_info.itemAt(0).widget().deleteLater()
self.label_profiles.hide()
self.label_profiles_per_sec.hide()
self.label_cells.hide()
self.label_cell_size.hide()
self.label_pulse_length.hide()
self.label_pings_per_sec.hide()
self.label_pings_per_profile.hide()
self.label_freq.hide()
self.label_kt.hide()
self.label_rx.hide()
self.label_tx.hide()
# self.label_to_do.show()
#
# self.gridLayout_goupbox_info.addWidget(self.label_to_do, 0, 0, 1, 1)
self.label_freq.show()
self.gridLayout_goupbox_info.addWidget(self.label_freq, 0, 0, 1, 1)
def clicked_pushbutton_noise_level(self):
self.WindowNoiseLevelTailAveragedProfile().show()
def open_dialog_box(self):
# print(self.combobox_ABS_system_choice.currentText())
# print(self.sender().objectName())
# --- Open dialog box + choice directory and select file ---
if self.combobox_ABS_system_choice.currentIndex() == 0:
msgBox = QMessageBox()
msgBox.setWindowTitle("Download Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Choose ABS system before download acoustic files")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
elif self.combobox_ABS_system_choice.currentIndex() == 1:
filename = QFileDialog.getOpenFileName(self, "Open file",
"/home/bmoudjed/Documents/3 SSC acoustic meas project/Graphical interface project/Data",
"Aquascat file (*.aqa)")
dir_name = path.dirname(filename[0])
name = path.basename(filename[0])
# print(dir_name, name)
elif self.combobox_ABS_system_choice.currentIndex() == 2:
filename = QFileDialog.getOpenFileName(self, "Open file", "", "UBSediFlow file (*.udt)")
dir_name = path.dirname(filename[0])
name = path.basename(filename[0])
print(f"dir name : {dir_name} & file name : {name}")
# --- 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.sender().objectName() == "pushbutton_acoustic_file":
# if self.sender():
# stg.path_BS_raw_data = dir_name
# stg.filename_BS_raw_data = name
# self.load_BS_acoustic_raw_data()
try:
stg.path_BS_raw_data = dir_name
stg.filename_BS_raw_data = name
self.load_BS_acoustic_raw_data()
# print("0 Je suis sur la donnée BS")
except ValueError as e:
# print("error : ", e)
# print("1 Je suis sur la donnée BS")
msgBox = QMessageBox()
msgBox.setWindowTitle("Download Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Please select a file")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
else:
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(
_translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date))
self.label_hour_groupbox_acoustic_file.setText(
_translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour))
self.fill_measurements_information_groupbox()
self.combobox_freq_choice.addItems([f for f in stg.freq_text])
self.combobox_frequency_profile.addItems([f for f in stg.freq_text])
# if self.sender().objectName() == "pushbutton_noise_file":
# print("--- 0. Je suis dans le push button noise file ---")
# try:
# print("--- 1. Je suis dans le push button noise file ---")
# stg.path_BS_noise_data = dir_name
# stg.filename_BS_noise_data = name
# print("dir_name ", stg.path_BS_noise_data)
# print("filename ", stg.filename_BS_noise_data)
# self.load_noise_data_and_compute_SNR()
# print("0 je suis sur la donnée SNR")
# except ValueError as e:
# print("1 je suis sur la donnée SNR")
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Download Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Please select a file")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# else:
# 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(
# _translate("CONSTANT_STRING", cs.DATE) + ": " + str(stg.date_noise))
# self.label_hour_groupbox_noise_file.setText(
# _translate("CONSTANT_STRING", cs.HOUR) + ": " + str(stg.hour_noise))
def load_BS_acoustic_raw_data(self):
if self.combobox_ABS_system_choice.currentIndex() == 1:
acoustic_data = AcousticDataLoader(stg.path_BS_raw_data + "/" + stg.filename_BS_raw_data)
stg.ABS_name = self.combobox_ABS_system_choice.currentText()
stg.BS_raw_data = acoustic_data._BS_raw_data
stg.BS_raw_data_reshape = acoustic_data.reshape_BS_raw_cross_section()
stg.r = acoustic_data._r
stg.r_2D = acoustic_data.compute_r_2D()
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
elif self.combobox_ABS_system_choice.currentIndex() == 2:
acoustic_data = AcousticDataLoaderUBSediFlow(stg.path_BS_raw_data + "/" + stg.filename_BS_raw_data)
stg.ABS_name = self.combobox_ABS_system_choice.currentText()
stg.date = acoustic_data._date
stg.hour = acoustic_data._hour
stg.freq = acoustic_data._freq
stg.time = acoustic_data._time
stg.r = acoustic_data._r
stg.r_2D = acoustic_data.compute_r_2D()
stg.freq_text = acoustic_data._freq_text
stg.BS_raw_data = acoustic_data._BS_raw_data
stg.BS_raw_data_reshape = acoustic_data.reshape_BS_raw_cross_section()
stg.r_reshape = acoustic_data.reshape_r()
stg.time_reshape = acoustic_data.reshape_t()
# stg.SNR_data = acoustic_data._SNR_data
# stg.snr_reshape = acoustic_data.reshape_SNR_data()
# print(f"r = {stg.r}")
# def load_noise_data_and_compute_SNR(self):
# if self.combobox_ABS_system_choice.currentIndex() == 1:
#
# noise_data = AcousticDataLoader(stg.path_BS_noise_data + "/" + stg.filename_BS_noise_data)
# stg.BS_noise_raw_data = noise_data._BS_raw_data
# stg.date_noise = noise_data._date
# stg.hour_noise = noise_data._hour
# stg.time_snr = stg.time
# stg.time_snr_reshape = stg.time_reshape
# print(stg.time_snr.shape)
# noise = np.zeros(stg.BS_raw_data.shape)
# for f, _ in enumerate(noise_data._freq):
# noise[f, :, :] = np.mean(stg.BS_noise_raw_data[f, :, :], axis=(0, 1))
# stg.BS_noise_averaged_data = noise
# stg.SNR_data = np.divide((stg.BS_raw_data - stg.BS_noise_averaged_data) ** 2, stg.BS_noise_averaged_data ** 2)
# stg.SNR_reshape = np.reshape(stg.SNR_data, (stg.r.shape[1] * stg.time.shape[1], stg.freq.shape[0]), order="F")
#
# elif self.combobox_ABS_system_choice.currentIndex() == 2:
#
# noise_data = AcousticDataLoaderUBSediFlow(stg.path_BS_noise_data + "/" + stg.filename_BS_noise_data)
# stg.BS_noise_raw_data = noise_data._BS_raw_data
# print(f"BS noise raw data : {stg.BS_noise_raw_data}")
# stg.date_noise = noise_data._date
# print(f"date noise : {stg.date_noise}")
# stg.hour_noise = noise_data._hour
# print(f"hour noise : {stg.hour_noise}")
# stg.time_snr = noise_data._time_snr
# stg.time_snr_reshape = noise_data.reshape_t_snr()
# print(f"BS shape : {stg.BS_noise_raw_data.shape}")
# # stg.SNR_data = noise_data._SNR_data
# # stg.SNR_reshape = noise_data.reshape_SNR_data()
def fill_measurements_information_groupbox(self):
if self.combobox_ABS_system_choice.currentIndex() == 1:
self.label_profiles.setText(
_translate("CONSTANT_STRING", cs.NB_PROFILES) + ": " + str(stg.nb_profiles))
self.label_profiles_per_sec.setText(
_translate("CONSTANT_STRING", cs.NB_PROFILES_PER_SEC) + ": " +
str(stg.nb_profiles_per_sec) + " Hz")
self.label_freq.setText(
_translate("CONSTANT_STRING", cs.FREQUENCY) + ": " + ', '.join(stg.freq_text))
self.label_cells.setText(
_translate("CONSTANT_STRING", cs.NB_CELLS) + ": " + str(stg.nb_cells))
self.label_cell_size.setText(
_translate("CONSTANT_STRING", cs.CELL_SIZE) + ": " + str(100*round(stg.cell_size, 3)) + " cm")
self.label_pulse_length.setText(
_translate("CONSTANT_STRING", cs.PULSE_LENGHT) + ": " + str(round(stg.pulse_length,6)) + "sec")
self.label_pings_per_sec.setText(
_translate("CONSTANT_STRING", cs.NB_PINGS_PER_SEC) + ": " + str(stg.nb_pings_per_sec) + " Hz")
self.label_pings_per_profile.setText(
_translate("CONSTANT_STRING", cs.NB_PINGS_PER_PROFILE) + ": " +
str(stg.nb_pings_averaged_per_profile))
self.label_kt.setText(
_translate("CONSTANT_STRING", cs.KT) + ": " + ', '.join(map(str, stg.kt)))
self.label_rx.setText(
_translate("CONSTANT_STRING", cs.GAIN_RX) + ": " + ', '.join(map(str, stg.gain_rx)))
self.label_tx.setText(
_translate("CONSTANT_STRING", cs.GAIN_TX) + ": " + ', '.join(map(str, stg.gain_tx)))
elif self.combobox_ABS_system_choice.currentIndex() == 2:
self.label_freq.setText(
_translate("CONSTANT_STRING", cs.FREQUENCY) + ": " + ', '.join(stg.freq_text))
def fill_table(self):
# if self.combobox_ABS_system_choice.currentIndex() == 2:
# if ((self.lineEdit_acoustic_file.text()) and (self.lineEdit_noise_file.text())):
# stg.DataFrame_acoustic = pd.DataFrame(
# np.concatenate((stg.time_reshape, stg.BS_raw_data_reshape, stg.snr_reshape), axis=1),
# columns=list(map(str, ["Time"] + ["BS - " + f for f in stg.freq_text] +
# ["SNR - " + f for f in stg.freq_text])))
# self.tableModel = TableModel(stg.DataFrame_acoustic)
# self.tableView.setModel(self.tableModel)
# elif self.lineEdit_acoustic_file.text():
# stg.DataFrame_acoustic = pd.DataFrame(
# np.concatenate((stg.time_reshape, stg.BS_raw_data_reshape), axis=1),
# columns=list(map(str, ["Time"] + ["BS - " + f for f in stg.freq_text])))
# self.tableModel = TableModel(stg.DataFrame_acoustic)
# self.tableView.setModel(self.tableModel)
# else:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Fill table Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Download files before fill table")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# elif self.combobox_ABS_system_choice.currentIndex() == 1:
# if ((self.lineEdit_acoustic_file.text()) and (self.lineEdit_noise_file.text())):
# stg.DataFrame_acoustic = pd.DataFrame(
# np.concatenate((stg.time_reshape, stg.BS_raw_data_reshape, stg.time_snr_reshape, stg.SNR_reshape), axis=1),
# columns=list(map(str, ["Time BS - " + f for f in stg.freq_text] +
# ["BS - " + f for f in stg.freq_text] +
# ["Time SNR - " + f for f in stg.freq_text] +
# ["SNR - " + f for f in stg.freq_text])))
# self.tableModel = TableModel(stg.DataFrame_acoustic)
# self.tableView.setModel(self.tableModel)
if self.lineEdit_acoustic_file.text():
stg.DataFrame_acoustic = pd.DataFrame(
np.concatenate((stg.time_reshape, stg.BS_raw_data_reshape), axis=1),
columns=list(map(str, ["Time BS - " + f for f in stg.freq_text] + ["BS - " + f for f in stg.freq_text])))
self.tableModel = TableModel(stg.DataFrame_acoustic)
self.tableView.setModel(self.tableModel)
else:
msgBox = QMessageBox()
msgBox.setWindowTitle("Fill table Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Download files before fill table")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
def export_table(self):
if self.tableWidget.columnCount() == 10:
msgBox = QMessageBox()
msgBox.setWindowTitle("Export table Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Fill table before export table")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
else:
print("export table")
def transect_xaxis_choice(self):
if self.groupbox_xaxis_time.isChecked() == True:
# self.groupbox_xaxis_time.setDisabled(True)
self.groupbox_xaxis_space.setChecked(False)
# self.groupbox_xaxis_space.setDisabled(False)
elif self.groupbox_xaxis_space.isChecked() == True:
self.groupbox_xaxis_time.setChecked(False)
# self.groupbox_xaxis_time.setDisabled(False)
# self.groupbox_xaxis_space.setDisabled(True)
def plot_transect_with_BS_raw_data(self):
# --- Condition if table is not filled ---
if not self.lineEdit_acoustic_file.text():
msgBox = QMessageBox()
msgBox.setWindowTitle("Plot transect Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Load data before plot transect 2D field")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
# elif self.tableModel.rowCount(1) == 10:
# 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()
# --- Condition if table is filled and figure is not plotted ---
# --- => Then plot transect for each frequency by pressing the button "Plot transect"
# elif (self.tableModel.rowCount(1) > 10) and (self.canvas_BS == None):
elif 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.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.canvas_BS)
self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.removeWidget(self.scroll_BS)
self.scroll_BS = QScrollArea()
self.scroll_BS.setWidget(self.canvas_BS)
self.scroll_BS.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.scroll_BS.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
# self.scroll_BS.setWidgetResizable(True)
self.scroll_BS.setAlignment(Qt.AlignCenter)
self.verticalLayout_groupbox_transect_2Dplot_raw_BS_data.addWidget(self.scroll_BS)
self.spinbox_tmin.setValue(np.round(np.min(stg.time[0, :]), 2))
self.spinbox_tmax.setValue(np.round(np.max(stg.time[0, :]), 2))
stg.tmin = np.array([])
stg.tmax = np.array([])
for f, _ in enumerate(stg.freq):
val_min = np.nanmin(stg.BS_raw_data[f, :, :])
val_max = np.nanmax(stg.BS_raw_data[f, :, :])
if val_min == 0:
val_min = 1e-5
stg.tmin = (
np.append(stg.tmin,
np.where(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmin.value()) ==
np.nanmin(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmin.value())))[0][0])
)
stg.tmax = (
np.append(stg.tmax,
np.where(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmax.value()) ==
np.nanmin(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmax.value())))[0][0])
)
# print(f"freq = {f}")
print(f"tmin {stg.tmin}")
print(f"tmax {stg.tmax}")
if self.combobox_ABS_system_choice.currentIndex() == 1:
pcm = self.axis_BS[f].pcolormesh(stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])],
-stg.r[f, :],
stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif self.combobox_ABS_system_choice.currentIndex() == 2:
pcm = self.axis_BS[f].pcolormesh(stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])],
-stg.r[f, :],
np.log(stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]),
cmap='Blues')
# --- Plot red solid line on transect to visualize position of plotted profile ---
self.axis_BS[self.combobox_frequency_profile.currentIndex()].plot(
stg.time[self.combobox_frequency_profile.currentIndex(), 0] * np.ones(
stg.r.shape[1]),
-stg.r[self.combobox_frequency_profile.currentIndex(), :],
color='red', linestyle="solid", linewidth=2)
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('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)
self.fig_BS.canvas.draw_idle()
self.plot_profile()
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.setWindowTitle("Plot transect Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Plot transect before change x-axis value")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
# elif stg.BS_cross_section.size == 0:
#
# for f, _ in enumerate(stg.freq):
#
# self.axis_BS[f].cla()
#
# val_min = np.nanmin(stg.BS_raw_data[f, :, :])
# val_max = np.nanmax(stg.BS_raw_data[f, :, :])
# if val_min == 0:
# val_min = 1e-5
#
# if self.combobox_ABS_system_choice.currentIndex() == 1:
# pcm = self.axis_BS[f].pcolormesh(stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])],
# -stg.r[f, :],
# stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])],
# cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
#
# elif self.combobox_ABS_system_choice.currentIndex() == 2:
# pcm = self.axis_BS[f].pcolormesh(stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])],
# -stg.r[f, :],
# np.log(stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]),
# cmap='Blues')
#
# # --- Plot red solid line on transect to visualize position of plotted profile ---
# self.axis_BS[self.combobox_frequency_profile.currentIndex()].plot(
# stg.time[self.combobox_frequency_profile.currentIndex(), self.slider.value()] * np.ones(stg.r.shape[1]),
# -stg.r[self.combobox_frequency_profile.currentIndex(), :],
# color='red', linestyle="solid", linewidth=2)
#
# 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('Time (sec)', fontsize=10)
# self.fig_BS.supylabel('Depth (m)', fontsize=10)
# self.fig_BS.canvas.draw_idle()
else:
# --- Backscatter acoustic signal is recorded for next tab ---
stg.BS_cross_section = np.array([[[]]])
stg.t = np.array([[]])
for f, _ in enumerate(stg.freq):
stg.tmin[f] = np.where(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmin.value()) ==
np.nanmin(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmin.value())))[0][0]
stg.tmax[f] = np.where(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmax.value()) ==
np.nanmin(np.abs(np.round(stg.time[f, :], 2) - self.spinbox_tmax.value())))[0][0]
# print("stg.tmin[f] ", stg.tmin[f])
# print("stg.tmax[f] ", stg.tmax[f])
# print("shape of BS_raw_data ", np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]]).shape)
# print("BS_data shape ", stg.BS_cross_section.shape)
if stg.BS_cross_section.shape[2] == 0:
stg.BS_cross_section = np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]])
else:
stg.BS_cross_section = np.append(stg.BS_cross_section, np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=0)
# stg.BS_cross_section = np.stack(np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=0)
# stg.BS_cross_section = np.append(stg.BS_cross_section, np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=2)
# print("stg.BS_cross_section.shape ", stg.BS_cross_section.shape)
# print("stg.BS_cross_section.size ", stg.BS_cross_section.size)
# print("stg.time shape ", stg.time.shape)
# print("stg.t shape ", stg.t.shape)
if stg.t.shape[1] == 0:
stg.t = np.array([stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])]])
else:
stg.t = np.append(stg.t, np.array([stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=0)
# stg.t = np.append(stg.t, np.array([stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=0)
print("stg.t shape ", stg.t.shape)
# print(f"stg.t : {stg.t}")
# stg.r_2D = stg.r_2D[:, 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]]
# print("stg.r shape ", stg.r_2D.shape)
print("self.combobox_frequency_profile.currentIndex() ", self.combobox_frequency_profile.currentIndex())
print("slider value = ", [
self.slider.value() - 1 if self.slider.value() - 1 <= stg.t.shape[1] - 1 else np.max(
stg.t.shape[1] - 1)][0])
print(stg.t[0,
[self.slider.value() - 1 if self.slider.value() - 1 <= stg.t.shape[1] - 1 else np.max(
stg.t.shape[1] - 1)][0]])
self.axis_BS[f].cla()
val_min = np.min(stg.BS_cross_section[f, :, :])
val_max = np.max(stg.BS_cross_section[f, :, :])
if val_min == 0:
val_min = 1e-5
# print("stg.t[f, :].shape ", stg.t[f])
# print("stg.r[f, :].shape ", stg.r[f, :])
if self.combobox_ABS_system_choice.currentIndex() == 1:
pcm = self.axis_BS[f].pcolormesh(stg.t[f, :], -stg.r[f, :], stg.BS_cross_section[f, :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif self.combobox_ABS_system_choice.currentIndex() == 2:
pcm = self.axis_BS[f].pcolormesh(stg.t[f, :], -stg.r[f, :], np.log(stg.BS_cross_section[f, :, :]),
cmap='Blues')
# --- Plot red solid line on transect to visualize position of plotted profile ---
self.axis_BS[self.combobox_frequency_profile.currentIndex()].plot(
stg.t[0, # self.combobox_frequency_profile.currentIndex(),
[self.slider.value() - 1 if self.slider.value() -1 <= stg.t.shape[1]-1 else np.max(stg.t.shape[1]-1)][0]] * np.ones(stg.r.shape[1]),
-stg.r[self.combobox_frequency_profile.currentIndex(), :],
color='red', linestyle="solid", linewidth=2)
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('Time (sec)', fontsize=10)
self.fig_BS.supylabel('Depth (m)', fontsize=10)
self.fig_BS.canvas.draw_idle()
def plot_profile(self):
# --- Figure to plot profiles ---
self.fig_profile, self.axis_profile = plt.subplots(nrows=1, ncols=1, layout="constrained")
self.canvas_plot_profile = FigureCanvas(self.fig_profile)
self.verticalLayout_groupbox_plot_profile.addWidget(self.canvas_plot_profile)
# --- Slider for moving the profile ---
self.horizontalLayout_slider = QHBoxLayout()
self.verticalLayout_groupbox_plot_profile.addLayout(self.horizontalLayout_slider)
self.pushbutton_slider_left = QPushButton()
self.pushbutton_slider_left.setIcon(self.icon_triangle_left)
self.horizontalLayout_slider.addWidget(self.pushbutton_slider_left)
self.pushbutton_slider_left.clicked.connect(self.slide_profile_number_to_left)
self.pushbutton_slider_right = QPushButton()
self.pushbutton_slider_right.setIcon(self.icon_triangle_right)
self.horizontalLayout_slider.addWidget(self.pushbutton_slider_right)
self.pushbutton_slider_right.clicked.connect(self.slide_profile_number_to_right)
self.lineEdit_slider = QLineEdit()
self.lineEdit_slider.setText("1")
self.lineEdit_slider.setFixedWidth(50)
self.horizontalLayout_slider.addWidget(self.lineEdit_slider)
self.lineEdit_slider.returnPressed.connect(self.profile_number_on_lineEdit)
self.slider = QSlider()
self.horizontalLayout_slider.addWidget(self.slider, 9)
self.slider.setOrientation(Qt.Horizontal)
self.slider.setCursor(Qt.OpenHandCursor)
self.slider.setMinimum(1)
self.slider.setMaximum(stg.BS_raw_data.shape[2])
self.slider.setTickInterval(1)
self.slider.setValue(1)
self.slider.valueChanged.connect(self.update_lineEdit_by_moving_slider)
# self.slider.valueChanged.connect(self.update_plot_profile_position_on_transect)
self.slider.valueChanged.connect(self.update_plot_profile)
self.slider.valueChanged.connect(self.update_xaxis_transect_with_BS_raw_data)
self.combobox_frequency_profile.currentIndexChanged.connect(self.update_xaxis_transect_with_BS_raw_data)
self.combobox_frequency_profile.currentIndexChanged.connect(self.update_plot_profile)
# for f, _ in enumerate(stg.freq[0]):
self.axis_profile.cla()
self.axis_profile.plot(stg.BS_raw_data[
self.combobox_frequency_profile.currentIndex(), :, self.slider.value() - 1],
-stg.r[self.combobox_frequency_profile.currentIndex(), :],
linestyle='solid', color='k', linewidth=1)
self.axis_profile.text(.95, .05, stg.freq_text[self.combobox_frequency_profile.currentIndex()],
fontsize=10, fontweight='bold', fontname="Ubuntu",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_profile.transAxes)
self.fig_profile.supxlabel("Acoustic Backscatter Signal (V)")
self.fig_profile.supylabel("Depth (m)")
def slide_profile_number_to_right(self):
self.slider.setValue(int(self.slider.value()) + 1)
self.lineEdit_slider.setText(str(self.slider.value()))
def slide_profile_number_to_left(self):
self.slider.setValue(int(self.slider.value()) - 1)
self.lineEdit_slider.setText(str(self.slider.value()))
def profile_number_on_lineEdit(self):
self.slider.setValue(int(self.lineEdit_slider.text()))
def update_lineEdit_by_moving_slider(self):
self.lineEdit_slider.setText(str(self.slider.value()))
def update_plot_profile(self):
if stg.BS_cross_section.size == 0:
self.axis_profile.cla()
self.axis_profile.plot(stg.BS_raw_data[
self.combobox_frequency_profile.currentIndex(), :, self.slider.value() - 1],
-stg.r[self.combobox_frequency_profile.currentIndex(), :],
linestyle='solid', color='k', linewidth=1)
self.axis_profile.text(.95, .05, stg.freq_text[self.combobox_frequency_profile.currentIndex()],
fontsize=10, fontweight='bold', fontname="Ubuntu",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_profile.transAxes)
else:
self.slider.setMaximum(stg.t.shape[1])
self.axis_profile.cla()
self.axis_profile.plot(stg.BS_cross_section[
self.combobox_frequency_profile.currentIndex(), :,
[self.slider.value() - 1 if self.slider.value() -1 <= stg.t.shape[1]-1 else np.max(stg.t.shape[1]-1)][0]],
-stg.r[self.combobox_frequency_profile.currentIndex(), :],
linestyle='solid', color='k', linewidth=1)
self.axis_profile.text(.95, .05, stg.freq_text[self.combobox_frequency_profile.currentIndex()],
fontsize=10, fontweight='bold', fontname="Ubuntu",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_profile.transAxes)
self.fig_profile.supxlabel("Acoustic Backscatter Signal (V)")
self.fig_profile.supylabel("Depth (m)")
self.fig_profile.canvas.draw_idle()
# def plot_transect_with_SNR_data(self):
# if not self.lineEdit_noise_file.text():
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Plot transect Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Load data before plot SNR 2D field")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# elif self.tableModel.rowCount(1) == 10:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Plot transect Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Fill table before plot SNR 2D field")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# elif self.canvas_BS == None:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Plot transect Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Plot backscatter acoustic raw data 2D field before plot SNR 2D field")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
# elif (self.lineEdit_noise_file.text()) and (self.tableModel.rowCount(1) > 11):
#
# 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)
#
# self.verticalLayout_groupbox_transect_2Dplot_snr_data.removeWidget(self.scroll_SNR)
# self.scroll_SNR = QScrollArea()
# self.scroll_SNR.setWidget(self.canvas_SNR)
# self.scroll_SNR.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# self.scroll_SNR.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
# self.scroll_SNR.setAlignment(Qt.AlignCenter)
# self.verticalLayout_groupbox_transect_2Dplot_snr_data.addWidget(self.scroll_SNR)
#
# # self.spinbox_tmin.setValue(np.min(noise_data._time_snr))
# # self.spinbox_tmax.setValue(np.round(np.max(noise_data._time_snr), 2))
#
# # if self.combobox_ABS_system_choice.currentIndex() == 1:
# #
# # 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]):
# #
# # 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.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, 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('Time (sec)', fontsize=10)
# # self.fig_SNR.supylabel('Depth (m)', fontsize=10)
# # 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()
#
# # elif self.combobox_ABS_system_choice.currentIndex() == 2:
#
# x = np.array([[[]]])
# y = np.array([[[]]])
# print(f"x : {x.shape}, y : {y.shape}")
# for f, freq in enumerate(stg.freq):
#
# if x.shape[2] == 0:
# x, y = np.meshgrid(stg.time_snr[f, :], stg.r[f, :])
# x = np.array([x])
# y = np.array([y])
# print(f"x : {x.shape}, y : {y.shape}")
# else:
# x0, y0 = np.meshgrid(stg.time_snr[f, :], stg.r[f, :])
# x = np.append(x, np.array([x0]), axis=0)
# y = np.append(y, np.array([y0]), axis=0)
# print(f"x : {x.shape}, y : {y.shape}")
#
# val_min = np.nanmin(abs(stg.SNR_data[f, :, :]))
# # print(f"val_min = {val_min}")
# val_max = np.nanmax(abs(stg.SNR_data[f, :, :]))
# # print(f"val_max = {val_max}")
# if int(val_min) == 0:
# val_min = 1e-5
# if int(val_max) < 1000:
# levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
# bounds = [00.1, 1, 2, 10, 100, 1000, 1e6, 1e6 * 1.2]
# 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)
#
# # print(f"levels = {levels}")
# # print(f"norm = {norm.boundaries}")
# if self.combobox_ABS_system_choice.currentIndex() == 1:
#
# cf = self.axis_SNR[f].contourf(x[f, :, :], -y[f, :, :],
# stg.SNR_data[f, :, :], levels, cmap='gist_rainbow', norm=norm)
#
# elif self.combobox_ABS_system_choice.currentIndex() == 2:
#
# cf = self.axis_SNR[f].contourf(x[f, :, :], -y[f, :, :], stg.SNR_data[f, :, :])#, levels, cmap='gist_rainbow', norm=norm)
#
# 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('Time (sec)', fontsize=10)
# self.fig_SNR.supylabel('Depth (m)', fontsize=10)
# 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)
# self.fig_SNR.canvas.draw_idle()
# def update_xaxis_transect_with_SNR_data(self):
#
# # 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)):
#
# # --- Backscatter noise signal is recorded for next tab ---
#
# stg.tmin_snr = np.array([])
# stg.tmax_snr = np.array([])
#
# stg.SNR_cross_section = np.array([[[]]])
# stg.t_snr = np.array([[]])
#
# x = np.array([[[]]])
# y = np.array([[[]]])
# # print(f"x : {x.shape}, y : {y.shape}")
# for f, _ in enumerate(stg.freq):
#
# if x.shape[2] == 0:
# x, y = np.meshgrid(stg.time_snr[f, :], stg.r[f, :])
# x = np.array([x])
# y = np.array([y])
# # print(f"x : {x.shape}, y : {y.shape}")
# else:
# x0, y0 = np.meshgrid(stg.time_snr[f, :], stg.r[f, :])
# x = np.append(x, np.array([x0]), axis=0)
# y = np.append(y, np.array([y0]), axis=0)
# # print(f"x : {x.shape}, y : {y.shape}")
#
# # print(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmin.value()))
# # print(np.where(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmin.value()) ==
# # np.nanmin(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmin.value())))[0][0])
#
# stg.tmin_snr = (
# np.append(stg.tmin_snr,
# np.where(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmin.value()) ==
# np.nanmin(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmin.value())))[0][
# 0])
# )
#
# stg.tmax_snr = (
# np.append(stg.tmax_snr,
# np.where(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmax.value()) ==
# np.nanmin(np.abs(np.round(stg.time_snr[f, :], 2) - self.spinbox_tmax.value())))[0][
# 0])
# )
#
# # print("stg.tmin[f] ", stg.tmin_snr[f])
# # print("stg.tmax[f] ", stg.tmax_snr[f])
#
# if stg.SNR_cross_section.shape[2] == 0:
# stg.SNR_cross_section = np.array([stg.SNR_data[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])]])
# else:
# stg.SNR_cross_section = np.append(stg.SNR_cross_section,
# np.array([stg.SNR_data[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])]]),
# axis=0)
#
# # stg.BS_cross_section = np.stack(np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=0)
# # stg.BS_cross_section = np.append(stg.BS_cross_section, np.array([stg.BS_raw_data[f, :, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=2)
#
# if stg.t_snr.shape[1] == 0:
# stg.t_snr = np.array([stg.time_snr[f, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])]])
# else:
# stg.t_snr = np.append(stg.t_snr, np.array([stg.time_snr[f, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])]]), axis=0)
# # stg.t = np.append(stg.t, np.array([stg.time[f, int(stg.tmin[f]):int(stg.tmax[f])]]), axis=0)
# # print("stg.t shape ", stg.t_snr.shape)
#
# self.axis_SNR[f].cla()
#
# # if self.combobox_ABS_system_choice.currentIndex() == 1:
# #
# # val_min = np.nanmin(stg.SNR_data[f, :, :])
# # val_max = np.nanmax(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)
# #
# # 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)
# #
# # elif self.combobox_ABS_system_choice.currentIndex() == 2:
#
# val_min = np.nanmin(abs(stg.SNR_data[f, :, :]))
# # print(f"val_min = {val_min}")
# val_max = np.nanmax(abs(stg.SNR_data[f, :, :]))
# # print(f"val_max = {val_max}")
# if int(val_min) == 0:
# val_min = 1e-5
# if int(val_max) < 1000:
# levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
# bounds = [00.1, 1, 2, 10, 100, 1000, 1e6, 1e6 * 1.2]
# 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)
#
# # print(f"levels = {levels}")
# # print(f"norm = {norm.boundaries}")
#
# if self.combobox_ABS_system_choice.currentIndex() == 1:
#
# cf = self.axis_SNR[f].contourf(x[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# -y[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# stg.SNR_data[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# levels, cmap='gist_rainbow', norm=norm)
#
# elif self.combobox_ABS_system_choice.currentIndex() == 2:
#
# cf = self.axis_SNR[f].contourf(x[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# -y[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# stg.SNR_data[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])]) # , levels, cmap='gist_rainbow', norm=norm)
#
# 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)
# self.fig_SNR.canvas.draw_idle()
def detect_bottom(self):
if self.lineEdit_acoustic_file.text() == "":
msgBox = QMessageBox()
msgBox.setWindowTitle("Detect bottom Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Load data before compute bathymety algorithm")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
# elif self.tableModel.rowCount(1) == 10:
# msgBox = QMessageBox()
# msgBox.setWindowTitle("Detect bottom Error")
# msgBox.setIcon(QMessageBox.Warning)
# msgBox.setText("Fill table before compute bathymety algorithm")
# msgBox.setStandardButtons(QMessageBox.Ok)
# msgBox.exec()
elif self.canvas_BS == 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_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 != None:
# else:
# --- Record frequency choose for bottom detection ---
stg.freq_bottom_detection = self.combobox_freq_choice.currentIndex()
# Selecting the range in which we look for the bottom reflection
rmin = np.float32(self.spinbox_depth_min.text().replace(",", "."))
rmax = np.float32(self.spinbox_depth_max.text().replace(",", "."))
# print(f"rmin = {rmin}")
# print(f"rmax = {rmax}")
# empty result arrays
# r_bottom = np.zeros(stg.nb_profiles)
# val_bottom = np.zeros(stg.nb_profiles)
r_bottom = np.zeros(stg.t.shape[1])
val_bottom = np.zeros(stg.t.shape[1])
r_bottom_ind = []
# print(f"r_bottom shape with zeros : {r_bottom.shape}")
BS_smooth = deepcopy(stg.BS_raw_data[self.combobox_freq_choice.currentIndex(), :, :])
# print(f"BS_smooth shape : {BS_smooth.shape}")
for k in range(stg.time.shape[1]):
BS_smooth[:, k] = savgol_filter(BS_smooth[:, k], 10, 2)
# fig1, ax1 = plt.subplots(nrows=1, ncols=1, layout="constrained")
# pcm1 = ax1.pcolormesh(stg.time[0, :], -stg.r[0, :], np.log(BS_smooth[:, :]), cmap='Blues')
# fig1.colorbar(pcm1, ax=ax1, shrink=1, location='right')
# plt.show()
# ----------- Detecting the bottom -------------
# for d in range(stg.nb_profiles):
for d in range(stg.t.shape[1]):
# Index of the range where we look for the peak
# print(f"self.combobox_freq_choice.currentIndex() : {self.combobox_freq_choice.currentIndex()}")
# print(f"r = {stg.r}")
ind_min = np.where(stg.r[int(self.combobox_freq_choice.currentIndex()), :] >= rmin)[0][0]
ind_max = np.where(stg.r[int(self.combobox_freq_choice.currentIndex()), :] <= rmax)[0][-1]
# print(f"ind_min : {ind_min}")
# print(f"ind_max : {ind_max}")
# Getting the peak
try:
# val_bottom[d] = np.nanmax((stg.BS_raw_data[self.combobox_freq_choice.currentIndex(), ind_min:ind_max, d]))
val_bottom[d] = np.nanmax(BS_smooth[ind_min:ind_max, d])
# print('---------------------------------------------------')
# print(f"d = {d}")
# print("stg.BS_raw_data[ind_min:ind_max] : ", stg.BS_raw_data[self.combobox_freq_choice.currentIndex(), ind_min:ind_max, d])
except ValueError as e:
msgBox = QMessageBox()
msgBox.setWindowTitle("Detect bottom Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText(f"1/ {e} : maximum value of section bottom is not found. \n "
f"Please change parameter of algorithm")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox_return = msgBox.exec()
if msgBox_return == msgBox.Ok:
break #msgBox.close()
else:
# Getting the range cell of the peak
# ind_bottom = np.where((stg.BS_raw_data[self.combobox_freq_choice.currentIndex(), ind_min:ind_max, d])
# == val_bottom[d])[0][0]
ind_bottom = np.where((BS_smooth[ind_min:ind_max, d]) == val_bottom[d])[0][0]
np.append(stg.ind_bottom, ind_bottom)
r_bottom[d] = stg.r[self.combobox_freq_choice.currentIndex(), 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())
# rmax = r_bottom[d] + locale.atof(self.doublespinbox_next_cell.text())
rmin = r_bottom[d] - np.float32(self.doublespinbox_next_cell.text().replace(",", "."))
rmax = r_bottom[d] + np.float32(self.doublespinbox_next_cell.text().replace(",", "."))
# --- Plot vertical profile for bottom detection ---
# n = 60
# t0 = 200
# t1 = np.where(np.abs(stg.time[0, :] - t0) == np.nanmin(np.abs(stg.time[0, :] - t0)))[0][0]
# # print(np.abs(self._time[0, :] - 200))
# # print(f"x0 = {x0}")
# r1 = 98
# r2 = 150
# fig2, ax2 = plt.subplots(nrows=1, ncols=n, layout="constrained")
# for i in range(n):
# ax2[i].plot(stg.BS_raw_data[self.combobox_freq_choice.currentIndex(), r1:r2, t1 + i],
# -stg.r[0, r1:r2], 'b')
# ax2[i].plot(BS_smooth[r1:r2, t1 + i], -stg.r[0, r1:r2], 'r')
# ax2[i].scatter(val_bottom[i], -r_bottom[i], marker="o", fc="black", s=12)
# ax2[i].set_xticks([])
# if i != 0:
# ax2[i].set_yticks([])
# plt.show()
# print(f"r_bootom shape : {r_bottom.shape}")
BS_section_bottom = np.zeros((stg.r.shape[1], stg.t.shape[1]))
for i in range(BS_section_bottom.shape[0]):
try:
# print(f"r_bottom_ind : {r_bottom_ind}")
BS_section_bottom[r_bottom_ind[i]][i] = 1
except IndexError as e:
msgBox = QMessageBox()
msgBox.setWindowTitle("Detect bottom Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText(f"2/ {e} : maximum value of section bottom is not found. \n "
f"Please change parameter of algorithm")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox_return = msgBox.exec()
if msgBox_return == msgBox.Ok:
break # msgBox.close()
if BS_section_bottom.sum() > 2:
# --- Record r_bottom for other tabs ---
# stg.r_bottom = 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]]
# stg.val_bottom = val_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]]
stg.r_bottom = r_bottom#[int(stg.tmin[self.combobox_freq_choice.currentIndex()]):
# int(stg.tmax[self.combobox_freq_choice.currentIndex()])]
stg.val_bottom = val_bottom#[int(stg.tmin[self.combobox_freq_choice.currentIndex()]):
# int(stg.tmax[self.combobox_freq_choice.currentIndex()])]
# --- Plot transect BS with bathymetry ---
for f, _ in enumerate(stg.freq):
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))
if self.combobox_ABS_system_choice.currentIndex() == 1:
pcm = self.axis_BS[f].pcolormesh(stg.t[f, :], -stg.r[f, :], stg.BS_cross_section[f, :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif self.combobox_ABS_system_choice.currentIndex() == 2:
pcm = self.axis_BS[f].pcolormesh(stg.t[f, :], -stg.r[f, :], np.log(stg.BS_cross_section[f, :, :]),
cmap='Blues')
# self.axis_BS[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]],
# color='black', linewidth=1, linestyle="solid")
# print("stg.t[self.combobox_freq_choice.currentIndex(), :] : ", stg.t[self.combobox_freq_choice.currentIndex(), :].shape)
# print("-stg.r_bottom : ", stg.r_bottom.shape)
self.axis_BS[f].plot(stg.t[self.combobox_freq_choice.currentIndex(), :], -stg.r_bottom,
color='black', linewidth=1, linestyle="solid")
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 ---
# if self.canvas_SNR != None:
# # 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)
#
# x = np.array([[[]]])
# y = np.array([[[]]])
# # print(f"x : {x.shape}, y : {y.shape}")
#
# for f, _ in enumerate(stg.freq):
#
# if x.shape[2] == 0:
# x, y = np.meshgrid(stg.time_snr[f, :], stg.r[f, :])
# x = np.array([x])
# y = np.array([y])
# # print(f"x : {x.shape}, y : {y.shape}")
# else:
# x0, y0 = np.meshgrid(stg.time_snr[f, :], stg.r[f, :])
# x = np.append(x, np.array([x0]), axis=0)
# y = np.append(y, np.array([y0]), axis=0)
# # print(f"x : {x.shape}, y : {y.shape}")
#
# self.axis_SNR[f].cla()
#
# val_min = abs(np.nanmin(stg.SNR_data[f, :, :]))
# val_max = abs(np.nanmax(stg.SNR_data[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')
#
# if self.combobox_ABS_system_choice.currentIndex() == 1:
#
# cf = self.axis_SNR[f].contourf(x[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# -y[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# stg.SNR_data[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# levels, cmap='gist_rainbow', norm=norm)
#
# elif self.combobox_ABS_system_choice.currentIndex() == 2:
#
# cf = self.axis_SNR[f].contourf(x[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# -y[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[f])],
# stg.SNR_data[f, :, int(stg.tmin_snr[f]):int(stg.tmax_snr[
# f])]) # , levels, cmap='gist_rainbow', norm=norm)
#
# 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.t[self.combobox_freq_choice.currentIndex(), :], -stg.r_bottom,
# color='black', linewidth=1, linestyle="solid")
#
# # 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_SNR[f].transAxes)
#
# self.fig_SNR.canvas.draw_idle()
# 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)
#
#
# self.fig_BS.supxlabel('Distance from left bank (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.set_label(label='Backscatter acoustic signal (V)', rotation=270, labelpad=10)
# self.fig_SNR.canvas.draw_idle()
# return r_bottom, val_bottom, r_bottom_ind, BS_section_bottom