88import os
99import os .path as op
1010import shutil
11- import warnings
1211
1312import numpy as np
1413import nibabel as nb
1514import networkx as nx
1615
1716from ... import logging
18- from ... utils . misc import package_check
19- from .. base import ( BaseInterface , BaseInterfaceInputSpec , traits , File ,
17+ from ..base import ( BaseInterface , LibraryBaseInterface ,
18+ BaseInterfaceInputSpec , traits , File ,
2019 TraitedSpec , Directory , isdefined )
20+ from .base import have_cmp
2121iflogger = logging .getLogger ('interface' )
2222
23- have_cmp = True
24- try :
25- package_check ('cmp' )
26- except Exception as e :
27- have_cmp = False
28- else :
29- import cmp
30- from cmp .util import runCmd
31-
3223
3324def create_annot_label (subject_id , subjects_dir , fs_dir , parcellation_name ):
25+ import cmp
26+ from cmp .util import runCmd
3427 iflogger .info ("Create the cortical labels necessary for our ROIs" )
3528 iflogger .info ("=================================================" )
3629 fs_label_dir = op .join (op .join (subjects_dir , subject_id ), 'label' )
@@ -174,6 +167,8 @@ def create_annot_label(subject_id, subjects_dir, fs_dir, parcellation_name):
174167def create_roi (subject_id , subjects_dir , fs_dir , parcellation_name , dilation ):
175168 """ Creates the ROI_%s.nii.gz files using the given parcellation information
176169 from networks. Iteratively create volume. """
170+ import cmp
171+ from cmp .util import runCmd
177172 iflogger .info ("Create the ROIs:" )
178173 output_dir = op .abspath (op .curdir )
179174 fs_dir = op .join (subjects_dir , subject_id )
@@ -306,6 +301,8 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name, dilation):
306301
307302
308303def create_wm_mask (subject_id , subjects_dir , fs_dir , parcellation_name ):
304+ import cmp
305+ import scipy .ndimage .morphology as nd
309306 iflogger .info ("Create white matter mask" )
310307 fs_dir = op .join (subjects_dir , subject_id )
311308 cmp_config = cmp .configuration .PipelineConfiguration ()
@@ -328,11 +325,6 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
328325 aseg = nb .load (op .join (fs_dir , 'mri' , 'aseg.nii.gz' ))
329326 asegd = aseg .get_data ()
330327
331- try :
332- import scipy .ndimage .morphology as nd
333- except ImportError :
334- raise Exception ('Need scipy for binary erosion of white matter mask' )
335-
336328 # need binary erosion function
337329 imerode = nd .binary_erosion
338330
@@ -438,6 +430,7 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
438430
439431def crop_and_move_datasets (subject_id , subjects_dir , fs_dir , parcellation_name ,
440432 out_roi_file , dilation ):
433+ from cmp .util import runCmd
441434 fs_dir = op .join (subjects_dir , subject_id )
442435 cmp_config = cmp .configuration .PipelineConfiguration ()
443436 cmp_config .parcellation_scheme = "Lausanne2008"
@@ -549,7 +542,7 @@ class ParcellateOutputSpec(TraitedSpec):
549542 )
550543
551544
552- class Parcellate (BaseInterface ):
545+ class Parcellate (LibraryBaseInterface ):
553546 """Subdivides segmented ROI file into smaller subregions
554547
555548 This interface implements the same procedure as in the ConnectomeMapper's
@@ -571,6 +564,8 @@ class Parcellate(BaseInterface):
571564
572565 input_spec = ParcellateInputSpec
573566 output_spec = ParcellateOutputSpec
567+ _pkg = 'cmp'
568+ imports = ('scipy' , )
574569
575570 def _run_interface (self , runtime ):
576571 if self .inputs .subjects_dir :
0 commit comments