canns 0.14.3__py3-none-any.whl → 0.15.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. canns/analyzer/data/asa/__init__.py +56 -21
  2. canns/analyzer/data/asa/coho.py +21 -0
  3. canns/analyzer/data/asa/cohomap.py +453 -0
  4. canns/analyzer/data/asa/cohomap_vectors.py +365 -0
  5. canns/analyzer/data/asa/cohospace.py +155 -1165
  6. canns/analyzer/data/asa/cohospace_phase_centers.py +119 -0
  7. canns/analyzer/data/asa/cohospace_scatter.py +1115 -0
  8. canns/analyzer/data/asa/embedding.py +5 -7
  9. canns/analyzer/data/asa/fr.py +1 -8
  10. canns/analyzer/data/asa/path.py +70 -0
  11. canns/analyzer/data/asa/plotting.py +5 -30
  12. canns/analyzer/data/asa/utils.py +160 -0
  13. canns/analyzer/data/cell_classification/__init__.py +10 -0
  14. canns/analyzer/data/cell_classification/core/__init__.py +4 -0
  15. canns/analyzer/data/cell_classification/core/btn.py +272 -0
  16. canns/analyzer/data/cell_classification/visualization/__init__.py +3 -0
  17. canns/analyzer/data/cell_classification/visualization/btn_plots.py +241 -0
  18. canns/analyzer/visualization/__init__.py +2 -0
  19. canns/analyzer/visualization/core/config.py +20 -0
  20. canns/analyzer/visualization/theta_sweep_plots.py +142 -0
  21. canns/pipeline/asa/runner.py +19 -19
  22. canns/pipeline/asa_gui/__init__.py +5 -3
  23. canns/pipeline/asa_gui/analysis_modes/pathcompare_mode.py +3 -1
  24. canns/pipeline/asa_gui/core/runner.py +23 -23
  25. canns/pipeline/asa_gui/views/pages/preprocess_page.py +7 -12
  26. {canns-0.14.3.dist-info → canns-0.15.1.dist-info}/METADATA +1 -1
  27. {canns-0.14.3.dist-info → canns-0.15.1.dist-info}/RECORD +30 -23
  28. canns/analyzer/data/asa/filters.py +0 -208
  29. {canns-0.14.3.dist-info → canns-0.15.1.dist-info}/WHEEL +0 -0
  30. {canns-0.14.3.dist-info → canns-0.15.1.dist-info}/entry_points.txt +0 -0
  31. {canns-0.14.3.dist-info → canns-0.15.1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,119 @@
1
+ """Phase-center utilities for CohoSpace (skewed coordinates)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
+
10
+ from ...visualization.core import PlotConfig, finalize_figure
11
+ from .path import skew_transform
12
+ from .utils import _ensure_parent_dir, _ensure_plot_config
13
+
14
+
15
+ def cohospace_phase_centers(cohospace_result: dict[str, Any]) -> dict[str, Any]:
16
+ """
17
+ Compute per-neuron CohoSpace phase centers and their skewed coordinates.
18
+
19
+ Input
20
+ -----
21
+ cohospace_result : dict
22
+ Output from `data.cohospace(...)` (must include `centers`).
23
+ """
24
+ centers = np.asarray(cohospace_result["centers"], dtype=float) % (2 * np.pi)
25
+ centers_skew = skew_transform(centers)
26
+ return {
27
+ "centers": centers,
28
+ "centers_skew": centers_skew,
29
+ }
30
+
31
+
32
+ def plot_cohospace_phase_centers(
33
+ cohospace_result: dict[str, Any],
34
+ *,
35
+ neuron_id: int | None = None,
36
+ show_all: bool = False,
37
+ config: PlotConfig | None = None,
38
+ save_path: str | None = None,
39
+ show: bool = False,
40
+ figsize: tuple[int, int] = (5, 5),
41
+ all_color: str = "tab:blue",
42
+ highlight_color: str = "tab:red",
43
+ alpha: float = 0.7,
44
+ s: int = 12,
45
+ ) -> plt.Figure:
46
+ """
47
+ Plot CohoSpace phase centers on the skewed torus domain.
48
+
49
+ If neuron_id is None, plot all neurons. If neuron_id is provided, show_all controls
50
+ whether all neurons are drawn lightly or only the selected neuron is shown.
51
+ """
52
+ centers_result = cohospace_phase_centers(cohospace_result)
53
+ centers_skew = centers_result["centers_skew"]
54
+ num_neurons = centers_skew.shape[0]
55
+
56
+ if neuron_id is not None and (neuron_id < 0 or neuron_id >= num_neurons):
57
+ raise ValueError(f"neuron_id out of range: {neuron_id}")
58
+
59
+ title = "CohoSpace phase centers (skewed)"
60
+ if neuron_id is not None and not show_all:
61
+ title = f"CohoSpace phase center (neuron {neuron_id}, skewed)"
62
+ elif neuron_id is not None and show_all:
63
+ title = f"CohoSpace phase centers (all + neuron {neuron_id}, skewed)"
64
+
65
+ config = _ensure_plot_config(
66
+ config,
67
+ PlotConfig.for_static_plot,
68
+ title=title,
69
+ xlabel=r"$\theta_1 + \frac{1}{2}\theta_2$",
70
+ ylabel=r"$\frac{\sqrt{3}}{2}\theta_2$",
71
+ figsize=figsize,
72
+ save_path=save_path,
73
+ show=show,
74
+ )
75
+
76
+ fig, ax = plt.subplots(figsize=config.figsize)
77
+
78
+ # fundamental domain parallelogram
79
+ e1 = np.array([2 * np.pi, 0.0])
80
+ e2 = np.array([np.pi, np.sqrt(3) * np.pi])
81
+ poly = np.vstack([[0.0, 0.0], e1, e1 + e2, e2, [0.0, 0.0]])
82
+ ax.plot(poly[:, 0], poly[:, 1], lw=1.2, color="0.35")
83
+
84
+ if neuron_id is None:
85
+ ax.scatter(centers_skew[:, 0], centers_skew[:, 1], s=s, alpha=alpha, color=all_color)
86
+ else:
87
+ if show_all:
88
+ ax.scatter(
89
+ centers_skew[:, 0],
90
+ centers_skew[:, 1],
91
+ s=max(4, s - 4),
92
+ alpha=0.25,
93
+ color=all_color,
94
+ )
95
+ ax.scatter(
96
+ centers_skew[neuron_id, 0],
97
+ centers_skew[neuron_id, 1],
98
+ s=max(10, s + 6),
99
+ alpha=0.9,
100
+ color=highlight_color,
101
+ )
102
+
103
+ base = np.vstack([[0.0, 0.0], e1, e2, e1 + e2])
104
+ xmin, ymin = base.min(axis=0)
105
+ xmax, ymax = base.max(axis=0)
106
+ padx = 0.03 * (xmax - xmin)
107
+ pady = 0.03 * (ymax - ymin)
108
+ ax.set_xlim(xmin - padx, xmax + padx)
109
+ ax.set_ylim(ymin - pady, ymax + pady)
110
+ ax.set_aspect("equal")
111
+ ax.set_xlabel(config.xlabel)
112
+ ax.set_ylabel(config.ylabel)
113
+ ax.set_title(config.title)
114
+ ax.set_xticks([])
115
+ ax.set_yticks([])
116
+
117
+ _ensure_parent_dir(config.save_path)
118
+ finalize_figure(fig, config)
119
+ return fig