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
1917from ..base import (BaseInterface , BaseInterfaceInputSpec , traits , File ,
2018 TraitedSpec , Directory , isdefined )
19+ from .base import have_cmp
2120iflogger = logging .getLogger ('interface' )
2221
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-
3222
3323def create_annot_label (subject_id , subjects_dir , fs_dir , parcellation_name ):
24+ import cmp
25+ from cmp .util import runCmd
3426 iflogger .info ("Create the cortical labels necessary for our ROIs" )
3527 iflogger .info ("=================================================" )
3628 fs_label_dir = op .join (op .join (subjects_dir , subject_id ), 'label' )
@@ -174,6 +166,8 @@ def create_annot_label(subject_id, subjects_dir, fs_dir, parcellation_name):
174166def create_roi (subject_id , subjects_dir , fs_dir , parcellation_name , dilation ):
175167 """ Creates the ROI_%s.nii.gz files using the given parcellation information
176168 from networks. Iteratively create volume. """
169+ import cmp
170+ from cmp .util import runCmd
177171 iflogger .info ("Create the ROIs:" )
178172 output_dir = op .abspath (op .curdir )
179173 fs_dir = op .join (subjects_dir , subject_id )
@@ -306,6 +300,8 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name, dilation):
306300
307301
308302def create_wm_mask (subject_id , subjects_dir , fs_dir , parcellation_name ):
303+ import cmp
304+ import scipy .ndimage .morphology as nd
309305 iflogger .info ("Create white matter mask" )
310306 fs_dir = op .join (subjects_dir , subject_id )
311307 cmp_config = cmp .configuration .PipelineConfiguration ()
@@ -328,11 +324,6 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
328324 aseg = nb .load (op .join (fs_dir , 'mri' , 'aseg.nii.gz' ))
329325 asegd = aseg .get_data ()
330326
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-
336327 # need binary erosion function
337328 imerode = nd .binary_erosion
338329
@@ -438,6 +429,7 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
438429
439430def crop_and_move_datasets (subject_id , subjects_dir , fs_dir , parcellation_name ,
440431 out_roi_file , dilation ):
432+ from cmp .util import runCmd
441433 fs_dir = op .join (subjects_dir , subject_id )
442434 cmp_config = cmp .configuration .PipelineConfiguration ()
443435 cmp_config .parcellation_scheme = "Lausanne2008"
@@ -549,7 +541,7 @@ class ParcellateOutputSpec(TraitedSpec):
549541 )
550542
551543
552- class Parcellate (BaseInterface ):
544+ class Parcellate (LibraryBaseInterface ):
553545 """Subdivides segmented ROI file into smaller subregions
554546
555547 This interface implements the same procedure as in the ConnectomeMapper's
@@ -571,6 +563,8 @@ class Parcellate(BaseInterface):
571563
572564 input_spec = ParcellateInputSpec
573565 output_spec = ParcellateOutputSpec
566+ _pkg = 'cmp'
567+ imports = ('scipy' , )
574568
575569 def _run_interface (self , runtime ):
576570 if self .inputs .subjects_dir :
0 commit comments