Compare commits

..

No commits in common. "2c1b01118e573ac99a9e188276109442058900d4" and "e300cfe643b8c5421b70f7306dd878a0203bf063" have entirely different histories.

8 changed files with 714 additions and 410 deletions

View File

@ -155,17 +155,6 @@ class CreateTableForSaveAs:
) )
""" """
self.create_Calibration_parameters = """
CREATE TABLE CalibrationParameters(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER,
freq_1 INTEGER,
freq_2 INTEGER,
fine_profiles TEXT,
sand_target INTEGER
)
"""
self.create_Calibration = """ self.create_Calibration = """
CREATE TABLE Calibration( CREATE TABLE Calibration(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
@ -195,14 +184,8 @@ class CreateTableForSaveAs:
) )
""" """
def save_as(self):
self.open_file_dialog() self.open_file_dialog()
self.save()
def save(self):
start = time.time()
self.create_table()
print(f"end : {time.time() - start} sec")
def open_file_dialog(self): def open_file_dialog(self):
name, _ = QFileDialog.getSaveFileName( name, _ = QFileDialog.getSaveFileName(
@ -226,6 +209,10 @@ class CreateTableForSaveAs:
os.chdir(stg.dirname_save_as) os.chdir(stg.dirname_save_as)
except OSError as e: except OSError as e:
logger.warning(f"chdir: {str(e)}") logger.warning(f"chdir: {str(e)}")
start = time.time()
self.create_table()
print(f"end : {time.time() - start} sec")
else: else:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Save Error") msgBox.setWindowTitle("Save Error")
@ -244,7 +231,6 @@ class CreateTableForSaveAs:
self.create_table_settings(cnx, cur) self.create_table_settings(cnx, cur)
self.create_table_sediments_file(cnx, cur) self.create_table_sediments_file(cnx, cur)
self.create_table_sediments_data(cnx, cur) self.create_table_sediments_data(cnx, cur)
self.create_table_calibration_parameters(cnx, cur)
self.create_table_calibration(cnx, cur) self.create_table_calibration(cnx, cur)
self.create_table_inversion(cnx, cur) self.create_table_inversion(cnx, cur)
@ -531,36 +517,6 @@ class CreateTableForSaveAs:
logger.info(f"table SedimentsData : {time.time() - start_table_SedimentsData} sec") logger.info(f"table SedimentsData : {time.time() - start_table_SedimentsData} sec")
def create_table_calibration_parameters(self, cnx, cur):
start_table = time.time()
cur.execute("DROP TABLE if exists CalibrationParameters")
cur.execute(self.create_Calibration_parameters)
if stg.calib_acoustic_data != -1:
cur.execute(
"""
INSERT INTO CalibrationParameters(
acoustic_data,
freq_1, freq_2,
fine_profiles,
sand_target
)
VALUES(?, ?, ?, ?, ?)
""",
(
stg.calib_acoustic_data,
stg.calib_freq_1, stg.calib_freq_2,
",".join(map(str, stg.calib_fine_profiles)),
stg.calib_sand_target,
)
)
cnx.commit()
logger.info(f"table CalibrationParameters : {time.time() - start_table} sec")
def create_table_calibration(self, cnx, cur): def create_table_calibration(self, cnx, cur):
start_table_Calibration = time.time() start_table_Calibration = time.time()
@ -571,7 +527,7 @@ class CreateTableForSaveAs:
if len(stg.range_lin_interp) != 0: if len(stg.range_lin_interp) != 0:
cur.execute( cur.execute(
""" """
INSERT INTO Calibration( INSERT into Calibration(
path_calibration_file, filename_calibration_file, path_calibration_file, filename_calibration_file,
range_lin_interp, M_profile_fine, range_lin_interp, M_profile_fine,
ks, sv, X_exponent, alpha_s, zeta, ks, sv, X_exponent, alpha_s, zeta,

View File

@ -83,7 +83,6 @@ class ReadTableForOpen:
self.read_table_settings() self.read_table_settings()
self.read_table_sediment_file() self.read_table_sediment_file()
self.read_table_table_sediment_data() self.read_table_table_sediment_data()
self.read_table_table_calibration_parameters()
self.read_table_table_calibration() self.read_table_table_calibration()
logger.debug(f"Reading '{stg.filename_open}' done") logger.debug(f"Reading '{stg.filename_open}' done")
@ -610,69 +609,6 @@ class ReadTableForOpen:
logger.debug(f"fine: {stg.Ctot_fine}, sand: {stg.sample_sand}") logger.debug(f"fine: {stg.Ctot_fine}, sand: {stg.sample_sand}")
@trace
def read_table_table_calibration_parameters(self):
np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64)
query = f'''
SELECT
acoustic_data,
freq_1, freq_2,
fine_profiles,
sand_target
FROM CalibrationParameters
'''
data = self.execute(query)
it = iter(data[0])
stg.calib_acoustic_data = next(it)
stg.calib_freq_1 = next(it)
stg.calib_freq_2 = next(it)
stg.calib_fine_profiles = list(
map(
int,
filter(
lambda x: x != '',
next(it).split(",")
)
)
)
stg.calib_sand_target = next(it)
logger.debug(f"stg.calib_acoustic_data: {stg.calib_acoustic_data}")
logger.debug(f"stg.calib_freq_1: {stg.calib_freq_1}")
logger.debug(f"stg.calib_freq_2: {stg.calib_freq_2}")
logger.debug(f"stg.calib_fine_profiles: {stg.calib_fine_profiles}")
logger.debug(f"stg.calib_sand_target: {stg.calib_sand_target}")
stg.frequencies_for_calibration.clear()
for freq in [stg.calib_freq_1, stg.calib_freq_2]:
stg.frequencies_for_calibration.append(
(
stg.freq[stg.calib_acoustic_data][freq],
freq
)
)
stg.fine_sample_profile.clear()
for profile_id in stg.calib_fine_profiles:
stg.fine_sample_profile.append(
(
stg.sample_fine[profile_id],
profile_id
)
)
stg.sand_sample_target.clear()
if stg.calib_sand_target != -1:
stg.sand_sample_target.append(
(
stg.sample_sand[stg.calib_sand_target],
stg.calib_sand_target
)
)
@trace @trace
def read_table_table_calibration(self): def read_table_table_calibration(self):
np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64) np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64)

View File

@ -0,0 +1,469 @@
# ============================================================================== #
# update_table_for_save.py - AcouSed #
# Copyright (C) 2024 INRAE #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# by Brahim MOUDJED #
# ============================================================================== #
# -*- coding: utf-8 -*-
import numpy as np
from PyQt5.QtWidgets import QFileDialog, QApplication, QMessageBox
import sqlite3
import settings as stg
from os import chdir, getcwd
import time
class UpdateTableForSave:
def __init__(self):
if stg.dirname_save_as:
start = time.time()
chdir(stg.dirname_save_as)
print("get cwd for save :", getcwd())
print("stg.filename_save_as ", stg.filename_save_as)
self.update_table()
print(f"end : {time.time() - start} sec")
else:
msgBox = QMessageBox()
msgBox.setWindowTitle("Save Error")
msgBox.setIcon(QMessageBox.Warning)
msgBox.setText("Use 'Save as' before 'Save'")
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec()
def update_table(self):
# Create a new database and open a database connection to allow sqlite3 to work with it.
cnx = sqlite3.connect(stg.filename_save_as)
# Create database cursor to execute SQL statements and fetch results from SQL queries.
cur = cnx.cursor()
# --------------------------------------------------------------------------------------------------------------
# +++++++++++++++++++++++++++
# --- Table Acoustic File ---
# +++++++++++++++++++++++++++
start_table_AcousticFile = time.time()
cur.execute('''DROP TABLE AcousticFile''')
cur.execute("""CREATE TABLE AcousticFile(ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER,
acoustic_file STRING,
ABS_name STRING,
path_BS_noise_data STRING,
filename_BS_noise_data STRING,
noise_method FLOAT,
noise_value FLOAT,
data_preprocessed STRING
)"""
)
for i in stg.acoustic_data:
print("stg.acoustic_data ", stg.acoustic_data[i])
print("stg.filename_BS_raw_data ", stg.filename_BS_raw_data[i])
print('stg.ABS_name', stg.ABS_name)
print("stg.path_BS_raw_data ", stg.path_BS_raw_data[i])
cur.execute(''' INSERT into AcousticFile(acoustic_data, acoustic_file, ABS_name, path_BS_noise_data,
filename_BS_noise_data, noise_method, noise_value, data_preprocessed)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)''',
(stg.acoustic_data[i], stg.filename_BS_raw_data[i].split('.')[0], stg.ABS_name[i],
stg.path_BS_noise_data[i], stg.filename_BS_noise_data[i], stg.noise_method[i],
stg.noise_value[i], stg.data_preprocessed[i])
)
cnx.commit()
print(f"Table AcousticFile : {time.time() - start_table_AcousticFile} sec")
# --------------------------------------------------------------------------------------------------------------
# ++++++++++++++++++++++++++
# --- Table Measurements ---
# ++++++++++++++++++++++++++
start_table_Measure = time.time()
# Drop Table if exists
cur.execute("DROP TABLE if exists Measure")
cur.execute(
"""
CREATE TABLE Measure(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER,
Date STRING,
Hour STRING,
frequency FLOAT,
sound_attenuation FLOAT,
kt_read FLOAT,
kt_corrected FLOAT,
NbProfiles FLOAT,
NbProfilesPerSeconds FLOAT,
NbCells FLOAT,
CellSize FLOAT,
PulseLength FLOAT,
NbPingsPerSeconds FLOAT,
NbPingsAveragedPerProfile FLOAT,
GainRx FLOAT,
GainTx FLOAT
)"""
)
# Fill the table Measure
for i in stg.acoustic_data:
for j in range(stg.freq[i].shape[0]):
cur.execute(
'''
INSERT into Measure(
acoustic_data,
Date, Hour,
frequency,
sound_attenuation,
kt_read, kt_corrected,
NbProfiles, NbProfilesPerSeconds,
NbCells, CellSize,
PulseLength,
NbPingsPerSeconds,
NbPingsAveragedPerProfile,
GainRx, GainTx
) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(
stg.acoustic_data[i],
stg.date[i].isoformat(),
stg.hour[i].isoformat(),
stg.freq[i][j],
stg.water_attenuation[i][j],
stg.kt_read[j],
stg.kt_corrected[j],
stg.nb_profiles[i][j],
stg.nb_profiles_per_sec[i][j],
stg.nb_cells[i][j],
stg.cell_size[i][j],
stg.pulse_length[i][j],
stg.nb_pings_per_sec[i][j],
stg.nb_pings_averaged_per_profile[i][j],
stg.gain_rx[i][j], stg.gain_tx[i][j]
)
)
# Commit the transaction after executing INSERT.
cnx.commit()
print(f"table Measure : {time.time() - start_table_Measure} sec")
# --------------------------------------------------------------------------------------------------------------
# +++++++++++++++++++++++++++
# --- Table Acoustic Data ---
# +++++++++++++++++++++++++++
start_table_BSRawData = time.time()
cur.execute(''' DROP TABLE BSRawData ''')
cur.execute('''CREATE TABLE BSRawData(ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER,
time BLOB, depth BLOB, BS_raw_data BLOB,
time_reshape BLOB, depth_reshape BLOB, BS_raw_data_reshape BLOB,
time_cross_section BLOB, depth_cross_section BLOB, BS_cross_section BLOB, BS_stream_bed BLOB,
depth_bottom, val_bottom, ind_bottom,
time_noise BLOB, depth_noise BLOB, BS_noise_raw_data BLOB,
SNR_raw_data BLOB, SNR_cross_section BLOB, SNR_stream_bed BLOB,
BS_raw_data_pre_process_SNR BLOB, BS_raw_data_pre_process_average BLOB,
BS_cross_section_pre_process_SNR BLOB, BS_cross_section_pre_process_average BLOB,
BS_stream_bed_pre_process_SNR BLOB, BS_stream_bed_pre_process_average BLOB,
BS_mean BLOB
)''')
for i in stg.acoustic_data:
cur.execute(''' INSERT into BSRawData(acoustic_data, time, depth, BS_raw_data,
time_reshape, depth_reshape, BS_raw_data_reshape,
time_cross_section, depth_cross_section,
BS_cross_section, BS_stream_bed,
depth_bottom, val_bottom, ind_bottom,
time_noise, depth_noise, BS_noise_raw_data,
SNR_raw_data, SNR_cross_section, SNR_stream_bed,
BS_raw_data_pre_process_SNR, BS_raw_data_pre_process_average,
BS_cross_section_pre_process_SNR, BS_cross_section_pre_process_average,
BS_stream_bed_pre_process_SNR, BS_stream_bed_pre_process_average,
BS_mean)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(stg.acoustic_data[i], stg.time[i].tobytes(), stg.depth[i].tobytes(), stg.BS_raw_data[i].tobytes(),
stg.time_reshape[i].tobytes(),
stg.depth_reshape[i].tobytes(),
stg.BS_raw_data_reshape[i].tobytes(),
stg.time_cross_section[i].tobytes(),
stg.depth_cross_section[i].tobytes(),
stg.BS_cross_section[i].tobytes(),
np.array(stg.BS_stream_bed[i]).tobytes(),
np.array(stg.depth_bottom[i]).tobytes(),
np.array(stg.val_bottom[i]).tobytes(),
np.array(stg.ind_bottom[i]).tobytes(),
np.array(stg.time_noise[i]).tobytes(),
np.array(stg.depth_noise[i]).tobytes(),
np.array(stg.BS_noise_raw_data[i]).tobytes(),
np.array(stg.SNR_raw_data[i]).tobytes(),
np.array(stg.SNR_cross_section[i]).tobytes(),
np.array(stg.SNR_stream_bed[i]).tobytes(),
np.array(stg.BS_raw_data_pre_process_SNR[i]).tobytes(),
np.array(stg.BS_raw_data_pre_process_average[i]).tobytes(),
np.array(stg.BS_cross_section_pre_process_SNR[i]).tobytes(),
np.array(stg.BS_cross_section_pre_process_average[i]).tobytes(),
np.array(stg.BS_stream_bed_pre_process_SNR[i]).tobytes(),
np.array(stg.BS_stream_bed_pre_process_average[i]).tobytes(),
np.array(stg.BS_mean[i]).tobytes()
)
)
cnx.commit()
print(f"table BSRawData : {time.time() - start_table_BSRawData} sec")
# --------------------------------------------------------------------------------------------------------------
# ++++++++++++++++++++++
# --- Table Settings ---
# ++++++++++++++++++++++
start_table_Settings = time.time()
cur.execute(''' DROP TABLE Settings''')
cur.execute('''
CREATE TABLE Settings(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
acoustic_data INTEGER,
temperature FLOAT,
distance_to_free_surface FLOAT,
tmin_index FLOAT, tmin_value FLOAT,
tmax_index FLOAT, tmax_value FLOAT,
rmin_index FLOAT, rmin_value FLOAT,
rmax_index FLOAT, rmax_value FLOAT,
freq_bottom_detection_index FLOAT,
freq_bottom_detection_value STRING,
SNR_filter_value FLOAT,
Nb_cells_to_average_BS_signal FLOAT
)
'''
)
for i in stg.acoustic_data:
cur.execute('''
INSERT into Settings(
acoustic_data, temperature,
distance_to_free_surface,
tmin_index, tmin_value, tmax_index, tmax_value,
rmin_index, rmin_value, rmax_index, rmax_value,
freq_bottom_detection_index, freq_bottom_detection_value,
SNR_filter_value, Nb_cells_to_average_BS_signal
) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''',
(
stg.acoustic_data[i], stg.temperature,
stg.distance_from_ABS_to_free_surface[i],
stg.tmin[i][0], stg.tmin[i][1],
stg.tmax[i][0], stg.tmax[i][1],
stg.rmin[i][0], stg.rmin[i][1],
stg.rmax[i][0], stg.rmax[i][1],
stg.freq_bottom_detection[i][0],
stg.freq_bottom_detection[i][1],
stg.SNR_filter_value[i],
stg.Nb_cells_to_average_BS_signal[i]
)
)
cnx.commit()
print(f"table Settings : {time.time() - start_table_Settings} sec")
# --------------------------------------------------------------------------------------------------------------
# ++++++++++++++++++++++++++++
# --- Table Sediments File ---
# ++++++++++++++++++++++++++++
start_table_SedimentsFile = time.time()
cur.execute("DROP TABLE if exists SedimentsFile")
cur.execute("""CREATE TABLE SedimentsFile(ID INTEGER PRIMARY KEY AUTOINCREMENT,
path_fine STRING,
filename_fine STRING,
radius_grain_fine BLOB,
path_sand STRING,
filename_sand STRING,
radius_grain_sand BLOB,
time_column_label STRING,
distance_from_bank_column_label STRING,
depth_column_label STRING,
Ctot_fine_column_label STRING,
D50_fine_column_label STRING,
Ctot_sand_column_label STRING,
D50_sand_column_label STRING
)"""
)
cur.execute('''INSERT into SedimentsFile(path_fine, filename_fine, radius_grain_fine,
path_sand, filename_sand, radius_grain_sand,
time_column_label, distance_from_bank_column_label,
depth_column_label, Ctot_fine_column_label,
D50_fine_column_label, Ctot_sand_column_label,
D50_sand_column_label)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(stg.path_fine, stg.filename_fine, stg.radius_grain_fine.tobytes(),
stg.path_sand, stg.filename_sand, stg.radius_grain_sand.tobytes(),
stg.columns_fine[0], stg.columns_fine[1], stg.columns_fine[2],
stg.columns_fine[3], stg.columns_fine[4], stg.columns_sand[3], stg.columns_sand[4]))
cnx.commit()
print(f"table SedimentsFile : {time.time() - start_table_SedimentsFile} sec")
# --------------------------------------------------------------------------------------------------------------
# ++++++++++++++++++++++++++++
# --- Table Sediments Data ---
# ++++++++++++++++++++++++++++
start_table_SedimentsData = time.time()
cur.execute("DROP TABLE if exists SedimentsData")
cur.execute("""CREATE TABLE SedimentsData(ID INTEGER PRIMARY KEY AUTOINCREMENT,
sample_fine_name STRING,
sample_fine_index INTEGER,
distance_from_bank_fine FLOAT,
depth_fine FLOAT,
time_fine FLOAT,
Ctot_fine FLOAT,
Ctot_fine_per_cent FLOAT,
D50_fine FLOAT,
frac_vol_fine BLOB,
frac_vol_fine_cumul BLOB,
sample_sand_name STRING,
sample_sand_index INTEGER,
distance_from_bank_sand FLOAT,
depth_sand FLOAT,
time_sand FLOAT,
Ctot_sand FLOAT,
Ctot_sand_per_cent FLOAT,
D50_sand FLOAT,
frac_vol_sand BLOB,
frac_vol_sand_cumul BLOB
)"""
)
for f in range(len(stg.sample_fine)):
cur.execute('''INSERT into SedimentsData(sample_fine_name, sample_fine_index, distance_from_bank_fine,
depth_fine, time_fine, Ctot_fine, Ctot_fine_per_cent, D50_fine, frac_vol_fine,
frac_vol_fine_cumul,
sample_sand_name, sample_sand_index, distance_from_bank_sand,
depth_sand, time_sand, Ctot_sand, Ctot_sand_per_cent, D50_sand, frac_vol_sand,
frac_vol_sand_cumul)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(stg.sample_fine[f][0], stg.sample_fine[f][1],
stg.distance_from_bank_fine[f], stg.depth_fine[f], stg.time_fine[f], stg.Ctot_fine[f],
stg.Ctot_fine_per_cent[f], stg.D50_fine[f],
stg.frac_vol_fine[f].tobytes(), stg.frac_vol_fine_cumul[f].tobytes(),
stg.sample_sand[f][0], stg.sample_sand[f][1],
stg.distance_from_bank_sand[f], stg.depth_sand[f], stg.time_sand[f], stg.Ctot_sand[f],
stg.Ctot_sand_per_cent[f], stg.D50_sand[f],
stg.frac_vol_sand[f].tobytes(), stg.frac_vol_sand_cumul[f].tobytes()
))
cnx.commit()
print(f"table SedimentsData : {time.time() - start_table_SedimentsData} sec")
# --------------------------------------------------------------------------------------------------------------
# ++++++++++++++++++++++++++++++
# --- Table Calibration ---
# ++++++++++++++++++++++++++++++
start_table_Calibration = time.time()
cur.execute("DROP TABLE if exists Calibration")
cur.execute("""CREATE TABLE Calibration(ID INTEGER PRIMARY KEY AUTOINCREMENT,
path_calibration_file STRING,
filename_calibration_file STRING,
range_lin_interp BLOB,
M_profile_fine BLOB,
ks BLOB,
sv BLOB,
X_exponent BLOB,
alpha_s BLOB,
zeta BLOB,
FCB BLOB,
depth_real BLOB,
lin_reg BLOB
)"""
)
cur.execute('''INSERT into Calibration(path_calibration_file, filename_calibration_file,
range_lin_interp, M_profile_fine,
ks, sv, X_exponent, alpha_s, zeta,
FCB, depth_real, lin_reg)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(stg.path_calibration_file, stg.filename_calibration_file,
stg.range_lin_interp.tobytes(), stg.M_profile_fine.tobytes(),
np.array(stg.ks).tobytes(), np.array(stg.sv).tobytes(), np.array(stg.X_exponent).tobytes(),
np.array(stg.alpha_s).tobytes(), np.array(stg.zeta).tobytes(),
stg.FCB.tobytes(), stg.depth_real.tobytes(), np.array(stg.lin_reg).tobytes())
)
cnx.commit()
print(f"table Calibration : {time.time() - start_table_Calibration} sec")
# --------------------------------------------------------------------------------------------------------------
# ++++++++++++++++++++++++++++++
# --- Table Inversion ---
# ++++++++++++++++++++++++++++++
start_table_Inversion = time.time()
cur.execute("DROP TABLE if exists Inversion")
cur.execute("""CREATE TABLE Inversion(ID INTEGER PRIMARY KEY AUTOINCREMENT,
J_cross_section_freq1 BLOB,
J_cross_section_freq2 BLOB,
VBI_cross_section BLOB,
SSC_fine BLOB,
SSC_sand BLOB
)""")
for i in range(len(stg.SSC_fine)):
cur.execute('''INSERT into Inversion(J_cross_section_freq1, J_cross_section_freq2,
VBI_cross_section, SSC_fine, SSC_sand)
VALUES(?, ?, ?, ?, ?)''',
(stg.J_cross_section[i][0].tobytes(), stg.J_cross_section[i][1].tobytes(),
stg.VBI_cross_section[i].tobytes(), stg.SSC_fine[i].tobytes(), stg.SSC_sand[i].tobytes())
)
cnx.commit()
print(f"table Inversion : {time.time() - start_table_Inversion} sec")
# --------------------------------------------------------------------------------------------------------------
# Close database cursor
cur.close()
# Close database connection
cnx.close()

View File

@ -438,21 +438,18 @@ class AcousticInversionTab(QWidget):
self.plot_measured_vs_inverted_SSC_sand() self.plot_measured_vs_inverted_SSC_sand()
def compute_VBI(self): def compute_VBI(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
stg.VBI_cross_section[data_id] = np.array([]) stg.VBI_cross_section[self.combobox_acoustic_data_choice.currentIndex()] = np.array([])
stg.VBI_cross_section[data_id] = self.inv_hc.VBI_cross_section( stg.VBI_cross_section[self.combobox_acoustic_data_choice.currentIndex()] = self.inv_hc.VBI_cross_section(
freq1=stg.frequencies_for_calibration[0][0], freq1=stg.frequencies_for_calibration[0][0],
freq2=stg.frequencies_for_calibration[1][0], freq2=stg.frequencies_for_calibration[1][0],
zeta_freq1=stg.zeta[0], zeta_freq2=stg.zeta[1], zeta_freq1=stg.zeta[0], zeta_freq2=stg.zeta[1],
j_cross_section_freq1=stg.J_cross_section[data_id][0], j_cross_section_freq1=stg.J_cross_section[self.combobox_acoustic_data_choice.currentIndex()][0],
j_cross_section_freq2=stg.J_cross_section[data_id][1], j_cross_section_freq2=stg.J_cross_section[self.combobox_acoustic_data_choice.currentIndex()][1],
r2D=stg.depth_2D[data_id][ r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1] stg.frequency_for_inversion[1]],
], water_attenuation_freq1=stg.alpha_s[0], water_attenuation_freq2=stg.alpha_s[1],
water_attenuation_freq1=stg.alpha_s[0],
water_attenuation_freq2=stg.alpha_s[1],
X=stg.X_exponent[0] X=stg.X_exponent[0]
) )

View File

@ -121,18 +121,6 @@ class CheckableComboBox(QComboBox):
res.append(self.model().item(i).data()) res.append(self.model().item(i).data())
return res return res
def currentIndexes(self):
# Return the list of selected items id
res = []
for i in range(self.model().rowCount()):
if self.model().item(i).checkState() == Qt.Checked:
res.append(i)
return res
def setCurrentIndexes(self, indexes):
for i in range(self.model().rowCount()):
if i in indexes:
self.model().item(i).setCheckState(Qt.Checked)
# class CheckableComboBox(QComboBox): # class CheckableComboBox(QComboBox):
# def __init__(self): # def __init__(self):
@ -163,3 +151,4 @@ class CheckableComboBox(QComboBox):
# def itemChecked(self, index): # def itemChecked(self, index):
# item = self.model().item(index, self.modelColumn()) # item = self.model().item(index, self.modelColumn())
# return item.checkState() == Qt.Checked # return item.checkState() == Qt.Checked

View File

@ -39,6 +39,7 @@ from subprocess import Popen
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from Model.create_table_for_save_as import CreateTableForSaveAs from Model.create_table_for_save_as import CreateTableForSaveAs
from Model.update_table_for_save import UpdateTableForSave
from Model.read_table_for_open import ReadTableForOpen from Model.read_table_for_open import ReadTableForOpen
from Model.calibration_constant_kt import CalibrationConstantKt from Model.calibration_constant_kt import CalibrationConstantKt
from View.about_window import AboutWindow from View.about_window import AboutWindow
@ -265,9 +266,7 @@ class Ui_MainWindow(object):
self.centralwidget.addAction(self.actionDB_Browser_for_SQLite) self.centralwidget.addAction(self.actionDB_Browser_for_SQLite)
def save_as(self): def save_as(self):
db = CreateTableForSaveAs() CreateTableForSaveAs()
db.save_as()
self.mainwindow.setWindowTitle( self.mainwindow.setWindowTitle(
"AcouSed - " + "AcouSed - " +
stg.filename_save_as stg.filename_save_as
@ -275,8 +274,7 @@ class Ui_MainWindow(object):
def save(self): def save(self):
if stg.dirname_save_as: if stg.dirname_save_as:
db = CreateTableForSaveAs() UpdateTableForSave()
db.save()
else: else:
self.save_as() self.save_as()

View File

@ -866,39 +866,8 @@ class SedimentCalibrationTab(QWidget):
self.function_pushbutton_update_acoustic_file() self.function_pushbutton_update_acoustic_file()
self._update_calibration_parameters()
self.function_pushbutton_plot_sample()
self.blockSignals(False) self.blockSignals(False)
def _update_calibration_parameters(self):
if stg.calib_acoustic_data == -1:
return
self.combobox_acoustic_data_choice.blockSignals(True)
self.combobox_freq1.blockSignals(True)
self.combobox_freq2.blockSignals(True)
self.combobox_fine_sample_choice.blockSignals(True)
self.combobox_sand_sample_choice.blockSignals(True)
self.combobox_acoustic_data_choice\
.setCurrentIndex(stg.calib_acoustic_data)
self.combobox_freq1.setCurrentIndex(stg.calib_freq_1)
self.combobox_freq2.setCurrentIndex(stg.calib_freq_2)
self.combobox_fine_sample_choice\
.setCurrentIndexes(stg.calib_fine_profiles)
self.combobox_sand_sample_choice\
.setCurrentIndex(stg.calib_sand_target)
self.combobox_sand_sample_choice.blockSignals(False)
self.combobox_fine_sample_choice.blockSignals(False)
self.combobox_freq2.blockSignals(False)
self.combobox_freq1.blockSignals(False)
self.combobox_acoustic_data_choice.blockSignals(False)
def function_pushbutton_update_acoustic_file(self): def function_pushbutton_update_acoustic_file(self):
if len(stg.data_preprocessed) == 0: if len(stg.data_preprocessed) == 0:
return return
@ -945,6 +914,8 @@ class SedimentCalibrationTab(QWidget):
[s[0] for s in stg.sample_sand] [s[0] for s in stg.sample_sand]
) )
self.plot_acoustic_recording()
self.label_temperature.clear() self.label_temperature.clear()
self.label_temperature.setText("T = " + str(stg.temperature) + " °C") self.label_temperature.setText("T = " + str(stg.temperature) + " °C")
@ -966,34 +937,30 @@ class SedimentCalibrationTab(QWidget):
data_id = self.combobox_acoustic_data_choice.currentIndex() data_id = self.combobox_acoustic_data_choice.currentIndex()
# --- Record frequencies for calibration --- # --- Record frequencies for calibration ---
stg.calib_acoustic_data = data_id
freq1 = self.combobox_freq1.currentIndex()
freq2 = self.combobox_freq2.currentIndex()
stg.frequencies_for_calibration.clear() stg.frequencies_for_calibration.clear()
stg.frequencies_for_calibration.append( stg.frequencies_for_calibration.append(
( (
stg.freq[data_id][freq1], stg.freq[data_id][
freq1 self.combobox_freq1.currentIndex()
],
self.combobox_freq1.currentIndex()
) )
) )
stg.calib_freq_1 = freq1
stg.frequencies_for_calibration.append( stg.frequencies_for_calibration.append(
( (
stg.freq[data_id][freq2], stg.freq[data_id][
freq2 self.combobox_freq2.currentIndex()
],
self.combobox_freq2.currentIndex()
) )
) )
stg.calib_freq_2 = freq2
stg.frequency_for_inversion = tuple() stg.frequency_for_inversion = tuple()
stg.frequency_for_inversion = ( stg.frequency_for_inversion = (
stg.freq[data_id][ stg.freq[data_id][
freq2 self.combobox_freq2.currentIndex()
], ],
freq2 self.combobox_freq2.currentIndex()
) )
# --- Plot acoustic data recording --- # --- Plot acoustic data recording ---
@ -1014,14 +981,14 @@ class SedimentCalibrationTab(QWidget):
stg.BS_stream_bed_pre_process_average[ stg.BS_stream_bed_pre_process_average[
data_id data_id
][ ][
freq2, :, : self.combobox_freq2.currentIndex(), :, :
] ]
) )
val_max = np.nanmax( val_max = np.nanmax(
stg.BS_stream_bed_pre_process_average[ stg.BS_stream_bed_pre_process_average[
data_id data_id
][ ][
freq2, :, : self.combobox_freq2.currentIndex(), :, :
] ]
) )
if val_min == 0: if val_min == 0:
@ -1031,39 +998,39 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_average[data_id][ stg.BS_stream_bed_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_average[data_id][ stg.BS_stream_bed_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_average[data_id][ stg.BS_stream_bed_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_average[data_id][ stg.BS_stream_bed_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
@ -1072,10 +1039,10 @@ class SedimentCalibrationTab(QWidget):
val_min = np.nanmin( val_min = np.nanmin(
stg.BS_stream_bed_pre_process_SNR[data_id][ stg.BS_stream_bed_pre_process_SNR[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax( val_max = np.nanmax(
stg.BS_stream_bed_pre_process_SNR[data_id][ stg.BS_stream_bed_pre_process_SNR[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
@ -1083,48 +1050,48 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_SNR[data_id][ stg.BS_stream_bed_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_SNR[data_id][ stg.BS_stream_bed_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_SNR[data_id][ stg.BS_stream_bed_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed_pre_process_SNR[data_id][ stg.BS_stream_bed_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_stream_bed[data_id].shape != (0,): elif stg.BS_stream_bed[data_id].shape != (0,):
val_min = np.nanmin( val_min = np.nanmin(
stg.BS_stream_bed[data_id][freq2, stg.BS_stream_bed[data_id][self.combobox_freq2.currentIndex(),
:, :]) :, :])
val_max = np.nanmax( val_max = np.nanmax(
stg.BS_stream_bed[data_id][freq2, stg.BS_stream_bed[data_id][self.combobox_freq2.currentIndex(),
:, :]) :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
@ -1133,19 +1100,19 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed[data_id][freq2, stg.BS_stream_bed[data_id][self.combobox_freq2.currentIndex(),
:, :], :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed[data_id][freq2, stg.BS_stream_bed[data_id][self.combobox_freq2.currentIndex(),
:, :], :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
@ -1153,19 +1120,19 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed[data_id][freq2, stg.BS_stream_bed[data_id][self.combobox_freq2.currentIndex(),
:, :], :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_stream_bed[data_id][freq2, stg.BS_stream_bed[data_id][self.combobox_freq2.currentIndex(),
:, :], :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
@ -1173,10 +1140,10 @@ class SedimentCalibrationTab(QWidget):
val_min = np.nanmin( val_min = np.nanmin(
stg.BS_cross_section_pre_process_average[data_id][ stg.BS_cross_section_pre_process_average[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax( val_max = np.nanmax(
stg.BS_cross_section_pre_process_average[data_id][ stg.BS_cross_section_pre_process_average[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
@ -1184,49 +1151,49 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_average[data_id][ stg.BS_cross_section_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_average[data_id][ stg.BS_cross_section_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_average[data_id][ stg.BS_cross_section_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_average[data_id][ stg.BS_cross_section_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_cross_section_pre_process_SNR[data_id].shape != (0,): elif stg.BS_cross_section_pre_process_SNR[data_id].shape != (0,):
val_min = np.nanmin( val_min = np.nanmin(
stg.BS_cross_section_pre_process_SNR[data_id][ stg.BS_cross_section_pre_process_SNR[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax( val_max = np.nanmax(
stg.BS_cross_section_pre_process_SNR[data_id][ stg.BS_cross_section_pre_process_SNR[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
@ -1234,49 +1201,49 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0): if stg.depth_cross_section[data_id].shape != (0):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_SNR[data_id][ stg.BS_cross_section_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_SNR[data_id][ stg.BS_cross_section_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
if stg.depth_cross_section[data_id].shape != (0): if stg.depth_cross_section[data_id].shape != (0):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_SNR[data_id][ stg.BS_cross_section_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section_pre_process_SNR[data_id][ stg.BS_cross_section_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_cross_section[data_id].shape != (0,): elif stg.BS_cross_section[data_id].shape != (0,):
val_min = np.nanmin( val_min = np.nanmin(
stg.BS_cross_section[data_id][ stg.BS_cross_section[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax( val_max = np.nanmax(
stg.BS_cross_section[data_id][ stg.BS_cross_section[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
@ -1284,56 +1251,56 @@ class SedimentCalibrationTab(QWidget):
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section[data_id][ stg.BS_cross_section[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section[data_id][ stg.BS_cross_section[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
if stg.depth_cross_section[data_id].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section[data_id][ stg.BS_cross_section[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
else: else:
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][ stg.time[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][ -stg.depth[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
stg.BS_cross_section[data_id][ stg.BS_cross_section[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_raw_data_pre_process_average[data_id].shape != (0,): elif stg.BS_raw_data_pre_process_average[data_id].shape != (0,):
val_min = np.nanmin(stg.BS_raw_data_pre_process_average[data_id][ val_min = np.nanmin(stg.BS_raw_data_pre_process_average[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(stg.BS_raw_data_pre_process_average[data_id][ val_max = np.nanmax(stg.BS_raw_data_pre_process_average[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][freq2, :], stg.time[data_id][self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][freq2, :], -stg.depth[data_id][self.combobox_freq2.currentIndex(), :],
stg.BS_raw_data_pre_process_average[data_id][ stg.BS_raw_data_pre_process_average[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
@ -1341,33 +1308,33 @@ class SedimentCalibrationTab(QWidget):
elif stg.BS_raw_data_pre_process_SNR[data_id].shape != (0,): elif stg.BS_raw_data_pre_process_SNR[data_id].shape != (0,):
val_min = np.nanmin(stg.BS_raw_data_pre_process_SNR[data_id][ val_min = np.nanmin(stg.BS_raw_data_pre_process_SNR[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(stg.BS_raw_data_pre_process_SNR[data_id][ val_max = np.nanmax(stg.BS_raw_data_pre_process_SNR[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][freq2, :], stg.time[data_id][self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][freq2, :], -stg.depth[data_id][self.combobox_freq2.currentIndex(), :],
stg.BS_raw_data_pre_process_SNR[data_id][ stg.BS_raw_data_pre_process_SNR[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
elif stg.BS_raw_data[data_id].shape != (0,): elif stg.BS_raw_data[data_id].shape != (0,):
val_min = np.nanmin(stg.BS_raw_data[data_id][ val_min = np.nanmin(stg.BS_raw_data[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
val_max = np.nanmax(stg.BS_raw_data[data_id][ val_max = np.nanmax(stg.BS_raw_data[data_id][
freq2, :, :]) self.combobox_freq2.currentIndex(), :, :])
if val_min == 0: if val_min == 0:
val_min = 1e-5 val_min = 1e-5
self.axis_BS.pcolormesh( self.axis_BS.pcolormesh(
stg.time[data_id][freq2, :], stg.time[data_id][self.combobox_freq2.currentIndex(), :],
-stg.depth[data_id][freq2, :], -stg.depth[data_id][self.combobox_freq2.currentIndex(), :],
stg.BS_raw_data[data_id][ stg.BS_raw_data[data_id][
freq2, :, :], self.combobox_freq2.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
# --- Plot samples --- # --- Plot samples ---
@ -1412,10 +1379,10 @@ class SedimentCalibrationTab(QWidget):
self.red_line_plot_return, = ( self.red_line_plot_return, = (
self.axis_BS.plot( self.axis_BS.plot(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, stg.sand_sample_target_indice[0][1]] * self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth_cross_section[data_id].shape[1]), np.ones(stg.depth_cross_section[data_id].shape[1]),
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2)) color='red', linestyle="solid", linewidth=2))
else: else:
@ -1423,10 +1390,10 @@ class SedimentCalibrationTab(QWidget):
self.red_line_plot_return, = ( self.red_line_plot_return, = (
self.axis_BS.plot( self.axis_BS.plot(
stg.time[data_id][ stg.time[data_id][
freq2, stg.sand_sample_target_indice[0][1]] * self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth_cross_section[data_id].shape[1]), np.ones(stg.depth_cross_section[data_id].shape[1]),
-stg.depth_cross_section[data_id][ -stg.depth_cross_section[data_id][
freq2, :], self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2)) color='red', linestyle="solid", linewidth=2))
else: else:
@ -1436,9 +1403,10 @@ class SedimentCalibrationTab(QWidget):
self.red_line_plot_return, = ( self.red_line_plot_return, = (
self.axis_BS.plot( self.axis_BS.plot(
stg.time_cross_section[data_id][ stg.time_cross_section[data_id][
freq2, stg.sand_sample_target_indice[0][1]] * self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth[data_id].shape[1]), np.ones(stg.depth[data_id].shape[1]),
-stg.depth[data_id][freq2, :], -stg.depth[data_id][
self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2)) color='red', linestyle="solid", linewidth=2))
else: else:
@ -1446,9 +1414,10 @@ class SedimentCalibrationTab(QWidget):
self.red_line_plot_return, = ( self.red_line_plot_return, = (
self.axis_BS.plot( self.axis_BS.plot(
stg.time[data_id][ stg.time[data_id][
freq2, stg.sand_sample_target_indice[0][1]] * self.combobox_freq2.currentIndex(), stg.sand_sample_target_indice[0][1]] *
np.ones(stg.depth[data_id].shape[1]), np.ones(stg.depth[data_id].shape[1]),
-stg.depth[data_id][freq2, :], -stg.depth[data_id][
self.combobox_freq2.currentIndex(), :],
color='red', linestyle="solid", linewidth=2)) color='red', linestyle="solid", linewidth=2))
self.axis_BS.set_xlabel("Time (sec)") self.axis_BS.set_xlabel("Time (sec)")
@ -1458,13 +1427,11 @@ class SedimentCalibrationTab(QWidget):
def sample_choice_for_calibration(self): def sample_choice_for_calibration(self):
# --- List selected fine samples --- # --- List selected fine samples ---
stg.fine_sample_profile = [(f, int(f[1:]) - 1) for f in self.combobox_fine_sample_choice.currentData()] stg.fine_sample_profile = [(f, int(f[1:]) - 1) for f in self.combobox_fine_sample_choice.currentData()]
stg.calib_fine_profiles = self.combobox_fine_sample_choice.currentIndexes()
# --- List selected sand samples --- # --- List selected sand samples ---
# stg.sand_sample_target = [(s, int(s[1:]) - 1) for s in self.combobox_sand_sample_choice.currentData()] # stg.sand_sample_target = [(s, int(s[1:]) - 1) for s in self.combobox_sand_sample_choice.currentData()]
stg.sand_sample_target = [(self.combobox_sand_sample_choice.currentText(), stg.sand_sample_target = [(self.combobox_sand_sample_choice.currentText(),
self.combobox_sand_sample_choice.currentIndex())] self.combobox_sand_sample_choice.currentIndex())]
stg.calib_sand_target = self.combobox_sand_sample_choice.currentIndex()
# --- Find index in time (along acoustic recording) of sand sample target --- # --- Find index in time (along acoustic recording) of sand sample target ---
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
@ -1846,142 +1813,136 @@ class SedimentCalibrationTab(QWidget):
) )
def read_calibration_file_and_fill_parameter(self): def read_calibration_file_and_fill_parameter(self):
if stg.filename_calibration_file == "": if stg.filename_calibration_file == "":
return
# --- Read calibration file --- pass
data = pd.read_csv(
os.path.join(
stg.path_calibration_file,
stg.filename_calibration_file
), header=0, index_col=0
)
# --- Fill spinboxes of calibration parameter --- else:
self.label_temperature.clear() # --- Read calibration file ---
self.label_temperature.setText( data = pd.read_csv(os.path.join(stg.path_calibration_file, stg.filename_calibration_file), header=0, index_col=0)
"T = " + str(stg.temperature) + " °C"
)
self.label_freq1.clear() # --- Fill spinboxes of calibration parameter ---
self.label_freq1.setText(data.columns[0]) self.label_temperature.clear()
self.label_temperature.setText(
data_id = self.combobox_acoustic_data_choice.currentIndex() "T = " + str(stg.temperature) + " °C"
stg.calib_acoustic_data = data_id
index_freq1 = np.where(
np.asarray(
stg.freq_text[data_id]
) == data.columns[0]
)[0][0]
stg.frequencies_for_calibration.clear()
stg.frequencies_for_calibration.append(
(
stg.freq[data_id][index_freq1],
index_freq1
) )
)
stg.calib_freq_1 = index_freq1
self.label_freq2.clear() self.label_freq1.clear()
self.label_freq2.setText(data.columns[1]) self.label_freq1.setText(data.columns[0])
index_freq2 = np.where( data_id = self.combobox_acoustic_data_choice.currentIndex()
np.asarray(
stg.freq_text[data_id]
) == data.columns[1]
)[0][0]
stg.frequencies_for_calibration.append( index_freq1 = np.where(
( np.asarray(
stg.freq_text[data_id]
) == data.columns[0]
)[0][0]
stg.frequencies_for_calibration.clear()
stg.frequencies_for_calibration.append(
(
stg.freq[data_id][index_freq1],
index_freq1
)
)
self.label_freq2.clear()
self.label_freq2.setText(data.columns[1])
index_freq2 = np.where(
np.asarray(
stg.freq_text[data_id]
) == data.columns[1]
)[0][0]
stg.frequencies_for_calibration.append(
(
stg.freq[data_id][index_freq2],
index_freq2
)
)
stg.frequency_for_inversion = tuple()
stg.frequency_for_inversion = (
stg.freq[data_id][index_freq2], stg.freq[data_id][index_freq2],
index_freq2 index_freq2
) )
)
stg.calib_freq_2 = index_freq2
stg.frequency_for_inversion = tuple() self.lineEdit_ks_freq1.clear()
stg.frequency_for_inversion = ( self.lineEdit_ks_freq1.setText(
stg.freq[data_id][index_freq2], str("%.5f" % float(data.iloc[0][0]))
index_freq2 )
)
self.lineEdit_ks_freq1.clear() self.lineEdit_ks_freq2.clear()
self.lineEdit_ks_freq1.setText( self.lineEdit_ks_freq2.setText(
str("%.5f" % float(data.iloc[0][0])) str("%.5f" % float(data.iloc[0][1]))
) )
self.lineEdit_ks_freq2.clear() stg.ks.clear()
self.lineEdit_ks_freq2.setText( stg.ks = [
str("%.5f" % float(data.iloc[0][1])) float(self.lineEdit_ks_freq1.text()),
) float(self.lineEdit_ks_freq2.text())
]
stg.ks.clear() self.lineEdit_sv_freq1.clear()
stg.ks = [ self.lineEdit_sv_freq1.setText(
float(self.lineEdit_ks_freq1.text()), str("%.5f" % float(data.iloc[1][0]))
float(self.lineEdit_ks_freq2.text()) )
]
self.lineEdit_sv_freq1.clear() self.lineEdit_sv_freq2.clear()
self.lineEdit_sv_freq1.setText( self.lineEdit_sv_freq2.setText(
str("%.5f" % float(data.iloc[1][0])) str("%.5f" % float(data.iloc[1][1]))
) )
self.lineEdit_sv_freq2.clear() stg.sv.clear()
self.lineEdit_sv_freq2.setText( stg.sv = [
str("%.5f" % float(data.iloc[1][1])) float(self.lineEdit_sv_freq1.text()),
) float(self.lineEdit_sv_freq2.text())
]
stg.sv.clear() self.lineEdit_X.clear()
stg.sv = [ self.lineEdit_X.setText(
float(self.lineEdit_sv_freq1.text()), str("%.2f" % float(data.iloc[2][0]))
float(self.lineEdit_sv_freq2.text()) )
]
self.lineEdit_X.clear() stg.X_exponent.clear()
self.lineEdit_X.setText( stg.X_exponent.append(float(self.lineEdit_X.text()))
str("%.2f" % float(data.iloc[2][0]))
)
stg.X_exponent.clear() self.lineEdit_alphas_freq1.clear()
stg.X_exponent.append(float(self.lineEdit_X.text())) self.lineEdit_alphas_freq1.setText(
str("%.5f" % float(data.iloc[3][0]))
)
self.lineEdit_alphas_freq1.clear() self.lineEdit_alphas_freq2.clear()
self.lineEdit_alphas_freq1.setText( self.lineEdit_alphas_freq2.setText(
str("%.5f" % float(data.iloc[3][0])) str("%.5f" % float(data.iloc[3][1]))
) )
self.lineEdit_alphas_freq2.clear() stg.alpha_s.clear()
self.lineEdit_alphas_freq2.setText( stg.alpha_s = [
str("%.5f" % float(data.iloc[3][1])) float(self.lineEdit_alphas_freq1.text()),
) float(self.lineEdit_alphas_freq2.text())
]
stg.alpha_s.clear() self.lineEdit_zeta_freq1.clear()
stg.alpha_s = [ self.lineEdit_zeta_freq1.setText(
float(self.lineEdit_alphas_freq1.text()), str("%.5f" % float(data.iloc[4][0]))
float(self.lineEdit_alphas_freq2.text()) )
]
self.lineEdit_zeta_freq1.clear() self.lineEdit_zeta_freq2.clear()
self.lineEdit_zeta_freq1.setText( self.lineEdit_zeta_freq2.setText(
str("%.5f" % float(data.iloc[4][0])) str("%.5f" % float(data.iloc[4][1]))
) )
self.lineEdit_zeta_freq2.clear() stg.zeta.clear()
self.lineEdit_zeta_freq2.setText( stg.zeta = [
str("%.5f" % float(data.iloc[4][1])) float(self.lineEdit_zeta_freq1.text()),
) float(self.lineEdit_zeta_freq2.text())
]
stg.zeta.clear() self.compute_kt2D_kt3D()
stg.zeta = [ self.compute_J_cross_section()
float(self.lineEdit_zeta_freq1.text()),
float(self.lineEdit_zeta_freq2.text())
]
self.compute_kt2D_kt3D()
self.compute_J_cross_section()
def compute_depth_2D(self): def compute_depth_2D(self):
if self.combobox_acoustic_data_choice.count() > 0: if self.combobox_acoustic_data_choice.count() > 0:

View File

@ -215,12 +215,6 @@ frac_vol_sand_cumul = [] # Cumulated volume fraction (%) of the sand sedi
# --- Parameters choice for calibration --- # --- Parameters choice for calibration ---
calib_acoustic_data = -1
calib_freq_1 = -1
calib_freq_2 = -1
calib_fine_profiles = []
calib_sand_target = -1
frequencies_for_calibration = [] # Frequencies chosen for calibration [(f1_val, f1_ind), (f2_val, f2_ind)] # List of 2 tuples frequencies_for_calibration = [] # Frequencies chosen for calibration [(f1_val, f1_ind), (f2_val, f2_ind)] # List of 2 tuples
frequency_for_inversion = tuple() # Frequency chosen for inversion (finv_val, finv_ind) # Tuple frequency_for_inversion = tuple() # Frequency chosen for inversion (finv_val, finv_ind) # Tuple
@ -265,3 +259,7 @@ fine_sample_position = [] # Fine samples indexes position for time and dep
sand_sample_position = [] # Sand samples indexes position for time and depth [(time_index, depth_index)] # List of tuples sand_sample_position = [] # Sand samples indexes position for time and depth [(time_index, depth_index)] # List of tuples
SSC_fine = [] # Suspended Sediment Concentration of the fine sediments # List of one 3D array SSC_fine = [] # Suspended Sediment Concentration of the fine sediments # List of one 3D array
SSC_sand = [] # Suspended Sediment Concentration of the sand sediments # List of one 3D array SSC_sand = [] # Suspended Sediment Concentration of the sand sediments # List of one 3D array