Skip to content

Commit ccaaf0f

Browse files
committed
chore: comply with ruff by ignoring napari specific import errors
1 parent 37a32cb commit ccaaf0f

4 files changed

Lines changed: 42 additions & 29 deletions

File tree

vesskel/_napari.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
if TYPE_CHECKING:
1616
# These imports are only used for annotations and are therefore
1717
# guarded by TYPE_CHECKING to avoid runtime import-time coupling.
18-
from napari.layers import Image
18+
from napari.layers import Image # noqa: F401
1919

2020
from vesskel.config import (
2121
ExtractionConfig,
@@ -40,7 +40,7 @@ def __init__(self, napari_viewer):
4040
def _setup_ui(self):
4141
# ---------- extraction parameters (magicgui) ----------
4242
def _extraction_params(
43-
image: "napari.layers.Image",
43+
image: "napari.layers.Image", # noqa: F821
4444
extract_branches: bool = False,
4545
extract_branch_text: bool = False,
4646
extract_nodes: bool = False,
@@ -347,9 +347,7 @@ def _on_analyze(self) -> None:
347347

348348
n_fg = int((img.data > 0).sum())
349349
n_skel = int(result.skeleton.sum())
350-
show_info(
351-
f"Analysis: {n_fg}{n_skel} skeleton pixels " f"in {elapsed:.3f}s"
352-
)
350+
show_info(f"Analysis: {n_fg}{n_skel} skeleton pixels in {elapsed:.3f}s")
353351

354352
# Always add skeleton layer first.
355353
self.viewer.add_layer(
@@ -379,7 +377,7 @@ def _on_analyze(self) -> None:
379377
self.viewer.add_layer(layer)
380378
except Exception as e:
381379
show_info(
382-
f"Failed to add layer " f"{meta.get('name', '<unnamed>')}: {e}"
380+
f"Failed to add layer {meta.get('name', '<unnamed>')}: {e}"
383381
)
384382
except (ValueError, RuntimeError, OSError) as e:
385383
show_error(f"Analysis failed: {e}")

vesskel/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ def _make_parser() -> argparse.ArgumentParser:
6868
"init",
6969
help="Create a starter config JSON.",
7070
)
71-
init_parser.add_argument("out", nargs="?", default="vesskel.json", help="Output config path.")
71+
init_parser.add_argument(
72+
"out", nargs="?", default="vesskel.json", help="Output config path."
73+
)
7274

7375
validate_parser = subparsers.add_parser(
7476
"validate",
7577
help="Validate and print a normalised config JSON.",
7678
)
77-
validate_parser.add_argument("config", nargs="?", default="vesskel.json", help="Config JSON path.")
79+
validate_parser.add_argument(
80+
"config", nargs="?", default="vesskel.json", help="Config JSON path."
81+
)
7882

7983
completions_parser = subparsers.add_parser(
8084
"completions",

vesskel/napari_layers.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from vesskel.features import compute_tortuosity, extract_node_features
1010

1111
if TYPE_CHECKING:
12-
from napari.types import LayerDataTuple
12+
from napari.types import LayerDataTuple # noqa: F401
1313

1414

1515
def extract_skeleton_layers(
@@ -20,7 +20,7 @@ def extract_skeleton_layers(
2020
config: ExtractionConfig | None = None,
2121
features: dict[str, float] | None = None,
2222
radius_matrix: np.ndarray | None = None,
23-
) -> list["napari.types.LayerDataTuple"]:
23+
) -> list["napari.types.LayerDataTuple"]: # noqa: F821
2424
"""Extract visualization layers from a binary skeleton.
2525
2626
Parameters
@@ -56,15 +56,15 @@ def extract_skeleton_layers(
5656
layers.append(text_layer)
5757

5858
if config.nodes:
59-
node_layer = _extract_node_features_layer(base_name, graph, branch_data, radius_matrix=radius_matrix)
59+
node_layer = _extract_node_features_layer(
60+
base_name, graph, branch_data, radius_matrix=radius_matrix
61+
)
6062
if node_layer is not None:
6163
layers.append(node_layer)
6264

6365
if config.summary:
6466
if features is None:
65-
raise ValueError(
66-
"features is required when summary is enabled"
67-
)
67+
raise ValueError("features is required when summary is enabled")
6868
summary_layer = _extract_summary_features_layer(
6969
skeleton,
7070
base_name,
@@ -84,7 +84,7 @@ def _extract_radius_layer(
8484
radius_matrix: np.ndarray,
8585
skeleton: np.ndarray,
8686
base_name: str,
87-
) -> "napari.types.LayerDataTuple | None":
87+
) -> "napari.types.LayerDataTuple | None": # noqa: F821
8888
"""Create an image layer showing per-pixel vessel radius on the skeleton."""
8989
if not np.any(radius_matrix):
9090
return None
@@ -103,7 +103,7 @@ def _extract_branch_features_layer(
103103
base_name: str,
104104
graph: Skeleton,
105105
branch_data,
106-
) -> "napari.types.LayerDataTuple | None":
106+
) -> "napari.types.LayerDataTuple | None": # noqa: F821
107107
"""Extract branch features and generate paths layer.
108108
109109
Parameters
@@ -161,9 +161,9 @@ def _extract_branch_features_layer(
161161

162162

163163
def _extract_branch_text_layer(
164-
branch_layer: "napari.types.LayerDataTuple",
164+
branch_layer: "napari.types.LayerDataTuple", # noqa: F821
165165
base_name: str,
166-
) -> "napari.types.LayerDataTuple":
166+
) -> "napari.types.LayerDataTuple": # noqa: F821
167167
path_data = branch_layer[0]
168168
branch_data = branch_layer[1]["properties"]
169169

@@ -197,7 +197,7 @@ def _extract_summary_features_layer(
197197
skeleton: np.ndarray,
198198
base_name: str,
199199
features: dict[str, float],
200-
) -> "napari.types.LayerDataTuple":
200+
) -> "napari.types.LayerDataTuple": # noqa: F821
201201
"""Create a summary point layer displaying global skeleton features.
202202
203203
Parameters
@@ -242,17 +242,24 @@ def _extract_node_features_layer(
242242
graph: Skeleton,
243243
branch_data,
244244
radius_matrix: np.ndarray | None = None,
245-
) -> "napari.types.LayerDataTuple | None":
245+
) -> "napari.types.LayerDataTuple | None": # noqa: F821
246246
"""Create a points layer showing graph nodes colored by degree."""
247-
node_records = extract_node_features(graph, branch_data, radius_matrix=radius_matrix)
247+
node_records = extract_node_features(
248+
graph, branch_data, radius_matrix=radius_matrix
249+
)
248250
if not node_records:
249251
return None
250252

251253
ndim = graph.coordinates.shape[1]
252-
points = np.array([tuple(r[f"coord_{d}"] for d in range(ndim)) for r in node_records], dtype=float)
253-
254-
props = {k: [r[k] for r in node_records] for k in node_records[0].keys()
255-
if not k.startswith("coord_")}
254+
points = np.array(
255+
[tuple(r[f"coord_{d}"] for d in range(ndim)) for r in node_records], dtype=float
256+
)
257+
258+
props = {
259+
k: [r[k] for r in node_records]
260+
for k in node_records[0].keys()
261+
if not k.startswith("coord_")
262+
}
256263

257264
meta = {
258265
"name": f"{base_name}_nodes",

vesskel/pipeline.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
from vesskel.thin import lee94_thin
2525

2626
if TYPE_CHECKING:
27-
from napari.types import LayerDataTuple
27+
from napari.types import LayerDataTuple # noqa: F401
2828

2929

3030
@dataclass
3131
class AnalysisResult:
3232
"""Container for single-image analysis outputs."""
3333

3434
skeleton: np.ndarray
35-
layers: list["napari.types.LayerDataTuple"]
35+
layers: list["napari.types.LayerDataTuple"] # noqa: F821
3636
summary_features: dict[str, float]
3737
branch_records: list[dict[str, object]]
3838
node_records: list[dict[str, object]]
@@ -121,8 +121,12 @@ def analyze_binary_image(
121121
branch_data[key] = arr
122122

123123
if radius_stats is not None:
124-
radius_stats["mean_segment_volume"] = float(np.nanmean(branch_data["volume"]))
125-
radius_stats["mean_surface_area"] = float(np.nanmean(branch_data["surface_area"]))
124+
radius_stats["mean_segment_volume"] = float(
125+
np.nanmean(branch_data["volume"])
126+
)
127+
radius_stats["mean_surface_area"] = float(
128+
np.nanmean(branch_data["surface_area"])
129+
)
126130

127131
if not branch_data.empty:
128132
euclidean = branch_data["euclidean-distance"].to_numpy(dtype=float)

0 commit comments

Comments
 (0)