From 1bda848671ff85952dfd3b31117dc921420326ee Mon Sep 17 00:00:00 2001 From: brahim Date: Fri, 13 Oct 2023 15:25:09 +0200 Subject: [PATCH] Aquascat data are averaged with new shape of array (freq shape, r shape, t shape) --- View/signal_processing_tab.py | 139 ++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 55 deletions(-) diff --git a/View/signal_processing_tab.py b/View/signal_processing_tab.py index bf512f8..2902c2c 100644 --- a/View/signal_processing_tab.py +++ b/View/signal_processing_tab.py @@ -637,10 +637,10 @@ class SignalProcessingTab(QWidget): stg.BS_data_section = deepcopy(stg.BS_data) elif stg.r_bottom.size != 0: stg.BS_data_section = deepcopy(stg.BS_data) - for f in range(stg.freq.shape[0]): - for k in range(stg.r_bottom.shape[0]): + for f, _ in enumerate(stg.freq): + for k, _ in enumerate(stg.r_bottom): # print(k, np.where(stg.r >= stg.r_bottom[k])[0]) - stg.BS_data_section[np.where(stg.r >= stg.r_bottom[k])[0], f, k] = np.nan + stg.BS_data_section[f, np.where(stg.r[self.combobox_frequency.currentIndex(), :] >= stg.r_bottom[k])[0], k] = np.nan # --- Choose frequency (Combo box) to plot transect with profile position --- self.combobox_frequency.addItems(stg.freq_text) @@ -653,7 +653,7 @@ class SignalProcessingTab(QWidget): self.combobox_frequency_compute_alphaS.addItems(stg.freq_text) # --- Fix maximum value of slider + Edit Label Profile number --- - self.slider.setMaximum(stg.t.shape[0]) + self.slider.setMaximum(stg.t.shape[1]) self.label_profile_number.clear() self.label_profile_number.setText("Profile " + str(self.slider.value()) + " / " + str(self.slider.maximum())) @@ -680,13 +680,17 @@ class SignalProcessingTab(QWidget): msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec() else: - filter_convolve = np.ones(self.spinbox_average_horizontal.value()) - - stg.BS_data_section_averaged = np.zeros((stg.r.shape[0], stg.freq.shape[0], stg.t.shape[0])) - for f in range(stg.freq.shape[0]): - for i in range(stg.r.shape[0]): - stg.BS_data_section_averaged[i, f, :] \ - = convolve1d(stg.BS_data_section[i, f, :], weights=filter_convolve) / filter_convolve.shape[0] + filter_convolve = np.ones( self.spinbox_average_horizontal.value()) + print(filter_convolve) + # stg.BS_data_section_averaged = np.zeros((stg.r.shape[0], stg.freq.shape[0], stg.t.shape[0])) + # stg.BS_data_section_averaged = np.zeros((stg.freq.shape[0], stg.r.shape[1], stg.t.shape[1])) + stg.BS_data_section_averaged = deepcopy(stg.BS_data_section) + for f, _ in enumerate(stg.freq): + for i in range(stg.r.shape[1]): + stg.BS_data_section_averaged[f, i, :] \ + = convolve1d(stg.BS_data_section[f, i, :], weights=filter_convolve) / filter_convolve.shape[0] + # stg.BS_data_section_averaged[i, f, :] \ + # = convolve1d(stg.BS_data_section[i, f, :], weights=filter_convolve) / filter_convolve.shape[0] self.label_cells_horizontal.clear() self.label_cells_horizontal.setText( @@ -699,6 +703,19 @@ class SignalProcessingTab(QWidget): self.plot_averaged_profile() self.update_plot_profile_position_on_transect() + # fig, ax = plt.subplots(nrows=1, ncols=1) + # val_min = np.nanmin(stg.BS_data_section_averaged[self.combobox_frequency.currentIndex(), :, :]) + # val_max = np.nanmax(stg.BS_data_section_averaged[self.combobox_frequency.currentIndex(), :, :]) + # if val_min == 0: + # val_min = 1e-5 + # + # ax.pcolormesh(stg.t[self.combobox_frequency.currentIndex(), :], + # -stg.r[self.combobox_frequency.currentIndex(), :], + # stg.BS_data_section_averaged[self.combobox_frequency.currentIndex(), :, :], + # cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) + # + # plt.show() + # ---------------------------------------- Connect Groupbox filter with SNR ---------------------------------------- def remove_point_with_snr_filter(self): @@ -716,26 +733,26 @@ class SignalProcessingTab(QWidget): if stg.BS_data_section_averaged.size == 0: stg.BS_data_section_SNR_filter = deepcopy(stg.BS_data_section) stg.SNR_data_average = np.divide( - (stg.BS_data_section_SNR_filter - stg.Noise_data[:, :, :stg.t.shape[0]])**2, - stg.Noise_data[:, :, :stg.t.shape[0]]**2) + (stg.BS_data_section_SNR_filter - stg.Noise_data[:, :, :stg.t.shape[1]])**2, + stg.Noise_data[:, :, :stg.t.shape[1]]**2) - for f in range(stg.freq.shape[0]): - stg.BS_data_section_SNR_filter[np.where(stg.SNR_data_average[:, f, :] < self.spinbox_SNR_criterion.value())[0], - f, - np.where(stg.SNR_data_average[:, f, :] < self.spinbox_SNR_criterion.value())[1]] \ + for f, _ in enumerate(stg.freq): + stg.BS_data_section_SNR_filter[f, + np.where(stg.SNR_data_average[f, :, :] < self.spinbox_SNR_criterion.value())[0], + np.where(stg.SNR_data_average[f, :, :] < self.spinbox_SNR_criterion.value())[1]] \ = np.nan elif stg.BS_data_section_averaged.size != 0: stg.BS_data_section_SNR_filter = deepcopy(stg.BS_data_section_averaged) stg.SNR_data_average = np.divide( - (stg.BS_data_section_SNR_filter - stg.Noise_data[:, :, :stg.t.shape[0]]) ** 2, - stg.Noise_data[:, :, :stg.t.shape[0]] ** 2) + (stg.BS_data_section_SNR_filter - stg.Noise_data[:, :, :stg.t.shape[1]]) ** 2, + stg.Noise_data[:, :, :stg.t.shape[1]] ** 2) - for f in range(stg.freq.shape[0]): + for f in enumerate(stg.freq): stg.BS_data_section_SNR_filter[ - np.where(stg.SNR_data_average[:, f, :] < self.spinbox_SNR_criterion.value())[0], + np.where(stg.SNR_data_average[f, :, :] < self.spinbox_SNR_criterion.value())[0], f, - np.where(stg.SNR_data_average[:, f, :] < self.spinbox_SNR_criterion.value())[1]] \ + np.where(stg.SNR_data_average[f, :, :] < self.spinbox_SNR_criterion.value())[1]] \ = np.nan self.update_plot_profile_position_on_transect() @@ -895,21 +912,22 @@ class SignalProcessingTab(QWidget): self.verticalLayout_groupbox_display_profile_position.addWidget(self.canvas_plot_profile_position_on_transect) # --- Plot transect with profile position --- - val_min = np.nanmin(stg.BS_data_section[:, stg.freq_bottom_detection, :]) - val_max = np.nanmax(stg.BS_data_section[:, stg.freq_bottom_detection, :]) + val_min = np.nanmin(stg.BS_data_section[stg.freq_bottom_detection, :, :]) + val_max = np.nanmax(stg.BS_data_section[stg.freq_bottom_detection, :, :]) if val_min == 0: val_min = 1e-5 self.axis_plot_profile_position_on_transect.pcolormesh( - stg.t, -stg.r, stg.BS_data_section[:, stg.freq_bottom_detection, :], + stg.t[stg.freq_bottom_detection, :], -stg.r[stg.freq_bottom_detection, :], + stg.BS_data_section[stg.freq_bottom_detection, :, :], cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) if stg.r_bottom.size != 0: self.axis_plot_profile_position_on_transect.plot( - stg.t, -stg.r_bottom, color='black', linewidth=1, linestyle="solid") + stg.t[stg.freq_bottom_detection, :], -stg.r_bottom, color='black', linewidth=1, linestyle="solid") self.axis_plot_profile_position_on_transect.plot( - stg.t[self.slider.value() - 1] * np.ones(stg.r.shape[0]), -stg.r, + stg.t[stg.freq_bottom_detection, self.slider.value() - 1] * np.ones(stg.r.shape[1]), -stg.r[stg.freq_bottom_detection, :], color='red', linestyle="solid", linewidth=2) self.axis_plot_profile_position_on_transect.set_xticks([]) @@ -939,21 +957,24 @@ class SignalProcessingTab(QWidget): self.axis_plot_profile_position_on_transect.cla() - val_min = np.nanmin(stg.BS_data_section[:, self.combobox_frequency.currentIndex(), :]) - val_max = np.nanmax(stg.BS_data_section[:, self.combobox_frequency.currentIndex(), :]) + val_min = np.nanmin(stg.BS_data_section[self.combobox_frequency.currentIndex(), :, :]) + val_max = np.nanmax(stg.BS_data_section[self.combobox_frequency.currentIndex(), :, :]) if val_min == 0: val_min = 1e-5 self.axis_plot_profile_position_on_transect.pcolormesh( - stg.t, -stg.r, stg.BS_data_section[:, self.combobox_frequency.currentIndex(), :], + stg.t[self.combobox_frequency.currentIndex(), :], -stg.r[self.combobox_frequency.currentIndex(), :], + stg.BS_data_section[self.combobox_frequency.currentIndex(), :, :], cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) if stg.r_bottom.size != 0: - self.axis_plot_profile_position_on_transect.plot(stg.t, -stg.r_bottom, + self.axis_plot_profile_position_on_transect.plot(stg.t[self.combobox_frequency.currentIndex(), :], + -stg.r_bottom, color='black', linewidth=1, linestyle="solid") self.axis_plot_profile_position_on_transect.plot( - stg.t[self.slider.value()-1] * np.ones(stg.r.shape[0]), -stg.r, + stg.t[self.combobox_frequency.currentIndex(), self.slider.value()-1] * np.ones(stg.r.shape[1]), + -stg.r[self.combobox_frequency.currentIndex(), :], color='red', linestyle="solid", linewidth=2) self.axis_plot_profile_position_on_transect.set_xticks([]) @@ -965,21 +986,24 @@ class SignalProcessingTab(QWidget): self.axis_plot_profile_position_on_transect.cla() - val_min = np.nanmin(stg.BS_data_section_averaged[:, self.combobox_frequency.currentIndex(), :]) - val_max = np.nanmax(stg.BS_data_section_averaged[:, self.combobox_frequency.currentIndex(), :]) + val_min = np.nanmin(stg.BS_data_section_averaged[self.combobox_frequency.currentIndex(), :, :]) + val_max = np.nanmax(stg.BS_data_section_averaged[self.combobox_frequency.currentIndex(), :, :]) if val_min == 0: val_min = 1e-5 self.axis_plot_profile_position_on_transect.pcolormesh( - stg.t, -stg.r, stg.BS_data_section_averaged[:, self.combobox_frequency.currentIndex(), :], + stg.t[self.combobox_frequency.currentIndex(), :], -stg.r[self.combobox_frequency.currentIndex(), :], + stg.BS_data_section_averaged[self.combobox_frequency.currentIndex(), :, :], cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) if stg.r_bottom.size != 0: - self.axis_plot_profile_position_on_transect.plot(stg.t, -stg.r_bottom, + self.axis_plot_profile_position_on_transect.plot(stg.t[self.combobox_frequency.currentIndex(), :], + -stg.r_bottom, color='black', linewidth=1, linestyle="solid") self.axis_plot_profile_position_on_transect.plot( - stg.t[self.slider.value() - 1] * np.ones(stg.r.shape[0]), -stg.r, + stg.t[self.combobox_frequency.currentIndex(), self.slider.value() - 1] * np.ones(stg.r.shape[1]), + -stg.r[self.combobox_frequency.currentIndex(), :], color='red', linestyle="solid", linewidth=2) self.axis_plot_profile_position_on_transect.set_xticks([]) @@ -991,21 +1015,24 @@ class SignalProcessingTab(QWidget): self.axis_plot_profile_position_on_transect.cla() - val_min = np.nanmin(stg.BS_data_section_SNR_filter[:, self.combobox_frequency.currentIndex(), :]) - val_max = np.nanmax(stg.BS_data_section_SNR_filter[:, self.combobox_frequency.currentIndex(), :]) + val_min = np.nanmin(stg.BS_data_section_SNR_filter[self.combobox_frequency.currentIndex(), :, :]) + val_max = np.nanmax(stg.BS_data_section_SNR_filter[self.combobox_frequency.currentIndex(), :, :]) if val_min == 0: val_min = 1e-5 self.axis_plot_profile_position_on_transect.pcolormesh( - stg.t, -stg.r, stg.BS_data_section_SNR_filter[:, self.combobox_frequency.currentIndex(), :], + stg.t[self.combobox_frequency.currentIndex(), :], -stg.r[self.combobox_frequency.currentIndex(), :], + stg.BS_data_section_SNR_filter[self.combobox_frequency.currentIndex(), :, :], cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) if stg.r_bottom.size != 0: - self.axis_plot_profile_position_on_transect.plot(stg.t, -stg.r_bottom, + self.axis_plot_profile_position_on_transect.plot(stg.t[self.combobox_frequency.currentIndex(), :], + -stg.r_bottom, color='black', linewidth=1, linestyle="solid") self.axis_plot_profile_position_on_transect.plot( - stg.t[self.slider.value() - 1] * np.ones(stg.r.shape[0]), -stg.r, + stg.t[self.combobox_frequency.currentIndex(), self.slider.value() - 1] * np.ones(stg.r.shape[1]), + -stg.r[self.combobox_frequency.currentIndex(), :], color='red', linestyle="solid", linewidth=2) self.axis_plot_profile_position_on_transect.set_xticks([]) @@ -1030,9 +1057,9 @@ class SignalProcessingTab(QWidget): # self.scroll_profile.setAlignment(Qt.AlignCenter) # self.verticalLayout_groupbox_plot_profile.addWidget(self.scroll_profile) - for f in range(stg.freq.shape[0]): + for f, _ in enumerate(stg.freq): self.axis_profile[f].cla() - self.axis_profile[f].plot(stg.BS_data_section[:, f, self.slider.value() - 1], -stg.r, + self.axis_profile[f].plot(stg.BS_data_section[f, :, self.slider.value() - 1], -stg.r[f, :], linestyle='solid', color='k', linewidth=1) self.axis_profile[f].text(.95, .05, stg.freq_text[f], fontsize=10, fontweight='bold', fontname="Ubuntu", @@ -1091,9 +1118,9 @@ class SignalProcessingTab(QWidget): msgBox.exec() else: - for f in range(stg.freq.shape[0]): + for f, _ in enumerate(stg.freq): self.axis_profile[f].cla() - self.axis_profile[f].plot(stg.BS_data_section[:, f, self.slider.value() - 1], -stg.r, + self.axis_profile[f].plot(stg.BS_data_section[f, :, self.slider.value() - 1], -stg.r[f, :], linestyle='solid', color='k', linewidth=1) self.axis_profile[f].text(.95, .05, stg.freq_text[f], fontsize=10, fontweight='bold', fontname="Ubuntu", @@ -1109,11 +1136,11 @@ class SignalProcessingTab(QWidget): def plot_averaged_profile(self): - for f in range(stg.freq.shape[0]): + for f, _ in enumerate(stg.freq): self.axis_averaged_profile[f].cla() - self.axis_averaged_profile[f].plot(stg.BS_data_section_averaged[:, f, self.slider.value()-1], -stg.r, + self.axis_averaged_profile[f].plot(stg.BS_data_section_averaged[f, :, self.slider.value()-1], -stg.r[f, :], linestyle='solid', color='k', linewidth=1) - self.axis_averaged_profile[f].set_ylim(-np.max(stg.r), np.min(stg.r)) + self.axis_averaged_profile[f].set_ylim(-np.max(stg.r[f, :]), np.min(stg.r[f, :])) self.axis_averaged_profile[f].text(.95, .05, stg.freq_text[f], fontsize=10, fontweight='bold', fontname="Ubuntu", fontstyle="normal", c="black", alpha=0.2, @@ -1139,11 +1166,12 @@ class SignalProcessingTab(QWidget): else: if stg.BS_data_section_SNR_filter.size == 0: - for f in range(stg.freq.shape[0]): + for f, _ in enumerate(stg.freq): self.axis_averaged_profile[f].cla() - self.axis_averaged_profile[f].plot(stg.BS_data_section_averaged[:, f, self.slider.value() - 1], -stg.r, - linestyle='solid', color='k', linewidth=1) - self.axis_averaged_profile[f].set_ylim(-np.max(stg.r), np.min(stg.r)) + self.axis_averaged_profile[f].plot(stg.BS_data_section_averaged[f, :, self.slider.value() - 1], + -stg.r[f, :], + linestyle='solid', color='k', linewidth=1) + self.axis_averaged_profile[f].set_ylim(-np.max(stg.r[f, :]), np.min(stg.r[f, :])) self.axis_averaged_profile[f].text(.95, .05, stg.freq_text[f], fontsize=10, fontweight='bold', fontname="Ubuntu", fontstyle="normal", c="black", alpha=0.2, @@ -1158,9 +1186,10 @@ class SignalProcessingTab(QWidget): for f in range(stg.freq.shape[0]): self.axis_averaged_profile[f].cla() - self.axis_averaged_profile[f].plot(stg.BS_data_section_SNR_filter[:, f, self.slider.value() - 1], -stg.r, + self.axis_averaged_profile[f].plot(stg.BS_data_section_SNR_filter[f, :, self.slider.value() - 1], + -stg.r[f, :], linestyle='solid', color='k', linewidth=1) - self.axis_averaged_profile[f].set_ylim(-np.max(stg.r), np.min(stg.r)) + self.axis_averaged_profile[f].set_ylim(-np.max(stg.r[f, :]), np.min(stg.r[f, :])) self.axis_averaged_profile[f].text(.95, .05, stg.freq_text[f], fontsize=10, fontweight='bold', fontname="Ubuntu", fontstyle="normal", c="black", alpha=0.2,