Acoustic data: Some refactoring.

dev
Pierre-Antoine 2025-04-23 11:40:58 +02:00
parent 2ad980248d
commit 99103bc98a
1 changed files with 262 additions and 130 deletions

View File

@ -1396,7 +1396,6 @@ class AcousticDataTab(QWidget):
self.open_acoustic_data()
@trace
def open_acoustic_data(self):
# --- Fill lineEdit with path and file names + load acoustic data ---
# --- fill date, hour and measurements information + fill frequency combobox for bottom detection ---
@ -2168,209 +2167,344 @@ class AcousticDataTab(QWidget):
if self.fileListWidget.currentRow() == -1:
return
file_id = self.fileListWidget.currentRow()
data_id = self.fileListWidget.currentRow()
tmin_indice = np.where(
np.abs(
stg.time[file_id][0, :] - np.nanmin(stg.time[file_id][0, :])
stg.time[data_id][0, :] - np.nanmin(stg.time[data_id][0, :])
) == np.nanmin(
np.abs(
stg.time[file_id][0, :]
- np.nanmin(stg.time[file_id][0, :])
stg.time[data_id][0, :]
- np.nanmin(stg.time[data_id][0, :])
)
)
)[0][0]
tmin_value = np.round(
np.nanmin(stg.time[file_id][0, :]), 2
np.nanmin(stg.time[data_id][0, :]), 2
)
stg.tmin[file_id] = (tmin_indice, tmin_value)
stg.tmin[data_id] = (tmin_indice, tmin_value)
tmax_indice = np.where(
np.abs(
stg.time[file_id][0, :] - np.nanmax(stg.time[file_id][0, :])
stg.time[data_id][0, :] - np.nanmax(stg.time[data_id][0, :])
) == np.nanmin(
np.abs(
stg.time[file_id][0, :]
- np.nanmax(stg.time[file_id][0, :])
stg.time[data_id][0, :]
- np.nanmax(stg.time[data_id][0, :])
)
)
)[0][0]
tmax_value = np.round(np.nanmax(stg.time[file_id][0, :]), 2)
stg.tmax[file_id] = (tmax_indice + 1, tmax_value)
tmax_value = np.round(np.nanmax(stg.time[data_id][0, :]), 2)
stg.tmax[data_id] = (tmax_indice + 1, tmax_value)
self.set_range_for_time_boundaries_option()
def set_range_for_time_boundaries_option(self):
data_id = self.fileListWidget.currentRow()
self.label_time_min.clear()
self.label_time_min.setText("%.5s" % str(stg.time[self.fileListWidget.currentRow()][0, 0]))
self.label_time_min.setText(
f"{stg.time[data_id][0, 0]:.1f}"
)
self.label_time_max.clear()
self.label_time_max.setText("%.5s" % str(stg.time[self.fileListWidget.currentRow()][0, -1]))
if stg.time_cross_section[self.fileListWidget.currentRow()].shape != (0,):
self.lineEdit_time_min_limits.setText("%.5s" % str(stg.time_cross_section[self.fileListWidget.currentRow()][0, 0]))
self.lineEdit_time_max_limits.setText("%.5s" % str(stg.time_cross_section[self.fileListWidget.currentRow()][0, -1]))
self.label_time_max.setText(
f"{stg.time[data_id][0, -1]:.1f}"
)
if stg.time_cross_section[data_id].shape != (0,):
self.lineEdit_time_min_limits.setText(
f"{stg.time_cross_section[data_id][0, 0]:.1f}"
)
self.lineEdit_time_max_limits.setText(
f"{stg.time_cross_section[data_id][0, -1]:.1f}"
)
else:
self.lineEdit_time_min_limits.setText("%.5s" % str(stg.time[self.fileListWidget.currentRow()][0, 0]))
self.lineEdit_time_max_limits.setText("%.5s" % str(stg.time[self.fileListWidget.currentRow()][0, -1]))
self.lineEdit_time_min_limits.setText(
f"{stg.time[data_id][0, 0]:.1f}"
)
self.lineEdit_time_max_limits.setText(
f"{stg.time[data_id][0, -1]:.1f}"
)
def compute_time_cross_section(self):
''' tmin and tmax are updated with double slider of time '''
data_id = max(0, self.fileListWidget.currentRow())
time_min = float(self.lineEdit_time_min_limits.text().replace(",", "."))
time_max = float(self.lineEdit_time_max_limits.text().replace(",", "."))
stg.tmin[self.fileListWidget.currentRow()] = ((
np.where(np.abs(np.round(stg.time[self.fileListWidget.currentRow()][0, :], 2) -
float(self.lineEdit_time_min_limits.text().replace(",", "."))) ==
np.nanmin(np.abs(np.round(stg.time[self.fileListWidget.currentRow()][0, :],
2) - float(self.lineEdit_time_min_limits.text().replace(",", ".")))))[0][0],
float(self.lineEdit_time_min_limits.text().replace(",", "."))
stg.tmin[data_id] = ((
np.where(
np.abs(
np.round(
stg.time[data_id][0, :], 2
) - time_min
) == np.nanmin(
np.abs(
np.round(
stg.time[data_id][0, :], 2
) - time_min
)
)
)[0][0],
time_min
))
stg.tmax[self.fileListWidget.currentRow()] = ((
np.where(np.abs(np.round(stg.time[self.fileListWidget.currentRow()][0, :], 2) -
float(self.lineEdit_time_max_limits.text().replace(",", "."))) ==
np.nanmin(np.abs(np.round(stg.time[self.fileListWidget.currentRow()][0, :],
2) - float(self.lineEdit_time_max_limits.text().replace(",", ".")))))[0][0]+1,
float(self.lineEdit_time_max_limits.text().replace(",", "."))
stg.tmax[data_id] = ((
np.where(
np.abs(
np.round(
stg.time[data_id][0, :], 2)
- time_max
) == np.nanmin(
np.abs(
np.round(
stg.time[data_id][0, :],2)
- time_max
)
)
)[0][0] + 1,
time_max
))
stg.time_cross_section[self.fileListWidget.currentRow()] = (
stg.time[self.fileListWidget.currentRow()][:, stg.tmin[self.fileListWidget.currentRow()][0]:
stg.tmax[self.fileListWidget.currentRow()][0]]
stg.time_cross_section[data_id] = (
stg.time[data_id][
:, stg.tmin[data_id][0]: stg.tmax[data_id][0]
]
)
def compute_rmin_rmax(self):
''' rmin and rmax are filled with min and max of depth when data are uploaded and
double slider of depth are updated with these values '''
if self.fileListWidget.currentRow() != -1:
if self.fileListWidget.currentRow() == -1:
return
data_id = self.fileListWidget.currentRow()
# --- rmim / rmax ---
rmin_indice = np.where(np.abs(stg.depth[self.fileListWidget.currentRow()][0, :] - np.nanmin(
stg.depth[self.fileListWidget.currentRow()][0, :])) ==
np.nanmin(np.abs(stg.depth[self.fileListWidget.currentRow()][0, :] - np.nanmin(
stg.depth[self.fileListWidget.currentRow()][0, :]))))[0][0]
rmin_value = np.round(np.nanmin(stg.depth[self.fileListWidget.currentRow()][0, :]), 2)
stg.rmin[self.fileListWidget.currentRow()] = (rmin_indice, rmin_value)
rmin_indice = np.where(
np.abs(
stg.depth[data_id][0, :] - np.nanmin(stg.depth[data_id][0, :])
) == np.nanmin(
np.abs(
stg.depth[data_id][0, :]
- np.nanmin(stg.depth[data_id][0, :])
)
)
)[0][0]
rmax_indice = np.where(np.abs(stg.depth[self.fileListWidget.currentRow()][0, :] - np.nanmax(
stg.depth[self.fileListWidget.currentRow()][0, :])) ==
np.nanmin(np.abs(stg.depth[self.fileListWidget.currentRow()][0, :] - np.nanmax(
stg.depth[self.fileListWidget.currentRow()][0, :]))))[0][0]
rmax_value = np.round(np.nanmax(stg.depth[self.fileListWidget.currentRow()][0, :]), 2)
stg.rmax[self.fileListWidget.currentRow()] = (rmax_indice + 1, rmax_value)
rmin_value = np.round(np.nanmin(stg.depth[data_id][0, :]), 2)
stg.rmin[data_id] = (rmin_indice, rmin_value)
rmax_indice = np.where(
np.abs(
stg.depth[data_id][0, :] - np.nanmax(stg.depth[data_id][0, :])
) == np.nanmin(
np.abs(
stg.depth[data_id][0, :]
- np.nanmax(stg.depth[data_id][0, :])
)
)
)[0][0]
rmax_value = np.round(np.nanmax(stg.depth[data_id][0, :]), 2)
stg.rmax[data_id] = (rmax_indice + 1, rmax_value)
self.set_range_for_depth_boundaries_option()
def set_range_for_depth_boundaries_option(self):
data_id = self.fileListWidget.currentRow()
self.label_depth_min.clear()
self.label_depth_min.setText("-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, -1]))
self.label_depth_min.setText("-" + str("%.5s" % stg.depth[data_id][0, -1]))
self.label_depth_max.clear()
self.label_depth_max.setText("-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, 0]))
if stg.depth_cross_section[self.fileListWidget.currentRow()].shape != (0,):
self.lineEdit_depth_min_limits.setText("-" + str("%.5s" % stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1]))
self.lineEdit_depth_max_limits.setText("-" + str("%.5s" % stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0]))
self.label_depth_max.setText("-" + str("%.5s" % stg.depth[data_id][0, 0]))
if stg.depth_cross_section[data_id].shape != (0,):
self.lineEdit_depth_min_limits.setText(
"-" + str("%.5s" % stg.depth_cross_section[data_id][0, -1])
)
self.lineEdit_depth_max_limits.setText(
"-" + str("%.5s" % stg.depth_cross_section[data_id][0, 0])
)
else:
self.lineEdit_depth_min_limits.setText("-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, -1]))
self.lineEdit_depth_max_limits.setText("-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, 0]))
self.lineEdit_depth_min_limits.setText(
"-" + str("%.5s" % stg.depth[data_id][0, -1])
)
self.lineEdit_depth_max_limits.setText(
"-" + str("%.5s" % stg.depth[data_id][0, 0])
)
def compute_depth_cross_section(self):
''' rmin and rmax are updated with double slider of depth '''
data_id = self.fileListWidget.currentRow()
stg.rmin[self.fileListWidget.currentRow()] = ((
np.where(np.abs(np.round(stg.depth[self.fileListWidget.currentRow()][0, :], 2) -
float("".join(findall("[.0-9]", self.lineEdit_depth_max_limits.text())))) ==
np.nanmin(np.abs(np.round(stg.depth[self.fileListWidget.currentRow()][0, :],
2) - (float("".join(findall("[.0-9]", self.lineEdit_depth_max_limits.text()))))
)))[0][0]+1,
float("".join(findall("[.0-9]", self.lineEdit_depth_max_limits.text())))
stg.rmin[data_id] = ((
np.where(
np.abs(
np.round(
stg.depth[data_id][0, :], 2
) - float(
"".join(
findall(
"[.0-9]",
self.lineEdit_depth_max_limits.text()
)
)
)
) == np.nanmin(
np.abs(
np.round(stg.depth[data_id][0, :], 2)
- float(
"".join(
findall(
"[.0-9]",
self.lineEdit_depth_max_limits.text()
)
)
)
)
)
)[0][0]+1,
float(
"".join(
findall(
"[.0-9]",
self.lineEdit_depth_max_limits.text()
)
)
)
))
stg.rmax[self.fileListWidget.currentRow()] = ((
np.where(np.abs(np.round(stg.depth[self.fileListWidget.currentRow()][0, :], 2) -
float("".join(findall("[.0-9]", self.lineEdit_depth_min_limits.text())))) ==
np.nanmin(np.abs(np.round(stg.depth[self.fileListWidget.currentRow()][0, :],
2) - (float("".join(findall("[.0-9]", self.lineEdit_depth_min_limits.text()))))
)))[0][0],
float("".join(findall("[.0-9]", self.lineEdit_depth_min_limits.text())))
stg.rmax[data_id] = ((
np.where(
np.abs(
np.round(
stg.depth[data_id][0, :], 2
) - float(
"".join(
findall(
"[.0-9]",
self.lineEdit_depth_min_limits.text()
)
)
)
) == np.nanmin(
np.abs(
np.round(stg.depth[data_id][0, :], 2)
- float(
"".join(
findall(
"[.0-9]",
self.lineEdit_depth_min_limits.text()
)
)
)
)
)
)[0][0],
float(
"".join(
findall(
"[.0-9]",
self.lineEdit_depth_min_limits.text()
)
)
)
))
stg.depth_cross_section[self.fileListWidget.currentRow()] = (
stg.depth[self.fileListWidget.currentRow()][:,
stg.rmin[self.fileListWidget.currentRow()][0]:stg.rmax[self.fileListWidget.currentRow()][0]]
stg.depth_cross_section[data_id] = (
stg.depth[data_id][:,
stg.rmin[data_id][0]:stg.rmax[data_id][0]]
)
def compute_BS_cross_section(self):
if self.fileListWidget.currentRow() != -1:
if self.fileListWidget.currentRow() == -1:
return
data_id = self.fileListWidget.currentRow()
self.compute_depth_cross_section()
self.compute_time_cross_section()
stg.BS_cross_section[self.fileListWidget.currentRow()] = (
stg.BS_raw_data[self.fileListWidget.currentRow()]
[:, stg.rmin[self.fileListWidget.currentRow()][0]:stg.rmax[self.fileListWidget.currentRow()][0],
stg.tmin[self.fileListWidget.currentRow()][0]:stg.tmax[self.fileListWidget.currentRow()][0]])
stg.BS_cross_section[data_id] = (
stg.BS_raw_data[data_id][
:,
stg.rmin[data_id][0]:stg.rmax[data_id][0],
stg.tmin[data_id][0]:stg.tmax[data_id][0]
]
)
def update_frequency_combobox(self):
if self.fileListWidget.currentRow() != -1:
data_id = self.fileListWidget.currentRow()
if data_id == -1:
return
self.combobox_frequency_bathymetry.clear()
self.combobox_frequency_bathymetry.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]])
self.combobox_frequency_bathymetry.addItems(
[f for f in stg.freq_text[data_id]]
)
self.combobox_frequency_profile.clear()
self.combobox_frequency_profile.addItems([f for f in stg.freq_text[self.fileListWidget.currentRow()]])
self.combobox_frequency_profile.addItems(
[f for f in stg.freq_text[data_id]]
)
def set_range_for_doubleRangeSlider_intg_area(self):
if self.fileListWidget.currentRow() != -1:
if self.fileListWidget.currentRow() == -1:
return
if stg.depth_cross_section[self.fileListWidget.currentRow()].shape == (0,):
data_id = self.fileListWidget.currentRow()
if stg.depth_cross_section[data_id].shape == (0,):
self.doubleRangeSlider_intg_area.setRange(
min=-stg.depth[self.fileListWidget.currentRow()][0, -1],
max=-stg.depth[self.fileListWidget.currentRow()][0, 0])
min=-stg.depth[data_id][0, -1],
max=-stg.depth[data_id][0, 0]
)
self.doubleRangeSlider_intg_area.setValue(
value=(-stg.depth[self.fileListWidget.currentRow()][0, -1],
-stg.depth[self.fileListWidget.currentRow()][0, 0]))
value=(
-stg.depth[data_id][0, -1],
-stg.depth[data_id][0, 0]
)
)
else:
self.doubleRangeSlider_intg_area.setRange(
min=-stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1],
max=-stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0])
min=-stg.depth_cross_section[data_id][0, -1],
max=-stg.depth_cross_section[data_id][0, 0]
)
self.doubleRangeSlider_intg_area.setValue(
value=(-stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1],
-stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0]))
value=(
-stg.depth_cross_section[data_id][0, -1],
-stg.depth_cross_section[data_id][0, 0]
)
)
def set_range_for_spinboxes_bathymetry(self):
if self.fileListWidget.currentRow() != -1:
if self.fileListWidget.currentRow() == -1:
return
if stg.depth_cross_section[self.fileListWidget.currentRow()].shape != (0,):
data_id = self.fileListWidget.currentRow()
# self.spinbox_depth_min_bathy.setValue(stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0])
if stg.depth_cross_section[data_id].shape != (0,):
self.lineEdit_depth_min_bathy.setText(
"-" + str("%.5s" % stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1]))
# self.spinbox_depth_max_bathy.setValue(stg.depth_cross_section[self.fileListWidget.currentRow()][0, -1])
"-" + str("%.5s" % stg.depth_cross_section[data_id][0, -1])
)
self.lineEdit_depth_max_bathy.setText(
"-" + str("%.5s" % stg.depth_cross_section[self.fileListWidget.currentRow()][0, 0]))
"-" + str("%.5s" % stg.depth_cross_section[data_id][0, 0])
)
else:
self.lineEdit_depth_min_bathy.setText(
"-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, -1]))
"-" + str("%.5s" % stg.depth[data_id][0, -1])
)
self.lineEdit_depth_max_bathy.setText(
"-" + str("%.5s" % stg.depth[self.fileListWidget.currentRow()][0, 0]))
"-" + str("%.5s" % stg.depth[data_id][0, 0])
)
def plot_backscattered_acoustic_signal_recording(self):
if self.fileListWidget.count() <= 0:
@ -2466,7 +2600,7 @@ class AcousticDataTab(QWidget):
msgBox.exec()
return
data_id = self.fileListWidget.currentRow()
data_id = max(0, self.fileListWidget.currentRow())
if data_id == -1:
return
@ -2756,8 +2890,6 @@ class AcousticDataTab(QWidget):
float(self.lineEdit_slider.text().replace(",", ".")))))[0][0]))
def update_lineEdit_by_moving_slider(self):
print("min ", np.nanmin(stg.time[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex()]))
print("max ", np.nanmax(stg.time[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex()]))
if stg.time_cross_section[self.fileListWidget.currentRow()].shape != (0,):
self.lineEdit_slider.setText(
str(stg.time_cross_section[self.fileListWidget.currentRow()][self.combobox_frequency_profile.currentIndex(), self.slider.value()-1]))
@ -2815,7 +2947,7 @@ class AcousticDataTab(QWidget):
self.detect_bottom_compute()
def detect_bottom_compute(self):
data_id = self.fileListWidget.currentRow()
data_id = max(0, self.fileListWidget.currentRow())
freq_id = self.combobox_frequency_bathymetry.currentIndex()
freq_text = self.combobox_frequency_bathymetry.currentText()
@ -2950,7 +3082,7 @@ class AcousticDataTab(QWidget):
def detect_bottom_compute_plot_BS_with_bathymetry(
self, BS_data, time_data, depth_data
):
data_id = self.fileListWidget.currentRow()
data_id = max(0, self.fileListWidget.currentRow())
freq_id = self.combobox_frequency_bathymetry.currentIndex()
for f, _ in enumerate(stg.freq[data_id]):