Skip to content

Commit

Permalink
Merge pull request #147 from jhlegarreta/FormatCodebase
Browse files Browse the repository at this point in the history
STYLE: Format the code base style
  • Loading branch information
effigies authored Apr 3, 2024
2 parents 8b29477 + b6c5a4b commit c8c6c0d
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions .maint/paper_author_list.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)])
)
13 changes: 4 additions & 9 deletions .maint/update_zenodo.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])]
Expand Down
1 change: 1 addition & 0 deletions src/eddymotion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Top-level package for eddymotion."""

from eddymotion._version import __version__

__packagename__ = "eddymotion"
Expand Down
3 changes: 2 additions & 1 deletion src/eddymotion/data/dmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/eddymotion/data/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/eddymotion/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/eddymotion/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Data models."""

from eddymotion.model.base import (
AverageDWModel,
DKIModel,
Expand Down
1 change: 1 addition & 0 deletions src/eddymotion/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/eddymotion/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""py.test configuration."""

import os
from pathlib import Path

Expand Down
5 changes: 2 additions & 3 deletions test/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down
32 changes: 8 additions & 24 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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(
Expand Down
11 changes: 7 additions & 4 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Unit tests exercising models."""

import numpy as np
import pytest

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Test _version.py."""

import sys
from importlib import reload

Expand Down

0 comments on commit c8c6c0d

Please sign in to comment.