cellcanvas-core 0.1.0__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.
- cellcanvas_core-0.1.0/.copier-answers.yml +17 -0
- cellcanvas_core-0.1.0/.github/ISSUE_TEMPLATE.md +15 -0
- cellcanvas_core-0.1.0/.github/TEST_FAIL_TEMPLATE.md +12 -0
- cellcanvas_core-0.1.0/.github/dependabot.yml +10 -0
- cellcanvas_core-0.1.0/.github/workflows/ci.yml +91 -0
- cellcanvas_core-0.1.0/.gitignore +111 -0
- cellcanvas_core-0.1.0/.pre-commit-config.yaml +27 -0
- cellcanvas_core-0.1.0/LICENSE +22 -0
- cellcanvas_core-0.1.0/PKG-INFO +56 -0
- cellcanvas_core-0.1.0/README.md +20 -0
- cellcanvas_core-0.1.0/benchmarks/compare_classifiers.py +135 -0
- cellcanvas_core-0.1.0/pyproject.toml +141 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/__init__.py +10 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_geometry.py +84 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_image.py +71 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/__init__.py +0 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_annotation_alignment.py +116 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_data_manager.py +62 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_feature_chunks.py +41 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_feature_contracts.py +83 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_ngff_images.py +132 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_seeding.py +188 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_spatial_coordinates.py +126 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/_tests/test_storage.py +87 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/data_manager.py +65 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/data_set.py +202 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/data/seeding.py +173 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/py.typed +5 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/__init__.py +0 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/__init__.py +0 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/mocks.py +27 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/test_fewshot.py +316 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/test_picking.py +129 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/test_prediction_storage.py +189 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/test_routing.py +473 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/_tests/test_segmentation_manager.py +72 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/fewshot.py +495 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/picking.py +122 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/routing.py +389 -0
- cellcanvas_core-0.1.0/src/cellcanvas_core/semantic/segmentation_manager.py +241 -0
- cellcanvas_core-0.1.0/tests/test_cellcanvas_core.py +2 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Do not edit - changes here will be overwritten by Copier
|
|
2
|
+
_commit: v1
|
|
3
|
+
_src_path: gh:pydev-guide/pyrepo-copier
|
|
4
|
+
author_email: kevin.yamauchi@gmail.com
|
|
5
|
+
author_name: CellCanvas team
|
|
6
|
+
git_versioning: true
|
|
7
|
+
github_username: cellcanvas
|
|
8
|
+
mode: customize
|
|
9
|
+
module_name: cellcanvas_core
|
|
10
|
+
project_license: BSD-3-Clause
|
|
11
|
+
project_name: cellcanvas-core
|
|
12
|
+
project_short_description: Core components for CellCanvas
|
|
13
|
+
test_pre_release: false
|
|
14
|
+
use_mypy: false
|
|
15
|
+
use_pre_commit: true
|
|
16
|
+
use_ruff: true
|
|
17
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
* cellcanvas-core version:
|
|
2
|
+
* Python version:
|
|
3
|
+
* Operating System:
|
|
4
|
+
|
|
5
|
+
### Description
|
|
6
|
+
|
|
7
|
+
Describe what you were trying to get done.
|
|
8
|
+
Tell us what happened, what went wrong, and what you expected to happen.
|
|
9
|
+
|
|
10
|
+
### What I Did
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
Paste the command(s) you ran and the output.
|
|
14
|
+
If there was a crash, please include the traceback here.
|
|
15
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "{{ env.TITLE }}"
|
|
3
|
+
labels: [bug]
|
|
4
|
+
---
|
|
5
|
+
The {{ workflow }} workflow failed on {{ date | date("YYYY-MM-DD HH:mm") }} UTC
|
|
6
|
+
|
|
7
|
+
The most recent failing test was on {{ env.PLATFORM }} py{{ env.PYTHON }}
|
|
8
|
+
with commit: {{ sha }}
|
|
9
|
+
|
|
10
|
+
Full run: https://github.com/{{ repo }}/actions/runs/{{ env.RUN_ID }}
|
|
11
|
+
|
|
12
|
+
(This post will be updated if another test fails, as long as this issue remains open.)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
2
|
+
|
|
3
|
+
version: 2
|
|
4
|
+
updates:
|
|
5
|
+
- package-ecosystem: "github-actions"
|
|
6
|
+
directory: "/"
|
|
7
|
+
schedule:
|
|
8
|
+
interval: "weekly"
|
|
9
|
+
commit-message:
|
|
10
|
+
prefix: "ci(dependabot):"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
tags:
|
|
8
|
+
- "v*"
|
|
9
|
+
pull_request:
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# cancel in-progress runs that use the same workflow and branch
|
|
14
|
+
concurrency:
|
|
15
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
16
|
+
cancel-in-progress: true
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
check-manifest:
|
|
20
|
+
# check-manifest is a tool that checks that all files in version control are
|
|
21
|
+
# included in the sdist (unless explicitly excluded)
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- run: pipx run check-manifest
|
|
26
|
+
|
|
27
|
+
test:
|
|
28
|
+
name: ${{ matrix.platform }} (${{ matrix.python-version }})
|
|
29
|
+
runs-on: ${{ matrix.platform }}
|
|
30
|
+
strategy:
|
|
31
|
+
fail-fast: false
|
|
32
|
+
matrix:
|
|
33
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
34
|
+
platform: [ubuntu-latest, macos-latest, windows-latest]
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
|
|
39
|
+
- name: 🐍 Set up Python ${{ matrix.python-version }}
|
|
40
|
+
uses: actions/setup-python@v5
|
|
41
|
+
with:
|
|
42
|
+
python-version: ${{ matrix.python-version }}
|
|
43
|
+
cache-dependency-path: "pyproject.toml"
|
|
44
|
+
cache: "pip"
|
|
45
|
+
|
|
46
|
+
- name: Install Dependencies
|
|
47
|
+
run: |
|
|
48
|
+
python -m pip install -U pip
|
|
49
|
+
python -m pip install .[test]
|
|
50
|
+
|
|
51
|
+
- name: 🧪 Run Tests
|
|
52
|
+
run: pytest --color=yes --cov --cov-report=xml --cov-report=term-missing
|
|
53
|
+
|
|
54
|
+
- name: Coverage
|
|
55
|
+
uses: codecov/codecov-action@v4
|
|
56
|
+
|
|
57
|
+
deploy:
|
|
58
|
+
name: Deploy
|
|
59
|
+
needs: test
|
|
60
|
+
if: success() && startsWith(github.ref, 'refs/tags/')
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
|
|
63
|
+
permissions:
|
|
64
|
+
# IMPORTANT: this permission is mandatory for trusted publishing on PyPi
|
|
65
|
+
# see https://docs.pypi.org/trusted-publishers/
|
|
66
|
+
id-token: write
|
|
67
|
+
# This permission allows writing releases
|
|
68
|
+
contents: write
|
|
69
|
+
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v4
|
|
72
|
+
with:
|
|
73
|
+
fetch-depth: 0
|
|
74
|
+
|
|
75
|
+
- name: 🐍 Set up Python
|
|
76
|
+
uses: actions/setup-python@v5
|
|
77
|
+
with:
|
|
78
|
+
python-version: "3.x"
|
|
79
|
+
|
|
80
|
+
- name: 👷 Build
|
|
81
|
+
run: |
|
|
82
|
+
python -m pip install build
|
|
83
|
+
python -m build
|
|
84
|
+
|
|
85
|
+
- name: 🚢 Publish to PyPI
|
|
86
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
87
|
+
|
|
88
|
+
- uses: softprops/action-gh-release@v2
|
|
89
|
+
with:
|
|
90
|
+
generate_release_notes: true
|
|
91
|
+
files: './dist/*'
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
env/
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
|
|
28
|
+
.DS_Store
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
local_settings.py
|
|
59
|
+
|
|
60
|
+
# Flask stuff:
|
|
61
|
+
instance/
|
|
62
|
+
.webassets-cache
|
|
63
|
+
|
|
64
|
+
# Scrapy stuff:
|
|
65
|
+
.scrapy
|
|
66
|
+
|
|
67
|
+
# Sphinx documentation
|
|
68
|
+
docs/_build/
|
|
69
|
+
|
|
70
|
+
# PyBuilder
|
|
71
|
+
target/
|
|
72
|
+
|
|
73
|
+
# Jupyter Notebook
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
|
|
76
|
+
# pyenv
|
|
77
|
+
.python-version
|
|
78
|
+
|
|
79
|
+
# celery beat schedule file
|
|
80
|
+
celerybeat-schedule
|
|
81
|
+
|
|
82
|
+
# SageMath parsed files
|
|
83
|
+
*.sage.py
|
|
84
|
+
|
|
85
|
+
# dotenv
|
|
86
|
+
.env
|
|
87
|
+
|
|
88
|
+
# virtualenv
|
|
89
|
+
.venv
|
|
90
|
+
venv/
|
|
91
|
+
ENV/
|
|
92
|
+
|
|
93
|
+
# Spyder project settings
|
|
94
|
+
.spyderproject
|
|
95
|
+
.spyproject
|
|
96
|
+
|
|
97
|
+
# Rope project settings
|
|
98
|
+
.ropeproject
|
|
99
|
+
|
|
100
|
+
# mkdocs documentation
|
|
101
|
+
/site
|
|
102
|
+
|
|
103
|
+
# mypy
|
|
104
|
+
.mypy_cache/
|
|
105
|
+
|
|
106
|
+
# ruff
|
|
107
|
+
.ruff_cache/
|
|
108
|
+
|
|
109
|
+
# IDE settings
|
|
110
|
+
.vscode/
|
|
111
|
+
.idea/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# enable pre-commit.ci at https://pre-commit.ci/
|
|
2
|
+
# it adds:
|
|
3
|
+
# 1. auto fixing pull requests
|
|
4
|
+
# 2. auto updating the pre-commit configuration
|
|
5
|
+
ci:
|
|
6
|
+
autoupdate_schedule: monthly
|
|
7
|
+
autofix_commit_msg: "style(pre-commit.ci): auto fixes [...]"
|
|
8
|
+
autoupdate_commit_msg: "ci(pre-commit.ci): autoupdate"
|
|
9
|
+
|
|
10
|
+
repos:
|
|
11
|
+
- repo: https://github.com/abravalheri/validate-pyproject
|
|
12
|
+
rev: v0.18
|
|
13
|
+
hooks:
|
|
14
|
+
- id: validate-pyproject
|
|
15
|
+
|
|
16
|
+
- repo: https://github.com/crate-ci/typos
|
|
17
|
+
rev: typos-dict-v0.11.20
|
|
18
|
+
hooks:
|
|
19
|
+
- id: typos
|
|
20
|
+
args: [--force-exclude] # omitting --write-changes
|
|
21
|
+
|
|
22
|
+
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
|
23
|
+
rev: v0.4.8
|
|
24
|
+
hooks:
|
|
25
|
+
- id: ruff
|
|
26
|
+
args: [--fix] # may also add '--unsafe-fixes'
|
|
27
|
+
- id: ruff-format
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CellCanvas contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cellcanvas-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Core components for CellCanvas
|
|
5
|
+
Project-URL: homepage, https://github.com/cellcanvas/cellcanvas-core
|
|
6
|
+
Project-URL: repository, https://github.com/cellcanvas/cellcanvas-core
|
|
7
|
+
Author-email: CellCanvas team <kevin.yamauchi@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: dask
|
|
19
|
+
Requires-Dist: numpy>=2
|
|
20
|
+
Requires-Dist: scikit-learn
|
|
21
|
+
Requires-Dist: scipy
|
|
22
|
+
Requires-Dist: tqdm
|
|
23
|
+
Requires-Dist: zarr<4,>=3.1
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: ipython; extra == 'dev'
|
|
26
|
+
Requires-Dist: pdbpp; extra == 'dev'
|
|
27
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
28
|
+
Requires-Dist: rich; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
30
|
+
Provides-Extra: gpu
|
|
31
|
+
Requires-Dist: torch; extra == 'gpu'
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest; extra == 'test'
|
|
34
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# cellcanvas-core
|
|
38
|
+
|
|
39
|
+
[](https://github.com/cellcanvas/cellcanvas-core/raw/main/LICENSE)
|
|
40
|
+
[](https://pypi.org/project/cellcanvas-core)
|
|
41
|
+
[](https://python.org)
|
|
42
|
+
[](https://github.com/cellcanvas/cellcanvas-core/actions/workflows/ci.yml)
|
|
43
|
+
[](https://codecov.io/gh/cellcanvas/cellcanvas-core)
|
|
44
|
+
|
|
45
|
+
Core components for CellCanvas
|
|
46
|
+
|
|
47
|
+
Requires Python 3.11+ and Zarr 3. New annotations use Zarr format 3.
|
|
48
|
+
|
|
49
|
+
## Array dimensions
|
|
50
|
+
|
|
51
|
+
- Images: **CZYX** (channel, depth, row, column); **BCZYX** with a batch axis.
|
|
52
|
+
- 2D images keep **Z=1**. Add a channel axis to legacy ZYX images.
|
|
53
|
+
- Labels: **ZYX**, shared across channels; zero is unannotated. Add one to
|
|
54
|
+
classifier predictions before saving as labels.
|
|
55
|
+
- Features: **DZYX**, where D is feature width. Use `feature_axis=-1` for
|
|
56
|
+
ZYXD inputs. Keep feature order consistent between training and prediction.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# cellcanvas-core
|
|
2
|
+
|
|
3
|
+
[](https://github.com/cellcanvas/cellcanvas-core/raw/main/LICENSE)
|
|
4
|
+
[](https://pypi.org/project/cellcanvas-core)
|
|
5
|
+
[](https://python.org)
|
|
6
|
+
[](https://github.com/cellcanvas/cellcanvas-core/actions/workflows/ci.yml)
|
|
7
|
+
[](https://codecov.io/gh/cellcanvas/cellcanvas-core)
|
|
8
|
+
|
|
9
|
+
Core components for CellCanvas
|
|
10
|
+
|
|
11
|
+
Requires Python 3.11+ and Zarr 3. New annotations use Zarr format 3.
|
|
12
|
+
|
|
13
|
+
## Array dimensions
|
|
14
|
+
|
|
15
|
+
- Images: **CZYX** (channel, depth, row, column); **BCZYX** with a batch axis.
|
|
16
|
+
- 2D images keep **Z=1**. Add a channel axis to legacy ZYX images.
|
|
17
|
+
- Labels: **ZYX**, shared across channels; zero is unannotated. Add one to
|
|
18
|
+
classifier predictions before saving as labels.
|
|
19
|
+
- Features: **DZYX**, where D is feature width. Use `feature_axis=-1` for
|
|
20
|
+
ZYXD inputs. Keep feature order consistent between training and prediction.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Compare pixel classifiers across volumes.
|
|
2
|
+
|
|
3
|
+
Paints random voxels of every class in k evenly spaced z slices of a
|
|
4
|
+
training volume's ground truth, fits each classifier through
|
|
5
|
+
SemanticSegmentationManager and scores the prediction against the ground
|
|
6
|
+
truth of a test volume (another tomogram), or, without one, against the
|
|
7
|
+
unpainted voxels of the training volume. Reports Dice per class, their mean,
|
|
8
|
+
and fit and predict time.
|
|
9
|
+
|
|
10
|
+
python benchmarks/compare_classifiers.py TRAIN_FEATURES.zarr \
|
|
11
|
+
TRAIN_TRUTH.zarr [TEST_FEATURES.zarr TEST_TRUTH.zarr] \
|
|
12
|
+
[--slices 1 4 16] [--voxels 200] [--seeds 0 1 2] [--background 1]
|
|
13
|
+
|
|
14
|
+
FEATURES.zarr is a (c, z, y, x) array; TRUTH.zarr a (z, y, x) integer array
|
|
15
|
+
with the stored label convention (1, 2, ... are classes; 0 is not scored).
|
|
16
|
+
Use --voxels large (e.g. 20000) to paint whole slices.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import time
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
import zarr
|
|
24
|
+
from sklearn.ensemble import RandomForestClassifier
|
|
25
|
+
|
|
26
|
+
from cellcanvas_core.data.data_manager import DataManager
|
|
27
|
+
from cellcanvas_core.data.data_set import DataSet
|
|
28
|
+
from cellcanvas_core.semantic.fewshot import FewShotClassifier
|
|
29
|
+
from cellcanvas_core.semantic.segmentation_manager import SemanticSegmentationManager
|
|
30
|
+
|
|
31
|
+
MODELS = {
|
|
32
|
+
"random forest": lambda seed: RandomForestClassifier(random_state=seed, n_jobs=-1),
|
|
33
|
+
"few-shot": lambda seed: FewShotClassifier(random_state=seed),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def paint(truth, n_slices, n_voxels, rng):
|
|
38
|
+
"""Up to n_voxels random voxels of each class in n_slices evenly spaced slices."""
|
|
39
|
+
labels = np.zeros_like(truth)
|
|
40
|
+
step = truth.shape[0] / n_slices
|
|
41
|
+
for z in (rng.uniform(0, step) + step * np.arange(n_slices)).astype(int):
|
|
42
|
+
for c in np.unique(truth[z]):
|
|
43
|
+
if c == 0:
|
|
44
|
+
continue
|
|
45
|
+
y, x = np.nonzero(truth[z] == c)
|
|
46
|
+
pick = rng.choice(len(y), min(n_voxels, len(y)), replace=False)
|
|
47
|
+
labels[z, y[pick], x[pick]] = c
|
|
48
|
+
return labels
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def dice(prediction, truth, scored, classes):
|
|
52
|
+
"""Dice of each class over the scored voxels."""
|
|
53
|
+
out = {}
|
|
54
|
+
for c in classes:
|
|
55
|
+
p, t = (prediction == c) & scored, (truth == c) & scored
|
|
56
|
+
denominator = p.sum() + t.sum()
|
|
57
|
+
out[c] = 2 * (p & t).sum() / denominator if denominator else np.nan
|
|
58
|
+
return out
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def dataset(features, labels):
|
|
62
|
+
"""A DataSet holding features and labels, with an empty image."""
|
|
63
|
+
shape = labels.shape
|
|
64
|
+
return DataSet(
|
|
65
|
+
np.zeros((1, *shape), dtype=np.uint8),
|
|
66
|
+
{"features": features},
|
|
67
|
+
labels,
|
|
68
|
+
np.zeros(shape, dtype=labels.dtype),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main():
|
|
73
|
+
"""Fit, predict and score every model."""
|
|
74
|
+
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
|
75
|
+
parser.add_argument("paths", nargs="+", help="train, then test, FEATURES TRUTH")
|
|
76
|
+
parser.add_argument("--slices", type=int, nargs="+", default=[1, 4, 16])
|
|
77
|
+
parser.add_argument("--voxels", type=int, default=200, help="per class and slice")
|
|
78
|
+
parser.add_argument("--seeds", type=int, nargs="+", default=[0, 1, 2])
|
|
79
|
+
parser.add_argument(
|
|
80
|
+
"--background", type=int, help="label left out of the mean Dice"
|
|
81
|
+
)
|
|
82
|
+
args = parser.parse_args()
|
|
83
|
+
if len(args.paths) not in (2, 4):
|
|
84
|
+
parser.error("give TRAIN_FEATURES TRAIN_TRUTH [TEST_FEATURES TEST_TRUTH]")
|
|
85
|
+
|
|
86
|
+
train_features = zarr.open_array(args.paths[0], mode="r")
|
|
87
|
+
train_truth = np.asarray(zarr.open_array(args.paths[1], mode="r"))
|
|
88
|
+
if len(args.paths) == 4:
|
|
89
|
+
test_features = zarr.open_array(args.paths[2], mode="r")
|
|
90
|
+
test_truth = np.asarray(zarr.open_array(args.paths[3], mode="r"))
|
|
91
|
+
test = dataset(test_features, np.zeros_like(test_truth))
|
|
92
|
+
else:
|
|
93
|
+
test, test_truth = None, train_truth
|
|
94
|
+
classes = [c for c in np.unique(test_truth) if c > 0]
|
|
95
|
+
shown = [c for c in classes if c != args.background]
|
|
96
|
+
|
|
97
|
+
print(
|
|
98
|
+
"| slices | model | mean Dice | "
|
|
99
|
+
+ " ".join(f"Dice {c}" for c in shown)
|
|
100
|
+
+ " | fit s | predict s |"
|
|
101
|
+
)
|
|
102
|
+
print("|---|---|---|---|---|---|")
|
|
103
|
+
for n_slices in args.slices:
|
|
104
|
+
for name, make in MODELS.items():
|
|
105
|
+
scores, fit_s, predict_s = [], [], []
|
|
106
|
+
for seed in args.seeds:
|
|
107
|
+
labels = paint(
|
|
108
|
+
train_truth, n_slices, args.voxels, np.random.default_rng(seed)
|
|
109
|
+
)
|
|
110
|
+
train = dataset(train_features, labels)
|
|
111
|
+
manager = SemanticSegmentationManager(DataManager([train]), make(seed))
|
|
112
|
+
manager.logger.setLevel("WARNING")
|
|
113
|
+
start = time.perf_counter()
|
|
114
|
+
manager.fit()
|
|
115
|
+
fit_s.append(time.perf_counter() - start)
|
|
116
|
+
start = time.perf_counter()
|
|
117
|
+
features = (train if test is None else test).concatenated_features
|
|
118
|
+
prediction = manager.predict(features) + 1
|
|
119
|
+
predict_s.append(time.perf_counter() - start)
|
|
120
|
+
scored = test_truth > 0
|
|
121
|
+
if test is None:
|
|
122
|
+
scored &= labels == 0
|
|
123
|
+
scores.append(dice(prediction, test_truth, scored, classes))
|
|
124
|
+
per_class = [np.nanmean([s[c] for s in scores]) for c in shown]
|
|
125
|
+
print(
|
|
126
|
+
f"| {n_slices} | {name} "
|
|
127
|
+
f"| {np.mean(per_class):.3f} "
|
|
128
|
+
f"| {' '.join(f'{d:.2f}' for d in per_class)} "
|
|
129
|
+
f"| {np.mean(fit_s):.1f} | {np.mean(predict_s):.1f} |",
|
|
130
|
+
flush=True,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if __name__ == "__main__":
|
|
135
|
+
main()
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# https://peps.python.org/pep-0517/
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
4
|
+
build-backend = "hatchling.build"
|
|
5
|
+
|
|
6
|
+
# https://hatch.pypa.io/latest/config/metadata/
|
|
7
|
+
[tool.hatch.version]
|
|
8
|
+
source = "vcs"
|
|
9
|
+
|
|
10
|
+
# read more about configuring hatch at:
|
|
11
|
+
# https://hatch.pypa.io/latest/config/build/
|
|
12
|
+
[tool.hatch.build.targets.wheel]
|
|
13
|
+
only-include = ["src"]
|
|
14
|
+
sources = ["src"]
|
|
15
|
+
|
|
16
|
+
# https://peps.python.org/pep-0621/
|
|
17
|
+
[project]
|
|
18
|
+
name = "cellcanvas-core"
|
|
19
|
+
dynamic = ["version"]
|
|
20
|
+
description = "Core components for CellCanvas"
|
|
21
|
+
readme = "README.md"
|
|
22
|
+
requires-python = ">=3.11"
|
|
23
|
+
license = { text = "MIT" }
|
|
24
|
+
authors = [{ name = "CellCanvas team", email = "kevin.yamauchi@gmail.com" }]
|
|
25
|
+
# https://pypi.org/classifiers/
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 3 - Alpha",
|
|
28
|
+
"License :: OSI Approved :: MIT License",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"Programming Language :: Python :: 3.13",
|
|
33
|
+
"Typing :: Typed",
|
|
34
|
+
]
|
|
35
|
+
# add your package dependencies here
|
|
36
|
+
dependencies = [
|
|
37
|
+
"numpy>=2",
|
|
38
|
+
"zarr>=3.1,<4",
|
|
39
|
+
"dask",
|
|
40
|
+
"scikit-learn",
|
|
41
|
+
"scipy",
|
|
42
|
+
"tqdm"
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
|
|
46
|
+
# "extras" (e.g. for `pip install .[test]`)
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
# add dependencies used for testing here
|
|
49
|
+
test = ["pytest", "pytest-cov"]
|
|
50
|
+
# PyTorch for FewShotClassifier on the GPU
|
|
51
|
+
gpu = ["torch"]
|
|
52
|
+
# add anything else you like to have in your dev environment here
|
|
53
|
+
dev = [
|
|
54
|
+
"ipython",
|
|
55
|
+
"pdbpp", # https://github.com/pdbpp/pdbpp
|
|
56
|
+
"pre-commit",
|
|
57
|
+
"rich", # https://github.com/Textualize/rich
|
|
58
|
+
"ruff",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[project.urls]
|
|
62
|
+
homepage = "https://github.com/cellcanvas/cellcanvas-core"
|
|
63
|
+
repository = "https://github.com/cellcanvas/cellcanvas-core"
|
|
64
|
+
|
|
65
|
+
# Entry points
|
|
66
|
+
# https://peps.python.org/pep-0621/#entry-points
|
|
67
|
+
# same as console_scripts entry point
|
|
68
|
+
# [project.scripts]
|
|
69
|
+
# cellcanvas-core-cli = "cellcanvas_core:main_cli"
|
|
70
|
+
|
|
71
|
+
# [project.entry-points."some.group"]
|
|
72
|
+
# tomatoes = "cellcanvas_core:main_tomatoes"
|
|
73
|
+
|
|
74
|
+
# https://docs.astral.sh/ruff
|
|
75
|
+
[tool.ruff]
|
|
76
|
+
line-length = 88
|
|
77
|
+
target-version = "py311"
|
|
78
|
+
src = ["src"]
|
|
79
|
+
|
|
80
|
+
# https://docs.astral.sh/ruff/rules
|
|
81
|
+
[tool.ruff.lint]
|
|
82
|
+
pydocstyle = { convention = "numpy" }
|
|
83
|
+
select = [
|
|
84
|
+
"E", # style errors
|
|
85
|
+
"W", # style warnings
|
|
86
|
+
"F", # flakes
|
|
87
|
+
"D", # pydocstyle
|
|
88
|
+
"D417", # Missing argument descriptions in Docstrings
|
|
89
|
+
"I", # isort
|
|
90
|
+
"UP", # pyupgrade
|
|
91
|
+
"C4", # flake8-comprehensions
|
|
92
|
+
"B", # flake8-bugbear
|
|
93
|
+
"A001", # flake8-builtins
|
|
94
|
+
"RUF", # ruff-specific rules
|
|
95
|
+
"TCH", # flake8-type-checking
|
|
96
|
+
"TID", # flake8-tidy-imports
|
|
97
|
+
]
|
|
98
|
+
ignore = [
|
|
99
|
+
"D401", # First line should be in imperative mood (remove to opt in)
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
[tool.ruff.lint.per-file-ignores]
|
|
103
|
+
"tests/*.py" = ["D", "S"]
|
|
104
|
+
|
|
105
|
+
# https://docs.astral.sh/ruff/formatter/
|
|
106
|
+
[tool.ruff.format]
|
|
107
|
+
docstring-code-format = true
|
|
108
|
+
skip-magic-trailing-comma = false # default is false
|
|
109
|
+
|
|
110
|
+
# https://docs.pytest.org/
|
|
111
|
+
[tool.pytest.ini_options]
|
|
112
|
+
minversion = "7.0"
|
|
113
|
+
addopts = "--import-mode=importlib"
|
|
114
|
+
testpaths = ["tests", "src/cellcanvas_core"]
|
|
115
|
+
filterwarnings = ["error"]
|
|
116
|
+
|
|
117
|
+
# https://coverage.readthedocs.io/
|
|
118
|
+
[tool.coverage.report]
|
|
119
|
+
show_missing = true
|
|
120
|
+
exclude_lines = [
|
|
121
|
+
"pragma: no cover",
|
|
122
|
+
"if TYPE_CHECKING:",
|
|
123
|
+
"@overload",
|
|
124
|
+
"except ImportError",
|
|
125
|
+
"\\.\\.\\.",
|
|
126
|
+
"raise NotImplementedError()",
|
|
127
|
+
"pass",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
[tool.coverage.run]
|
|
131
|
+
source = ["cellcanvas_core"]
|
|
132
|
+
|
|
133
|
+
# https://github.com/mgedmin/check-manifest#configuration
|
|
134
|
+
# add files that you want check-manifest to explicitly ignore here
|
|
135
|
+
# (files that are in the repo but shouldn't go in the package)
|
|
136
|
+
[tool.check-manifest]
|
|
137
|
+
ignore = [
|
|
138
|
+
".pre-commit-config.yaml",
|
|
139
|
+
".ruff_cache/**/*",
|
|
140
|
+
"tests/**/*",
|
|
141
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Core components for CellCanvas"""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version("cellcanvas-core")
|
|
7
|
+
except PackageNotFoundError:
|
|
8
|
+
__version__ = "uninstalled"
|
|
9
|
+
__author__ = "CellCanvas team"
|
|
10
|
+
__email__ = "kevin.yamauchi@gmail.com"
|