Inversion: Some refactoring.

dev
Pierre-Antoine 2025-04-16 11:30:57 +02:00
parent 598635dca3
commit 0241f33109
1 changed files with 164 additions and 206 deletions

View File

@ -911,235 +911,193 @@ class AcousticInversionTab(QWidget):
) )
def update_lineEdit_by_moving_slider_fine(self): def update_lineEdit_by_moving_slider_fine(self):
if stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,): data_id = self.combobox_acoustic_data_choice.currentIndex()
self.lineEdit_slider_fine.setText(
str(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ if stg.time_cross_section[data_id].shape != (0,):
stg.frequency_for_inversion[1], self.slider_fine.value()])) time_data = stg.time_cross_section
else: else:
time_data = stg.time
self.lineEdit_slider_fine.setText( self.lineEdit_slider_fine.setText(
str(stg.time[self.combobox_acoustic_data_choice.currentIndex()][ str(
stg.frequency_for_inversion[1], self.slider_fine.value()])) time_data[data_id][
stg.frequency_for_inversion[1],
self.slider_fine.value()
]
)
)
# --- Plot fine SSC : measured vs inverted --- # --- Plot fine SSC : measured vs inverted ---
def fill_combobox_fine_sample(self): def fill_combobox_fine_sample(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
self.combobox_fine_sample_choice.addItems([f for f, _ in stg.sample_fine]) self.combobox_fine_sample_choice.addItems(
[f for f, _ in stg.sample_fine]
)
# --- Get position (index, value) of sample in acoustic measurement space --- # --- Get position (index, value) of sample in acoustic measurement space ---
if ((stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and if ((stg.time_cross_section[data_id].shape != (0,))
(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))): and (stg.depth_cross_section[data_id].shape != (0,))):
time_data = stg.time_cross_section
depth_data = stg.depth_cross_section
elif ((stg.time_cross_section[data_id].shape != (0,))
and (stg.depth[data_id].shape != (0,))):
time_data = stg.time_cross_section
depth_data = stg.depth
elif ((stg.time[data_id].shape != (0,))
and (stg.depth_cross_section[data_id].shape != (0,))):
time_data = stg.time
depth_data = stg.depth_cross_section
elif ((stg.time[data_id].shape != (0,))
and (stg.depth[data_id].shape != (0,))):
time_data = stg.time
depth_data = stg.depth
for j in range(len(stg.time_fine)): for j in range(len(stg.time_fine)):
stg.fine_sample_position\
(stg.fine_sample_position. .append(
append(
( (
np.where( np.where(
np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ np.abs(
stg.frequency_for_inversion[1]] - stg.time_fine[j]) time_data[data_id][
== stg.frequency_for_inversion[1]
np.nanmin(np.abs(stg.time_cross_section[ ] - stg.time_fine[j]
self.combobox_acoustic_data_choice.currentIndex()][ ) == np.nanmin(
stg.frequency_for_inversion[1]] - stg.time_fine[j])) np.abs(
time_data[data_id][
stg.frequency_for_inversion[1]
] - stg.time_fine[j]
)
)
)[0][0], )[0][0],
np.where( np.where(
np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][ np.abs(
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j])) depth_data[data_id][
== stg.frequency_for_inversion[1]
np.nanmin(np.abs(stg.depth_cross_section[ ] - (-stg.depth_fine[j]))
self.combobox_acoustic_data_choice.currentIndex()][ == np.nanmin(
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j]))) np.abs(
depth_data[data_id][
stg.frequency_for_inversion[1]
] - (-stg.depth_fine[j])
)
)
)[0][0] )[0][0]
) )
) )
)
elif ((stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and
(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))):
for j in range(len(stg.time_fine)):
(stg.fine_sample_position.
append(
(
np.where(
np.abs(stg.time_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - stg.time_fine[j])
==
np.nanmin(np.abs(stg.time_cross_section[
self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - stg.time_fine[j]))
)[0][0],
np.where(
np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j]))
==
np.nanmin(np.abs(stg.depth[
self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j])))
)[0][0]
)
)
)
elif ((stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and
(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))):
for j in range(len(stg.time_fine)):
(stg.fine_sample_position.
append(
(
np.where(
np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - stg.time_fine[j])
==
np.nanmin(np.abs(stg.time[
self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - stg.time_fine[j]))
)[0][0],
np.where(
np.abs(stg.depth_cross_section[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j]))
==
np.nanmin(np.abs(stg.depth_cross_section[
self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j])))
)[0][0]
)
)
)
elif ((stg.time[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,)) and
(stg.depth[self.combobox_acoustic_data_choice.currentIndex()].shape != (0,))):
for j in range(len(stg.time_fine)):
(stg.fine_sample_position.
append(
(
np.where(
np.abs(stg.time[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - stg.time_fine[j])
==
np.nanmin(np.abs(stg.time[
self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - stg.time_fine[j]))
)[0][0],
np.where(
np.abs(stg.depth[self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j]))
==
np.nanmin(np.abs(stg.depth[
self.combobox_acoustic_data_choice.currentIndex()][
stg.frequency_for_inversion[1]] - (-stg.depth_fine[j])))
)[0][0]
)
)
)
def plot_measured_vs_inverted_SSC_fine(self): def plot_measured_vs_inverted_SSC_fine(self):
data_id = self.combobox_acoustic_data_choice.currentIndex()
if self.combobox_acoustic_data_choice.count() > 0: if self.combobox_acoustic_data_choice.count() <= 0:
return
if stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()].shape == (0,): self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine\
.removeWidget(self.toolbar_inverted_vs_measured_SSC_fine)
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.removeWidget(self.toolbar_inverted_vs_measured_SSC_fine) self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine\
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.removeWidget(self.canvas_inverted_vs_measured_SSC_fine) .removeWidget(self.canvas_inverted_vs_measured_SSC_fine)
if stg.SSC_fine[data_id].shape == (0,):
self.canvas_inverted_vs_measured_SSC_fine = FigureCanvas() self.canvas_inverted_vs_measured_SSC_fine = FigureCanvas()
self.toolbar_inverted_vs_measured_SSC_fine = NavigationToolBar(self.canvas_inverted_vs_measured_SSC_fine, self) self.toolbar_inverted_vs_measured_SSC_fine = NavigationToolBar(
self.canvas_inverted_vs_measured_SSC_fine, self
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.addWidget(self.toolbar_inverted_vs_measured_SSC_fine) )
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.addWidget(self.canvas_inverted_vs_measured_SSC_fine)
else: else:
fig, ax = plt.subplots(nrows=1, ncols=1, layout="constrained")
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.removeWidget(self.toolbar_inverted_vs_measured_SSC_fine) self.figure_measured_vs_inverted_fine = fig
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.removeWidget(self.canvas_inverted_vs_measured_SSC_fine) self.axis_measured_vs_inverted_fine = ax
self.figure_measured_vs_inverted_fine, self.axis_measured_vs_inverted_fine = ( self.canvas_inverted_vs_measured_SSC_fine = FigureCanvas(
plt.subplots(nrows=1, ncols=1, layout="constrained")) self.figure_measured_vs_inverted_fine
)
self.toolbar_inverted_vs_measured_SSC_fine = NavigationToolBar(
self.canvas_inverted_vs_measured_SSC_fine, self
)
self.canvas_inverted_vs_measured_SSC_fine = FigureCanvas(self.figure_measured_vs_inverted_fine) self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine\
self.toolbar_inverted_vs_measured_SSC_fine = NavigationToolBar(self.canvas_inverted_vs_measured_SSC_fine, self) .addWidget(self.toolbar_inverted_vs_measured_SSC_fine)
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine\
.addWidget(self.canvas_inverted_vs_measured_SSC_fine)
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.addWidget(self.toolbar_inverted_vs_measured_SSC_fine) if stg.SSC_fine[data_id].shape == (0,):
self.verticalLayout_groupbox_plot_measured_vs_inverted_SSC_fine.addWidget(self.canvas_inverted_vs_measured_SSC_fine) fine_id = self.combobox_fine_sample_choice.currentData()
self.fine_sample_to_plot = [int(f[1:]) - 1 for f in self.combobox_fine_sample_choice.currentData()] self.fine_sample_to_plot = [
int(f[1:]) - 1 for f in fine_id
]
if self.fine_sample_to_plot: if self.fine_sample_to_plot:
fine_range = lambda : self.fine_sample_to_plot
else:
fine_range = lambda : range(len(stg.sample_fine))
self.axis_measured_vs_inverted_fine.plot( self.axis_measured_vs_inverted_fine.plot(
[stg.Ctot_fine[k] for k in self.fine_sample_to_plot], [stg.Ctot_fine[k] for k in fine_range()],
[stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][ [
stg.SSC_fine[data_id][
stg.fine_sample_position[k][1], stg.fine_sample_position[k][1],
stg.fine_sample_position[k][0]] for k in self.fine_sample_to_plot], stg.fine_sample_position[k][0]
] for k in fine_range()
],
ls=" ", marker='o', ms=5, mec='black', mfc="black" ls=" ", marker='o', ms=5, mec='black', mfc="black"
) )
self.axis_measured_vs_inverted_fine.plot( self.axis_measured_vs_inverted_fine.plot(
[0, np.nanmax([np.nanmax([stg.Ctot_fine[c] for c in self.fine_sample_to_plot]), [
np.nanmax([stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][ 0, np.nanmax(
[
np.nanmax(
[stg.Ctot_fine[c] for c in fine_range()]
),
np.nanmax(
[
stg.SSC_fine[data_id][
stg.fine_sample_position[i][1], stg.fine_sample_position[i][1],
stg.fine_sample_position[i][0]] stg.fine_sample_position[i][0]
for i in self.fine_sample_to_plot]) ]) + 1], ] for i in fine_range()
[0, np.nanmax([np.nanmax([stg.Ctot_fine[c] for c in self.fine_sample_to_plot]), ]
np.nanmax([stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][ )
]
) + 1
],
[
0, np.nanmax(
[
np.nanmax(
[stg.Ctot_fine[c] for c in fine_range()]
),
np.nanmax(
[
stg.SSC_fine[data_id][
stg.fine_sample_position[i][1], stg.fine_sample_position[i][1],
stg.fine_sample_position[i][0]] stg.fine_sample_position[i][0]
for i in self.fine_sample_to_plot])]) + 1], ] for i in fine_range()
]
)
]
) + 1
],
ls="solid", linewidth=1, color="k" ls="solid", linewidth=1, color="k"
) )
# --- Display sample label on plot --- # --- Display sample label on plot ---
for i in self.fine_sample_to_plot: for i in fine_range():
self.axis_measured_vs_inverted_fine.text( self.axis_measured_vs_inverted_fine.text(
stg.Ctot_fine[i], stg.Ctot_fine[i],
stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][ stg.SSC_fine[data_id][
stg.fine_sample_position[i][1], stg.fine_sample_position[i][1],
stg.fine_sample_position[i][0]], stg.fine_sample_position[i][0]
],
stg.sample_fine[i][0], stg.sample_fine[i][0],
fontstyle="normal", fontweight="light", fontsize=10) fontstyle="normal", fontweight="light", fontsize=10
else:
self.axis_measured_vs_inverted_fine.plot(
[stg.Ctot_fine[k] for k in range(len(stg.sample_fine))],
[stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][
stg.fine_sample_position[k][1],
stg.fine_sample_position[k][0]] for k in
range(len(stg.sample_fine))],
ls=" ", marker='o', ms=5, mec='black', mfc="black"
) )
self.axis_measured_vs_inverted_fine.plot( self.axis_measured_vs_inverted_fine\
[0, np.nanmax([np.nanmax([stg.Ctot_fine[c] for c in range(len(stg.sample_fine))]), .set_xlabel("Measured SSC fine (g/L)")
np.nanmax([stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][ self.axis_measured_vs_inverted_fine\
stg.fine_sample_position[i][1], .set_ylabel("Inverted SSC fine (g/L)")
stg.fine_sample_position[i][0]]
for i in range(len(stg.sample_fine))])]) + 1],
[0, np.nanmax([np.nanmax([stg.Ctot_fine[c] for c in range(len(stg.sample_fine))]),
np.nanmax([stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][
stg.fine_sample_position[i][1],
stg.fine_sample_position[i][0]]
for i in range(len(stg.sample_fine))])]) + 1],
ls="solid", linewidth=1, color="k"
)
for j in range(len(stg.sample_fine)):
self.axis_measured_vs_inverted_fine.text(
stg.Ctot_fine[j],
stg.SSC_fine[self.combobox_acoustic_data_choice.currentIndex()][
stg.fine_sample_position[j][1],
stg.fine_sample_position[j][0]],
stg.sample_fine[j][0],
fontstyle="normal", fontweight="light", fontsize=10)
self.axis_measured_vs_inverted_fine.set_xlabel("Measured SSC fine (g/L)")
self.axis_measured_vs_inverted_fine.set_ylabel("Inverted SSC fine (g/L)")
self.figure_measured_vs_inverted_fine.canvas.draw_idle() self.figure_measured_vs_inverted_fine.canvas.draw_idle()