diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index 94df73c..4c4b2b9 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -1,28 +1,21 @@ -name: 'build-test-publish' +name: "build-test-publish" -on: - [push, pull_request] - -environment: - name: pypi - url: https://pypi.org/p/ -permissions: - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing +on: [push, pull_request] jobs: build_wheel: name: Build Python wheels runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: "3.11" - name: "Build pure Python wheels" run: | python -m pip wheel -w dist -e src/ - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: wheel path: ./dist/itk_dreg-*.whl @@ -33,36 +26,36 @@ jobs: needs: - build_wheel steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Update pip - run: | - python -m pip install --upgrade pip + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + - name: Update pip + run: | + python -m pip install --upgrade pip - - name: "Install Dependencies" - shell: bash - run: | - python -m pip install flit - cd src - flit install --deps develop + - name: "Install Dependencies" + shell: bash + run: | + python -m pip install flit + cd src + flit install --deps develop - - name: Download Python Wheel Artifact - uses: actions/download-artifact@v3 - with: - name: wheel + - name: Download Python Wheel Artifact + uses: actions/download-artifact@v4 + with: + name: wheel - - name: "Install itk_dreg from Wheel Artifact" - run: | - wheel_name_full=`(find . -name "itk_dreg-*.whl")` - python -m pip uninstall -y itk_dreg - python -m pip install ${wheel_name_full} + - name: "Install itk_dreg from Wheel Artifact" + run: | + wheel_name_full=`(find . -name "itk_dreg-*.whl")` + python -m pip uninstall -y itk_dreg + python -m pip install ${wheel_name_full} - - name: "Run Tests" - shell: bash - run: | - pytest ./test -vvv -s -k "not localcluster and not serialize_pairwise_result" + - name: "Run Tests" + shell: bash + run: | + pytest ./test -vvv -s -k "not localcluster and not serialize_pairwise_result" publish: needs: @@ -70,14 +63,20 @@ jobs: - pytest runs-on: ubuntu-22.04 if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') + environment: + name: pypi + url: https://pypi.org/p/itk-dreg + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: - - name: Download Python Wheel Artifact - uses: actions/download-artifact@v3 - with: - name: wheel - path: dist + - name: Download Python Wheel Artifact + uses: actions/download-artifact@v4 + with: + name: wheel + path: dist - - name: "Publish Python wheel to the Python Package Index" - uses: pypa/gh-action-pypi-publish@v1.8.10 - with: - skip_existing: true + - name: "Publish Python wheel to the Python Package Index" + uses: pypa/gh-action-pypi-publish@v1.8.10 + with: + skip_existing: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 08d68b5..ed84bf5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,23 +1,22 @@ -name: 'lint' +name: "lint" -on: - [push, pull_request] +on: [push, pull_request] jobs: ruff-check: name: "Lint with Ruff" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: chartboost/ruff-action@v1 - with: - src: "./src" + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 + with: + src: "./src" black-autoformat: name: "Lint with Black" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: psf/black@stable - with: - src: "./src" + - uses: actions/checkout@v4 + - uses: psf/black@stable + with: + src: "./src" diff --git a/.github/workflows/make-docs.yml b/.github/workflows/make-docs.yml deleted file mode 100644 index 5e62712..0000000 --- a/.github/workflows/make-docs.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: 'doc' - -on: - [push, pull_request] - -permissions: - pages: write - id-token: write - -jobs: - sphinx-doc: - name: "Build HTML Documentation with Sphinx" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Update pip - run: | - python -m pip install --upgrade pip - - - name: "Install Dependencies" - shell: bash - run: | - python -m pip install flit - cd src - flit install --deps develop - - - name: "Build HTML API Documentation" - shell: bash - run: | - sphinx-apidoc -o tmp/apidoc src/itk_dreg --full - sed -i -e 's/alabaster/furo/' tmp/apidoc/conf.py - sphinx-build tmp/apidoc tmp/html - - - name: Upload HTML artifact - uses: actions/upload-artifact@v3 - with: - name: itk-dreg-html-docs - path: tmp/html/* - - - uses: actions/upload-pages-artifact@v2.0.0 - with: - path: tmp/html - - deploy: - if: github.ref == 'refs/heads/main' - needs: - - sphinx-doc - runs-on: ubuntu-22.04 - name: "Deploy HTML Documentation" - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v2 diff --git a/.github/workflows/test-notebooks.yml b/.github/workflows/test-notebooks.yml index 54c29db..94a1062 100644 --- a/.github/workflows/test-notebooks.yml +++ b/.github/workflows/test-notebooks.yml @@ -1,7 +1,6 @@ -name: 'test-notebooks' +name: "test-notebooks" -on: - [push, pull_request] +on: [push, pull_request] env: aind-ccf-alignment-experiments-tag: 756e846d08b07fcffbc3c387216a59a9fa563fd6 @@ -11,32 +10,32 @@ jobs: name: "Test Jupyter Notebooks with PyTest" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Update pip - run: | - python -m pip install --upgrade pip - - name: Setup Graphviz - uses: ts-graphviz/setup-graphviz@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + - name: Update pip + run: | + python -m pip install --upgrade pip + - name: Setup Graphviz + uses: ts-graphviz/setup-graphviz@v1 - - name: "Install Dependencies Not Available on PyPI" - shell: bash - run: | - git clone https://github.com/AllenNeuralDynamics/aind-ccf-alignment-experiments.git - pushd aind-ccf-alignment-experiments - git checkout ${{ env.aind-ccf-alignment-experiments-tag }} - python -m pip install . + - name: "Install Dependencies Not Available on PyPI" + shell: bash + run: | + git clone https://github.com/AllenNeuralDynamics/aind-ccf-alignment-experiments.git + pushd aind-ccf-alignment-experiments + git checkout ${{ env.aind-ccf-alignment-experiments-tag }} + python -m pip install . - - name: "Install Dependencies with Flit" - shell: bash - run: | - python -m pip install flit - pushd src - flit install --extras all + - name: "Install Dependencies with Flit" + shell: bash + run: | + python -m pip install flit + pushd src + flit install --extras all - - name: "Run Tests" - shell: bash - run: | - pytest --nbmake --nbmake-timeout=30000 examples/*.ipynb -vvv -s -k "not LightsheetRegistration.ipynb" + - name: "Run Tests" + shell: bash + run: | + pytest --nbmake --nbmake-timeout=30000 examples/*.ipynb -vvv -s -k "not LightsheetRegistration.ipynb" diff --git a/.gitignore b/.gitignore index 76335b4..c3ef096 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ examples/mydask.png data/ _build/ tmp/ +docs/apidocs/ diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/_static/favicon.png b/docs/_static/favicon.png new file mode 100644 index 0000000..bd1e535 Binary files /dev/null and b/docs/_static/favicon.png differ diff --git a/docs/_static/logo.svg b/docs/_static/logo.svg new file mode 100644 index 0000000..669a445 --- /dev/null +++ b/docs/_static/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..c015a7f --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,57 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +from datetime import date +import os + +project = 'itk-dreg' +copyright = f'{date.today().year}, NumFOCUS' +author = 'Insight Software Consortium' + +extensions = [ + 'sphinx.ext.autosummary', + 'autodoc2', + 'myst_parser', + 'sphinx.ext.intersphinx', + 'sphinx_copybutton', + 'sphinxext.opengraph', + 'sphinx_design', +] + +myst_enable_extensions = ["colon_fence", "fieldlist"] + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +autodoc2_packages = [ + { + "path": "../src/itk_dreg", + "exclude_files": [], + }, +] +autodoc2_render_plugin = "myst" + +intersphinx_mapping = { + "python": ("https://docs.python.org/3/", None), + "itkwasm": ("https://itkwasm.readthedocs.io/en/latest/", None), +} + +html_theme = 'furo' +html_static_path = ['_static'] +html_logo = "_static/logo.svg" +html_favicon = "_static/favicon.png" +html_title = f"{project}" +html_baseurl = os.environ.get("SPHINX_BASE_URL", "") + +# Furo options +html_theme_options = { + "top_of_page_button": "edit", + "source_repository": "https://github.com/InsightSoftwareConsortium/itk-dreg", + "source_branch": "main", + "source_directory": "docs", +} diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..e9f5edf --- /dev/null +++ b/docs/index.md @@ -0,0 +1,28 @@ +itk-dreg +======= + +> A framework for distributed, large-scale image registration. + +[![itk-dreg version](https://badge.fury.io/py/itk-dreg.svg)](https://pypi.org/project/itk-dreg/) + +## Installation + +```shell +pip install itk-dreg +``` + +```{toctree} +:hidden: +:maxdepth: 3 +:caption: 📖 Reference + +apidocs/index.rst +``` + +```{toctree} +:hidden: +:maxdepth: 3 +:caption: 📖 Contributors + +develop.md +``` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..c10181d --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,7 @@ +sphinx +furo +sphinx-autodoc2>=0.5.0 +myst-parser +sphinx-copybutton +sphinxext-opengraph +sphinx-design diff --git a/src/itk_dreg/block/image.py b/src/itk_dreg/block/image.py index 36169aa..199a85d 100644 --- a/src/itk_dreg/block/image.py +++ b/src/itk_dreg/block/image.py @@ -182,9 +182,11 @@ def physical_region_to_itk_image( voxel_0_corner = np.array( [ - np.min(output_region, axis=0)[dim] - if physical_step[dim] > 0 - else np.max(output_region, axis=0)[dim] + ( + np.min(output_region, axis=0)[dim] + if physical_step[dim] > 0 + else np.max(output_region, axis=0)[dim] + ) for dim in range(3) ] ) diff --git a/src/itk_dreg/elastix/register.py b/src/itk_dreg/elastix/register.py index 44f1d9b..1e217f9 100644 --- a/src/itk_dreg/elastix/register.py +++ b/src/itk_dreg/elastix/register.py @@ -208,9 +208,9 @@ def __call__( physical_region=block_convert.image_to_physical_region( image_region=fixed_subimage.GetBufferedRegion(), ref_image=fixed_subimage, - src_transform=None - if preprocess_initial_transform - else initial_transform, + src_transform=( + None if preprocess_initial_transform else initial_transform + ), ), spacing=itk.spacing(fixed_subimage), direction=fixed_subimage.GetDirection(), diff --git a/src/itk_dreg/reduce_dfield/transform_collection.py b/src/itk_dreg/reduce_dfield/transform_collection.py index e58f608..df8cfb8 100644 --- a/src/itk_dreg/reduce_dfield/transform_collection.py +++ b/src/itk_dreg/reduce_dfield/transform_collection.py @@ -124,9 +124,11 @@ def blend_distance_weighted_mean( entry.transform.TransformPoint(input_pt) for entry in region_contributors ] weights = [ - cls._physical_distance_from_edge(input_pt, entry.domain)[0] - if entry.domain - else MIN_WEIGHT + ( + cls._physical_distance_from_edge(input_pt, entry.domain)[0] + if entry.domain + else MIN_WEIGHT + ) for entry in region_contributors ]