diff --git a/CHANGELOG b/CHANGELOG index 3a269b6..4e2102b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,8 @@ of the Quick View (#195) - enh: add the fluorescence baseline offset ([fluorescence]: "baseline N offset") to the traces shown in the Quick View (#81) + - enh: button for applying the fluorescence crosstalk coefficients + to all datasets in the Dataset tab of the Analysis View (#198) - 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/analysis/ana_slot.py b/dcscope/gui/analysis/ana_slot.py index caea506..8b24216 100644 --- a/dcscope/gui/analysis/ana_slot.py +++ b/dcscope/gui/analysis/ana_slot.py @@ -33,6 +33,8 @@ def __init__(self, *args, **kwargs): self.ui.toolButton_duplicate.clicked.connect(self.on_duplicate_slot) self.ui.toolButton_remove.clicked.connect(self.on_remove_slot) self.ui.pushButton_apply.clicked.connect(self.write_slot) + self.ui.pushButton_ct_apply_all.clicked.connect( + self.on_crosstalk_apply_all) self.ui.pushButton_reset.clicked.connect(self.update_content) self.ui.comboBox_slots.currentIndexChanged.connect(self.update_content) self.ui.comboBox_medium.currentIndexChanged.connect(self.on_ui_changed) @@ -497,6 +499,21 @@ def update_content(self, slot_index=None, **kwargs): else: self.setEnabled(False) + @QtCore.pyqtSlot() + def on_crosstalk_apply_all(self): + """Set the crosstalk values shown for all datasets (#198) + + Only the crosstalk values are applied; other (not yet applied) + changes of the current dataset are not. + """ + crosstalk = self.read_pipeline_state()["crosstalk"] + with self.pipeline.lock: + for slot in self.pipeline.slots: + state = slot.__getstate__() + state["crosstalk"].update(crosstalk) + slot.__setstate__(state) + self.pp_mod_send.emit({"pipeline": {"feature_changed": "crosstalk"}}) + def write_slot(self): """Update the dcscope.pipeline.Dataslot instance""" with self.pipeline.lock: diff --git a/dcscope/gui/analysis/ana_slot_ui.py b/dcscope/gui/analysis/ana_slot_ui.py index 8c5d3c7..3cfccff 100644 --- a/dcscope/gui/analysis/ana_slot_ui.py +++ b/dcscope/gui/analysis/ana_slot_ui.py @@ -223,6 +223,9 @@ def setupUi(self, Form): self.doubleSpinBox_ct23.setSingleStep(0.1) self.doubleSpinBox_ct23.setObjectName("doubleSpinBox_ct23") self.gridLayout_3.addWidget(self.doubleSpinBox_ct23, 2, 3, 1, 1) + self.pushButton_ct_apply_all = QtWidgets.QPushButton(parent=self.groupBox_fl_cross) + self.pushButton_ct_apply_all.setObjectName("pushButton_ct_apply_all") + self.gridLayout_3.addWidget(self.pushButton_ct_apply_all, 4, 0, 1, 4) self.verticalLayout_5.addWidget(self.groupBox_fl_cross) self.groupBox_fl_labels = QtWidgets.QGroupBox(parent=Form) self.groupBox_fl_labels.setObjectName("groupBox_fl_labels") @@ -331,6 +334,8 @@ def retranslateUi(self, Form): self.label_to_fl3.setText(_translate("Form", "to FL-3")) self.label_from_fl1.setText(_translate("Form", "from FL-1")) self.label_from_fl3.setText(_translate("Form", "from FL-3")) + self.pushButton_ct_apply_all.setToolTip(_translate("Form", "Set these crosstalk values for all datasets in the session (other changes in this tab are not applied)")) + self.pushButton_ct_apply_all.setText(_translate("Form", "Apply crosstalk to all datasets")) self.groupBox_fl_labels.setToolTip(_translate("Form", "Choose user-definde labels that will be used for axes labels.")) self.groupBox_fl_labels.setTitle(_translate("Form", "Fluorescence labels")) self.label_fl2.setText(_translate("Form", "FL-2")) diff --git a/docs/scrots/make_scrots_qg_fl_crosstalk.py b/docs/scrots/make_scrots_qg_fl_crosstalk.py index d5aa5a1..174d7b9 100644 --- a/docs/scrots/make_scrots_qg_fl_crosstalk.py +++ b/docs/scrots/make_scrots_qg_fl_crosstalk.py @@ -64,7 +64,7 @@ mw.on_modify_slot(mw.pipeline.slot_ids[0]) mw.widget_ana_view.repaint() wsl = mw.widget_ana_view.ui.widget_slot -wsl.ui.groupBox_fl_cross.setFixedSize(360, 150) +wsl.ui.groupBox_fl_cross.setFixedSize(360, 185) wsl.ui.doubleSpinBox_ct12.setValue(0.214) wsl.ui.doubleSpinBox_ct13.setValue(0.012) diff --git a/docs/scrots/qg_fl_crosstalk_matrix.png b/docs/scrots/qg_fl_crosstalk_matrix.png index 5e89b7a..7217baa 100644 Binary files a/docs/scrots/qg_fl_crosstalk_matrix.png and b/docs/scrots/qg_fl_crosstalk_matrix.png differ diff --git a/docs/sec_qg_fl_crosstalk.rst b/docs/sec_qg_fl_crosstalk.rst index d6778f3..20d2721 100644 --- a/docs/sec_qg_fl_crosstalk.rst +++ b/docs/sec_qg_fl_crosstalk.rst @@ -53,7 +53,8 @@ one channel *to* the other channels. For instance, in additionally detected in FL-2. Only the coefficients between the fluorescence channels of the dataset are shown. Click *Apply* to apply the coefficients to the dataset. The coefficients are set for each dataset -individually. +individually. To use the same coefficients for all datasets of the session +(e.g. measured with the same setup), click *Apply crosstalk to all datasets*. As soon as any of the coefficients is set (not zero), the crosstalk-corrected features *FL-1 maximum, crosstalk-corrected* (fl1_max_ctc), diff --git a/tests/test_gui_ana_slot.py b/tests/test_gui_ana_slot.py new file mode 100644 index 0000000..ab7ec7c --- /dev/null +++ b/tests/test_gui_ana_slot.py @@ -0,0 +1,46 @@ +"""Test the Dataset tab of the Analysis View""" +import pathlib + +import pytest + +from dcscope import session + +import conftest # noqa: F401 + + +datapath = pathlib.Path(__file__).parent / "data" + + +@pytest.fixture(autouse=True) +def run_around_tests(): + session.clear_session() + yield + session.clear_session() + + +def test_crosstalk_apply_to_all_issue_198(qtbot, mw): + """Apply the crosstalk values to all datasets (#198)""" + qtbot.addWidget(mw) + path = datapath / "calibration_beads_47.rtdc" + mw.add_dataslot(paths=[path, path, path]) + mw.widget_ana_view.ui.tabWidget.setCurrentWidget( + mw.widget_ana_view.ui.tab_slot) + wsl = mw.widget_ana_view.ui.widget_slot + + wsl.ui.doubleSpinBox_ct12.setValue(0.1) + wsl.ui.doubleSpinBox_ct31.setValue(0.25) + # this change is not applied with "Apply crosstalk to all datasets" + wsl.ui.lineEdit_name.setText("new name") + # (the Analysis View is not shown, so we cannot use qtbot.mouseClick) + wsl.ui.pushButton_ct_apply_all.click() + + for ii, slot in enumerate(mw.pipeline.slots): + state = slot.__getstate__() + assert state["crosstalk"]["crosstalk fl12"] == 0.1 + assert state["crosstalk"]["crosstalk fl31"] == 0.25 + assert state["crosstalk"]["crosstalk fl13"] == 0 + assert state["name"] != "new name" + # the values are used for computing the corrected fluorescence + ds = mw.pipeline.get_dataset(ii) + assert ds.config["calculation"]["crosstalk fl12"] == 0.1 + assert ds.config["calculation"]["crosstalk fl31"] == 0.25 diff --git a/ui/analysis/ana_slot.ui b/ui/analysis/ana_slot.ui index af7ef5d..a386dfa 100644 --- a/ui/analysis/ana_slot.ui +++ b/ui/analysis/ana_slot.ui @@ -521,6 +521,16 @@ + + + + Set these crosstalk values for all datasets in the session (other changes in this tab are not applied) + + + Apply crosstalk to all datasets + + +