Skip to content

Commit 3434912

Browse files
authored
Merge pull request #444 from dPys/development
Development
2 parents 4c96cc5 + cf47579 commit 3434912

23 files changed

+820
-982
lines changed

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Required
2323

2424
:(B): A supported connectivity model specified with the `-mod` flag. If PyNets is executed in multimodal mode (i.e. with both fMRI and dMRI inputs in the same command-line call), multiple modality-applicable connectivity models should be specified (minimally providing at least one for either modality). PyNets will automatically parse which model is appropriate for which data.
2525

26-
:(C): If an atlas is not specified with the `-a` flag must be included, then a parcellation file must be specified with the `-ua` flag. The following curated list of atlases is currently supported:
26+
:(C): If an atlas is not specified with the `-a` flag, then a parcellation file must be specified with the `-ua` flag. The following curated list of atlases is currently supported:
2727

2828
:Atlas Library:
2929
- 'atlas_harvard_oxford'

pynets/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# from ._version import get_versions
77
# __version__ = get_versions()['version']
88
# del get_versions
9-
__version__ = "1.0.15"
9+
__version__ = "1.0.16"
1010

1111
__packagename__ = "pynets"
1212
__copyright__ = "Copyright 2016, Derek Pisner"

pynets/cli/pynets_run.py

Lines changed: 206 additions & 236 deletions
Large diffs are not rendered by default.

pynets/core/interfaces.py

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class FetchNodesLabels(SimpleInterface):
5858
output_spec = _FetchNodesLabelsOutputSpec
5959

6060
def _run_interface(self, runtime):
61+
import sys
6162
from pynets.core import utils, nodemaker
6263
from nipype.utils.filemanip import fname_presuffix, copyfile
6364
from nilearn.image import concat_imgs
@@ -109,13 +110,9 @@ def _run_interface(self, runtime):
109110
else:
110111
parcel_list = None
111112
else:
112-
try:
113-
raise FileNotFoundError(
114-
f"\nAtlas file for {self.inputs.atlas} not found!"
115-
)
116-
except FileNotFoundError:
117-
import sys
118-
sys.exit(0)
113+
raise FileNotFoundError(
114+
f"\nAtlas file for {self.inputs.atlas} not found!"
115+
)
119116

120117
atlas = self.inputs.atlas
121118
elif (
@@ -167,12 +164,9 @@ def _run_interface(self, runtime):
167164
else:
168165
parcel_list = None
169166
else:
170-
try:
171-
raise FileNotFoundError(
172-
f"\nAtlas file for {self.inputs.atlas} not found!")
173-
except FileNotFoundError:
174-
import sys
175-
sys.exit(0)
167+
raise FileNotFoundError(
168+
f"\nAtlas file for {self.inputs.atlas} not found!")
169+
176170
par_max = None
177171
atlas = self.inputs.atlas
178172
label_intensities = None
@@ -205,13 +199,13 @@ def _run_interface(self, runtime):
205199
parcel_list = None
206200
# Describe user atlas coords
207201
print(f"\n{self.inputs.atlas} comes with {par_max} parcels\n")
208-
except ValueError:
209-
import sys
210-
print(
202+
except ValueError as e:
203+
print(e,
211204
"Either you have specified the name of an atlas that does"
212205
" not exist in the nilearn or local repository or you have"
213206
" not supplied a 3d atlas parcellation image!")
214-
sys.exit(0)
207+
import sys
208+
sys.exit(1)
215209
labels = None
216210
networks_list = None
217211
atlas = self.inputs.atlas
@@ -251,24 +245,21 @@ def _run_interface(self, runtime):
251245

252246
# Describe user atlas coords
253247
print(f"\n{atlas} comes with {par_max} parcels\n")
254-
except ValueError:
255-
import sys
256-
print(
248+
except ValueError as e:
249+
print(e,
257250
"Either you have specified the name of an atlas that does"
258251
" not exist in the nilearn or local repository or you have"
259252
" not supplied a 3d atlas parcellation image!")
260-
sys.exit(0)
253+
import sys
254+
sys.exit(1)
261255
labels = None
262256
networks_list = None
263257
else:
264-
try:
265-
raise ValueError(
266-
"Either you have specified the name of an atlas that does"
267-
" not exist in the nilearn or local repository or you have"
268-
" not supplied a 3d atlas parcellation image!")
269-
except ValueError:
270-
import sys
271-
sys.exit(0)
258+
raise ValueError(
259+
"Either you have specified the name of an atlas that does"
260+
" not exist in the nilearn or local repository or you have"
261+
" not supplied a 3d atlas parcellation image!")
262+
272263
# Labels prep
273264
if atlas and not labels:
274265
if (self.inputs.ref_txt is not None) and (
@@ -758,15 +749,11 @@ def run_bs_iteration(i, ts_data, work_dir, local_corr,
758749
parcellation.to_filename(out_path)
759750

760751
else:
761-
try:
762-
raise ValueError(
763-
"Clustering method not recognized. See: "
764-
"https://nilearn.github.io/modules/generated/"
765-
"nilearn.regions.Parcellations."
766-
"html#nilearn.regions.Parcellations")
767-
except ValueError:
768-
import sys
769-
sys.exit(0)
752+
raise ValueError(
753+
"Clustering method not recognized. See: "
754+
"https://nilearn.github.io/modules/generated/"
755+
"nilearn.regions.Parcellations."
756+
"html#nilearn.regions.Parcellations")
770757

771758
# Give it a minute
772759
ix = 0
@@ -776,12 +763,8 @@ def run_bs_iteration(i, ts_data, work_dir, local_corr,
776763
ix += 1
777764

778765
if not os.path.isfile(nip.uatlas):
779-
try:
780-
raise FileNotFoundError(f"Parcellation clustering failed for"
781-
f" {nip.uatlas}")
782-
except FileNotFoundError:
783-
import sys
784-
sys.exit(0)
766+
raise FileNotFoundError(f"Parcellation clustering failed for"
767+
f" {nip.uatlas}")
785768

786769
self._results["atlas"] = atlas
787770
self._results["uatlas"] = nip.uatlas
@@ -936,12 +919,10 @@ def _run_interface(self, runtime):
936919
== te.ts_within_nodes.shape[1]
937920
)
938921
except AssertionError as e:
939-
import sys
940922
e.args += ('Coords: ', len(self.inputs.coords),
941923
self.inputs.coords, 'Labels:',
942924
len(self.inputs.labels),
943925
self.inputs.labels, te.ts_within_nodes.shape)
944-
raise
945926

946927
self._results["ts_within_nodes"] = te.ts_within_nodes
947928
self._results["node_size"] = te.node_size
@@ -2311,11 +2292,11 @@ def _run_interface(self, runtime):
23112292
aligned_atlas_gm, self.inputs.coords,
23122293
self.inputs.labels)
23132294

2314-
except FileNotFoundError:
2295+
except FileNotFoundError as e:
23152296
import sys
2316-
print('T1w-space parcellation not found. Did you delete '
2297+
print(e, 'T1w-space parcellation not found. Did you delete '
23172298
'outputs?')
2318-
sys.exit(0)
2299+
sys.exit(1)
23192300
else:
23202301
if self.inputs.uatlas is None:
23212302
uatlas_tmp_path = None
@@ -2475,13 +2456,11 @@ def _run_interface(self, runtime):
24752456
) if i != 0]
24762457
try:
24772458
assert len(coords) == len(labels) == len(intensities)
2478-
except ValueError as err:
2479-
import sys
2480-
print('Failed!')
2459+
except ValueError as e:
2460+
print(e, 'Failed!')
24812461
print(f"# Coords: {len(coords)}")
24822462
print(f"# Labels: {len(labels)}")
24832463
print(f"# Intensities: {len(intensities)}")
2484-
sys.exit(1)
24852464

24862465
self._results["aligned_atlas_gm"] = aligned_atlas_gm
24872466
self._results["coords"] = coords
@@ -2697,6 +2676,7 @@ class Tracking(SimpleInterface):
26972676
def _run_interface(self, runtime):
26982677
import gc
26992678
import os
2679+
import sys
27002680
import os.path as op
27012681
from dipy.io import load_pickle
27022682
from colorama import Fore, Style
@@ -2945,11 +2925,7 @@ def _run_interface(self, runtime):
29452925
f" Maximum"
29462926
)
29472927
else:
2948-
try:
2949-
raise ValueError("Direction-getting type not recognized!")
2950-
except ValueError:
2951-
import sys
2952-
sys.exit(0)
2928+
raise ValueError("Direction-getting type not recognized!")
29532929

29542930
print(Style.RESET_ALL)
29552931

@@ -3039,12 +3015,8 @@ def _run_interface(self, runtime):
30393015
f"streamlines output {namer_dir}/{op.basename(streams)}"
30403016
f" is recommended.")
30413017
if len(streamlines) < 0.5*orig_count:
3042-
try:
3043-
raise ValueError('LiFE revealed no plausible streamlines '
3044-
'in the tractogram!')
3045-
except ValueError:
3046-
import sys
3047-
sys.exit(0)
3018+
raise ValueError('LiFE revealed no plausible streamlines '
3019+
'in the tractogram!')
30483020
del dwi_data, mask_data
30493021

30503022
stf = StatefulTractogram(

0 commit comments

Comments
 (0)