Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions formats/pyramid-generator-3d-tool/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[bumpversion]
current_version = 0.1.1-dev0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{dev}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = _
first_value = dev
values =
dev
_

[bumpversion:part:dev]

[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:VERSION]

[bumpversion:file:README.md]

[bumpversion:file:plugin.json]

[bumpversion:file:src/polus/images/formats/pyramid_generator_3d/__init__.py]

[bumpversion:file:pyramidgenerator3d.cwl]

[bumpversion:ict.yml]
162 changes: 162 additions & 0 deletions formats/pyramid-generator-3d-tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
1 change: 1 addition & 0 deletions formats/pyramid-generator-3d-tool/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
25 changes: 25 additions & 0 deletions formats/pyramid-generator-3d-tool/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM polusai/bfio:2.4.7

# environment variables defined in polusai/bfio
ENV EXEC_DIR="/opt/executables"
ENV POLUS_IMG_EXT=".ome.tif"
ENV POLUS_TAB_EXT=".csv"
ENV POLUS_LOG="INFO"

# Work directory defined in the base container
WORKDIR ${EXEC_DIR}

# TODO: Change the tool_dir to the tool directory
ENV TOOL_DIR="formats/pyramid-generator-3d-tool"

# Copy the repository into the container
RUN mkdir image-tools
COPY . ${EXEC_DIR}/image-tools

# Install the tool
RUN pip3 install "${EXEC_DIR}/image-tools/${TOOL_DIR}" --no-cache-dir

# Set the entrypoint
# TODO: Change the entrypoint to the tool entrypoint
ENTRYPOINT ["python3", "-m", "polus.images.formats.pyramid_generator_3d"]
CMD ["--help"]
75 changes: 75 additions & 0 deletions formats/pyramid-generator-3d-tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# pyramid_generator_3d (0.1.1-dev0)

Generate 3D Image Pyramid from an image collection or Zarr directory. This plugin is a wrapper for argolid.
This tool offers 2 subcommands: `Vol` and `Py3D`, for volume generation and 3D pyramid generation respectively. See [Usage](##usage) section for details.

## Options
| Name | Description | I/O | Type |
|-------------|-----------------------------------------------------------------------------|-----|--------|
|`--subCmd` | Subcommand to invoke. Options are `Vol` and `Py3D`. |Input|string |
|`--zarrDir` | Directory to Zarr arrays for generating 3D pyramid. |Input|collection|
|`--inpDir` | Directory to input image collection. Required if `--zarrDir` is unspecified.|Input|collection|
|`--filePattern` | File pattern for discovering images in `--inpDir`. |Input|collection|
|`--groupBy` | Grouping variable for images. Options are `t`, `z`, `c`. |Input|string|
|`--outDir` | Path of output directory. |Output|collection|
|`--outImgName` | Output name for Zarr arrays when using volume generation. |Input|string|
|`--baseScaleKey`| Base scale key for 3D pyramid generation. Default to 0. |Input|integer|
|`--numLevels` | Number of levels for 3D pyramid. |Input|integer|

## Usage
### Volume Generation
Use `Vol` subcommand to generate Zarr arrays from image stacks. It reads images from the input directory, groups them by specific dimension, and writes Zarr array into the output directory.
The ***required*** options for `Vol` subcommand are `--inpDir`, `--filePattern`, `--groupBy`, `outDir`, `--outImgName`
Example usage:
```
python3 -m polus.images.formats.pyramid_generator_3d --subCmd Vol --inpDir /path/to/input/images --filePattern img_r{r:ddd}_c{c:ddd}.ome.tif --groupBy c --outDir /path/to/output --outImgName output_image
```

### 3D Pyramid
Use `Py3D` subcommand to generate 3D pyramid from either <ins>(1) a directory with Zarr array</ins> or <ins>(2) a directory of images</ins>.
#### From Zarr directory
When generating from a Zarr directory, the ***required*** options are `--zarrDir`, `--outDir`, and `--numLevels`. `--baseScaleKey` defaults to 0. Since the output will be written into the Zarr directory, use the same directory for `--zarrDir` and `--outDir`.
Example usage:
```
python -m polus.images.formats.pyramid_generator_3d --subCmd Py3D --zarrDir /path/to/zarr/array --outDir /path/to/zarr/array --baseScaleKey 0 --numLevels 2
```

#### From image collection
When generating directly from an image collection, the current tool firsts calls the volume generation routine first to generate Zarr array, from which 3D pyramid is subsequently generated. Thus, all options required for `Vol` subcommand are required in addition to the required options of `Py3D` (excluding `--zarrDir`).
Together, the ***required*** options are `--inpDir`, `--filePattern`, `--groupBy`, `--outDir`, `--outImgName`, `--numLevels`. `--baseScaleKey` defaults to 0.
Example usage:
```
python -m polus.images.formats.pyramid_generator_3d --subCmd Py3D --inpDir /path/to/input/images --filePattern img_r{r:ddd}_c{c:ddd}.ome.tif --groupBy c --outDir /path/to/output --outImgName test_output --baseScaleKey 0 --numLevels 2
```

## Testing with real data

1. install ome-zarr
```
pip install ome-zarr
```

2. download an example dataset
```
cd <input_dir>
ome_zarr download https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/1884807.zarr
```

More dataset can be found [here](https://www.openmicroscopy.org/2020/11/04/zarr-data.html). To download other dataset, replace the link in the command above with other links copied from the "S3-entrypoint" column from the website.

3. modify .zarray file under `<input_dir>/1884807.zarr/0`, i.e., delete the first element in "chunks" and "shape", which correspond to the T dimension.

4. run the following command:
```
python -m polus.images.formats.pyramid_generator_3d --subCmd Py3D --zarrDir <input_path>/1884807.zarr --outDir <input_path>/1884807.zarr --baseScaleKey 0 --numLevels 2
```
Pyramid data will be written into the same folder.

## Building

To build the Docker image for the tool, run `./build-docker.sh`.

## Install WIPP Plugin

If WIPP is running, navigate to the plugins page and add a new plugin. Paste the
contents of `plugin.json` into the pop-up window and submit.
1 change: 1 addition & 0 deletions formats/pyramid-generator-3d-tool/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.1-dev0
23 changes: 23 additions & 0 deletions formats/pyramid-generator-3d-tool/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Change the name of the tool here
tool_dir="formats/"
tool_name="pyramid-generator-3d-tool"

# The version is read from the VERSION file
version=$(<VERSION)
tag="polusai/${tool_name}:${version}"
echo "Building docker image with tag: ${tag}"

# The current directory and the repository root are saved in variables
cur_dir=$(pwd)
repo_root=$(git rev-parse --show-toplevel)
echo "Repository root: ${repo_root}"

# The Dockerfile and .dockerignore files are copied to the repository root before building the image
cd ${repo_root}
cp ./${tool_dir}/${tool_name}/Dockerfile .
cp .gitignore .dockerignore
docker build . -t ${tag}
rm Dockerfile .dockerignore
cd ${cur_dir}
Loading