From edbc367e472ba98d8158081eb306286a13929a46 Mon Sep 17 00:00:00 2001 From: j1c Date: Sun, 7 Apr 2024 18:48:08 -0400 Subject: [PATCH] isort --- m2g/functional/m2g_func.py | 12 +++++++----- m2g/graph.py | 19 ++++++++++--------- m2g/preproc.py | 3 ++- m2g/register.py | 16 +++++++--------- m2g/scripts/__init__.py | 4 +--- m2g/scripts/m2g_bids.py | 22 ++++++++++------------ m2g/scripts/m2g_cloud.py | 15 +++++++-------- m2g/scripts/m2g_dwi_pipeline.py | 22 ++++++++-------------- m2g/stats/qa_fast.py | 5 +++-- m2g/stats/qa_reg.py | 14 ++++++++------ m2g/stats/qa_skullstrip.py | 14 ++++++++------ m2g/stats/qa_tensor.py | 13 +++++++------ m2g/stats/qa_tractography.py | 10 +++++----- m2g/track.py | 30 ++++++++++++++---------------- m2g/utils/cloud_utils.py | 4 ++-- m2g/utils/gen_utils.py | 24 +++++++++++------------- m2g/utils/reg_utils.py | 13 +++++-------- 17 files changed, 115 insertions(+), 125 deletions(-) diff --git a/m2g/functional/m2g_func.py b/m2g/functional/m2g_func.py index a213154ff..e79309b1e 100644 --- a/m2g/functional/m2g_func.py +++ b/m2g/functional/m2g_func.py @@ -1,11 +1,13 @@ -import subprocess -import yaml import os -import regex as re -from m2g.utils.gen_utils import run -import sys import shutil +import subprocess +import sys + import numpy as np +import regex as re +import yaml + +from m2g.utils.gen_utils import run def make_dataconfig(input_dir, sub, ses, anat, func, acquisition="alt+z", tr=2.0): diff --git a/m2g/graph.py b/m2g/graph.py index e8e67fa67..6d1a015e3 100644 --- a/m2g/graph.py +++ b/m2g/graph.py @@ -9,28 +9,29 @@ """ +import csv # standard library imports import os import time -import csv -from itertools import combinations -from functools import reduce from collections import defaultdict +from functools import reduce +from itertools import combinations from pathlib import Path -# package imports -import numpy as np +import matplotlib import networkx as nx import nibabel as nib +# package imports +import numpy as np from dipy.tracking._utils import _mapping_to_voxel, _to_voxel_coordinates -from m2g.utils.gen_utils import timer -import matplotlib from joblib import Parallel, delayed +from m2g.utils.gen_utils import timer + matplotlib.use("agg") -from matplotlib import pyplot as plt -from graspologic.utils import ptr from graspologic.plot import heatmap +from graspologic.utils import ptr +from matplotlib import pyplot as plt class GraphTools: diff --git a/m2g/preproc.py b/m2g/preproc.py index 82f667741..a832d8fc0 100644 --- a/m2g/preproc.py +++ b/m2g/preproc.py @@ -8,9 +8,10 @@ TODO : depracate or change name. Add other preprocessing functions created from m2g_dwi_pipeline. """ +import subprocess + # package imports import numpy as np -import subprocess # m2g imports from m2g.utils import gen_utils diff --git a/m2g/register.py b/m2g/register.py index c6edbe434..1698280e1 100644 --- a/m2g/register.py +++ b/m2g/register.py @@ -9,26 +9,24 @@ # standard library imports import os -from argparse import ArgumentParser import subprocess +from argparse import ArgumentParser from pathlib import Path # package imports import nibabel as nib import numpy as np -from nilearn.image import load_img -from nilearn.image import math_img -from dipy.tracking.streamline import deform_streamlines from dipy.io.streamline import load_trk from dipy.tracking import utils +from dipy.tracking.streamline import deform_streamlines +from nilearn.image import load_img, math_img -# m2g imports -from m2g.utils import gen_utils -from m2g.utils import reg_utils from m2g.scripts import m2g_bids -from m2g.stats.qa_skullstrip import gen_overlay_pngs -from m2g.stats.qa_reg import reg_mri_pngs from m2g.stats.qa_fast import qa_fast_png +from m2g.stats.qa_reg import reg_mri_pngs +from m2g.stats.qa_skullstrip import gen_overlay_pngs +# m2g imports +from m2g.utils import gen_utils, reg_utils @gen_utils.timer diff --git a/m2g/scripts/__init__.py b/m2g/scripts/__init__.py index 1513ff4ef..3be770e40 100644 --- a/m2g/scripts/__init__.py +++ b/m2g/scripts/__init__.py @@ -9,6 +9,4 @@ m2g_cloud : for performing batch processing on AWS """ -from . import m2g_bids -from . import m2g_cloud -from . import m2g_dwi_pipeline +from . import m2g_bids, m2g_cloud, m2g_dwi_pipeline diff --git a/m2g/scripts/m2g_bids.py b/m2g/scripts/m2g_bids.py index bc59166a2..396235761 100644 --- a/m2g/scripts/m2g_bids.py +++ b/m2g/scripts/m2g_bids.py @@ -12,25 +12,23 @@ """ -# standard library imports -import sys -import shutil import glob import os +import re +import shutil +# standard library imports +import sys from argparse import ArgumentParser + import numpy as np from numpy import genfromtxt -import re -# m2g imports -from m2g.utils import cloud_utils -from m2g.utils import gen_utils -from m2g.utils.gen_utils import DirectorySweeper -from m2g.utils.gen_utils import check_dependencies -from m2g.utils.gen_utils import is_bids -from m2g.utils.gen_utils import as_directory +from m2g.functional.m2g_func import func_dir_reorg, m2g_func_worker from m2g.scripts.m2g_dwi_pipeline import m2g_dwi_worker -from m2g.functional.m2g_func import m2g_func_worker, func_dir_reorg +# m2g imports +from m2g.utils import cloud_utils, gen_utils +from m2g.utils.gen_utils import (DirectorySweeper, as_directory, + check_dependencies, is_bids) def get_atlas(atlas_dir, vox_size): diff --git a/m2g/scripts/m2g_cloud.py b/m2g/scripts/m2g_cloud.py index 2b3a7b60a..6161a934c 100644 --- a/m2g/scripts/m2g_cloud.py +++ b/m2g/scripts/m2g_cloud.py @@ -8,23 +8,22 @@ For a tutorial on setting this up, see here : https://github.com/neurodata/m2g/blob/deploy/tutorials/Batch.ipynb """ +import json +import os +import re # standard library imports import subprocess -import re -import os import sys -import json -from copy import deepcopy -from collections import OrderedDict from argparse import ArgumentParser +from collections import OrderedDict +from copy import deepcopy from pathlib import Path # m2g imports import m2g from m2g.utils import gen_utils -from m2g.utils.cloud_utils import get_credentials -from m2g.utils.cloud_utils import get_matching_s3_objects -from m2g.utils.cloud_utils import s3_client +from m2g.utils.cloud_utils import (get_credentials, get_matching_s3_objects, + s3_client) def batch_submit( diff --git a/m2g/scripts/m2g_dwi_pipeline.py b/m2g/scripts/m2g_dwi_pipeline.py index 34cf210f1..d4b4dafb4 100644 --- a/m2g/scripts/m2g_dwi_pipeline.py +++ b/m2g/scripts/m2g_dwi_pipeline.py @@ -8,33 +8,27 @@ """ +# multithreading +import multiprocessing as mp +import os # standard library imports import shutil import time +from argparse import ArgumentParser from datetime import datetime -import os from pathlib import Path -from argparse import ArgumentParser +from subprocess import Popen # package imports import nibabel as nib import numpy as np -from subprocess import Popen -from dipy.tracking.streamline import Streamlines from dipy.io import read_bvals_bvecs +from dipy.tracking.streamline import Streamlines # m2g imports -from m2g import preproc -from m2g import register -from m2g import track -from m2g import graph -from m2g.utils import gen_utils -from m2g.utils import reg_utils -from m2g.utils import cloud_utils +from m2g import graph, preproc, register, track from m2g.stats.qa_tractography import qa_tractography - -# multithreading -import multiprocessing as mp +from m2g.utils import cloud_utils, gen_utils, reg_utils # TODO : not sure why this is here, potentially remove os.environ["MPLCONFIGDIR"] = "/tmp/" diff --git a/m2g/stats/qa_fast.py b/m2g/stats/qa_fast.py index a82125d1a..c0bd34419 100644 --- a/m2g/stats/qa_fast.py +++ b/m2g/stats/qa_fast.py @@ -1,8 +1,9 @@ import matplotlib.pyplot as plt -import numpy as np import nibabel as nb -from scipy import ndimage +import numpy as np from matplotlib.colors import LinearSegmentedColormap +from scipy import ndimage + from m2g.utils.qa_utils import pad_im diff --git a/m2g/stats/qa_reg.py b/m2g/stats/qa_reg.py index d2b5fb326..da90fc76e 100644 --- a/m2g/stats/qa_reg.py +++ b/m2g/stats/qa_reg.py @@ -13,18 +13,20 @@ import os import re import sys -import numpy as np +from argparse import ArgumentParser + +import matplotlib as mpl import nibabel as nb +import numpy as np +from matplotlib.colors import LinearSegmentedColormap +from scipy import ndimage + from m2g.utils.gen_utils import get_braindata, get_filename from m2g.utils.qa_utils import get_min_max, opaque_colorscale, pad_im -from argparse import ArgumentParser -from scipy import ndimage -from matplotlib.colors import LinearSegmentedColormap -import matplotlib as mpl mpl.use("Agg") # very important above pyplot import -from nilearn.plotting.edge_detect import _edge_map as edge_map import matplotlib.pyplot as plt +from nilearn.plotting.edge_detect import _edge_map as edge_map def reg_mri_pngs( diff --git a/m2g/stats/qa_skullstrip.py b/m2g/stats/qa_skullstrip.py index 404efd4a1..ee627a79d 100644 --- a/m2g/stats/qa_skullstrip.py +++ b/m2g/stats/qa_skullstrip.py @@ -16,18 +16,20 @@ import os import re import sys -import numpy as np -import nibabel as nb from argparse import ArgumentParser -from scipy import ndimage -from matplotlib.colors import LinearSegmentedColormap + import matplotlib as mpl +import nibabel as nb +import numpy as np +from matplotlib.colors import LinearSegmentedColormap +from scipy import ndimage mpl.use("Agg") # very important above pyplot import -from nilearn.plotting.edge_detect import _edge_map as edge_map import matplotlib.pyplot as plt +from nilearn.plotting.edge_detect import _edge_map as edge_map + +from m2g.utils.gen_utils import get_braindata, get_filename from m2g.utils.qa_utils import get_min_max, opaque_colorscale, pad_im -from m2g.utils.gen_utils import get_filename, get_braindata def gen_overlay_pngs( diff --git a/m2g/stats/qa_tensor.py b/m2g/stats/qa_tensor.py index 085d28733..a33730359 100644 --- a/m2g/stats/qa_tensor.py +++ b/m2g/stats/qa_tensor.py @@ -12,15 +12,16 @@ import warnings warnings.simplefilter("ignore") -from argparse import ArgumentParser -from scipy import ndimage -import numpy as np -import nibabel as nb -import matplotlib import itertools +from argparse import ArgumentParser -from dipy.viz import window, actor +import matplotlib +import nibabel as nb +import numpy as np +from dipy.viz import actor, window from fury.actor import orient2rgb +from scipy import ndimage + from m2g.utils import qa_utils matplotlib.use("Agg") # very important above pyplot import diff --git a/m2g/stats/qa_tractography.py b/m2g/stats/qa_tractography.py index bb34dcab9..a475aa65e 100644 --- a/m2g/stats/qa_tractography.py +++ b/m2g/stats/qa_tractography.py @@ -1,12 +1,12 @@ -import nibabel as nib -import numpy as np -import matplotlib.pyplot as plt import os -from fury import actor, window, colormap, ui +import matplotlib.pyplot as plt +import nibabel as nib +import numpy as np from dipy.tracking.streamline import Streamlines -from PIL import Image +from fury import actor, colormap, ui, window from matplotlib.colors import LinearSegmentedColormap +from PIL import Image def combine_plot(qa_out_path, brain_path): diff --git a/m2g/track.py b/m2g/track.py index 395bf2aad..cc8094fb9 100644 --- a/m2g/track.py +++ b/m2g/track.py @@ -11,28 +11,26 @@ # system imports import os +import nibabel as nib # external package imports import numpy as np -import nibabel as nib - +from dipy.data import get_sphere +from dipy.direction import ProbabilisticDirectionGetter, peaks_from_model +from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel, + recursive_response) +from dipy.reconst.dti import TensorModel, fractional_anisotropy, quantize_evecs +from dipy.reconst.shm import CsaOdfModel +from dipy.tracking import utils +from dipy.tracking.local_tracking import (LocalTracking, + ParticleFilteringTracking) +from dipy.tracking.stopping_criterion import (ActStoppingCriterion, + BinaryStoppingCriterion, + CmcStoppingCriterion) # dipy imports from dipy.tracking.streamline import Streamlines -from dipy.tracking import utils -from dipy.tracking.local_tracking import LocalTracking -from dipy.tracking.local_tracking import ParticleFilteringTracking -from dipy.tracking.stopping_criterion import BinaryStoppingCriterion -from dipy.tracking.stopping_criterion import ActStoppingCriterion -from dipy.tracking.stopping_criterion import CmcStoppingCriterion - -from dipy.reconst.dti import fractional_anisotropy, TensorModel, quantize_evecs -from dipy.reconst.shm import CsaOdfModel -from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel, recursive_response - -from dipy.data import get_sphere -from dipy.direction import peaks_from_model, ProbabilisticDirectionGetter -from m2g.utils.gen_utils import timer from m2g.stats import qa_tensor +from m2g.utils.gen_utils import timer def build_seed_list(mask_img_file, stream_affine, dens): diff --git a/m2g/utils/cloud_utils.py b/m2g/utils/cloud_utils.py index bd1fb4be5..bad1aa1eb 100644 --- a/m2g/utils/cloud_utils.py +++ b/m2g/utils/cloud_utils.py @@ -5,10 +5,10 @@ Contains utility functions for working on the cloud with AWS. """ -# standard library imports -from configparser import ConfigParser import os import sys +# standard library imports +from configparser import ConfigParser # package imports import boto3 diff --git a/m2g/utils/gen_utils.py b/m2g/utils/gen_utils.py index fcd57a112..9aba169d2 100644 --- a/m2g/utils/gen_utils.py +++ b/m2g/utils/gen_utils.py @@ -7,31 +7,29 @@ Contains general utility functions. """ +import functools +import json # system imports import os -import shutil -import sys import re +import shutil import subprocess +import sys import time -import functools -import json -from pathlib import Path from collections import namedtuple +from pathlib import Path # package imports import bids -import numpy as np +import dipy import nibabel as nib +import numpy as np +from dipy.align.reslice import reslice +from dipy.core.gradients import gradient_table +from dipy.io import read_bvals_bvecs +from fury import actor, window from nilearn.image import mean_img from scipy.sparse import lil_matrix -from fury import actor -from fury import window - -import dipy -from dipy.io import read_bvals_bvecs -from dipy.core.gradients import gradient_table -from dipy.align.reslice import reslice class DirectorySweeper: diff --git a/m2g/utils/reg_utils.py b/m2g/utils/reg_utils.py index ffd6d722a..4c901d53a 100644 --- a/m2g/utils/reg_utils.py +++ b/m2g/utils/reg_utils.py @@ -11,17 +11,14 @@ # package imports import nibabel as nib -import numpy as np import nilearn.image as nl - -from dipy.align.imaffine import MutualInformationMetric -from dipy.align.imaffine import AffineRegistration -from dipy.align.imaffine import transform_origins -from dipy.align.transforms import TranslationTransform3D -from dipy.align.transforms import RigidTransform3D -from dipy.align.transforms import AffineTransform3D +import numpy as np +from dipy.align.imaffine import (AffineRegistration, MutualInformationMetric, + transform_origins) from dipy.align.imwarp import SymmetricDiffeomorphicRegistration from dipy.align.metrics import CCMetric +from dipy.align.transforms import (AffineTransform3D, RigidTransform3D, + TranslationTransform3D) from dipy.viz import regtools # m2g imports