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 = """ self.create_Calibration = """
CREATE TABLE Calibration( CREATE TABLE Calibration(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
@ -184,8 +195,14 @@ 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(
@ -209,10 +226,6 @@ 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")
@ -231,6 +244,7 @@ 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)
@ -517,6 +531,36 @@ 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()
@ -527,7 +571,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,6 +83,7 @@ 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")
@ -609,6 +610,69 @@ 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

@ -438,18 +438,21 @@ 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[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], 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[self.combobox_acoustic_data_choice.currentIndex()][0], j_cross_section_freq1=stg.J_cross_section[data_id][0],
j_cross_section_freq2=stg.J_cross_section[self.combobox_acoustic_data_choice.currentIndex()][1], j_cross_section_freq2=stg.J_cross_section[data_id][1],
r2D=stg.depth_2D[self.combobox_acoustic_data_choice.currentIndex()][ r2D=stg.depth_2D[data_id][
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,6 +121,13 @@ 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
# class CheckableComboBox(QComboBox): # class CheckableComboBox(QComboBox):
# def __init__(self): # def __init__(self):
@ -151,4 +158,3 @@ 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

@ -266,7 +266,9 @@ 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):
CreateTableForSaveAs() db = CreateTableForSaveAs()
db.save_as()
self.mainwindow.setWindowTitle( self.mainwindow.setWindowTitle(
"AcouSed - " + "AcouSed - " +
stg.filename_save_as stg.filename_save_as
@ -274,7 +276,8 @@ class Ui_MainWindow(object):
def save(self): def save(self):
if stg.dirname_save_as: if stg.dirname_save_as:
UpdateTableForSave() db = CreateTableForSaveAs()
db.save()
else: else:
self.save_as() self.save_as()

View File

@ -937,23 +937,27 @@ 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
index_freq1 = self.combobox_freq1.currentIndex()
index_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][ stg.freq[data_id][index_freq1],
self.combobox_freq1.currentIndex() index_freq1
],
self.combobox_freq1.currentIndex()
) )
) )
stg.calib_freq_1 = index_freq1
stg.frequencies_for_calibration.append( stg.frequencies_for_calibration.append(
( (
stg.freq[data_id][ stg.freq[data_id][index_freq2],
self.combobox_freq2.currentIndex() index_freq2
],
self.combobox_freq2.currentIndex()
) )
) )
stg.calib_freq_2 = index_freq2
stg.frequency_for_inversion = tuple() stg.frequency_for_inversion = tuple()
stg.frequency_for_inversion = ( stg.frequency_for_inversion = (
@ -1427,11 +1431,13 @@ 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,):
@ -1813,14 +1819,16 @@ 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
pass
else:
# --- Read calibration file --- # --- Read calibration file ---
data = pd.read_csv(os.path.join(stg.path_calibration_file, stg.filename_calibration_file), header=0, index_col=0) 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 --- # --- Fill spinboxes of calibration parameter ---
self.label_temperature.clear() self.label_temperature.clear()
@ -1833,6 +1841,8 @@ class SedimentCalibrationTab(QWidget):
data_id = self.combobox_acoustic_data_choice.currentIndex() data_id = self.combobox_acoustic_data_choice.currentIndex()
stg.calib_acoustic_data = data_id
index_freq1 = np.where( index_freq1 = np.where(
np.asarray( np.asarray(
stg.freq_text[data_id] stg.freq_text[data_id]
@ -1846,6 +1856,7 @@ class SedimentCalibrationTab(QWidget):
index_freq1 index_freq1
) )
) )
stg.calib_freq_1 = index_freq1
self.label_freq2.clear() self.label_freq2.clear()
self.label_freq2.setText(data.columns[1]) self.label_freq2.setText(data.columns[1])
@ -1862,6 +1873,7 @@ class SedimentCalibrationTab(QWidget):
index_freq2 index_freq2
) )
) )
stg.calib_freq_2 = index_freq2
stg.frequency_for_inversion = tuple() stg.frequency_for_inversion = tuple()
stg.frequency_for_inversion = ( stg.frequency_for_inversion = (

View File

@ -215,6 +215,12 @@ 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
@ -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 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