SQL: Add calibration parameters table.

dev
Pierre-Antoine 2025-04-15 14:20:07 +02:00
parent e300cfe643
commit 0a60088596
7 changed files with 265 additions and 131 deletions

View File

@ -155,6 +155,17 @@ 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 = """
CREATE TABLE Calibration(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
@ -184,8 +195,14 @@ class CreateTableForSaveAs:
)
"""
def save_as(self):
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):
name, _ = QFileDialog.getSaveFileName(
@ -209,10 +226,6 @@ class CreateTableForSaveAs:
os.chdir(stg.dirname_save_as)
except OSError as e:
logger.warning(f"chdir: {str(e)}")
start = time.time()
self.create_table()
print(f"end : {time.time() - start} sec")
else:
msgBox = QMessageBox()
msgBox.setWindowTitle("Save Error")
@ -231,6 +244,7 @@ class CreateTableForSaveAs:
self.create_table_settings(cnx, cur)
self.create_table_sediments_file(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_inversion(cnx, cur)
@ -517,6 +531,36 @@ class CreateTableForSaveAs:
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):
start_table_Calibration = time.time()
@ -527,7 +571,7 @@ class CreateTableForSaveAs:
if len(stg.range_lin_interp) != 0:
cur.execute(
"""
INSERT into Calibration(
INSERT INTO Calibration(
path_calibration_file, filename_calibration_file,
range_lin_interp, M_profile_fine,
ks, sv, X_exponent, alpha_s, zeta,

View File

@ -83,6 +83,7 @@ class ReadTableForOpen:
self.read_table_settings()
self.read_table_sediment_file()
self.read_table_table_sediment_data()
self.read_table_table_calibration_parameters()
self.read_table_table_calibration()
logger.debug(f"Reading '{stg.filename_open}' done")
@ -609,6 +610,69 @@ class ReadTableForOpen:
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
def read_table_table_calibration(self):
np_f64_parse = lambda d: np.frombuffer(d, dtype=np.float64)

View File

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

View File

@ -121,6 +121,13 @@ class CheckableComboBox(QComboBox):
res.append(self.model().item(i).data())
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
# class CheckableComboBox(QComboBox):
# def __init__(self):
@ -151,4 +158,3 @@ class CheckableComboBox(QComboBox):
# def itemChecked(self, index):
# item = self.model().item(index, self.modelColumn())
# return item.checkState() == Qt.Checked

View File

@ -266,7 +266,9 @@ class Ui_MainWindow(object):
self.centralwidget.addAction(self.actionDB_Browser_for_SQLite)
def save_as(self):
CreateTableForSaveAs()
db = CreateTableForSaveAs()
db.save_as()
self.mainwindow.setWindowTitle(
"AcouSed - " +
stg.filename_save_as
@ -274,7 +276,8 @@ class Ui_MainWindow(object):
def save(self):
if stg.dirname_save_as:
UpdateTableForSave()
db = CreateTableForSaveAs()
db.save()
else:
self.save_as()

View File

@ -937,23 +937,27 @@ class SedimentCalibrationTab(QWidget):
data_id = self.combobox_acoustic_data_choice.currentIndex()
# --- Record frequencies for calibration ---
stg.calib_acoustic_data = data_id
index_freq1 = self.combobox_freq1.currentIndex()
index_freq2 = self.combobox_freq2.currentIndex()
stg.frequencies_for_calibration.clear()
stg.frequencies_for_calibration.append(
(
stg.freq[data_id][
self.combobox_freq1.currentIndex()
],
self.combobox_freq1.currentIndex()
stg.freq[data_id][index_freq1],
index_freq1
)
)
stg.calib_freq_1 = index_freq1
stg.frequencies_for_calibration.append(
(
stg.freq[data_id][
self.combobox_freq2.currentIndex()
],
self.combobox_freq2.currentIndex()
stg.freq[data_id][index_freq2],
index_freq2
)
)
stg.calib_freq_2 = index_freq2
stg.frequency_for_inversion = tuple()
stg.frequency_for_inversion = (
@ -1427,11 +1431,13 @@ class SedimentCalibrationTab(QWidget):
def sample_choice_for_calibration(self):
# --- List selected fine samples ---
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 ---
# 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(),
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 ---
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
@ -1813,136 +1819,142 @@ class SedimentCalibrationTab(QWidget):
)
def read_calibration_file_and_fill_parameter(self):
if stg.filename_calibration_file == "":
return
pass
# --- Read calibration file ---
data = pd.read_csv(
os.path.join(
stg.path_calibration_file,
stg.filename_calibration_file
), header=0, index_col=0
)
else:
# --- Read calibration file ---
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 ---
self.label_temperature.clear()
self.label_temperature.setText(
"T = " + str(stg.temperature) + " °C"
)
# --- Fill spinboxes of calibration parameter ---
self.label_temperature.clear()
self.label_temperature.setText(
"T = " + str(stg.temperature) + " °C"
self.label_freq1.clear()
self.label_freq1.setText(data.columns[0])
data_id = self.combobox_acoustic_data_choice.currentIndex()
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_freq1.clear()
self.label_freq1.setText(data.columns[0])
self.label_freq2.clear()
self.label_freq2.setText(data.columns[1])
data_id = self.combobox_acoustic_data_choice.currentIndex()
index_freq2 = np.where(
np.asarray(
stg.freq_text[data_id]
) == data.columns[1]
)[0][0]
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.frequencies_for_calibration.append(
(
stg.freq[data_id][index_freq2],
index_freq2
)
)
stg.calib_freq_2 = index_freq2
self.lineEdit_ks_freq1.clear()
self.lineEdit_ks_freq1.setText(
str("%.5f" % float(data.iloc[0][0]))
)
stg.frequency_for_inversion = tuple()
stg.frequency_for_inversion = (
stg.freq[data_id][index_freq2],
index_freq2
)
self.lineEdit_ks_freq2.clear()
self.lineEdit_ks_freq2.setText(
str("%.5f" % float(data.iloc[0][1]))
)
self.lineEdit_ks_freq1.clear()
self.lineEdit_ks_freq1.setText(
str("%.5f" % float(data.iloc[0][0]))
)
stg.ks.clear()
stg.ks = [
float(self.lineEdit_ks_freq1.text()),
float(self.lineEdit_ks_freq2.text())
]
self.lineEdit_ks_freq2.clear()
self.lineEdit_ks_freq2.setText(
str("%.5f" % float(data.iloc[0][1]))
)
self.lineEdit_sv_freq1.clear()
self.lineEdit_sv_freq1.setText(
str("%.5f" % float(data.iloc[1][0]))
)
stg.ks.clear()
stg.ks = [
float(self.lineEdit_ks_freq1.text()),
float(self.lineEdit_ks_freq2.text())
]
self.lineEdit_sv_freq2.clear()
self.lineEdit_sv_freq2.setText(
str("%.5f" % float(data.iloc[1][1]))
)
self.lineEdit_sv_freq1.clear()
self.lineEdit_sv_freq1.setText(
str("%.5f" % float(data.iloc[1][0]))
)
stg.sv.clear()
stg.sv = [
float(self.lineEdit_sv_freq1.text()),
float(self.lineEdit_sv_freq2.text())
]
self.lineEdit_sv_freq2.clear()
self.lineEdit_sv_freq2.setText(
str("%.5f" % float(data.iloc[1][1]))
)
self.lineEdit_X.clear()
self.lineEdit_X.setText(
str("%.2f" % float(data.iloc[2][0]))
)
stg.sv.clear()
stg.sv = [
float(self.lineEdit_sv_freq1.text()),
float(self.lineEdit_sv_freq2.text())
]
stg.X_exponent.clear()
stg.X_exponent.append(float(self.lineEdit_X.text()))
self.lineEdit_X.clear()
self.lineEdit_X.setText(
str("%.2f" % float(data.iloc[2][0]))
)
self.lineEdit_alphas_freq1.clear()
self.lineEdit_alphas_freq1.setText(
str("%.5f" % float(data.iloc[3][0]))
)
stg.X_exponent.clear()
stg.X_exponent.append(float(self.lineEdit_X.text()))
self.lineEdit_alphas_freq2.clear()
self.lineEdit_alphas_freq2.setText(
str("%.5f" % float(data.iloc[3][1]))
)
self.lineEdit_alphas_freq1.clear()
self.lineEdit_alphas_freq1.setText(
str("%.5f" % float(data.iloc[3][0]))
)
stg.alpha_s.clear()
stg.alpha_s = [
float(self.lineEdit_alphas_freq1.text()),
float(self.lineEdit_alphas_freq2.text())
]
self.lineEdit_alphas_freq2.clear()
self.lineEdit_alphas_freq2.setText(
str("%.5f" % float(data.iloc[3][1]))
)
self.lineEdit_zeta_freq1.clear()
self.lineEdit_zeta_freq1.setText(
str("%.5f" % float(data.iloc[4][0]))
)
stg.alpha_s.clear()
stg.alpha_s = [
float(self.lineEdit_alphas_freq1.text()),
float(self.lineEdit_alphas_freq2.text())
]
self.lineEdit_zeta_freq2.clear()
self.lineEdit_zeta_freq2.setText(
str("%.5f" % float(data.iloc[4][1]))
)
self.lineEdit_zeta_freq1.clear()
self.lineEdit_zeta_freq1.setText(
str("%.5f" % float(data.iloc[4][0]))
)
stg.zeta.clear()
stg.zeta = [
float(self.lineEdit_zeta_freq1.text()),
float(self.lineEdit_zeta_freq2.text())
]
self.lineEdit_zeta_freq2.clear()
self.lineEdit_zeta_freq2.setText(
str("%.5f" % float(data.iloc[4][1]))
)
self.compute_kt2D_kt3D()
self.compute_J_cross_section()
stg.zeta.clear()
stg.zeta = [
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):
if self.combobox_acoustic_data_choice.count() > 0:

View File

@ -215,6 +215,12 @@ frac_vol_sand_cumul = [] # Cumulated volume fraction (%) of the sand sedi
# --- 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
frequency_for_inversion = tuple() # Frequency chosen for inversion (finv_val, finv_ind) # Tuple
@ -259,7 +265,3 @@ 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
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