Compare commits
3 Commits
2df094f450
...
0dd38af7a9
| Author | SHA1 | Date |
|---|---|---|
|
|
0dd38af7a9 | |
|
|
34690264b1 | |
|
|
d5d8fa026f |
|
|
@ -1590,7 +1590,6 @@ class SedimentCalibrationTab(QWidget):
|
||||||
self.animaiton_groupbox_compute.start()
|
self.animaiton_groupbox_compute.start()
|
||||||
|
|
||||||
def import_calibration_file(self):
|
def import_calibration_file(self):
|
||||||
|
|
||||||
if self.combobox_acoustic_data_choice.count() == 0:
|
if self.combobox_acoustic_data_choice.count() == 0:
|
||||||
msgBox = QMessageBox()
|
msgBox = QMessageBox()
|
||||||
msgBox.setWindowTitle("Calibration import error")
|
msgBox.setWindowTitle("Calibration import error")
|
||||||
|
|
@ -1602,35 +1601,81 @@ class SedimentCalibrationTab(QWidget):
|
||||||
msgBox.setText("Update data before importing calibration")
|
msgBox.setText("Update data before importing calibration")
|
||||||
msgBox.setStandardButtons(QMessageBox.Ok)
|
msgBox.setStandardButtons(QMessageBox.Ok)
|
||||||
msgBox.exec()
|
msgBox.exec()
|
||||||
|
return
|
||||||
|
|
||||||
|
path = ""
|
||||||
|
if stg.path_calibration_file:
|
||||||
|
path = stg.path_calibration_file
|
||||||
|
elif self.combobox_acoustic_data_choice.count() > 0:
|
||||||
|
path = stg.path_BS_raw_data[-1]
|
||||||
|
|
||||||
|
file_type = {
|
||||||
|
"Calibration Files (*.csv *.ods *.xls *.xlsx)":
|
||||||
|
self.read_calibration_dispatch,
|
||||||
|
"CSV Files (*.csv)": self.read_calibration_csv,
|
||||||
|
"Excel Files (*.xlsx *.xls)": self.read_calibration_excel,
|
||||||
|
"LibreOffice Calc Files (*.ods)": self.read_calibration_ods,
|
||||||
|
}
|
||||||
|
|
||||||
|
filename, ftype = QFileDialog.getOpenFileName(
|
||||||
|
self, "Open calibration file", path,
|
||||||
|
";;".join(file_type),
|
||||||
|
options=QFileDialog.DontUseNativeDialog
|
||||||
|
)
|
||||||
|
|
||||||
|
if filename == '':
|
||||||
|
return
|
||||||
|
|
||||||
|
dir_name = os.path.dirname(filename)
|
||||||
|
name = os.path.basename(filename)
|
||||||
|
|
||||||
|
stg.path_calibration_file = dir_name
|
||||||
|
stg.filename_calibration_file = name
|
||||||
|
|
||||||
|
self.lineEdit_import_calibration.clear()
|
||||||
|
self.lineEdit_import_calibration.setText(name)
|
||||||
|
|
||||||
|
self.lineEdit_import_calibration.setToolTip(dir_name)
|
||||||
|
|
||||||
|
self.compute_depth_2D()
|
||||||
|
try:
|
||||||
|
parser = file_type[ftype]
|
||||||
|
data = parser(filename)
|
||||||
|
|
||||||
|
self.fill_calibration_select_frequencies(data)
|
||||||
|
self.fill_calibration_parameters(data)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"read calibration failed: {str(e)}")
|
||||||
|
|
||||||
|
def read_calibration_dispatch(self, filename):
|
||||||
|
if ".csv" in filename:
|
||||||
|
return self.read_calibration_csv(filename)
|
||||||
|
elif ".ods" in filename:
|
||||||
|
return self.read_calibration_ods(filename)
|
||||||
else:
|
else:
|
||||||
|
return self.read_calibration_excel(filename)
|
||||||
|
|
||||||
filename = QFileDialog.getOpenFileName(
|
def read_calibration_csv(self, filename):
|
||||||
self, "Open calibration",
|
data = pd.read_csv(
|
||||||
[
|
filename, header=0, index_col=0,
|
||||||
stg.path_calibration_file
|
)
|
||||||
if stg.path_calibration_file
|
logger.debug(f"Calibration data: {data}")
|
||||||
else stg.path_BS_raw_data[-1]
|
return data
|
||||||
if self.combobox_acoustic_data_choice.count() > 0
|
|
||||||
else ""
|
|
||||||
][0],
|
|
||||||
"Calibration file (*.xls, *.ods, *csv)",
|
|
||||||
options=QFileDialog.DontUseNativeDialog
|
|
||||||
)
|
|
||||||
|
|
||||||
dir_name = os.path.dirname(filename[0])
|
def read_calibration_ods(self, filename):
|
||||||
name = os.path.basename(filename[0])
|
data = pd.read_excel(
|
||||||
|
filename, header=0, index_col=0,
|
||||||
|
engine="odf"
|
||||||
|
)
|
||||||
|
logger.debug(f"Calibration data: {data}")
|
||||||
|
return data
|
||||||
|
|
||||||
stg.path_calibration_file = dir_name
|
def read_calibration_excel(self, filename):
|
||||||
stg.filename_calibration_file = name
|
data = pd.read_excel(
|
||||||
|
filename, header=0, index_col=0,
|
||||||
self.lineEdit_import_calibration.clear()
|
)
|
||||||
self.lineEdit_import_calibration.setText(name)
|
logger.debug(f"Calibration data: {data}")
|
||||||
|
return data
|
||||||
self.lineEdit_import_calibration.setToolTip(dir_name)
|
|
||||||
|
|
||||||
self.compute_depth_2D()
|
|
||||||
self.read_calibration_file_and_fill_parameter()
|
|
||||||
|
|
||||||
def update_label_freq1_for_calibration(self):
|
def update_label_freq1_for_calibration(self):
|
||||||
self.label_freq1.clear()
|
self.label_freq1.clear()
|
||||||
|
|
@ -1668,69 +1713,51 @@ class SedimentCalibrationTab(QWidget):
|
||||||
str('%.4f' % stg.kt_read[freq_2])
|
str('%.4f' % stg.kt_read[freq_2])
|
||||||
)
|
)
|
||||||
|
|
||||||
def read_calibration_file_and_fill_parameter(self):
|
def fill_calibration_select_frequencies(self, data):
|
||||||
if stg.filename_calibration_file == "":
|
if stg.filename_calibration_file == "":
|
||||||
return
|
return
|
||||||
|
|
||||||
# --- 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 ---
|
# --- Fill spinboxes of calibration parameter ---
|
||||||
self.label_temperature.clear()
|
self.label_temperature.clear()
|
||||||
self.label_temperature.setText(
|
self.label_temperature.setText(
|
||||||
"T = " + str(stg.temperature) + " °C"
|
"T = " + str(stg.temperature) + " °C"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.label_freq1.clear()
|
|
||||||
self.label_freq1.setText(data.columns[0])
|
|
||||||
|
|
||||||
data_id = self.combobox_acoustic_data_choice.currentIndex()
|
data_id = self.combobox_acoustic_data_choice.currentIndex()
|
||||||
|
|
||||||
stg.calib_acoustic_data = data_id
|
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.clear()
|
||||||
stg.frequencies_for_calibration.append(
|
|
||||||
(
|
for label, column in [
|
||||||
stg.freq[data_id][index_freq1],
|
(self.label_freq1, 0),
|
||||||
index_freq1
|
(self.label_freq2, 1)
|
||||||
|
]:
|
||||||
|
label.clear()
|
||||||
|
label.setText(data.columns[0])
|
||||||
|
|
||||||
|
index = next(
|
||||||
|
map(
|
||||||
|
lambda e: e[0],
|
||||||
|
filter(
|
||||||
|
lambda e: e[1] == data.columns[column],
|
||||||
|
enumerate(stg.freq_text[data_id])
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
stg.calib_freq_1 = index_freq1
|
|
||||||
|
|
||||||
self.label_freq2.clear()
|
stg.frequencies_for_calibration.append(
|
||||||
self.label_freq2.setText(data.columns[1])
|
(
|
||||||
|
stg.freq[data_id][index],
|
||||||
index_freq2 = np.where(
|
index
|
||||||
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.calib_freq_2 = index_freq2
|
|
||||||
|
|
||||||
stg.frequency_for_inversion = tuple()
|
logger.debug(f"Select freq {index}: {stg.freq_text[data_id][index]}")
|
||||||
stg.frequency_for_inversion = (
|
|
||||||
stg.freq[data_id][index_freq2],
|
|
||||||
index_freq2
|
|
||||||
)
|
|
||||||
|
|
||||||
|
stg.calib_freq_1 = stg.frequencies_for_calibration[0][1]
|
||||||
|
stg.calib_freq_2 = stg.frequencies_for_calibration[1][1]
|
||||||
|
|
||||||
|
def fill_calibration_parameters(self, data):
|
||||||
self.lineEdit_ks_freq1.clear()
|
self.lineEdit_ks_freq1.clear()
|
||||||
self.lineEdit_ks_freq1.setText(
|
self.lineEdit_ks_freq1.setText(
|
||||||
str("%.5f" % float(data.iloc[0][0]))
|
str("%.5f" % float(data.iloc[0][0]))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue