Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaeger committed Sep 11, 2024
1 parent 8f24668 commit 6972cdb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pydesigner/fitting/dwipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from tqdm import tqdm

from ..plotting import outlierplot
from ..system.utils import highprecisionexp, highprecisionpower, vectorize, writeNii
from ..tractography import dsistudio, odf, sphericalsampling
from ..system.models import input_path_validator
from ..system.utils import highprecisionexp, highprecisionpower, vectorize, writeNii
from ..tractography import dsistudio, odf, sphericalsampling
from . import dwi_fnames, dwidirs
from . import thresholds as th

Expand Down
55 changes: 40 additions & 15 deletions pydesigner/preprocessing/mrpreproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def miftonii(input: str, output: str, nthreads: int = None, force: bool = True,
--------
niitomif
"""
opts = modelmrtrix(input=input_path_validator(input, ".mif"), output=output_path_validator(output, ".nii"), nthreads=nthreads, force=force, verbose=verbose)
opts = modelmrtrix(
input=input_path_validator(input, ".mif"),
output=output_path_validator(output, ".nii"),
nthreads=nthreads,
force=force,
verbose=verbose,
)
input_path_validator(opts.input, ".mif")
output_path_validator(opts.output, ".nii")
arg = ["mrconvert"]
Expand Down Expand Up @@ -95,7 +101,13 @@ def niitomif(input: str, output: str, nthreads: int = None, force: bool = True,
--------
miftonii
"""
opts = modelmrtrix(input=input_path_validator(input, ".nii"), output=output_path_validator(output, ".mif"), nthreads=nthreads, force=force, verbose=verbose)
opts = modelmrtrix(
input=input_path_validator(input, ".nii"),
output=output_path_validator(output, ".mif"),
nthreads=nthreads,
force=force,
verbose=verbose,
)
input_path_validator(opts.input, ".nii")
path_bvec = input_path_validator(op.splitext(opts.input)[0] + ".bvec", ".bvec")
path_bval = input_path_validator(op.splitext(opts.input)[0] + ".bval", ".bval")
Expand Down Expand Up @@ -203,7 +215,13 @@ def denoise(
-------
None; writes out file
"""
opts = modelmrtrix(input=input_path_validator(input, ".mif"), output=output_path_validator(output, ".mif"), nthreads=nthreads, force=force, verbose=verbose)
opts = modelmrtrix(
input=input_path_validator(input, ".mif"),
output=output_path_validator(output, ".mif"),
nthreads=nthreads,
force=force,
verbose=verbose,
)
if not isinstance(noisemap, bool):
raise TypeError("Please specify whether noisemap generation is True or False.")
noisemap_path = op.join(op.dirname(opts.output), "noisemap.nii")
Expand All @@ -227,13 +245,7 @@ def denoise(
raise MRTrixError(msg)


def degibbs(
input: str,
output: str,
nthreads: int = None,
force: bool = False,
verbose: bool = False
) -> None:
def degibbs(input: str, output: str, nthreads: int = None, force: bool = False, verbose: bool = False) -> None:
"""Runs MRtrix3's `mrdegibbs` command with optimal parameters for
PyDesigner.
Expand All @@ -256,7 +268,13 @@ def degibbs(
-------
None; writes out file
"""
opts = modelmrtrix(input=input_path_validator(input, ".mif"), output=output_path_validator(output, ".mif"), nthreads=nthreads, force=force, verbose=verbose)
opts = modelmrtrix(
input=input_path_validator(input, ".mif"),
output=output_path_validator(output, ".mif"),
nthreads=nthreads,
force=force,
verbose=verbose,
)
arg = ["mrdegibbs"]
if opts.force:
arg.append("-force")
Expand Down Expand Up @@ -312,8 +330,14 @@ def undistort(
-------
None; writes out file
"""
opts = modelmrtrix(input=input_path_validator(input, ".mif"), output=output_path_validator(output, ".mif"), nthreads=nthreads, force=force, verbose=verbose)

opts = modelmrtrix(
input=input_path_validator(input, ".mif"),
output=output_path_validator(output, ".mif"),
nthreads=nthreads,
force=force,
verbose=verbose,
)

if rpe not in ["rpe_none", "rpe_pair", "rpe_all", "rpe_header"]:
msg = "Entered RPE selection is not valid. Please choose either "
msg += "'rpe_none', 'rpe_pair' 'rpe_all', or 'rpe_header'"
Expand Down Expand Up @@ -397,7 +421,7 @@ def undistort(
msg = "Dwifslpreproc failed. Return code: {completion.returncode}"
msg += f"\nCommand: {' '.join(arg_extract)}"
msg += f"\nMRtrix3 error: {completion.stderr}"
raise(MRTrixError(msg))
raise (MRTrixError(msg))
# Remove temporarily generated files
os.remove(op.join(outdir, "dwiec.bvec"))
os.remove(op.join(outdir, "dwiec.bval"))
Expand Down Expand Up @@ -439,7 +463,8 @@ def brainmask(input, output, thresh=0.25, nthreads=None, force=False, verbose=Fa
# Read FSL NifTi output format and change it if not '.nii'
fsl_suffix = os.getenv("FSLOUTPUTTYPE")
if fsl_suffix is None:
msg = "Unable to determine system environment variable 'FSF_OUTPUT_FORMAT'. Ensure that FSL is installed correctly."
msg = "Unable to determine system environment variable 'FSF_OUTPUT_FORMAT'. "
msg += "Ensure that FSL is installed correctly."
raise OSError(msg)
if fsl_suffix == "NIFTI_GZ":
os.environ["FSLOUTPUTTYPE"] = "NIFTI"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_preprocessing_mrpreproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_miftonii_output_success(tmp_path, nthreads, force, verbose):
img = nib.load(output_nii)
assert type(img).__name__ == "Nifti1Image"
assert img.shape == (2, 2, 2, 337)


def test_niitomif_failure_bval(tmp_path):
"""Test whether function `niitomif` fails when there is no sidecar file"""
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_denoise_output_failure(tmp_path):
mrpreproc.denoise(PATH_MIF, output_mif, noisemap=True, extent="1,1,1")
assert f"Dwidenoise failed" in str(exc.value)
assert "stderr" in str(exc.value)


@pytest.mark.parametrize(
"nthreads, force, verbose",
Expand Down Expand Up @@ -284,4 +284,4 @@ def subprocess_side_effect(*args, **kwargs):
# with pytest.raises(MRTrixError) as exc:
# mrpreproc.brainmask(PATH_MIF, output_nii)
# assert f"Unable to compute brain mask from B0" in str(exc.value)
# assert "stderr" in str(exc.value)
# assert "stderr" in str(exc.value)

0 comments on commit 6972cdb

Please sign in to comment.