From 5ea75b1fdb9830ec4039b75390c74e2e099a28ac Mon Sep 17 00:00:00 2001 From: plaresmedima Date: Tue, 17 Dec 2024 11:39:11 +0000 Subject: [PATCH 1/4] Add elastix error handling --- src/mdreg/elastix.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/mdreg/elastix.py b/src/mdreg/elastix.py index ceee3a0..472f872 100644 --- a/src/mdreg/elastix.py +++ b/src/mdreg/elastix.py @@ -1,5 +1,6 @@ import __main__ import os +import warnings import multiprocessing import numpy as np from tqdm import tqdm @@ -262,10 +263,16 @@ def _coreg_2d(source_large, target_large, spacing, downsample, log, mask, target_small.SetSpacing(spacing_small) source_small.SetOrigin(origin_small) target_small.SetOrigin(origin_small) - coreg_small, result_transform_parameters = itk.elastix_registration_method( - target_small, source_small, - parameter_object=params_obj, - log_to_console=log) + try: + coreg_small, result_transform_parameters = itk.elastix_registration_method( + target_small, source_small, + parameter_object=params_obj, + log_to_console=log) + except: + warnings.warn('Elastix coregistration failed. Returning zero ' + 'deformation field. To find out the error, set log=True.') + deformation_field = np.zeros(source_large.shape + (len(source_large.shape), )) + return source_large.copy(), deformation_field # Get coregistered image at original size large_shape_x, large_shape_y = source_large.shape @@ -331,10 +338,16 @@ def _coreg_3d(source_large, target_large, spacing, downsample, log, mask, target_small.SetSpacing(spacing_small) source_small.SetOrigin(origin_small) target_small.SetOrigin(origin_small) - coreg_small, result_transform_parameters = itk.elastix_registration_method( - target_small, source_small, - parameter_object=params_obj, - log_to_console=log) # perform registration of downsampled image + try: + coreg_small, result_transform_parameters = itk.elastix_registration_method( + target_small, source_small, + parameter_object=params_obj, + log_to_console=log) # perform registration of downsampled image + except: + warnings.warn('Elastix coregistration failed. Returning zero ' + 'deformation field. To find out the error, set log=True.') + deformation_field = np.zeros(source_large.shape + (len(source_large.shape), )) + return source_large.copy(), deformation_field # Get coregistered image at original size result_transform_parameters.SetParameter(0, "Size", [str(large_shape_z), str(large_shape_y), str(large_shape_x)]) From 9dcb33efa6e810e776b73f382922ee8bf714b9c4 Mon Sep 17 00:00:00 2001 From: plaresmedima Date: Tue, 17 Dec 2024 15:47:55 +0000 Subject: [PATCH 2/4] update homepage --- pyproject.toml | 3 +- sops.txt | 83 -------------------------------------------------- 2 files changed, 2 insertions(+), 84 deletions(-) delete mode 100644 sops.txt diff --git a/pyproject.toml b/pyproject.toml index 644ae71..5ca7624 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,8 @@ keywords = ['python', "medical imaging", "motion correction", "registration"] requires-python = ">=3.6" [project.urls] -"Homepage" = "https://github.com/QIB-Sheffield/mdreg" +"Homepage" = "https://qib-sheffield.github.io/mdreg/" +"Source Code" = "https://github.com/QIB-Sheffield/mdreg" [tool.setuptools] # ... diff --git a/sops.txt b/sops.txt deleted file mode 100644 index a6c4d5c..0000000 --- a/sops.txt +++ /dev/null @@ -1,83 +0,0 @@ -SOPs for maintainers -******************** - -Building a virtual environment ------------------------------- - -On windows: ->>> py -3 -m venv .venv # create virtual environment ->>> .venv/Scripts/activate # activate virtual environment - -Then select the Python interpreter in the .venv folder. In VSCode: -View > Command Palette > Python select interpreter -> enter interpreter path (.venv/Scripts/python.exe) - -Then install requirements - ->>> pip install -r requirements.txt - -To leave: ->>> deactivate - - -Creating a new release (from a fork) ------------------------------------- - -- Check test coverage is 100% (see below) -- Update the version number in the below locations, push and check that the test action passes. If it passes, make a pull-request to push to dev. - - pyproject.toml - - docs/source/conf.py -- Merge the dev branch with the main branch. Check that the documentation builds OK. -- Build release notes (see below) and push changes to dev and main. Check docs, actions, and badges on README. -- Create a release on github, with the main branch as target -- Create a release on PyPI (see below) -- Create a release on Zenodo (v1.0 and onwards) - -Check test coverage -------------------- - -cd to /dcmri top folder ->>> pytest --cov=dcmri --cov-report term-missing - -Build release notes -------------------- -- Get a personal token on https://github.com/settings/tokens (does not need any permissions) -- Save the token in the environment variable GH_TOKEN. On windows: ->>> $env:GH_TOKEN='token' -- Build the changelog from current version to current main. For instance: ->>> changelist QIB-Sheffield/mdreg v0.3.8 main --format rst -- Copy-paste the terminal output in an .rst file and save it in docs/source/releases -- Add an entry in the index of docs/source/releases - - -Creating a PyPi release ------------------------ - -If needed: - ->>> pip install build ->>> pip install twine - -In the terminal, cd to the /dcmri directory, and: - ->>> python -m build ->>> twine upload dist/* - -When prompted for user name, enter __token__ - -As password paste the API token generated in PyPi dcmri repository settings (https://pypi.org/manage/project/dcmri/settings/). Note: Paste with Ctrl-V does not work in Windows. Use Edit > Paste via the menu. - - - - -Changing dependencies ---------------------- - -- update requirements.txt -- update pyproject.toml -- generate a new poetry.lock file. On the terminal, run ->>> poetry lock - - - - - From 21af9bc5f9b3cc5dddaf28aa67b6587659ef1d81 Mon Sep 17 00:00:00 2001 From: plaresmedima Date: Tue, 17 Dec 2024 15:50:58 +0000 Subject: [PATCH 3/4] bump version number --- docs/source/conf.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index c25492c..da5dc2b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -8,7 +8,7 @@ project = 'mdreg' copyright = '2024, mdreg maintainers' author = 'mdreg maintainers' -release = '0.4.3' +release = '0.4.4' # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, diff --git a/pyproject.toml b/pyproject.toml index 5ca7624..876f867 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = ['setuptools>=61.2'] [project] name = "mdreg" -version = "0.4.3" +version = "0.4.4" dependencies = [ 'importlib-resources>=1.1.0', 'tqdm', From d0e96dcb4990eb85e9f2bd900cf4e91dbb68adf8 Mon Sep 17 00:00:00 2001 From: plaresmedima Date: Tue, 17 Dec 2024 15:54:56 +0000 Subject: [PATCH 4/4] v0.4.4 release notes --- docs/source/releases/index.rst | 1 + docs/source/releases/release_0.4.4.rst | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 docs/source/releases/release_0.4.4.rst diff --git a/docs/source/releases/index.rst b/docs/source/releases/index.rst index cc241a3..dab065f 100644 --- a/docs/source/releases/index.rst +++ b/docs/source/releases/index.rst @@ -11,6 +11,7 @@ Releases .. toctree:: :maxdepth: 2 + release_0.4.4 release_0.4.3 release_0.4.2 release_0.4.1 diff --git a/docs/source/releases/release_0.4.4.rst b/docs/source/releases/release_0.4.4.rst new file mode 100644 index 0000000..34816b9 --- /dev/null +++ b/docs/source/releases/release_0.4.4.rst @@ -0,0 +1,20 @@ +mdreg 0.4.4 +=========== + +Summary +------- + +- Added error handling for elastix + +Contributors +------------ + +1 authors added to this release (alphabetically): + +- Steven Sourbron (`@plaresmedima `_) + +1 reviewers added to this release (alphabetically): + +- Steven Sourbron (`@plaresmedima `_) + +