ossify 0.3.0__tar.gz → 0.3.2__tar.gz

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 (37) hide show
  1. ossify-0.3.2/.github/workflows/publish.yml +51 -0
  2. {ossify-0.3.0 → ossify-0.3.2}/PKG-INFO +1 -1
  3. {ossify-0.3.0 → ossify-0.3.2}/pyproject.toml +2 -2
  4. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/__init__.py +1 -1
  5. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/base.py +13 -1
  6. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/data_layers.py +84 -0
  7. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/translate.py +10 -0
  8. {ossify-0.3.0 → ossify-0.3.2}/.github/workflows/mkdocs_publish.yml +0 -0
  9. {ossify-0.3.0 → ossify-0.3.2}/.github/workflows/python-package.yml +0 -0
  10. {ossify-0.3.0 → ossify-0.3.2}/.gitignore +0 -0
  11. {ossify-0.3.0 → ossify-0.3.2}/.pre-commit-config.yaml +0 -0
  12. {ossify-0.3.0 → ossify-0.3.2}/LICENSE +0 -0
  13. {ossify-0.3.0 → ossify-0.3.2}/README.md +0 -0
  14. {ossify-0.3.0 → ossify-0.3.2}/mkdocs.yml +0 -0
  15. {ossify-0.3.0 → ossify-0.3.2}/scripts/build_example_cell.py +0 -0
  16. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/__init__.py +0 -0
  17. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/graph.py +0 -0
  18. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/mapping.py +0 -0
  19. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/mesh.py +0 -0
  20. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/morph.py +0 -0
  21. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/points.py +0 -0
  22. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/_sync/table.py +0 -0
  23. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/algorithms.py +0 -0
  24. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/base.py +0 -0
  25. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/compartment_models/minnie65_ds15_us0_bd0.json +0 -0
  26. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/compartment_models/v1dd_ds15_us0_bd0.json +0 -0
  27. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/compartment_models/xgb/minnie65_ds15_us0_bd0.ubj +0 -0
  28. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/compartment_models/xgb/v1dd_ds15_us0_bd0.ubj +0 -0
  29. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/compartments.py +0 -0
  30. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/file_io.py +0 -0
  31. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/graph_functions.py +0 -0
  32. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/plot.py +0 -0
  33. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/plot3d.py +0 -0
  34. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/plot_utils.py +0 -0
  35. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/structured_prediction.py +0 -0
  36. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/sync_classes.py +0 -0
  37. {ossify-0.3.0 → ossify-0.3.2}/src/ossify/utils.py +0 -0
@@ -0,0 +1,51 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v7
12
+ - name: Install system dependencies for PyVista/VTK rendering
13
+ run: |
14
+ sudo apt-get update
15
+ sudo apt-get install -y --no-install-recommends \
16
+ libgl1 libglx-mesa0 libxrender1 libxkbcommon0 libdbus-1-3 \
17
+ libegl1 libosmesa6 xvfb
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v10.2.0
20
+ with:
21
+ python-version: "3.13"
22
+ - name: Check release tag matches package version
23
+ run: |
24
+ version=$(grep -m1 '^version = ' pyproject.toml | cut -d'"' -f2)
25
+ if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
26
+ echo "::error::Release tag ${GITHUB_REF_NAME} does not match pyproject version ${version}"
27
+ exit 1
28
+ fi
29
+ - name: Run tests
30
+ run: uv run --locked pytest tests
31
+ - name: Build
32
+ run: uv build
33
+ - uses: actions/upload-artifact@v7
34
+ with:
35
+ name: dist
36
+ path: dist/
37
+
38
+ publish:
39
+ needs: build
40
+ runs-on: ubuntu-latest
41
+ environment:
42
+ name: pypi
43
+ url: https://pypi.org/p/ossify
44
+ permissions:
45
+ id-token: write
46
+ steps:
47
+ - uses: actions/download-artifact@v8
48
+ with:
49
+ name: dist
50
+ path: dist/
51
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ossify
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Mesh and skeleton analysis
5
5
  Author-email: Casey Schneider-Mizell <caseysm@gmail.com>
6
6
  License-File: LICENSE
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  allow-direct-references = true
7
7
  [project]
8
8
  name = "ossify"
9
- version = "0.3.0"
9
+ version = "0.3.2"
10
10
  description = "Mesh and skeleton analysis"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.11"
@@ -95,7 +95,7 @@ default-groups = ["dev", "docs", "lint", "profile", "viz"]
95
95
 
96
96
 
97
97
  [tool.bumpversion]
98
- current_version = "0.3.0"
98
+ current_version = "0.3.2"
99
99
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
100
100
  serialize = ["{major}.{minor}.{patch}"]
101
101
  regex = false
@@ -5,7 +5,7 @@ from .base import *
5
5
  from .file_io import *
6
6
  from .translate import *
7
7
 
8
- __version__ = "0.3.0"
8
+ __version__ = "0.3.2"
9
9
 
10
10
 
11
11
  def __getattr__(name):
@@ -272,7 +272,19 @@ def mask_and_remap(
272
272
  """
273
273
  if np.array(mask).dtype == bool:
274
274
  mask = np.where(mask)[0]
275
- return _mask_and_remap(np.array(arr, dtype=int), mask)
275
+ arr = np.array(arr, dtype=int)
276
+ mask = np.asarray(mask)
277
+ n = len(mask)
278
+ # Fast path: when the node index is already 0..n-1, index space and
279
+ # positional space coincide, so the remap is the identity and the only
280
+ # thing it can do is drop rows pointing outside the range -- and there are
281
+ # none. Worth special-casing because the general path below builds a Python
282
+ # dict and a Python list with one entry per node, which dominates
283
+ # everything else on a mesh with millions of vertices.
284
+ if n and (arr.size == 0 or (arr.min() >= 0 and arr.max() < n)):
285
+ if mask[0] == 0 and mask[-1] == n - 1 and np.array_equal(mask, np.arange(n)):
286
+ return arr
287
+ return _mask_and_remap(arr, mask)
276
288
 
277
289
 
278
290
  def _mask_and_remap(
@@ -1766,6 +1766,60 @@ class GraphLayer(PointMixin, EdgeMixin):
1766
1766
  """
1767
1767
  return np.array(self.csgraph_undirected.sum(axis=0)).flatten() / 2
1768
1768
 
1769
+ def _masked_component_labels(self, mask: Optional[np.ndarray]) -> np.ndarray:
1770
+ """Connected-component label per vertex within the subgraph ``mask`` induces.
1771
+
1772
+ Vertices outside ``mask`` get -1. Edges count only when both ends are
1773
+ inside it, so a mask that cuts through the graph splits it.
1774
+ """
1775
+ if mask is None:
1776
+ keep = np.ones(self.n_vertices, dtype=bool)
1777
+ else:
1778
+ keep = np.asarray(mask)
1779
+ if keep.dtype != bool or keep.shape != (self.n_vertices,):
1780
+ raise ValueError(
1781
+ "mask must be a boolean array with one entry per vertex "
1782
+ f"({self.n_vertices}), got dtype {keep.dtype} and shape {keep.shape}"
1783
+ )
1784
+ labels = np.full(self.n_vertices, -1, dtype=int)
1785
+ inside = np.flatnonzero(keep)
1786
+ if inside.size == 0:
1787
+ return labels
1788
+ subgraph = self.csgraph_binary_undirected[inside][:, inside]
1789
+ _, labels[inside] = sparse.csgraph.connected_components(
1790
+ subgraph, directed=False
1791
+ )
1792
+ return labels
1793
+
1794
+ def largest_connected_component(
1795
+ self, mask: Optional[np.ndarray] = None
1796
+ ) -> np.ndarray:
1797
+ """Boolean mask of the largest connected component, by vertex count.
1798
+
1799
+ Parameters
1800
+ ----------
1801
+ mask : np.ndarray, optional
1802
+ Boolean array with one entry per vertex. When given, components are
1803
+ found within the subgraph it induces: vertices outside it are never
1804
+ selected, and edges count only when both ends are inside it.
1805
+ Default None considers the whole layer.
1806
+
1807
+ Returns
1808
+ -------
1809
+ np.ndarray
1810
+ Boolean array with one entry per vertex, True on the largest
1811
+ component. Ties go to the component holding the lowest-positioned
1812
+ vertex. All False when ``mask`` selects nothing.
1813
+ """
1814
+ labels = self._masked_component_labels(mask)
1815
+ inside = labels >= 0
1816
+ if not inside.any():
1817
+ return inside
1818
+ # connected_components numbers components in order of first vertex, and
1819
+ # argmax takes the first maximum, so ties go to the earliest component.
1820
+ largest = int(np.argmax(np.bincount(labels[inside])))
1821
+ return labels == largest
1822
+
1769
1823
  def proximity_mapping(
1770
1824
  self,
1771
1825
  distance_threshold: float,
@@ -2202,6 +2256,36 @@ class SkeletonLayer(GraphLayer):
2202
2256
  return None
2203
2257
  return self.vertex_df.loc[self.root, self.spatial_columns].to_numpy(dtype=float)
2204
2258
 
2259
+ def root_component(self, mask: Optional[np.ndarray] = None) -> np.ndarray:
2260
+ """Boolean mask of the connected component that contains the root.
2261
+
2262
+ Parameters
2263
+ ----------
2264
+ mask : np.ndarray, optional
2265
+ Boolean array with one entry per vertex. When given, the component is
2266
+ found within the subgraph it induces, so vertices reachable from the
2267
+ root only through vertices outside the mask are excluded. Default
2268
+ None considers the whole skeleton.
2269
+
2270
+ Returns
2271
+ -------
2272
+ np.ndarray
2273
+ Boolean array with one entry per vertex, True on the root's
2274
+ component. All False when the root lies outside ``mask``.
2275
+
2276
+ Raises
2277
+ ------
2278
+ ValueError
2279
+ If the skeleton has no root.
2280
+ """
2281
+ root = self.root_positional
2282
+ if root is None:
2283
+ raise ValueError("Skeleton has no root, so it has no root component")
2284
+ labels = self._masked_component_labels(mask)
2285
+ if labels[root] < 0:
2286
+ return np.zeros(self.n_vertices, dtype=bool)
2287
+ return labels == labels[root]
2288
+
2205
2289
  @property
2206
2290
  def parent_node_array(self) -> np.ndarray:
2207
2291
  """Get the parent node array for the skeleton, or -1 for a missing parent."""
@@ -508,6 +508,11 @@ def fetch_frames_batch(
508
508
  not fetched (e.g. synapses off) are ``None``.
509
509
  """
510
510
  root_ids = [int(r) for r in root_ids]
511
+ if not root_ids:
512
+ # Nothing to fetch. Never issue a pooled query with an empty root-id filter: the
513
+ # materialization server rejects it with a misleading 500 ("ALL root id filters
514
+ # passed ([]) were invalid").
515
+ return {}
511
516
  if reference_suffixes is None:
512
517
  reference_suffixes = {}
513
518
  results: dict[int, dict] = {
@@ -660,6 +665,8 @@ def load_cell_batch_from_client(
660
665
  f"{len(invalid_ids)} root id(s) not valid at {ts}: {invalid_ids[:5]}"
661
666
  + (" ..." if len(invalid_ids) > 5 else "")
662
667
  )
668
+ if not valid_ids:
669
+ return {}
663
670
 
664
671
  # 2. Skeletons: one cached bulk download (chunked at the cached-bulk cap) to obtain lvl2_ids,
665
672
  # then injected into assembly. Assumes a prior generate_bulk_skeletons_async pre-pass.
@@ -677,6 +684,9 @@ def load_cell_batch_from_client(
677
684
  f"{no_skeleton[:5]}" + (" ..." if len(no_skeleton) > 5 else "")
678
685
  )
679
686
  valid_ids = [r for r in valid_ids if r in sk_by_root]
687
+ if not valid_ids:
688
+ # Every valid root lacked a cached skeleton (only reachable with skip_invalid=True).
689
+ return {}
680
690
  lvl2_ids_by_root = {r: sk_by_root[r]["lvl2_ids"] for r in valid_ids}
681
691
 
682
692
  # 3. Pooled synapse + L2 fetch.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes