Skip to content

Commit

Permalink
simplify imports for dwi preproc using t1
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Oct 16, 2023
1 parent 301a153 commit 1fe0562
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 49 deletions.
2 changes: 1 addition & 1 deletion clinica/pipelines/dwi_preprocessing_using_t1/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import dwi_preprocessing_using_t1_cli
from . import cli
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def cli(

from clinica.utils.ux import print_end_pipeline

from .dwi_preprocessing_using_t1_pipeline import DwiPreprocessingUsingT1
from .pipeline import DwiPreprocessingUsingT1

parameters = {
"low_bval": low_bval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def build_output_node(self):

from clinica.utils.nipype import container_from_filename, fix_join

from .dwi_preprocessing_using_t1_utils import rename_into_caps
from .utils import rename_into_caps

container_path = npe.Node(
nutil.Function(
Expand Down Expand Up @@ -257,15 +257,12 @@ def build_core_nodes(self):

from clinica.utils.dwi import compute_average_b0_task

from .dwi_preprocessing_using_t1_utils import (
from .utils import (
init_input_node,
prepare_reference_b0_task,
print_end_pipeline,
)
from .dwi_preprocessing_using_t1_workflows import (
eddy_fsl_pipeline,
epi_pipeline,
)
from .workflows import eddy_fsl_pipeline, epi_pipeline

init_node = npe.Node(
interface=nutil.Function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def broadcast_matrix_filename_to_match_b_vector_length(
"""Return a list of the matrix filename repeated as many times as there are B-vectors."""
import numpy as np

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import ( # noqa
from clinica.pipelines.dwi_preprocessing_using_t1.utils import ( # noqa
broadcast_filename_into_list,
)

Expand Down Expand Up @@ -287,7 +287,7 @@ def prepare_reference_b0_task(
"""Task called be Nipype to execute prepare_reference_b0."""
from pathlib import Path

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import ( # noqa
from clinica.pipelines.dwi_preprocessing_using_t1.utils import ( # noqa
prepare_reference_b0,
)
from clinica.utils.dwi import DWIDataset
Expand Down Expand Up @@ -496,9 +496,7 @@ def register_b0(
If the pipeline ran successfully, this file should be located in :
working_directory / b0_coregistration / concat_ref_moving / merged_files.nii.gz
"""
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows import (
b0_flirt_pipeline,
)
from clinica.pipelines.dwi_preprocessing_using_t1.workflows import b0_flirt_pipeline

b0_flirt = b0_flirt_pipeline(num_b0s=nb_b0s)
b0_flirt.inputs.inputnode.in_file = str(extracted_b0_filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ def eddy_fsl_pipeline(
from nipype.interfaces.fsl import BET
from nipype.interfaces.fsl.epi import Eddy

from .dwi_preprocessing_using_t1_utils import (
generate_acq_file_task,
generate_index_file_task,
)
from .utils import generate_acq_file_task, generate_index_file_task

inputnode = pe.Node(
niu.IdentityInterface(
Expand Down Expand Up @@ -397,7 +394,7 @@ def perform_ants_registration(
import nipype.interfaces.utility as niu
import nipype.pipeline.engine as pe

from .dwi_preprocessing_using_t1_utils import (
from .utils import (
broadcast_matrix_filename_to_match_b_vector_length,
change_itk_transform_type,
rotate_b_vectors,
Expand Down Expand Up @@ -605,8 +602,6 @@ def perform_dwi_epi_correction(
This workflow benefits a lot from parallelization as most operations are done on
single DWI direction.
"""
import os

import nipype.interfaces.ants as ants
import nipype.interfaces.fsl as fsl
import nipype.interfaces.io as nio
Expand Down
2 changes: 1 addition & 1 deletion test/instantiation/test_instantiate_all_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_instantiate_t1_volume_parcellation(cmdopt):


def test_instantiate_dwi_preprocessing_using_t1(cmdopt):
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_pipeline import (
from clinica.pipelines.dwi_preprocessing_using_t1.pipeline import (
DwiPreprocessingUsingT1,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_dwi_preprocessing_using_t1(cmdopt, tmp_path):
def run_dwi_preprocessing_using_t1(
input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path
) -> None:
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_pipeline import (
from clinica.pipelines.dwi_preprocessing_using_t1.pipeline import (
DwiPreprocessingUsingT1,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

@pytest.mark.fast
def test_dwi_b0_flirt(cmdopt, tmp_path):
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows import (
b0_flirt_pipeline,
)
from clinica.pipelines.dwi_preprocessing_using_t1.workflows import b0_flirt_pipeline

base_dir = Path(cmdopt["input"])
input_dir, tmp_dir, ref_dir = configure_paths(base_dir, tmp_path, "DWIB0Flirt")
Expand All @@ -41,9 +39,7 @@ def test_dwi_b0_flirt(cmdopt, tmp_path):

@pytest.mark.slow
def test_dwi_epi_pipeline(cmdopt, tmp_path):
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows import (
epi_pipeline,
)
from clinica.pipelines.dwi_preprocessing_using_t1.workflows import epi_pipeline

base_dir = Path(cmdopt["input"])
input_dir, tmp_dir, ref_dir = configure_paths(base_dir, tmp_path, "DWIEPIPipeline")
Expand Down Expand Up @@ -89,7 +85,7 @@ def test_dwi_perform_ants_registration(cmdopt, tmp_path):

import nibabel as nib

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows import (
from clinica.pipelines.dwi_preprocessing_using_t1.workflows import (
perform_ants_registration,
)

Expand Down Expand Up @@ -152,7 +148,7 @@ def test_dwi_perform_ants_registration(cmdopt, tmp_path):

@pytest.mark.slow
def test_dwi_perform_dwi_epi_correction(cmdopt, tmp_path):
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows import (
from clinica.pipelines.dwi_preprocessing_using_t1.workflows import (
perform_dwi_epi_correction,
)

Expand Down Expand Up @@ -192,9 +188,7 @@ def test_dwi_perform_dwi_epi_correction(cmdopt, tmp_path):

@pytest.mark.slow
def test_dwi_eddy_fsl(cmdopt, tmp_path):
from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows import (
eddy_fsl_pipeline,
)
from clinica.pipelines.dwi_preprocessing_using_t1.workflows import eddy_fsl_pipeline

base_dir = Path(cmdopt["input"])
input_dir, tmp_dir, ref_dir = configure_paths(base_dir, tmp_path, "DWIEddyFSL")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from numpy.testing import assert_array_almost_equal, assert_array_equal

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import (
from clinica.pipelines.dwi_preprocessing_using_t1.utils import (
broadcast_matrix_filename_to_match_b_vector_length,
change_itk_transform_type,
extract_sub_ses_folder_name,
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_rotate_b_vectors_wrong_content_in_vector_file(tmp_path):
def test_configure_working_directory(tmp_path):
import hashlib

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import (
from clinica.pipelines.dwi_preprocessing_using_t1.utils import (
configure_working_directory,
)

Expand All @@ -199,9 +199,7 @@ def test_configure_working_directory(tmp_path):
def test_compute_reference_b0_errors(tmp_path):
import numpy as np

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import (
compute_reference_b0,
)
from clinica.pipelines.dwi_preprocessing_using_t1.utils import compute_reference_b0

(tmp_path / "b0.nii.gz").touch()
np.savetxt(tmp_path / "foo.bval", [1000] * 9)
Expand All @@ -221,9 +219,7 @@ def test_compute_reference_b0_with_single_b0(tmp_path):
import numpy as np
from numpy.testing import assert_array_equal

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import (
compute_reference_b0,
)
from clinica.pipelines.dwi_preprocessing_using_t1.utils import compute_reference_b0

b0_data = 4.0 * np.ones((5, 5, 5, 1))
b0_img = nib.Nifti1Image(b0_data, affine=np.eye(4))
Expand Down Expand Up @@ -258,9 +254,7 @@ def test_compute_reference_b0_with_multiple_b0(tmp_path, mocker, clean_working_d
import numpy as np
from numpy.testing import assert_array_equal

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import (
compute_reference_b0,
)
from clinica.pipelines.dwi_preprocessing_using_t1.utils import compute_reference_b0

working_directory = tmp_path / "tmp"
working_directory.mkdir()
Expand All @@ -273,7 +267,7 @@ def test_compute_reference_b0_with_multiple_b0(tmp_path, mocker, clean_working_d
assert not mocked_output.exists()
mocked_output.parent.mkdir(parents=True)
mocker.patch(
"clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils.register_b0",
"clinica.pipelines.dwi_preprocessing_using_t1.utils.register_b0",
return_value=mocked_output,
)
# Build a dataset with 3 B0 volumes
Expand Down Expand Up @@ -325,14 +319,12 @@ def test_prepare_reference_b0(tmp_path, mocker):
import numpy as np
from numpy.testing import assert_array_equal

from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils import (
prepare_reference_b0,
)
from clinica.pipelines.dwi_preprocessing_using_t1.utils import prepare_reference_b0
from clinica.utils.dwi import DWIDataset

mocked_output = tmp_path / "reference_b0_volume.nii.gz"
mocker.patch(
"clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils.compute_reference_b0",
"clinica.pipelines.dwi_preprocessing_using_t1.utils.compute_reference_b0",
return_value=mocked_output,
)
ref_b0_data = 5.0 * np.ones((5, 5, 5, 1))
Expand Down

0 comments on commit 1fe0562

Please sign in to comment.