From 561c76f35baf1c8d89ec17efe725e74ee4b83f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Thu, 19 Nov 2026 17:41:31 +0100 Subject: [PATCH] enh: add the fluorescence baseline offset to the Quick View traces (#81) The baseline offset ([fluorescence]: "baseline N offset") is added to the trace data to obtain the actual signal (e.g. used for computing fl1_max), see dclab.definitions.meta_const. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG | 2 ++ dcscope/gui/quick_view/qv_main.py | 21 ++++++++++++++++--- tests/test_gui_quickview.py | 35 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7600cc2..3a269b6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,8 @@ were cut off in dropdown lists with the "Windows" style) (#194) - enh: show the current dataset and filter ray position in the title of the Quick View (#195) + - enh: add the fluorescence baseline offset ([fluorescence]: "baseline N + offset") to the traces shown in the Quick View (#81) - docs: add quick guide for fluorescence crosstalk correction (#120) - docs: screenshot scripts download missing datasets from figshare and use the icon theme of DCscope diff --git a/dcscope/gui/quick_view/qv_main.py b/dcscope/gui/quick_view/qv_main.py index d477e31..41dc275 100644 --- a/dcscope/gui/quick_view/qv_main.py +++ b/dcscope/gui/quick_view/qv_main.py @@ -461,6 +461,17 @@ def show_image(self, feat, view, data): view.setColorMap(cmap) self._last_cmap_pha[view] = cmap + def get_trace_baseline_offset(self, channel): + """Return the baseline offset of a fluorescence channel + + The offset is defined by the [fluorescence]: "baseline N offset" + configuration key (0 if not defined). + """ + if self.rtdc_ds is None: + return 0 + cfg_fl = self.rtdc_ds.config.get("fluorescence", {}) + return cfg_fl.get(f"baseline {channel} offset", 0) + def show_traces(self, tdata): state = self.read_pipeline_state() # remove legend items @@ -484,9 +495,13 @@ def show_traces(self, tdata): show = True flid = name.split("_")[0] if name in tdata and show and self.slot is not None: - range_fl[0] = min(range_fl[0], tdata[name].min()) - range_fl[1] = max(range_fl[1], tdata[name].max()) - self.trace_plots[name].setData(tdata["time"], tdata[name]) + # The baseline offset is added to the trace data to obtain + # the actual signal (e.g. used for computing fl1_max) (#81). + offset = self.get_trace_baseline_offset(channel=name[2]) + trace = np.asarray(tdata[name], dtype=float) + offset + range_fl[0] = min(range_fl[0], trace.min()) + range_fl[1] = max(range_fl[1], trace.max()) + self.trace_plots[name].setData(tdata["time"], trace) self.trace_plots[name].setVisible(True) if state["event"]["trace zoom"]: range_t[0] = min( diff --git a/tests/test_gui_quickview.py b/tests/test_gui_quickview.py index 59699c0..3bd2b90 100644 --- a/tests/test_gui_quickview.py +++ b/tests/test_gui_quickview.py @@ -1404,3 +1404,38 @@ def test_window_title_dataset_and_filter_issue_195(qtbot, mw): qtbot.waitUntil(lambda: qv.windowTitle() == title, timeout=5000) # also shown in the title bar of the MDI subwindow assert mw.subwindows["quick_view"].windowTitle() == title + + +def test_trace_baseline_offset_issue_81(qtbot, mw, tmp_path): + """The fluorescence baseline offset is added to the traces (#81)""" + path = tmp_path / "data.rtdc" + shutil.copy2(datapath / "calibration_beads_47.rtdc", path) + with h5py.File(path, "a") as h5: + h5.attrs["fluorescence:baseline 1 offset"] = 17 + qtbot.addWidget(mw) + mw.add_dataslot(paths=[path]) + + slot_id = mw.pipeline.slot_ids[0] + filt_id = mw.pipeline.filter_ids[0] + em = mw.ui.block_matrix.get_widget(slot_id, filt_id) + qtbot.mouseClick(em, QtCore.Qt.MouseButton.LeftButton) + qtbot.mouseClick(em, QtCore.Qt.MouseButton.LeftButton, + QtCore.Qt.KeyboardModifier.ShiftModifier) + qv = mw.widget_quick_view + qtbot.waitUntil(qv.isVisible, timeout=5000) + qtbot.mouseClick(qv.ui.toolButton_event, + QtCore.Qt.MouseButton.LeftButton) + + plot_fl1 = qv.trace_plots["fl1_raw"] + plot_fl2 = qv.trace_plots["fl2_raw"] + qtbot.waitUntil(lambda: plot_fl1.yData is not None + and plot_fl2.yData is not None, + timeout=5000) + + index = qv.ui.spinBox_event.value() - 1 + with dclab.new_dataset(path) as ds: + fl1 = ds["trace"]["fl1_raw"][index] + fl2 = ds["trace"]["fl2_raw"][index] + # offset only defined for channel 1 + assert np.allclose(plot_fl1.yData, fl1 + 17) + assert np.allclose(plot_fl2.yData, fl2)