Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change hypotheses boxes to QListWidget to reduce space #363

Merged
merged 12 commits into from
Aug 4, 2023
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.262
rev: v0.0.272
hooks:
- id: ruff
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.3
hooks:
- id: remove-tabs
exclude: Makefile|docs/Makefile|\.bat$
Expand All @@ -22,15 +22,15 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.0
rev: v0.23.1
hooks:
- id: toml-sort-fix
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.7
rev: v16.0.6
hooks:
- id: clang-format
types_or: [c++, c, cuda]
4 changes: 2 additions & 2 deletions btrack/btypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def from_dict(properties: dict[str, Any]) -> PyTrackObject:

# we can add any extra details to the properties dictionary
obj.properties = {
k: v for k, v in properties.items() if k not in fields.keys()
k: v for k, v in properties.items() if k not in fields
}
return obj

Expand Down Expand Up @@ -353,7 +353,7 @@ class Tracklet:
x values.
"""

def __init__(
def __init__( # noqa: PLR0913
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering what these new ruff rules are?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is complaining about too many arguments. I updated ruff a bit but not all the way as there was more to fix.

self,
ID: int,
data: list[PyTrackObject],
Expand Down
2 changes: 1 addition & 1 deletion btrack/io/_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __call__(
return nodes


def segmentation_to_objects(
def segmentation_to_objects( # noqa: PLR0913
segmentation: Union[np.ndarray, Generator],
*,
intensity_image: Optional[Union[np.ndarray, Generator]] = None,
Expand Down
5 changes: 4 additions & 1 deletion btrack/io/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def export_LBEP(filename: os.PathLike, tracks: list):


def _export_HDF(
filename: os.PathLike, tracker, obj_type=None, filter_by: str = None
filename: os.PathLike,
tracker,
obj_type=None,
filter_by: Optional[str] = None,
):
"""Export to HDF."""

Expand Down
2 changes: 1 addition & 1 deletion btrack/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def write_properties(

grp = self._hdf[f"objects/{self.object_type}"]

if "properties" not in grp.keys():
if "properties" not in grp:
props_grp = grp.create_group("properties")
else:
props_grp = self._hdf[f"objects/{self.object_type}/properties"]
Expand Down
2 changes: 1 addition & 1 deletion btrack/napari/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __getitem__(self, matrix_name):
return self.__dict__[matrix_name]

def __setitem__(self, matrix_name, sigma):
if matrix_name not in self.__dict__.keys():
if matrix_name not in self.__dict__:
_msg = f"Unknown matrix name '{matrix_name}'"
raise ValueError(_msg)
self.__dict__[matrix_name] = sigma
Expand Down
17 changes: 12 additions & 5 deletions btrack/napari/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import btrack.napari.widgets
from btrack.napari.config import Sigmas, UnscaledTrackerConfig

from qtpy import QtCore

import btrack.napari.constants


Expand Down Expand Up @@ -41,8 +43,9 @@ def update_config_from_widgets(
hypothesis_model = config.hypothesis_model
hypothesis_model.hypotheses = [
hypothesis
for hypothesis in btrack.optimise.hypothesis.H_TYPES
if btrack_widget[hypothesis].isChecked()
for i, hypothesis in enumerate(btrack.optimise.hypothesis.H_TYPES)
if btrack_widget["hypotheses"].item(i).checkState()
== QtCore.Qt.CheckState.Checked
]

# Update HypothesisModel scaling factors
Expand Down Expand Up @@ -91,9 +94,13 @@ def update_widgets_from_config(

# Update widgets from HypothesisModel.hypotheses values
hypothesis_model = config.hypothesis_model
for hypothesis in btrack.optimise.hypothesis.H_TYPES:
is_checked = hypothesis in hypothesis_model.hypotheses
btrack_widget[hypothesis].setChecked(is_checked)
for i, hypothesis in enumerate(btrack.optimise.hypothesis.H_TYPES):
is_checked = (
QtCore.Qt.CheckState.Checked
if hypothesis in hypothesis_model.hypotheses
else QtCore.Qt.CheckState.Unchecked
)
btrack_widget["hypotheses"].item(i).setCheckState(is_checked)

# Update widgets from HypothesisModel scaling factors
for scaling_factor in btrack.napari.constants.HYPOTHESIS_SCALING_FACTORS:
Expand Down
4 changes: 2 additions & 2 deletions btrack/napari/widgets/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from qtpy import QtWidgets


def create_input_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def create_input_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widgets for selecting labels layer and TrackerConfig"""

# TODO: annotation=napari.layers.Labels,
Expand All @@ -26,7 +26,7 @@ def create_input_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
return widgets


def create_update_method_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def create_update_method_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widgets for selecting the update method"""

update_method = QtWidgets.QComboBox()
Expand Down
46 changes: 27 additions & 19 deletions btrack/napari/widgets/_hypothesis.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

from qtpy import QtWidgets
from qtpy import QtCore, QtWidgets

import btrack.napari.constants


def _create_hypotheses_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def _create_hypotheses_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widgets for selecting which hypotheses to generate."""

hypotheses = btrack.optimise.hypothesis.H_TYPES
hypotheses = [
h.replace("_", " ") for h in btrack.optimise.hypothesis.H_TYPES
]
tooltips = [
"Hypothesis that a tracklet is a false positive detection. Always required.",
"Hypothesis that a tracklet starts at the beginning of the movie or edge of the field of view.", # noqa: E501
Expand All @@ -19,25 +21,31 @@ def _create_hypotheses_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
"Hypothesis that two tracklets merge into one tracklet.",
]

hypotheses_widgets = {}
for hypothesis, tooltip in zip(hypotheses, tooltips):
widget = QtWidgets.QCheckBox()
widget.setChecked(True) # noqa: FBT003
widget.setToolTip(tooltip)
widget.setTristate(False) # noqa: FBT003
hypotheses_widgets[hypothesis] = (hypothesis.replace("_", " "), widget)
widget = QtWidgets.QListWidget()
widget.addItems(hypotheses)
flags = QtCore.Qt.ItemFlags(
QtCore.Qt.ItemIsUserCheckable + QtCore.Qt.ItemIsEnabled
)
for i, tooltip in enumerate(tooltips):
widget.item(i).setCheckState(QtCore.Qt.CheckState.Checked)
widget.item(i).setFlags(flags)
widget.item(i).setToolTip(tooltip)

# P_FP is always required
hypotheses_widgets["P_FP"][1].setEnabled(False) # noqa: FBT003
widget.item(hypotheses.index("P FP")).setFlags(
QtCore.Qt.ItemIsUserCheckable,
)

# P_merge should be disabled by default
hypotheses_widgets["P_merge"][1].setChecked(False) # noqa: FBT003
# # P_merge should be disabled by default
widget.item(hypotheses.index("P merge")).setCheckState(
QtCore.Qt.CheckState.Unchecked
)

return hypotheses_widgets
return {"hypotheses": ("hypotheses", widget)}


def _create_scaling_factor_widgets() -> (
dict[str, tuple(str, QtWidgets.QWidget)]
dict[str, tuple[str, QtWidgets.QWidget]]
):
"""Create widgets for setting the scaling factors of the HypothesisModel"""

Expand Down Expand Up @@ -74,7 +82,7 @@ def _create_scaling_factor_widgets() -> (
return scaling_factor_widgets


def _create_threshold_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def _create_threshold_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widgets for setting thresholds for the HypothesisModel"""

distance_threshold = QtWidgets.QDoubleSpinBox()
Expand Down Expand Up @@ -113,7 +121,7 @@ def _create_threshold_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
return widgets


def _create_bin_size_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def _create_bin_size_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widget for setting bin sizes for the HypothesisModel"""

distance_bin_size = QtWidgets.QDoubleSpinBox()
Expand Down Expand Up @@ -142,9 +150,9 @@ def _create_bin_size_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:


def create_hypothesis_model_widgets() -> (
dict[str, tuple(str, QtWidgets.QWidget)]
dict[str, tuple[str, QtWidgets.QWidget]]
):
"""Create widgets for setting parameters of the MotionModel"""
"""Create widgets for setting parameters of the HypothesisModel"""

widgets = {
**_create_hypotheses_widgets(),
Expand Down
4 changes: 2 additions & 2 deletions btrack/napari/widgets/_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _make_label_bold(label: str) -> str:
return f"<b>{label}</b>"


def _create_sigma_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def _create_sigma_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widgets for setting the magnitudes of the MotionModel matrices"""

P_sigma = QtWidgets.QDoubleSpinBox()
Expand Down Expand Up @@ -43,7 +43,7 @@ def _create_sigma_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
return widgets


def create_motion_model_widgets() -> dict[str, tuple(str, QtWidgets.QWidget)]:
def create_motion_model_widgets() -> dict[str, tuple[str, QtWidgets.QWidget]]:
"""Create widgets for setting parameters of the MotionModel"""

widgets = _create_sigma_widgets()
Expand Down
14 changes: 0 additions & 14 deletions btrack/napari/widgets/create_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@
from btrack.napari.widgets._motion import create_motion_model_widgets


def create_widgets() -> (
dict[str, QtWidgets.QWidget | tuple[str, QtWidgets.QWidget]]
):
"""Create all the widgets for the plugin"""

return (
create_input_widgets()
| create_update_method_widgets()
| create_motion_model_widgets()
| create_hypothesis_model_widgets()
| create_io_widgets()
)
paddyroddy marked this conversation as resolved.
Show resolved Hide resolved


class BtrackWidget(QtWidgets.QScrollArea):
"""Main btrack widget"""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_shared_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_load_library():
def test_fails_load_library_debug(tmp_path):
"""Test loading a fake shared library."""
fake_lib_filename = Path(tmp_path) / "fakelib"
with pytest.raises(Exception):
with pytest.raises(Exception): # noqa: B017
load_library(fake_lib_filename)


Expand Down