8
8
import os
9
9
import os .path as op
10
10
import shutil
11
- import warnings
12
11
13
12
import numpy as np
14
13
import nibabel as nb
15
14
import networkx as nx
16
15
17
16
from ... 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 ,
20
19
TraitedSpec , Directory , isdefined )
20
+ from .base import have_cmp
21
21
iflogger = logging .getLogger ('interface' )
22
22
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
-
32
23
33
24
def create_annot_label (subject_id , subjects_dir , fs_dir , parcellation_name ):
25
+ import cmp
26
+ from cmp .util import runCmd
34
27
iflogger .info ("Create the cortical labels necessary for our ROIs" )
35
28
iflogger .info ("=================================================" )
36
29
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):
174
167
def create_roi (subject_id , subjects_dir , fs_dir , parcellation_name , dilation ):
175
168
""" Creates the ROI_%s.nii.gz files using the given parcellation information
176
169
from networks. Iteratively create volume. """
170
+ import cmp
171
+ from cmp .util import runCmd
177
172
iflogger .info ("Create the ROIs:" )
178
173
output_dir = op .abspath (op .curdir )
179
174
fs_dir = op .join (subjects_dir , subject_id )
@@ -306,6 +301,8 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name, dilation):
306
301
307
302
308
303
def create_wm_mask (subject_id , subjects_dir , fs_dir , parcellation_name ):
304
+ import cmp
305
+ import scipy .ndimage .morphology as nd
309
306
iflogger .info ("Create white matter mask" )
310
307
fs_dir = op .join (subjects_dir , subject_id )
311
308
cmp_config = cmp .configuration .PipelineConfiguration ()
@@ -328,11 +325,6 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
328
325
aseg = nb .load (op .join (fs_dir , 'mri' , 'aseg.nii.gz' ))
329
326
asegd = aseg .get_data ()
330
327
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
-
336
328
# need binary erosion function
337
329
imerode = nd .binary_erosion
338
330
@@ -438,6 +430,7 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
438
430
439
431
def crop_and_move_datasets (subject_id , subjects_dir , fs_dir , parcellation_name ,
440
432
out_roi_file , dilation ):
433
+ from cmp .util import runCmd
441
434
fs_dir = op .join (subjects_dir , subject_id )
442
435
cmp_config = cmp .configuration .PipelineConfiguration ()
443
436
cmp_config .parcellation_scheme = "Lausanne2008"
@@ -549,7 +542,7 @@ class ParcellateOutputSpec(TraitedSpec):
549
542
)
550
543
551
544
552
- class Parcellate (BaseInterface ):
545
+ class Parcellate (LibraryBaseInterface ):
553
546
"""Subdivides segmented ROI file into smaller subregions
554
547
555
548
This interface implements the same procedure as in the ConnectomeMapper's
@@ -571,6 +564,8 @@ class Parcellate(BaseInterface):
571
564
572
565
input_spec = ParcellateInputSpec
573
566
output_spec = ParcellateOutputSpec
567
+ _pkg = 'cmp'
568
+ imports = ('scipy' , )
574
569
575
570
def _run_interface (self , runtime ):
576
571
if self .inputs .subjects_dir :
0 commit comments