edit spectra should now work better; closes #152

This commit is contained in:
Dominik Demuth 2023-11-22 17:48:08 +01:00
parent dfe9eab817
commit 929bb80f2f
3 changed files with 57 additions and 38 deletions

View File

@ -76,38 +76,24 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
self.pivot_lineedit.textEdited.connect(lambda x: self.pvt_line.setValue(float(x)))
def add_data(self: QPreviewDialog, data: FID | Spectrum) -> bool:
if isinstance(data, FID):
if self._all_freq:
msg = QtWidgets.QMessageBox.warning(self, 'Mixed types',
'Timesignals and spectra cannot be edited at the same time.')
return False
else:
self._all_time = True
self._all_freq = False
valid, (real_plt, imag_plt, real_plt_fft, imag_plt_fft) = self._prep_time(data)
elif isinstance(data, Spectrum):
if self._all_time:
msg = QtWidgets.QMessageBox.warning(self, 'Mixed types',
'Timesignals and spectra cannot be edited at the same time.')
return False
else:
self._all_time = False
self._all_freq = True
valid, (real_plt, imag_plt, real_plt_fft, imag_plt_fft) = self._prep_freq(data)
fid = data.copy()
spec = self._temp_fft_time(fid.x, fid.y, self.baseline_box.isChecked())
else:
return False
if not valid:
return False
x_len = data.x.size
self.zf_spinbox.setMaximum(min(2**17//x_len, 3))
real_plt = PlotItem(x=fid.x, y=fid.y.real, pen=mkPen('b'))
imag_plt = PlotItem(x=fid.x, y=fid.y.imag, pen=mkPen('r'))
self.time_graph.addItem(imag_plt)
self.time_graph.addItem(real_plt)
real_plt_fft = PlotItem(x=spec[0], y=spec[1].real, pen=mkPen('b'))
imag_plt_fft = PlotItem(x=spec[0], y=spec[1].imag, pen=mkPen('r'))
self.freq_graph.addItem(imag_plt_fft)
self.freq_graph.addItem(real_plt_fft)
@ -118,12 +104,52 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
for p in [self._tmp_data_zf, self._tmp_data_ap]:
p.append((data.x, data.y.copy()))
self._tmp_data_ph.append((data.x, data.y, spec[0], spec[1]))
self.graphs.append((real_plt, imag_plt, real_plt_fft, imag_plt_fft))
return True
def _prep_time(self, data) -> tuple[bool, tuple]:
if self._all_freq:
_ = QtWidgets.QMessageBox.warning(self, 'Mixed types',
'Time signals and spectra cannot be edited at the same time.')
return False, tuple()
fid = data.copy()
spec = self._temp_fft_time(fid.x, fid.y, self.baseline_box.isChecked())
self._all_time = True
self._all_freq = False
real_plt = PlotItem(x=fid.x, y=fid.y.real, pen=mkPen('b'))
imag_plt = PlotItem(x=fid.x, y=fid.y.imag, pen=mkPen('r'))
real_plt_fft = PlotItem(x=spec[0], y=spec[1].real, pen=mkPen('b'))
imag_plt_fft = PlotItem(x=spec[0], y=spec[1].imag, pen=mkPen('r'))
self._tmp_data_ph.append((data.x, data.y, spec[0], spec[1]))
return True, (real_plt, imag_plt, real_plt_fft, imag_plt_fft)
def _prep_freq(self, data) -> tuple[bool, tuple]:
if self._all_time:
_ = QtWidgets.QMessageBox.warning(self, 'Mixed types',
'Time signals and spectra cannot be edited at the same time.')
return False, tuple()
spec = data.copy()
fid = self._temp_fft_time(spec.x, spec.y, self.baseline_box.isChecked())
self._all_time = False
self._all_freq = True
real_plt = PlotItem(x=fid[0], y=fid[1].real, pen=mkPen('b'))
imag_plt = PlotItem(x=fid[0], y=fid[1].imag, pen=mkPen('r'))
real_plt_fft = PlotItem(x=spec.x, y=spec.y.real, pen=mkPen('b'))
imag_plt_fft = PlotItem(x=spec.x, y=spec.y.imag, pen=mkPen('r'))
self._tmp_data_ph.append((data.x, data.y, spec.x, spec.y))
return True, (real_plt, imag_plt, real_plt_fft, imag_plt_fft)
@QtCore.pyqtSlot(name='on_baseline_box_clicked')
def _update_bl(self):
if self.baseline_box.isChecked():
@ -200,7 +226,7 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
ph1 = self.ph1_spinbox.value()
for i, (x, y) in enumerate(self._tmp_data_ap):
x_fft, y_fft = self._temp_fft_time(x, y, self.baseline_box.isChecked())
x_fft, y_fft = self._temp_fft(x, y, self.baseline_box.isChecked())
if ph0 != 0:
y = self._temp_phase(x, y, ph0, 0, 0)
@ -213,7 +239,7 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
else:
self.pvt_line.hide()
for i, (x, y) in enumerate(self._tmp_data_ap):
self._tmp_data_ph[i] = x, y, *self._temp_fft_time(x, y, self.baseline_box.isChecked())
self._tmp_data_ph[i] = x, y, *self._temp_fft(x, y, self.baseline_box.isChecked())
self._update_plots()
@ -346,7 +372,6 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
self.data = []
self.graphs = []
self.freq_graph.removeItem(self.pvt_line)
self.time_graph.removeItem(self.pvt_line)
self.blockSignals(False)
@ -395,6 +420,9 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
self.time_graph.setVisible(self._all_time)
self.logtime_widget.setVisible(self._all_time)
self._temp_baseline = self._temp_baseline_time if self._all_time else self._temp_baseline_freq
self._temp_fft = self._temp_fft_time if self._all_time else self._temp_fft_freq
@QtCore.pyqtSlot(int, name='on_logx_time_stateChanged')
@QtCore.pyqtSlot(int, name='on_logy_time_stateChanged')
@QtCore.pyqtSlot(int, name='on_logx_freq_stateChanged')
@ -414,14 +442,3 @@ class QPreviewDialog(QtWidgets.QDialog, Ui_ApodEdit):
vb = self.time_graph.getPlotItem().getViewBox()
vb.disableAutoRange(axis=vb.YAxis)
self._temp_baseline = self._temp_baseline_time if self._all_time else self._temp_baseline_freq
self._temp_fft = self._temp_fft_time if self._all_time else self._temp_fft_freq
self.freq_graph.setVisible(self._all_time)
if self._all_freq:
self.time_graph.addItem(self.pvt_line)
else:
self.freq_graph.addItem(self.pvt_line)

View File

@ -383,6 +383,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
for line in self.ptsselectwidget.pts_lines:
self.current_graph_widget.remove_external(line)
# TODO: removing tabs creates an unholy mess because it calls toggle_tabs
self.tabWidget.removeTab(self.tabWidget.indexOf(self.ptsselectwidget))
if self.t1tauwidget.connected_figure == gid:
@ -400,6 +401,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
self.current_graph_widget.remove_external(self.valuewidget.selection_real)
self.current_graph_widget.remove_external(self.valuewidget.selection_imag)
self.tabWidget.setCurrentIndex(0)
self.valuewidget.connected_figure = None
self.current_graph_widget.enable_picking(False)