Compare commits

...

2 Commits

Author SHA1 Message Date
Pierre-Antoine 3c2db523ac Sediment calibration: Refactoring. 2025-04-17 11:03:26 +02:00
Pierre-Antoine 9bb02edee4 Sediment calibration: Refactoring. 2025-04-17 09:51:41 +02:00
1 changed files with 364 additions and 333 deletions

View File

@ -1168,131 +1168,225 @@ class SedimentCalibrationTab(QWidget):
self.fig_BS.canvas.draw_idle() self.fig_BS.canvas.draw_idle()
def sample_choice_for_calibration(self): def sample_choice_for_calibration(self):
fine_id = self.combobox_fine_sample_choice.currentIndexes()
fine_data = self.combobox_fine_sample_choice.currentData()
sand_id = self.combobox_sand_sample_choice.currentIndex()
sand_data = self.combobox_sand_sample_choice.currentData()
sand_text = self.combobox_sand_sample_choice.currentText()
# --- 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 = [
stg.calib_fine_profiles = self.combobox_fine_sample_choice.currentIndexes() (f, int(f[1:]) - 1) for f in fine_data
]
stg.calib_fine_profiles = fine_id
# --- 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 = [(sand_text, sand_id)]
stg.sand_sample_target = [(self.combobox_sand_sample_choice.currentText(), stg.calib_sand_target = sand_id
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 --- t1, t2 = self.sample_choice_for_calibration_times()
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): d1, d2 = self.sample_choice_for_calibration_depths()
t1 = (
np.where(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]])))[0][0]
)
t2 = (
np.where(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[stg.sand_sample_target[0][1]])))[0][0]
)
else:
t1 = (
np.where(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]])))[0][0]
)
t2 = (
np.where(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]]) ==
np.nanmin(np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - stg.time_sand[
stg.sand_sample_target[0][1]])))[0][0]
)
# --- Find index in depth (along acoustic recording) of sand sample target ---
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
d1 = (
np.where(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) )))[0][0]
)
d2 = (
np.where(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[stg.sand_sample_target[0][1]]) )))[0][0]
)
else:
d1 = (
np.where(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq1.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) )))[0][0]
)
d2 = (
np.where(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) ) ==
np.nanmin(np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex()] - (-stg.depth_sand[
stg.sand_sample_target[0][1]]) )))[0][0]
)
stg.sand_sample_target_indice = [(d1, t1), (d2, t2)] stg.sand_sample_target_indice = [(d1, t1), (d2, t2)]
def summary_samples_choices(self): def sample_choice_for_calibration_times(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
self.pushbutton_compute_calibration.setToolTip("Calibration is computed at abscissa " + str(self.combobox_sand_sample_choice.currentText())) freq1_id = self.combobox_freq1.currentIndex()
freq2_id = self.combobox_freq1.currentIndex()
# --- Find index in time (along acoustic recording) of sand sample target ---
if stg.time_cross_section[data_id].shape != (0,):
time_data = stg.time_cross_section
else:
time_data = stg.time
t1 = (
np.where(
np.abs(
time_data[data_id][freq1_id]
- stg.time_sand[stg.sand_sample_target[0][1]]
) == np.nanmin(
np.abs(
time_data[data_id][freq1_id]
- stg.time_sand[stg.sand_sample_target[0][1]]
)
)
)[0][0]
)
t2 = (
np.where(
np.abs(
time_data[data_id][freq2_id]
- stg.time_sand[stg.sand_sample_target[0][1]]
) == np.nanmin(
np.abs(
time_data[data_id][freq2_id]
- stg.time_sand[stg.sand_sample_target[0][1]]
)
)
)[0][0]
)
return (t1, t2)
def sample_choice_for_calibration_depths(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
freq1_id = self.combobox_freq1.currentIndex()
freq2_id = self.combobox_freq2.currentIndex()
# --- Find index in depth (along acoustic recording) of sand sample target ---
if stg.depth_cross_section[data_id].shape != (0,):
depth_data = stg.depth_cross_section
else:
depth_data = stg.depth
d1 = (
np.where(
np.abs(
depth_data[data_id][freq1_id]
- (-stg.depth_sand[stg.sand_sample_target[0][1]])
) == np.nanmin(
np.abs(
depth_data[data_id][freq1_id] -
(-stg.depth_sand[stg.sand_sample_target[0][1]])
)
)
)[0][0]
)
d2 = (
np.where(
np.abs(
depth_data[data_id][freq2_id]
- (-stg.depth_sand[stg.sand_sample_target[0][1]])
) == np.nanmin(
np.abs(
depth_data[data_id][freq2_id]
- (-stg.depth_sand[stg.sand_sample_target[0][1]])
)
)
)[0][0]
)
return (d1, d2)
def summary_samples_choices(self):
self.pushbutton_compute_calibration\
.setToolTip(
"Calibration is computed at abscissa "
+ str(self.combobox_sand_sample_choice.currentText())
)
for i in reversed(range(self.gridLayout_groupbox_interpolate_info.count())): for i in reversed(range(self.gridLayout_groupbox_interpolate_info.count())):
self.gridLayout_groupbox_interpolate_info.itemAt(i).widget().setParent(None) self.gridLayout_groupbox_interpolate_info\
.itemAt(i)\
.widget()\
.setParent(None)
self.gridLayout_groupbox_interpolate_info.addWidget(self.pushbutton_interpolate_Mfine_profile, 0, 0, 1, 4, Qt.AlignCenter) self.gridLayout_groupbox_interpolate_info\
.addWidget(
self.pushbutton_interpolate_Mfine_profile,
0, 0, 1, 4,
Qt.AlignCenter
)
self.summary_samples_choices_fine()
self.summary_samples_choices_sand()
def summary_samples_choices_fine(self):
fine_head = ["Sample", "Depth (m)", "time", "Cfine (g/L)"] fine_head = ["Sample", "Depth (m)", "time", "Cfine (g/L)"]
fine_label = [self.label_sample_fine, self.label_depth_fine, self.label_time_fine, fine_label = [
self.label_concentration_fine] self.label_sample_fine,
self.label_depth_fine,
self.label_time_fine,
self.label_concentration_fine
]
for j in range(len(fine_head)): for j in range(len(fine_head)):
exec("fine_label[" + str(j) + "] = QLabel()") fine_label[j] = QLabel()
eval("fine_label[" + str(j) + "].setText(fine_head[" + str(j) + "])") fine_label[j].setText(fine_head[j])
print((f"self.gridLayout_groupbox_interpolate_info.addWidget(fine_label[{j}], 1, {j}, 1, 1, Qt.AlignCenter)")) self.gridLayout_groupbox_interpolate_info\
eval(f"self.gridLayout_groupbox_interpolate_info.addWidget(fine_label[{j}], 1, {j}, 1, 1, Qt.AlignCenter)") .addWidget(
fine_label[j], 1, j, 1, 1, Qt.AlignCenter
)
self.gridLayout_groupbox_interpolate_info\
.addWidget(
fine_label[j], 1, j, 1, 1, Qt.AlignCenter
)
fine_data = [] fine_data = []
for k in range(len(stg.fine_sample_profile)): for k in range(len(stg.fine_sample_profile)):
fine_data.append([stg.fine_sample_profile[k][0], str(stg.depth_fine[k]), str(stg.time_fine[k]), str(stg.Ctot_fine[k])]) fine_data.append(
print(fine_data) [
stg.fine_sample_profile[k][0],
str(stg.depth_fine[k]),
str(stg.time_fine[k]),
str(stg.Ctot_fine[k])
]
)
for p in range(len(fine_data)): for p in range(len(fine_data)):
for q in range(len(fine_data[0])): for q in range(len(fine_data[0])):
print(f"self.gridLayout_groupbox_interpolate_info.addWidget(QLabel(fine_data[{p}][{q}]), {2 + p}, {q}, 1, 1, Qt.AlignCenter)") self.gridLayout_groupbox_interpolate_info\
eval(f"self.gridLayout_groupbox_interpolate_info.addWidget(QLabel(fine_data[{p}][{q}]), {2 + p}, {q}, 1, 1, Qt.AlignCenter)") .addWidget(
QLabel(fine_data[p][q]),
2 + p, q, 1, 1,
Qt.AlignCenter
)
self.gridLayout_groupbox_interpolate_info.addWidget(self.double_horizontal_line, 2 + len(fine_data), 0, 1, 4, Qt.AlignCenter) self.gridLayout_groupbox_interpolate_info\
.addWidget(
self.double_horizontal_line,
2 + len(fine_data), 0, 1, 4,
Qt.AlignCenter
)
def summary_samples_choices_sand(self):
sand_head = ["Sample", "Depth (m)", "time", "Csand (g/L)"] sand_head = ["Sample", "Depth (m)", "time", "Csand (g/L)"]
sand_label = [self.label_sample_sand, self.label_depth_sand, self.label_time_sand, sand_label = [
self.label_concentration_sand] self.label_sample_sand,
self.label_depth_sand,
self.label_time_sand,
self.label_concentration_sand
]
fine_data = []
for k in range(len(stg.fine_sample_profile)):
fine_data.append(
[
stg.fine_sample_profile[k][0],
str(stg.depth_fine[k]),
str(stg.time_fine[k]),
str(stg.Ctot_fine[k])
]
)
for s in range(len(sand_head)): for s in range(len(sand_head)):
exec("sand_label[" + str(s) + "] = QLabel()") sand_label[s] = QLabel()
eval("sand_label[" + str(s) + "].setText(sand_head[" + str(s) + "])") sand_label[s].setText(sand_head[s])
print(f"self.gridLayout_groupbox_interpolate_info.addWidget(sand_label[{s}], {3 + len(fine_data)}, {s}, 1, 1, Qt.AlignCenter)") self.gridLayout_groupbox_interpolate_info\
eval(f"self.gridLayout_groupbox_interpolate_info.addWidget(sand_label[{s}], {3 + len(fine_data)}, {s}, 1, 1, Qt.AlignCenter)") .addWidget(
sand_label[s],
3 + len(fine_data), s, 1, 1,
Qt.AlignCenter
)
sand_data = [stg.sand_sample_target[0][0], sand_data = [
str(stg.depth_sand[stg.sand_sample_target[0][1]]), stg.sand_sample_target[0][0],
str(stg.time_sand[stg.sand_sample_target[0][1]]), str(stg.depth_sand[stg.sand_sample_target[0][1]]),
str(stg.Ctot_sand[stg.sand_sample_target[0][1]])] str(stg.time_sand[stg.sand_sample_target[0][1]]),
str(stg.Ctot_sand[stg.sand_sample_target[0][1]])
]
for t in range(len(sand_data)): for t in range(len(sand_data)):
self.gridLayout_groupbox_interpolate_info.addWidget(QLabel(sand_data[t]), 4 + len(fine_data), t, 1, 1, Qt.AlignCenter) self.gridLayout_groupbox_interpolate_info\
.addWidget(
QLabel(sand_data[t]),
4 + len(fine_data), t, 1, 1,
Qt.AlignCenter
)
def plot_profile_of_concentration_fine(self): def plot_profile_of_concentration_fine(self):
@ -2177,302 +2271,239 @@ class SedimentCalibrationTab(QWidget):
stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1], axis=2)) stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1], axis=2))
def compute_FCB(self): def compute_FCB(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
fcb_id = self.combobox_frequency_FCB.currentIndex()
self.combobox_frequency_FCB.clear() self.combobox_frequency_FCB.clear()
self.combobox_frequency_FCB.addItems(stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()]) self.combobox_frequency_FCB.addItems(stg.freq_text[data_id])
self.range_cells_function() self.range_cells_function()
if stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): BS_data = stg.BS_raw_data
stg.FCB = \ if stg.BS_stream_bed_pre_process_average[data_id].shape != (0,):
(np.log(stg.BS_stream_bed_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()]) + BS_data = stg.BS_stream_bed_pre_process_average
np.log(stg.depth_real) + elif stg.BS_stream_bed_pre_process_SNR[data_id].shape != (0,):
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][ BS_data = stg.BS_stream_bed_pre_process_SNR
self.combobox_frequency_FCB.currentIndex()] * elif stg.BS_stream_bed[data_id].shape != (0,):
stg.depth_real) BS_data = stg.BS_stream_bed
elif stg.BS_cross_section_pre_process_average[data_id].shape != (0,):
BS_data = stg.BS_cross_section_pre_process_average
elif stg.BS_cross_section_pre_process_SNR[data_id].shape != (0,):
BS_data = stg.BS_cross_section_pre_process_SNR
elif stg.BS_cross_section[data_id].shape != (0,):
BS_data = stg.BS_cross_section
elif stg.BS_raw_data_pre_process_average[data_id].shape != (0,):
BS_data = stg.BS_raw_data_pre_process_average
elif stg.BS_raw_data_pre_process_SNR[data_id].shape != (0,):
BS_data = stg.BS_raw_data_pre_process_SNR
elif stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): stg.FCB = (
np.log(BS_data[data_id])
stg.FCB = \ + np.log(stg.depth_real)
(np.log(stg.BS_stream_bed_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()]) + + 2 * stg.water_attenuation[data_id][fcb_id]
np.log(stg.depth_real) + * stg.depth_real
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][ )
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_stream_bed[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_cross_section_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_cross_section_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_cross_section[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_raw_data_pre_process_average[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_raw_data_pre_process_SNR[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
elif stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
stg.FCB = \
(np.log(stg.BS_raw_data[self.combobox_acoustic_data_choice.currentIndex()]) +
np.log(stg.depth_real) +
2 * stg.water_attenuation[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()] *
stg.depth_real)
self.plot_FCB() self.plot_FCB()
def plot_FCB(self): def plot_FCB(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
fcb_id = self.combobox_frequency_FCB.currentIndex()
if stg.FCB.shape != (0,): if stg.FCB.shape == (0,):
return
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): if stg.time_cross_section[data_id].shape != (0,):
self.slider_FCB.setMaximum(
stg.time_cross_section[data_id].shape[1]
)
else:
self.slider_FCB.setMaximum(stg.time[data_id].shape[1])
self.slider_FCB.setMaximum(stg.time_cross_section[ self.slider_FCB.setValue(stg.sand_sample_target_indice[0][1])
self.combobox_acoustic_data_choice.currentIndex()].shape[1])
else: self.verticalLayout_groupbox_FCB_plot.removeWidget(self.canvas_FCB)
self.verticalLayout_groupbox_FCB_plot.removeWidget(self.toolbar_FCB)
self.slider_FCB.setMaximum(stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape[1]) self.fig_FCB, self.axis_FCB = plt.subplots(
nrows=1, ncols=1, layout="constrained"
)
self.slider_FCB.setValue(stg.sand_sample_target_indice[0][1]) self.canvas_FCB = FigureCanvas(self.fig_FCB)
self.toolbar_FCB = NavigationToolBar(self.canvas_FCB, self)
self.verticalLayout_groupbox_FCB_plot.removeWidget(self.canvas_FCB) self.verticalLayout_groupbox_FCB_plot.addWidget(self.toolbar_FCB)
self.verticalLayout_groupbox_FCB_plot.removeWidget(self.toolbar_FCB) self.verticalLayout_groupbox_FCB_plot.addWidget(self.canvas_FCB)
self.fig_FCB, self.axis_FCB = plt.subplots(nrows=1, ncols=1, layout="constrained") if stg.depth_cross_section[data_id].shape != (0,):
self.canvas_FCB = FigureCanvas(self.fig_FCB) self.axis_FCB.plot(
self.toolbar_FCB = NavigationToolBar(self.canvas_FCB, self) stg.depth_cross_section[data_id][fcb_id],
stg.FCB[fcb_id, :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k"
)
else:
self.axis_FCB.plot(
stg.depth[data_id][fcb_id],
stg.FCB[fcb_id, :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k"
)
self.verticalLayout_groupbox_FCB_plot.addWidget(self.toolbar_FCB) self.axis_FCB.text(
self.verticalLayout_groupbox_FCB_plot.addWidget(self.canvas_FCB) .95, .05,
stg.freq_text[data_id][fcb_id],
fontsize=10, fontweight='bold', fontname="DejaVu Sans",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_FCB.transAxes
)
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): self.fig_FCB.supxlabel("Depth (m)")
self.fig_FCB.supylabel("FCB")
self.fig_FCB.canvas.draw_idle()
self.axis_FCB.plot( self.slider_FCB.valueChanged.connect(self.update_plot_FCB)
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ self.combobox_frequency_FCB.currentIndexChanged\
self.combobox_frequency_FCB.currentIndex()], .connect(self.update_plot_FCB)
stg.FCB[self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k")
else:
self.axis_FCB.plot(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
stg.FCB[self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1],
linestyle="solid", linewidth=1, color="k")
self.axis_FCB.text(.95, .05,
stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex()],
fontsize=10, fontweight='bold', fontname="DejaVu Sans",
fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_FCB.transAxes)
self.fig_FCB.supxlabel("Depth (m)")
self.fig_FCB.supylabel("FCB")
self.fig_FCB.canvas.draw_idle()
self.slider_FCB.valueChanged.connect(self.update_plot_FCB)
self.combobox_frequency_FCB.currentIndexChanged.connect(self.update_plot_FCB)
def update_plot_FCB(self): def update_plot_FCB(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
fcb_id = self.combobox_frequency_FCB.currentIndex()
freq1_id = self.combobox_freq1.currentIndex()
freq2_id = self.combobox_freq2.currentIndex()
if stg.FCB.shape != (0,): if stg.FCB.shape != (0,):
self.axis_FCB.cla() self.axis_FCB.cla()
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
self.axis_FCB.plot( self.axis_FCB.plot(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ stg.depth_cross_section[data_id][fcb_id],
self.combobox_frequency_FCB.currentIndex()], stg.FCB[fcb_id, :, self.slider_FCB.value() - 1],
stg.FCB[self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1], linestyle="solid", linewidth=1, color="k"
linestyle="solid", linewidth=1, color="k") )
else: else:
self.axis_FCB.plot( self.axis_FCB.plot(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][ stg.depth[data_id][fcb_id],
self.combobox_frequency_FCB.currentIndex()], stg.FCB[fcb_id, :, self.slider_FCB.value() - 1],
stg.FCB[self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1], linestyle="solid", linewidth=1, color="k"
linestyle="solid", linewidth=1, color="k") )
self.axis_FCB.text(.95, .05, self.axis_FCB.text(
stg.freq_text[self.combobox_acoustic_data_choice.currentIndex()][ .95, .05,
self.combobox_frequency_FCB.currentIndex()], stg.freq_text[data_id][fcb_id],
fontsize=10, fontweight='bold', fontname="DejaVu Sans", fontsize=10, fontweight='bold', fontname="DejaVu Sans",
fontstyle="normal", c="black", alpha=0.2, fontstyle="normal", c="black", alpha=0.2,
horizontalalignment='right', verticalalignment='bottom', horizontalalignment='right', verticalalignment='bottom',
transform=self.axis_FCB.transAxes) transform=self.axis_FCB.transAxes
)
self.fig_FCB.canvas.draw_idle() self.fig_FCB.canvas.draw_idle()
# --- Update red line on acoustic record plot --- # --- Update red line on acoustic record plot ---
if stg.sand_sample_target_indice: if stg.sand_sample_target_indice:
if stg.depth_cross_section[data_id].shape != (0,):
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): depth_data = stg.depth_cross_section
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,):
self.red_line_plot_return.set_data(
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[
1]),
-stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
else:
self.red_line_plot_return.set_data(
stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape[
1]),
-stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
else: else:
depth_data = stg.depth
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): if stg.time_cross_section[data_id].shape != (0,):
time_data = stg.time_cross_section
else:
time_data = stg.time
self.red_line_plot_return.set_data( self.red_line_plot_return.set_data(
stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ time_data[data_id][freq2_id, self.slider_FCB.value() -1]
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] * * np.ones(
np.ones(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1]), depth_data[data_id].shape[1]
-stg.depth[self.combobox_acoustic_data_choice.currentIndex()][ ),
self.combobox_freq2.currentIndex(), :]) -stg.depth_data[data_id][freq2_id, :]
)
else:
self.red_line_plot_return.set_data(
stg.time[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), self.slider_FCB.value() -1] *
np.ones(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape[1]),
-stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_freq2.currentIndex(), :])
self.fig_BS.canvas.draw_idle() self.fig_BS.canvas.draw_idle()
def fit_FCB_profile_with_linear_regression_and_compute_alphaS(self): def fit_FCB_profile_with_linear_regression_and_compute_alphaS(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
fcb_id = self.combobox_frequency_FCB.currentIndex()
self.update_plot_FCB() self.update_plot_FCB()
if stg.FCB.shape != (0,): if stg.FCB.shape == (0,):
return
# --- Identify FCB profile where value are not NaN --- # --- Identify FCB profile where value are not NaN ---
y0 = stg.FCB[self.combobox_frequency_FCB.currentIndex(), :, self.slider_FCB.value() - 1] y0 = stg.FCB[fcb_id, :, self.slider_FCB.value() - 1]
y = y0[np.where(np.isnan(y0) == False)] y = y0[np.where(np.isnan(y0) == False)]
if stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): if stg.depth_cross_section[data_id].shape != (0,):
depth_data = stg.depth_cross_section
else:
depth_data = stg.depth
# --- Select depth corresponding to the FCB profile where value are not NaN --- # --- Select depth corresponding to the FCB profile where value are not NaN ---
x0 = stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ x0 = depth_data[data_id][fcb_id, :]
self.combobox_frequency_FCB.currentIndex(), :] x = x0[np.where(np.isnan(y0) == False)]
x = x0[np.where(np.isnan(y0) == False)]
# --- Find the indices of the values between which the linear regression is fitted --- # --- Find the indices of the values between which the linear regression is fitted ---
value1 = np.where(np.round(np.abs(x - float(self.lineEdit_FCB_from.text().replace(',','.'))), 2) == value1 = np.where(
np.min(np.round(np.abs(x - float(self.lineEdit_FCB_from.text().replace(',','.'))), 2)))[0][0] np.round(
value2 = np.where(np.round(np.abs(x - float(self.lineEdit_FCB_to.text().replace(',', '.'))), 2) == np.abs(
np.min(np.round(np.abs(x - float(self.lineEdit_FCB_to.text().replace(',', '.'))), 2)))[0][0] x - float(
self.lineEdit_FCB_from\
.text().replace(',','.')
)
), 2
) == np.min(
np.round(
np.abs(
x - float(
self.lineEdit_FCB_from.text().replace(',','.'))
), 2
)
)
)[0][0]
lin_reg_compute = linregress(x[value1:value2], y[value1:value2]) value2 = np.where(
np.round(
np.abs(
x - float(
self.lineEdit_FCB_to.text().replace(',', '.')
)
), 2
) == np.min(
np.round(
np.abs(
x - float(
self.lineEdit_FCB_to.text().replace(',', '.')
)
), 2
)
)
)[0][0]
stg.lin_reg.clear() lin_reg_compute = linregress(x[value1:value2], y[value1:value2])
stg.lin_reg = [lin_reg_compute.slope, lin_reg_compute.intercept]
# --- Plot result of linear regression --- stg.lin_reg.clear()
self.axis_FCB.plot( stg.lin_reg = [lin_reg_compute.slope, lin_reg_compute.intercept]
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2],
stg.lin_reg[0] *
stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2] +
stg.lin_reg[1],
linestyle="dashed", linewidth=1, color="b")
else: # --- Plot result of linear regression ---
self.axis_FCB.plot(
depth_data[data_id][fcb_id, value1:value2],
stg.lin_reg[0]
* depth_data[data_id][fcb_id, value1:value2]
+ stg.lin_reg[1],
linestyle="dashed", linewidth=1, color="b"
)
# --- Select depth corresponding to the FCB profile where value are not NaN --- self.fig_FCB.canvas.draw_idle()
x0 = stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), :]
x = x0[np.where(np.isnan(y0) == False)]
# --- Find the indices of the values between which the linear regression is fitted --- # --- Display the value of alphaS compute with FCB ---
value1 = np.where(np.round(np.abs(x - float(self.lineEdit_FCB_from.text().replace(',','.'))), 2) == self.label_alphaS_FCB.clear()
np.min(np.round(np.abs(x - float(self.lineEdit_FCB_from.text().replace(',','.'))), 2)))[0][0] self.label_alphaS_FCB.setText(
value2 = np.where(np.round(np.abs(x - float(self.lineEdit_FCB_to.text().replace(',', '.'))), 2) == f"&alpha;<sub>s</sub> = {-0.5*stg.lin_reg[0]:.4f} dB/m"
np.min(np.round(np.abs(x - float(self.lineEdit_FCB_to.text().replace(',', '.'))), 2)))[0][0] )
lin_reg_compute = linregress(x[value1:value2], y[value1:value2])
stg.lin_reg.clear()
stg.lin_reg = [lin_reg_compute.slope, lin_reg_compute.intercept]
# --- Plot result of linear regression ---
self.axis_FCB.plot(
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2],
stg.lin_reg[0] *
stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
self.combobox_frequency_FCB.currentIndex(), value1:value2] +
stg.lin_reg[1],
linestyle="dashed", linewidth=1, color="b")
self.fig_FCB.canvas.draw_idle()
# --- Display the value of alphaS compute with FCB ---
self.label_alphaS_FCB.clear()
self.label_alphaS_FCB.setText(f"&alpha;<sub>s</sub> = {-0.5*stg.lin_reg[0]:.4f} dB/m")
def slider_profile_number_to_begin_FCB(self): def slider_profile_number_to_begin_FCB(self):
self.slider_FCB.setValue(int(self.slider_FCB.minimum())) self.slider_FCB.setValue(int(self.slider_FCB.minimum()))