Skip to content

Commit a92b054

Browse files
authored
webKnossos Python Libary: initial setup (#398)
* default to -1 for largestSegmentId * Update Changelog.md * minor fix * formatting * setup folder structure and basic CI checks * use dunamai instead of setuptools_scm * fix? gh actions * trigger CI * print error * fix properties path after merge * setup folder structure, copy dataset api * fix linting * rename wklib to webknossos * formatting * remove duplicated tests * set license * use single CI workflow, refactor publish for all projects * webknossos CI only on changes, fix docker build * fix docker smoke test * fix changed check in CI * checkout HEAD~1 in CI * fix publish.sh * use webknossos import in wkcuber * pylint: ignore wildcard imports * use public links in examples * type fixes * formatting * better CI handling for unchanged files * update changelog * fix client readme
1 parent 9da0bb0 commit a92b054

File tree

430 files changed

+3131
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

430 files changed

+3131
-546
lines changed

.dockerignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
testdata
2-
testoutput
1+
wkcuber/testdata
2+
wkcuber/testoutput
3+
webknossos/testdata
4+
webknossos/testoutput

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2
22
updates:
33
- package-ecosystem: pip
4-
directory: "/"
4+
directory: "/wkcuber"
55
schedule:
66
interval: daily
77
open-pull-requests-limit: 10

.github/workflows/main.yml renamed to .github/workflows/ci.yml

Lines changed: 102 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,77 @@
11
name: CI
22

3-
on: [push]
3+
on: push
44

55
jobs:
6-
build:
6+
changes:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
webknossos: ${{ steps.filter.outputs.webknossos }}
10+
wkcuber: ${{ steps.filter.outputs.wkcuber }}
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: dorny/paths-filter@v2
14+
id: filter
15+
with:
16+
filters: |
17+
webknossos:
18+
- 'webknossos/**'
19+
wkcuber:
20+
- 'wkcuber/**'
21+
22+
webknossos_linux:
23+
needs: changes
24+
if: ${{ needs.changes.outputs.webknossos == 'true' }}
25+
runs-on: ubuntu-latest
26+
strategy:
27+
max-parallel: 4
28+
matrix:
29+
python-version: [3.7, 3.8]
30+
defaults:
31+
run:
32+
working-directory: webknossos
33+
34+
steps:
35+
- uses: actions/checkout@v2
36+
- name: Set up Python ${{ matrix.python-version }}
37+
uses: actions/setup-python@v1
38+
with:
39+
python-version: ${{ matrix.python-version }}
40+
architecture: 'x64'
41+
42+
- name: Install dependencies
43+
run: |
44+
pip install poetry
45+
poetry install
46+
47+
- name: Check formatting
48+
run: poetry run ./format.sh check
49+
50+
- name: Lint code
51+
run: poetry run pylint -j4 webknossos
52+
53+
- name: Check typing
54+
run: |
55+
poetry run ./typecheck.sh
56+
57+
- name: Python tests
58+
run: poetry run pytest tests
59+
60+
- name: Check if git is dirty
61+
run: |
62+
git diff --no-ext-diff --quiet --exit-code
63+
[[ -z $(git status -s) ]]
64+
65+
wkcuber_linux:
66+
needs: [changes]
767
runs-on: ubuntu-latest
868
strategy:
969
max-parallel: 4
1070
matrix:
1171
python-version: [3.7, 3.8]
72+
defaults:
73+
run:
74+
working-directory: wkcuber
1275

1376
steps:
1477
- uses: actions/checkout@v2
@@ -27,9 +90,11 @@ jobs:
2790

2891
- name: Check formatting
2992
run: poetry run black --check .
93+
if: ${{ needs.changes.outputs.wkcuber == 'true' }}
3094

3195
- name: Lint code
3296
run: poetry run pylint -j4 wkcuber
97+
if: ${{ needs.changes.outputs.wkcuber == 'true' }}
3398

3499
- name: Check typing
35100
run: |
@@ -45,7 +110,7 @@ jobs:
45110
if: matrix.python-version == '3.8'
46111
run: |
47112
docs/api.sh --persist
48-
113+
49114
- name: Push docs (for branch)
50115
if: startsWith(github.event.ref, 'refs/heads') && matrix.python-version == '3.8'
51116
env:
@@ -72,20 +137,16 @@ jobs:
72137
git diff --no-ext-diff --quiet --exit-code
73138
[[ -z $(git status -s) ]]
74139
75-
- name: Publish python package
76-
if: startsWith(github.event.ref, 'refs/tags') && matrix.python-version == '3.8'
77-
env:
78-
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
79-
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
80-
run: ./publish.sh
81-
82-
build_win:
140+
wkcuber_win:
83141
# Caution! The Windows VM seems to be running out of storage rather quickly.
84142
runs-on: windows-latest
85143
strategy:
86144
max-parallel: 4
87145
matrix:
88146
python-version: [3.7, 3.8]
147+
defaults:
148+
run:
149+
working-directory: wkcuber
89150

90151
steps:
91152
- uses: actions/checkout@v2
@@ -112,12 +173,15 @@ jobs:
112173
shell: bash
113174
run: tests/scripts/all_tests.sh
114175

115-
build_mac:
176+
wkcuber_mac:
116177
runs-on: macos-latest
117178
strategy:
118179
max-parallel: 4
119180
matrix:
120181
python-version: [3.7, 3.8]
182+
defaults:
183+
run:
184+
working-directory: wkcuber
121185

122186
steps:
123187
- uses: actions/checkout@v2
@@ -140,19 +204,19 @@ jobs:
140204
- name: CLI tests
141205
run: tests/scripts/all_tests.sh
142206

143-
docker:
144-
needs: [build, build_win, build_mac]
207+
wkcuber_docker:
208+
needs: [webknossos_linux, wkcuber_linux, wkcuber_win, wkcuber_mac]
145209
runs-on: ubuntu-latest
146210

147211
steps:
148212
- uses: actions/checkout@v2
149213
- name: Build docker image
150-
run: docker build -t scalableminds/webknossos-cuber:$GITHUB_SHA .
214+
run: docker build -t scalableminds/webknossos-cuber:$GITHUB_SHA -f wkcuber/Dockerfile .
151215

152216
- name: Smoke test docker
153217
run: |
154218
docker run --rm \
155-
-v$(pwd)/testdata:/app/testdata \
219+
-v$(pwd)/wkcuber/testdata:/app/testdata \
156220
scalableminds/webknossos-cuber:$GITHUB_SHA \
157221
wkcuber.cubing \
158222
--jobs 2 \
@@ -196,3 +260,25 @@ jobs:
196260
scalableminds/webknossos-cuber:latest
197261
docker push scalableminds/webknossos-cuber:latest
198262
fi
263+
264+
pypi:
265+
needs: [webknossos_linux, wkcuber_linux, wkcuber_win, wkcuber_mac]
266+
if: startsWith(github.event.ref, 'refs/tags')
267+
runs-on: ubuntu-latest
268+
strategy:
269+
max-parallel: 4
270+
271+
steps:
272+
- uses: actions/checkout@v2
273+
- name: Set up Python 3.8
274+
uses: actions/setup-python@v1
275+
with:
276+
python-version: 3.8
277+
architecture: 'x64'
278+
- name: Install dependencies
279+
run: pip3 install -r requirements.txt
280+
- name: Publish python packages
281+
env:
282+
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
283+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
284+
run: ./publish.sh

Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,12 @@
1-
# webKnossos cuber (wkcuber)
2-
[![PyPI version](https://img.shields.io/pypi/v/wkcuber)](https://pypi.python.org/pypi/wkcuber)
3-
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/wkcuber.svg)](https://pypi.python.org/pypi/wkcuber)
4-
[![Build Status](https://img.shields.io/github/workflow/status/scalableminds/webknossos-cuber/CI/master)](https://github.com/scalableminds/webknossos-cuber/actions?query=workflow%3A%22CI%22)
5-
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1+
# webKnossos-libs
2+
<img align="right" src="https://static.webknossos.org/images/oxalis.svg" alt="webKnossos Logo" />
63

7-
Python library for creating and working with [webKnossos](https://webknossos.org) [WKW](https://github.com/scalableminds/webknossos-wrap) datasets. WKW is a container format for efficiently storing large, scale 3D image data as found in (electron) microscopy.
8-
9-
The tools are modular components to allow easy integration into existing pipelines and workflows.
10-
11-
## Features
12-
13-
* `wkcuber`: Convert supported input files to fully ready WKW datasets (includes type detection, downsampling, compressing and metadata generation)
14-
* `wkcuber.convert_image_stack_to_wkw`: Convert image stacks to fully ready WKW datasets (includes downsampling, compressing and metadata generation)
15-
* `wkcuber.export_wkw_as_tiff`: Convert WKW datasets to a tiff stack (writing as tiles to a `z/y/x.tiff` folder structure is also supported)
16-
* `wkcuber.cubing`: Convert image stacks (e.g., `tiff`, `jpg`, `png`, `dm3`, `dm4`) to WKW cubes
17-
* `wkcuber.tile_cubing`: Convert tiled image stacks (e.g. in `z/y/x.ext` folder structure) to WKW cubes
18-
* `wkcuber.convert_knossos`: Convert KNOSSOS cubes to WKW cubes
19-
* `wkcuber.convert_nifti`: Convert NIFTI files to WKW files (Currently without applying transformations).
20-
* `wkcuber.downsampling`: Create downsampled magnifications (with `median`, `mode` and linear interpolation modes). Downsampling compresses the new magnifications by default (disable via `--no-compress`).
21-
* `wkcuber.compress`: Compress WKW cubes for efficient file storage (especially useful for segmentation data)
22-
* `wkcuber.metadata`: Create (or refresh) metadata (with guessing of most parameters)
23-
* `wkcuber.recubing`: Read existing WKW cubes in and write them again specifying the WKW file length. Useful when dataset was written e.g. with file length 1.
24-
* `wkcuber.check_equality`: Compare two WKW datasets to check whether they are equal (e.g., after compressing a dataset, this task can be useful to double-check that the compressed dataset contains the same data).
25-
* Most modules support multiprocessing
26-
27-
## Supported input formats
28-
29-
* Standard image formats, e.g. `tiff`, `jpg`, `png`, `bmp`
30-
* Proprietary image formats, e.g. `dm3`
31-
* Tiled image stacks (used for Catmaid)
32-
* KNOSSOS cubes
33-
* NIFTI files
34-
35-
## Installation
36-
### Python 3 with pip from PyPi
37-
- `wkcuber` requires at least Python 3.6+
38-
39-
```
40-
# Make sure to have lz4 installed:
41-
# Mac: brew install lz4
42-
# Ubuntu/Debian: apt-get install liblz4-1
43-
# CentOS/RHEL: yum install lz4
44-
45-
pip install wkcuber
46-
```
47-
48-
### Docker
49-
Use the CI-built image: [scalableminds/webknossos-cuber](https://hub.docker.com/r/scalableminds/webknossos-cuber/). Example usage `docker run -v <host path>:/data --rm scalableminds/webknossos-cuber wkcuber --layer_name color --scale 11.24,11.24,25 --name great_dataset /data/source/color /data/target`.
50-
51-
52-
## Usage
53-
54-
```
55-
# Convert arbitrary, supported input files into wkw datasets. This sets reasonable defaults, but see other commands for customization.
56-
python -m wkcuber \
57-
--scale 11.24,11.24,25 \
58-
data/source data/target
59-
60-
# Convert image stacks into wkw datasets
61-
python -m wkcuber.convert_image_stack_to_wkw \
62-
--layer_name color \
63-
--scale 11.24,11.24,25 \
64-
--name great_dataset \
65-
data/source/color data/target
66-
67-
# Convert image files to wkw cubes
68-
python -m wkcuber.cubing --layer_name color data/source/color data/target
69-
python -m wkcuber.cubing --layer_name segmentation data/source/segmentation data/target
70-
71-
# Convert tiled image files to wkw cubes
72-
python -m wkcuber.tile_cubing --layer_name color data/source data/target
73-
74-
# Convert Knossos cubes to wkw cubes
75-
python -m wkcuber.convert_knossos --layer_name color data/source/mag1 data/target
4+
Collection of libraries around webKnossos, please see the respective subfolders:
765

77-
# Convert NIFTI file to wkw file
78-
python -m wkcuber.convert_nifti --layer_name color --scale 10,10,30 data/source/nifti_file data/target
6+
## [webKnossos cuber (wkcuber)](wkcuber)
7+
[![PyPI version](https://img.shields.io/pypi/v/wkcuber)](https://pypi.python.org/pypi/wkcuber) [![Supported Python Versions](https://img.shields.io/pypi/pyversions/wkcuber.svg)](https://pypi.python.org/pypi/wkcuber)
798

80-
# Convert folder with NIFTI files to wkw files
81-
python -m wkcuber.convert_nifti --color_file one_nifti_file --segmentation_file --scale 10,10,30 another_nifti data/source/ data/target
82-
83-
# Create downsampled magnifications
84-
python -m wkcuber.downsampling --layer_name color data/target
85-
python -m wkcuber.downsampling --layer_name segmentation --interpolation_mode mode data/target
86-
87-
# Compress data in-place (mostly useful for segmentation)
88-
python -m wkcuber.compress --layer_name segmentation data/target
89-
90-
# Compress data copy (mostly useful for segmentation)
91-
python -m wkcuber.compress --layer_name segmentation data/target data/target_compress
92-
93-
# Create metadata
94-
python -m wkcuber.metadata --name great_dataset --scale 11.24,11.24,25 data/target
95-
96-
# Refresh metadata so that new layers and/or magnifications are picked up
97-
python -m wkcuber.metadata --refresh data/target
98-
99-
# Recubing an existing dataset
100-
python -m wkcuber.recubing --layer_name color --dtype uint8 /data/source/wkw /data/target
101-
102-
# Check two datasets for equality
103-
python -m wkcuber.check_equality /data/source /data/target
104-
```
105-
106-
### Parallelization
107-
108-
Most tasks can be configured to be executed in a parallelized manner. Via `--distribution_strategy` you can pass `multiprocessing` or `slurm`. The first can be further configured with `--jobs` and the latter via `--job_resources='{"mem": "10M"}'`. Use `--help` to get more information.
109-
110-
## Development
111-
Make sure to install all the required dependencies using Poetry:
112-
```
113-
pip install poetry
114-
poetry install
115-
```
116-
117-
Please, format, lint, and unit test your code changes before merging them.
118-
```
119-
poetry run black .
120-
poetry run pylint -j4 wkcuber
121-
poetry run pytest tests
122-
```
123-
124-
Please, run the extended test suite:
125-
```
126-
tests/scripts/all_tests.sh
127-
```
128-
129-
PyPi releases are automatically pushed when creating a new Git tag/Github release.
130-
131-
## API documentation
132-
Check out the [latest version of the API documentation](https://static.webknossos.org/lib-docs/master/wkcuber/api.html).
133-
134-
### Generate the API documentation
135-
Run `docs/api.sh` to open a server displaying the API docs. `docs/api.sh --persist` persists the html to `docs/api`.
136-
137-
## Test Data Credits
138-
Excerpts for testing purposes have been sampled from:
139-
- Dow Jacobo Hossain Siletti Hudspeth (2018). **Connectomics of the zebrafish's lateral-line neuromast reveals wiring and miswiring in a simple microcircuit.** eLife. [DOI:10.7554/eLife.33988](https://elifesciences.org/articles/33988)
140-
- Zheng Lauritzen Perlman Robinson Nichols Milkie Torrens Price Fisher Sharifi Calle-Schuler Kmecova Ali Karsh Trautman Bogovic Hanslovsky Jefferis Kazhdan Khairy Saalfeld Fetter Bock (2018). **A Complete Electron Microscopy Volume of the Brain of Adult Drosophila melanogaster.** Cell. [DOI:10.1016/j.cell.2018.06.019](https://www.cell.com/cell/fulltext/S0092-8674(18)30787-6). License: [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)
9+
Python library for creating and working with [webKnossos](https://webknossos.org) [WKW](https://github.com/scalableminds/webknossos-wrap) datasets. WKW is a container format for efficiently storing large, scale 3D image data as found in (electron) microscopy.
14110

142-
## License
143-
AGPLv3
144-
Copyright scalable minds
11+
## [webKnossos](webknossos) Python Library
12+
:construction: WIP

0 commit comments

Comments
 (0)