Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions dcscope/gui/quick_view/qv_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
35 changes: 35 additions & 0 deletions tests/test_gui_quickview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading