Computing noise from a value is implemented in signal pre-processing tab.

dev-brahim
brahim 2024-02-14 17:06:52 +01:00
parent d9927d5868
commit 343fc27aec
1 changed files with 109 additions and 16 deletions

View File

@ -129,6 +129,19 @@ class SignalProcessingTab(QWidget):
self.groupbox_compute_noise_from_value = QGroupBox() self.groupbox_compute_noise_from_value = QGroupBox()
self.groupbox_compute_noise_from_value.setVisible(False) self.groupbox_compute_noise_from_value.setVisible(False)
self.gridLayout_compute_noise_from_value = QGridLayout(self.groupbox_compute_noise_from_value)
self.label_noise_value = QLabel()
self.label_noise_value.setText("Value : ")
self.gridLayout_compute_noise_from_value.addWidget(self.label_noise_value, 0, 0, 1, 1)
self.spinbox_compute_noise_from_value = QDoubleSpinBox()
self.gridLayout_compute_noise_from_value.addWidget(self.spinbox_compute_noise_from_value, 0, 1, 1, 1)
self.label_Volts = QLabel("Volts")
self.gridLayout_compute_noise_from_value.addWidget(self.label_Volts, 0, 2, 1, 1)
self.pushbutton_compute_noise_from_value = QPushButton()
self.pushbutton_compute_noise_from_value.setText("Apply noise")
self.gridLayout_compute_noise_from_value.addWidget(self.pushbutton_compute_noise_from_value, 0, 3, 1, 1)
self.pushbutton_compute_noise_from_value.clicked.connect(self.compute_noise_from_value)
self.verticalLayout_groupbox_study_data.addWidget(self.groupbox_compute_noise_from_value) self.verticalLayout_groupbox_study_data.addWidget(self.groupbox_compute_noise_from_value)
# +++++++++++++++++++++++++++++ # +++++++++++++++++++++++++++++
@ -1038,6 +1051,61 @@ class SignalProcessingTab(QWidget):
stg.SNR_reshape = np.reshape(stg.SNR_stream_bed, (stg.r.shape[1] * stg.t.shape[1], stg.freq.shape[0]), stg.SNR_reshape = np.reshape(stg.SNR_stream_bed, (stg.r.shape[1] * stg.t.shape[1], stg.freq.shape[0]),
order="F") order="F")
def compute_noise_from_value(self):
# --- Compute noise from value and compute SNR ---
if stg.BS_stream_bed.size == 0:
stg.time_snr = stg.t
if self.spinbox_compute_noise_from_value.value() == 0:
stg.BS_noise_raw_data = np.full(stg.BS_cross_section.shape,
self.spinbox_compute_noise_from_value.value())
print(f"stg.BS_noise_raw_data.shape : {stg.BS_noise_raw_data.shape}")
stg.SNR_cross_section = np.full(stg.BS_cross_section.shape, 1e3)
else:
stg.BS_noise_raw_data = np.full(stg.BS_cross_section.shape, self.spinbox_compute_noise_from_value.value())
stg.SNR_cross_section = np.divide((stg.BS_cross_section - stg.BS_noise_raw_data) ** 2,
stg.BS_noise_raw_data ** 2)
else:
stg.time_snr = stg.t
if self.spinbox_compute_noise_from_value.value() == 0:
stg.BS_noise_raw_data = np.full(stg.BS_stream_bed.shape,
self.spinbox_compute_noise_from_value.value())
stg.SNR_stream_bed = np.full(stg.BS_stream_bed.shape, 1e3)
else:
stg.BS_noise_raw_data = np.full(stg.BS_stream_bed.shape,
self.spinbox_compute_noise_from_value.value())
stg.SNR_stream_bed = np.divide((stg.BS_stream_bed - stg.BS_noise_raw_data) ** 2,
stg.BS_noise_raw_data ** 2)
# --- Trigger graphic widgets ---
self.combobox_freq_noise.addItems([f for f in stg.freq_text])
self.plot_noise()
self.plot_transect_with_SNR_data()
self.combobox_freq_noise.currentIndexChanged.connect(self.plot_noise)
self.spinbox_SNR_criterion.setValue(0)
self.remove_point_with_snr_filter()
self.combobox_frequency_profile.addItems([f for f in stg.freq_text])
self.combobox_frequency_profile.currentIndexChanged.connect(self.plot_profile_and_position_on_transect_with_slider)
self.slider.setMaximum(stg.t.shape[1])
self.compute_averaged_BS_data()
self.plot_profile_and_position_on_transect_with_slider()
def plot_noise(self): def plot_noise(self):
self.horizontalLayout_groupbox_plot_noise_data.removeWidget(self.canvas_noise) self.horizontalLayout_groupbox_plot_noise_data.removeWidget(self.canvas_noise)
@ -1048,13 +1116,27 @@ class SignalProcessingTab(QWidget):
val_min = np.nanmin(stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :]) val_min = np.nanmin(stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :])
val_max = np.nanmax(stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :]) val_max = np.nanmax(stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :])
if val_min == 0:
val_min = 1e-5
pcm = self.axis_noise.pcolormesh(stg.time_snr[0, :], print(f"0/ val_min for plot noise = {val_min}")
-stg.r[self.combobox_freq_noise.currentIndex(), :], print(f"0/ val_max for plot noise = {val_max}")
stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max)) if val_min == val_max:
pcm = self.axis_noise.pcolormesh(stg.time_snr[0, :],
-stg.r[self.combobox_freq_noise.currentIndex(), :],
stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :],
cmap='viridis')
else:
if val_min == 0:
val_min = 1e-5
pcm = self.axis_noise.pcolormesh(stg.time_snr[0, :],
-stg.r[self.combobox_freq_noise.currentIndex(), :],
stg.BS_noise_raw_data[self.combobox_freq_noise.currentIndex(), :, :],
cmap='viridis', norm=LogNorm(vmin=val_min, vmax=val_max))
self.axis_noise.tick_params(axis='both', which='minor', labelsize=10) self.axis_noise.tick_params(axis='both', which='minor', labelsize=10)
# cbar = self.fig_noise.colorbar(pcm, ax=self.axis_noise, shrink=1, location='top') # cbar = self.fig_noise.colorbar(pcm, ax=self.axis_noise, shrink=1, location='top')
@ -1067,7 +1149,8 @@ class SignalProcessingTab(QWidget):
def plot_transect_with_SNR_data(self): def plot_transect_with_SNR_data(self):
# --- Condition if table is not filled --- # --- Condition if table is not filled ---
if not self.lineEdit_noise_file.text(): # if not self.lineEdit_noise_file.text():
if stg.BS_noise_raw_data.size == 0:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.setWindowTitle("Plot transect Error") msgBox.setWindowTitle("Plot transect Error")
msgBox.setIcon(QMessageBox.Warning) msgBox.setIcon(QMessageBox.Warning)
@ -1075,7 +1158,8 @@ class SignalProcessingTab(QWidget):
msgBox.setStandardButtons(QMessageBox.Ok) msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec() msgBox.exec()
elif self.canvas_SNR == None: # elif self.canvas_SNR == None:
else:
self.fig_SNR, self.axis_SNR = plt.subplots(nrows=stg.freq.shape[0], ncols=1, sharex=True, sharey=False, layout='constrained') self.fig_SNR, self.axis_SNR = plt.subplots(nrows=stg.freq.shape[0], ncols=1, sharex=True, sharey=False, layout='constrained')
self.canvas_SNR = FigureCanvas(self.fig_SNR) self.canvas_SNR = FigureCanvas(self.fig_SNR)
@ -1097,12 +1181,16 @@ class SignalProcessingTab(QWidget):
val_min = np.nanmin(stg.SNR_cross_section[f, :, :]) val_min = np.nanmin(stg.SNR_cross_section[f, :, :])
val_max = np.nanmax(stg.SNR_cross_section[f, :, :]) val_max = np.nanmax(stg.SNR_cross_section[f, :, :])
if val_min == 0: if val_min == val_max:
val_min = 1e-5
if val_max > 1000:
levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6]) levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
else: else:
levels = np.array([00.1, 1, 2, 10, 100, val_max]) if val_min == 0:
val_min = 1e-5
if val_max > 1000:
levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
else:
levels = np.array([00.1, 1, 2, 10, 100, val_max])
bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2] bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
norm = BoundaryNorm(boundaries=bounds, ncolors=300) norm = BoundaryNorm(boundaries=bounds, ncolors=300)
@ -1112,12 +1200,17 @@ class SignalProcessingTab(QWidget):
val_min = np.nanmin(stg.SNR_stream_bed[f, :, :]) val_min = np.nanmin(stg.SNR_stream_bed[f, :, :])
val_max = np.nanmax(stg.SNR_stream_bed[f, :, :]) val_max = np.nanmax(stg.SNR_stream_bed[f, :, :])
if val_min == 0:
val_min = 1e-5 if val_min == val_max:
if val_max > 1000:
levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6]) levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
else: else:
levels = np.array([00.1, 1, 2, 10, 100, val_max]) if val_min == 0:
val_min = 1e-5
if val_max > 1000:
levels = np.array([00.1, 1, 2, 10, 100, 1000, 1e6])
else:
levels = np.array([00.1, 1, 2, 10, 100, val_max])
bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2] bounds = [00.1, 1, 2, 10, 100, 1000, val_max, val_max * 1.2]
norm = BoundaryNorm(boundaries=bounds, ncolors=300) norm = BoundaryNorm(boundaries=bounds, ncolors=300)