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