Skip to content

Commit

Permalink
Merge pull request #33 from thewtex/hatch
Browse files Browse the repository at this point in the history
hatch
  • Loading branch information
thewtex authored Apr 22, 2024
2 parents 534fba9 + f06a2e7 commit 213b851
Show file tree
Hide file tree
Showing 19 changed files with 586 additions and 433 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ jobs:
python-version: "3.11"
- name: "Build pure Python wheels"
run: |
python -m pip wheel -w dist -e src/
python -m pip install hatch
cd src
hatch build
- uses: actions/upload-artifact@v4
with:
name: wheel
path: ./dist/itk_dreg-*.whl
path: ./src/dist/itk_dreg-*.whl

pytest:
name: "Test with PyTest"
Expand All @@ -36,26 +38,21 @@ jobs:
- name: "Install Dependencies"
shell: bash
working-directory: src
run: |
python -m pip install flit
cd src
flit install --deps develop
- name: Download Python Wheel Artifact
uses: actions/download-artifact@v4
with:
name: wheel
python -m pip install -e '.[test]'
- name: "Install itk_dreg from Wheel Artifact"
- name: "Install itk-dreg from source"
working-directory: src
run: |
wheel_name_full=`(find . -name "itk_dreg-*.whl")`
python -m pip uninstall -y itk_dreg
python -m pip install ${wheel_name_full}
python -m pip install -e '.[test]'
- name: "Run Tests"
shell: bash
working-directory: src
run: |
pytest ./test -vvv -s -k "not localcluster and not serialize_pairwise_result"
pytest -vvv -s -k "not localcluster and not serialize_pairwise_result"
publish:
needs:
Expand Down
4 changes: 2 additions & 2 deletions src/itk_dreg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ITK-DREG Distributed registration framework.
itk-dreg distributed registration framework.
"""

__version__ = "0.0.1"
__version__ = "0.1.0"
48 changes: 36 additions & 12 deletions src/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "itk_dreg"
authors = [{name = "InsightSoftwareConsortium", email = "matt.mccormick@kitware.com"}]
name = "itk-dreg"
authors = [
{name = "Matt McCormick", email = "matt.mccormick@kitware.com"},
{name = "Tom Birdsong", email = "tom.birdsong@kitware.com"}
]
license = {file = "LICENSE"}
classifiers = [
"License :: OSI Approved :: Apache Software License",
Expand All @@ -26,23 +29,25 @@ classifiers = [
"Operating System :: MacOS"
]
requires-python = ">=3.9"
dynamic = ["version", "description"]
dynamic = ["version"]
readme = "../README.md"
keywords = ['ITK','InsightToolkit']
keywords = ['itk','InsightToolkit','registration', 'brain','distributed', 'dask']

dependencies = [
'dask[distributed] >=2023.10.0',
'itk >=5.4rc02',
'itk >=5.4rc04',
'numpy'
]

[project.urls]
Home = "https://github.com/InsightSoftwareConsortium/itk-dreg"
Home = "https://itk-dreg.readthedocs.io/"
Source = "https://github.com/InsightSoftwareConsortium/itk-dreg"
Issues = "https://github.com/InsightSoftwareConsortium/issues"

[project.optional-dependencies]
test = [
'itk-elastix>=0.19.1',
'itk-ioomezarrngff>=0.2.1',
'itk-elastix>=0.19.2',
'itk-ioomezarrngff>=0.3rc1',
'nbmake',
'pytest',
'scipy>=1.11.3'
Expand All @@ -60,7 +65,7 @@ doc = [
]

impl = [
'itk-elastix>=0.19.0',
'itk-elastix>=0.19.2',
'scipy>=1.11.3'
]

Expand All @@ -77,6 +82,25 @@ notebook = [
'graphviz',
]

[tool.ruff]
[tool.ruff.lint]
extend-ignore = ["E501"]

[tool.hatch.version]
path = "itk_dreg/__init__.py"

[tool.hatch.envs.default]
dependencies = [
'itk-elastix>=0.19.2',
'scipy>=1.11.3',
'itk-ioomezarrngff>=0.3rc1',
'nbmake',
'pytest',
]

[tool.hatch.envs.default.scripts]
test = [
"pytest -vvv -s"
]

[tool.black]
line-length = 88
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@


def test_loadmodule():
import itk_dreg.elastix
import itk_dreg.elastix.util
import itk_dreg.elastix.register
pass
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import itk
import numpy as np
import dask
import dask.array as da

sys.path.append('./src')
import itk_dreg.itk
from itk_dreg.register import register_images

Expand All @@ -30,41 +28,47 @@
https://github.com/InsightSoftwareConsortium/ITKElastix/issues/255
"""


def test_run_dreg():
dask.config.set(scheduler='single-threaded')
dask.config.set(scheduler="single-threaded")

fixed_arr = np.ones([100] * 3)
moving_arr = np.random.random_sample([50] * 3).astype(np.float32)

fixed_arr = np.ones([100]*3)
moving_arr = np.random.random_sample([50]*3).astype(np.float32)

register_method = ElastixDRegBlockPairRegistrationMethod()
reduce_method = dreg_mock.CountingReduceResultsMethod()

registration_result = None
registration_schedule = None

with tempfile.TemporaryDirectory() as testdir:
FIXED_FILEPATH = f'{testdir}/fixed_image.mha'
MOVING_FILEPATH = f'{testdir}/moving_image.mha'
FIXED_FILEPATH = f"{testdir}/fixed_image.mha"
MOVING_FILEPATH = f"{testdir}/moving_image.mha"
fixed_image = itk.image_view_from_array(fixed_arr)
itk.imwrite(fixed_image, FIXED_FILEPATH, compression=False)
fixed_cb = lambda : itk_dreg.itk.make_reader(FIXED_FILEPATH)

def fixed_cb():
return itk_dreg.itk.make_reader(FIXED_FILEPATH)

moving_image = itk.image_view_from_array(moving_arr)
moving_image.SetSpacing([2]*3)
moving_image.SetSpacing([2] * 3)
itk.imwrite(moving_image, MOVING_FILEPATH, compression=False)
moving_cb = lambda : itk_dreg.itk.make_reader(MOVING_FILEPATH)

def moving_cb():
return itk_dreg.itk.make_reader(MOVING_FILEPATH)

parameter_object = itk.ParameterObject.New()
parameter_object.AddParameterMap(
parameter_object.GetDefaultParameterMap('rigid')
parameter_object.GetDefaultParameterMap("rigid")
)

registration_schedule = register_images(
fixed_chunk_size=(10,20,100),
initial_transform=itk.TranslationTransform[itk.D,3].New(),
fixed_chunk_size=(10, 20, 100),
initial_transform=itk.TranslationTransform[itk.D, 3].New(),
moving_reader_ctor=moving_cb,
fixed_reader_ctor=fixed_cb,
reduce_method=reduce_method,
overlap_factors=[0.1]*3,
overlap_factors=[0.1] * 3,
block_registration_method=register_method,
elx_parameter_object_serial=parameter_object_to_list(parameter_object),
itk_transform_types=[itk.Euler3DTransform[itk.D]],
Expand All @@ -76,4 +80,3 @@ def test_run_dreg():

assert reduce_method.num_calls == 1
assert registration_result.status.shape == registration_schedule.fixed_da.numblocks

Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
from unittest.mock import DEFAULT
import itk
itk.auto_progress(2)

import pickle
import dask.distributed.protocol

import itk_dreg.elastix.serialize

itk.auto_progress(2)


def validate_parameter_maps(m1, m2):
assert all([k in m2.keys() for k in m1.keys()])
assert all([k in m1.keys() for k in m2.keys()])
for key in m1.keys():
assert m1[key] == m2[key]


def validate_parameter_objects(p1, p2):
assert p1.GetNumberOfParameterMaps() == p2.GetNumberOfParameterMaps()
for map_index in range(p1.GetNumberOfParameterMaps()):
validate_parameter_maps(p1.GetParameterMap(map_index), p2.GetParameterMap(map_index))
validate_parameter_maps(
p1.GetParameterMap(map_index), p2.GetParameterMap(map_index)
)


def test_serialize_elx_parameter_object():
DEFAULT_PARAMETER_MAPS = ['rigid']
DEFAULT_PARAMETER_MAPS = ["rigid"]
parameter_object = itk.ParameterObject.New()
parameter_object.AddParameterMap(
itk.ParameterObject.GetDefaultParameterMap(DEFAULT_PARAMETER_MAPS[0])
)

parameter_list = itk_dreg.elastix.serialize.parameter_object_to_list(parameter_object)
parameter_list = itk_dreg.elastix.serialize.parameter_object_to_list(
parameter_object
)
pickled_parameter_list = pickle.dumps(parameter_list)
unpickled_parameter_list = pickle.loads(pickled_parameter_list)
unpickled_parameter_object = itk_dreg.elastix.serialize.list_to_parameter_object(unpickled_parameter_list)
unpickled_parameter_object = itk_dreg.elastix.serialize.list_to_parameter_object(
unpickled_parameter_list
)
validate_parameter_objects(unpickled_parameter_object, parameter_object)

# TODO: https://github.com/InsightSoftwareConsortium/ITKElastix/issues/257
Expand All @@ -43,7 +51,7 @@ def test_serialize_elx_parameter_object():

# Validate baseline is unchanged
assert parameter_object.GetNumberOfParameterMaps() == 1
validate_parameter_maps(parameter_object.GetParameterMap(0),
itk.ParameterObject.GetDefaultParameterMap(DEFAULT_PARAMETER_MAPS[0]))


validate_parameter_maps(
parameter_object.GetParameterMap(0),
itk.ParameterObject.GetDefaultParameterMap(DEFAULT_PARAMETER_MAPS[0]),
)
Loading

0 comments on commit 213b851

Please sign in to comment.