2
2
# -*- coding: utf-8 -*-
3
3
"""
4
4
Created on Fri Nov 10 15:44:46 2017
5
- Copyright (C) 2017
5
+ Copyright (C) 2016
6
6
@author: Derek Pisner (dPys)
7
7
"""
8
8
import warnings
@@ -107,9 +107,14 @@ def _run_interface(self, runtime):
107
107
else :
108
108
parcel_list = None
109
109
else :
110
- raise FileNotFoundError (
111
- f"\n Atlas file for { self .inputs .atlas } not found!"
112
- )
110
+ try :
111
+ raise FileNotFoundError (
112
+ f"\n Atlas file for { self .inputs .atlas } not found!"
113
+ )
114
+ except FileNotFoundError :
115
+ import sys
116
+ sys .exit (0 )
117
+
113
118
atlas = self .inputs .atlas
114
119
elif (
115
120
self .inputs .uatlas is None
@@ -159,8 +164,12 @@ def _run_interface(self, runtime):
159
164
else :
160
165
parcel_list = None
161
166
else :
162
- raise ValueError (
163
- f"\n Atlas file for { self .inputs .atlas } not found!" )
167
+ try :
168
+ raise FileNotFoundError (
169
+ f"\n Atlas file for { self .inputs .atlas } not found!" )
170
+ except FileNotFoundError :
171
+ import sys
172
+ sys .exit (0 )
164
173
par_max = None
165
174
atlas = self .inputs .atlas
166
175
label_intensities = None
@@ -194,14 +203,12 @@ def _run_interface(self, runtime):
194
203
# Describe user atlas coords
195
204
print (f"\n { self .inputs .atlas } comes with { par_max } parcels\n " )
196
205
except ValueError :
206
+ import sys
197
207
print (
198
208
"Either you have specified the name of an atlas that does"
199
209
" not exist in the nilearn or local repository or you have"
200
210
" not supplied a 3d atlas parcellation image!" )
201
- parcel_list = None
202
- par_max = None
203
- coords = None
204
- label_intensities = None
211
+ sys .exit (0 )
205
212
labels = None
206
213
networks_list = None
207
214
atlas = self .inputs .atlas
@@ -242,24 +249,23 @@ def _run_interface(self, runtime):
242
249
# Describe user atlas coords
243
250
print (f"\n { atlas } comes with { par_max } parcels\n " )
244
251
except ValueError :
252
+ import sys
245
253
print (
246
254
"Either you have specified the name of an atlas that does"
247
255
" not exist in the nilearn or local repository or you have"
248
256
" not supplied a 3d atlas parcellation image!" )
249
- parcel_list = None
250
- par_max = None
251
- coords = None
252
- atlas = None
253
- uatlas = None
254
- label_intensities = None
257
+ sys .exit (0 )
255
258
labels = None
256
259
networks_list = None
257
260
else :
258
- raise ValueError (
259
- "Either you have specified the name of an atlas that does not"
260
- " exist in the nilearn or local repository or you have not"
261
- " supplied a 3d atlas parcellation image!" )
262
-
261
+ try :
262
+ raise ValueError (
263
+ "Either you have specified the name of an atlas that does"
264
+ " not exist in the nilearn or local repository or you have"
265
+ " not supplied a 3d atlas parcellation image!" )
266
+ except ValueError :
267
+ import sys
268
+ sys .exit (0 )
263
269
# Labels prep
264
270
if atlas and not labels :
265
271
if (self .inputs .ref_txt is not None ) and (
@@ -748,11 +754,15 @@ def run_bs_iteration(i, ts_data, work_dir, local_corr,
748
754
parcellation .to_filename (out_path )
749
755
750
756
else :
751
- raise ValueError (
752
- "Clustering method not recognized. See: "
753
- "https://nilearn.github.io/modules/generated/"
754
- "nilearn.regions.Parcellations."
755
- "html#nilearn.regions.Parcellations" )
757
+ try :
758
+ raise ValueError (
759
+ "Clustering method not recognized. See: "
760
+ "https://nilearn.github.io/modules/generated/"
761
+ "nilearn.regions.Parcellations."
762
+ "html#nilearn.regions.Parcellations" )
763
+ except ValueError :
764
+ import sys
765
+ sys .exit (0 )
756
766
757
767
# Give it a minute
758
768
ix = 0
@@ -762,8 +772,12 @@ def run_bs_iteration(i, ts_data, work_dir, local_corr,
762
772
ix += 1
763
773
764
774
if not os .path .isfile (nip .uatlas ):
765
- raise FileNotFoundError (f"Parcellation clustering failed for"
766
- f" { nip .uatlas } " )
775
+ try :
776
+ raise FileNotFoundError (f"Parcellation clustering failed for"
777
+ f" { nip .uatlas } " )
778
+ except FileNotFoundError :
779
+ import sys
780
+ sys .exit (0 )
767
781
768
782
self ._results ["atlas" ] = atlas
769
783
self ._results ["uatlas" ] = nip .uatlas
@@ -918,6 +932,7 @@ def _run_interface(self, runtime):
918
932
== te .ts_within_nodes .shape [1 ]
919
933
)
920
934
except AssertionError as e :
935
+ import sys
921
936
e .args += ('Coords: ' , len (self .inputs .coords ),
922
937
self .inputs .coords , 'Labels:' ,
923
938
len (self .inputs .labels ),
@@ -2293,8 +2308,10 @@ def _run_interface(self, runtime):
2293
2308
self .inputs .labels )
2294
2309
2295
2310
except FileNotFoundError :
2311
+ import sys
2296
2312
print ('T1w-space parcellation not found. Did you delete '
2297
2313
'outputs?' )
2314
+ sys .exit (0 )
2298
2315
else :
2299
2316
if self .inputs .uatlas is None :
2300
2317
uatlas_tmp_path = None
@@ -2455,10 +2472,12 @@ def _run_interface(self, runtime):
2455
2472
try :
2456
2473
assert len (coords ) == len (labels ) == len (intensities )
2457
2474
except ValueError as err :
2475
+ import sys
2458
2476
print ('Failed!' )
2459
2477
print (f"# Coords: { len (coords )} " )
2460
2478
print (f"# Labels: { len (labels )} " )
2461
2479
print (f"# Intensities: { len (intensities )} " )
2480
+ sys .exit (1 )
2462
2481
2463
2482
self ._results ["aligned_atlas_gm" ] = aligned_atlas_gm
2464
2483
self ._results ["coords" ] = coords
@@ -2664,6 +2683,7 @@ class _TrackingOutputSpec(TraitedSpec):
2664
2683
min_length = traits .Any ()
2665
2684
error_margin = traits .Any ()
2666
2685
2686
+
2667
2687
class Tracking (SimpleInterface ):
2668
2688
"""Interface wrapper for Tracking"""
2669
2689
@@ -2921,7 +2941,12 @@ def _run_interface(self, runtime):
2921
2941
f" Maximum"
2922
2942
)
2923
2943
else :
2924
- raise ValueError ("Direction-getting type not recognized!" )
2944
+ try :
2945
+ raise ValueError ("Direction-getting type not recognized!" )
2946
+ except ValueError :
2947
+ import sys
2948
+ sys .exit (0 )
2949
+
2925
2950
print (Style .RESET_ALL )
2926
2951
2927
2952
# Commence Ensemble Tractography
@@ -3010,8 +3035,12 @@ def _run_interface(self, runtime):
3010
3035
f"streamlines output { namer_dir } /{ op .basename (streams )} "
3011
3036
f" is recommended." )
3012
3037
if len (streamlines ) < 0.5 * orig_count :
3013
- raise ValueError ('LiFE revealed no plausible streamlines in '
3014
- 'the tractogram!' )
3038
+ try :
3039
+ raise ValueError ('LiFE revealed no plausible streamlines '
3040
+ 'in the tractogram!' )
3041
+ except ValueError :
3042
+ import sys
3043
+ sys .exit (0 )
3015
3044
del dwi_data , mask_data
3016
3045
3017
3046
stf = StatefulTractogram (
0 commit comments