diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 2721732a..5e48a0b0 100755 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -21,3 +21,5 @@ jobs: python-version: 3 - name: Lint EddyMotion run: pipx run ruff check --diff + - name: Format EddyMotion + run: pipx run ruff format --diff diff --git a/.maint/paper_author_list.py b/.maint/paper_author_list.py index 20be36aa..2cde95f4 100644 --- a/.maint/paper_author_list.py +++ b/.maint/paper_author_list.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 """Generate an author list for a new paper or abstract.""" + import json import sys from pathlib import Path @@ -63,7 +64,5 @@ def _aslist(inlist): print( "\n\nAffiliations:\n%s" - % "\n".join( - ["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)] - ) + % "\n".join(["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)]) ) diff --git a/.maint/update_zenodo.py b/.maint/update_zenodo.py index 0f780f3c..fdaa7db9 100755 --- a/.maint/update_zenodo.py +++ b/.maint/update_zenodo.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 """Update and sort the creators list of the zenodo record.""" + import json import sys from pathlib import Path @@ -16,20 +17,14 @@ def sort_contributors(entries, git_lines, exclude=None, last=None): last = last or [] sorted_authors = sorted(entries, key=lambda i: i["name"]) - first_last = [ - " ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors - ] - first_last_excl = [ - " ".join(val["name"].split(",")[::-1]).strip() for val in exclude or [] - ] + first_last = [" ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors] + first_last_excl = [" ".join(val["name"].split(",")[::-1]).strip() for val in exclude or []] unmatched = [] author_matches = [] position = 1 for ele in git_lines: - matches = process.extract( - ele, first_last, scorer=fuzz.token_sort_ratio, limit=2 - ) + matches = process.extract(ele, first_last, scorer=fuzz.token_sort_ratio, limit=2) # matches is a list [('First match', % Match), ('Second match', % Match)] if matches[0][1] > 80: val = sorted_authors[first_last.index(matches[0][0])] diff --git a/src/eddymotion/__init__.py b/src/eddymotion/__init__.py index dd1f0ac7..412aab1f 100644 --- a/src/eddymotion/__init__.py +++ b/src/eddymotion/__init__.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Top-level package for eddymotion.""" + from eddymotion._version import __version__ __packagename__ = "eddymotion" diff --git a/src/eddymotion/data/dmri.py b/src/eddymotion/data/dmri.py index 2fbb2531..da2c1388 100644 --- a/src/eddymotion/data/dmri.py +++ b/src/eddymotion/data/dmri.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Representing data in hard-disk and memory.""" + from collections import namedtuple from pathlib import Path from tempfile import mkdtemp @@ -255,7 +256,7 @@ def load( warn( "Gradients table file and b-vec/val files are defined; " "dismissing b-vec/val files.", - stacklevel=2 + stacklevel=2, ) elif bvec_file and bval_file: grad = np.vstack( diff --git a/src/eddymotion/data/pet.py b/src/eddymotion/data/pet.py index 9df98e27..89e1c8c0 100644 --- a/src/eddymotion/data/pet.py +++ b/src/eddymotion/data/pet.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """PET data representation.""" + from collections import namedtuple from pathlib import Path from tempfile import mkdtemp diff --git a/src/eddymotion/estimator.py b/src/eddymotion/estimator.py index e99b67e7..ac0e360c 100644 --- a/src/eddymotion/estimator.py +++ b/src/eddymotion/estimator.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """A model-based algorithm for the realignment of dMRI data.""" + from collections import namedtuple from pathlib import Path from tempfile import TemporaryDirectory, mkstemp diff --git a/src/eddymotion/model/__init__.py b/src/eddymotion/model/__init__.py index 7e32df8b..3c44e2ad 100644 --- a/src/eddymotion/model/__init__.py +++ b/src/eddymotion/model/__init__.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Data models.""" + from eddymotion.model.base import ( AverageDWModel, DKIModel, diff --git a/src/eddymotion/model/base.py b/src/eddymotion/model/base.py index 9cf2f081..ee27e8d2 100644 --- a/src/eddymotion/model/base.py +++ b/src/eddymotion/model/base.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """A factory class that adapts DIPY's dMRI models.""" + import warnings import numpy as np diff --git a/src/eddymotion/viz.py b/src/eddymotion/viz.py index 84772258..1354606c 100644 --- a/src/eddymotion/viz.py +++ b/src/eddymotion/viz.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Visualization utilities.""" + import nibabel as nb import numpy as np from nireports.reportlets.nuisance import plot_carpet as nw_plot_carpet diff --git a/test/conftest.py b/test/conftest.py index dc400804..b9068404 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """py.test configuration.""" + import os from pathlib import Path diff --git a/test/test_estimator.py b/test/test_estimator.py index 84a77475..5b3da6a9 100644 --- a/test/test_estimator.py +++ b/test/test_estimator.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Unit tests exercising the estimator.""" + import nibabel as nb import nitransforms as nt import numpy as np @@ -69,9 +70,7 @@ def test_ANTs_config_b0(datadir, tmp_path, r_x, r_y, r_z, t_x, t_y, t_z): result = registration.run(cwd=str(tmp_path)).outputs xform = nt.linear.Affine( - nt.io.itk.ITKLinearTransform.from_filename( - result.forward_transforms[0] - ).to_ras(), + nt.io.itk.ITKLinearTransform.from_filename(result.forward_transforms[0]).to_ras(), reference=b0nii, ) diff --git a/test/test_integration.py b/test/test_integration.py index be55b5c3..e72e5415 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -39,27 +39,13 @@ def test_proximity_estimator_trivial_model(datadir, tmp_path): # Generate a list of large-yet-plausible bulk-head motion. xfms = nt.linear.LinearTransformsMapping( [ - nb.affines.from_matvec( - nb.eulerangles.euler2mat(x=0.03, z=0.005), (0.8, 0.2, 0.2) - ), - nb.affines.from_matvec( - nb.eulerangles.euler2mat(x=0.02, z=0.005), (0.8, 0.2, 0.2) - ), - nb.affines.from_matvec( - nb.eulerangles.euler2mat(x=0.02, z=0.02), (0.4, 0.2, 0.2) - ), - nb.affines.from_matvec( - nb.eulerangles.euler2mat(x=-0.02, z=0.02), (0.4, 0.2, 0.2) - ), - nb.affines.from_matvec( - nb.eulerangles.euler2mat(x=-0.02, z=0.002), (0.0, 0.2, 0.2) - ), - nb.affines.from_matvec( - nb.eulerangles.euler2mat(y=-0.02, z=0.002), (0.0, 0.2, 0.2) - ), - nb.affines.from_matvec( - nb.eulerangles.euler2mat(y=-0.01, z=0.002), (0.0, 0.4, 0.2) - ), + nb.affines.from_matvec(nb.eulerangles.euler2mat(x=0.03, z=0.005), (0.8, 0.2, 0.2)), + nb.affines.from_matvec(nb.eulerangles.euler2mat(x=0.02, z=0.005), (0.8, 0.2, 0.2)), + nb.affines.from_matvec(nb.eulerangles.euler2mat(x=0.02, z=0.02), (0.4, 0.2, 0.2)), + nb.affines.from_matvec(nb.eulerangles.euler2mat(x=-0.02, z=0.02), (0.4, 0.2, 0.2)), + nb.affines.from_matvec(nb.eulerangles.euler2mat(x=-0.02, z=0.002), (0.0, 0.2, 0.2)), + nb.affines.from_matvec(nb.eulerangles.euler2mat(y=-0.02, z=0.002), (0.0, 0.2, 0.2)), + nb.affines.from_matvec(nb.eulerangles.euler2mat(y=-0.01, z=0.002), (0.0, 0.4, 0.2)), ], reference=b0nii, ) @@ -81,9 +67,7 @@ def test_proximity_estimator_trivial_model(datadir, tmp_path): ) estimator = EddyMotionEstimator() - em_affines = estimator.fit( - dwdata=dwi_motion, models=("b0",), align_kwargs=None, seed=None - ) + em_affines = estimator.fit(dwdata=dwi_motion, models=("b0",), align_kwargs=None, seed=None) # Uncomment to see the realigned dataset # nt.linear.LinearTransformsMapping( diff --git a/test/test_model.py b/test/test_model.py index 4b3187d1..cad6b48a 100644 --- a/test/test_model.py +++ b/test/test_model.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Unit tests exercising models.""" + import numpy as np import pytest @@ -64,11 +65,13 @@ def test_average_model(): tmodel_mean = model.AverageDWModel(gtab=gtab, bias=False, stat="mean") tmodel_median = model.AverageDWModel(gtab=gtab, bias=False, stat="median") - tmodel_1000 = model.AverageDWModel( - gtab=gtab, bias=False, th_high=1000, th_low=900 - ) + tmodel_1000 = model.AverageDWModel(gtab=gtab, bias=False, th_high=1000, th_low=900) tmodel_2000 = model.AverageDWModel( - gtab=gtab, bias=False, th_high=2000, th_low=900, stat="mean", + gtab=gtab, + bias=False, + th_high=2000, + th_low=900, + stat="mean", ) # Verify that fit function returns nothing diff --git a/test/test_version.py b/test/test_version.py index 4215cac8..9ebd7a24 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -21,6 +21,7 @@ # https://www.nipreps.org/community/licensing/ # """Test _version.py.""" + import sys from importlib import reload