Skip to content

Commit e4dca02

Browse files
committed
Merge pull request #6 from satra/enh/sge
fix: parenthesis fixes
2 parents 8b0f36b + e85a59e commit e4dca02

File tree

5 files changed

+32
-49
lines changed

5 files changed

+32
-49
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ before_install:
1818

1919
# Install packages
2020
install:
21+
- conda update --yes conda
2122
- conda create -n testenv --yes pip python=$TRAVIS_PYTHON_VERSION
2223
- source activate testenv
24+
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then pip install ordereddict; fi
2325
- conda install --yes numpy scipy nose traits networkx dateutil
2426
- pip install nibabel --use-mirrors
2527
- pip install python-coveralls --use-mirrors

nipype/pipeline/engine.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,15 @@ def __repr__(self):
205205

206206
def save(self, filename=None):
207207
if filename is None:
208-
filename = 'temp.npz'
209-
np.savez(filename, object=self)
208+
filename = 'temp.pklz'
209+
savepkl(filename, self)
210210

211211
def load(self, filename):
212-
return np.load(filename)
212+
if '.npz' in filename:
213+
DeprecationWarning(('npz files will be deprecated in the next '
214+
'release. you can use numpy to open them.'))
215+
return np.load(filename)
216+
return loadpkl(filename)
213217

214218

215219
class Workflow(WorkflowBase):

nipype/pipeline/plugins/base.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from copy import deepcopy
77
from glob import glob
88
import os
9+
import pickle
910
import pwd
1011
import shutil
1112
from socket import gethostname
@@ -55,7 +56,7 @@ def report_crash(node, traceback=None, hostname=None):
5556
exc_traceback)
5657
timeofcrash = strftime('%Y%m%d-%H%M%S')
5758
login_name = pwd.getpwuid(os.geteuid())[0]
58-
crashfile = 'crash-%s-%s-%s.npz' % (timeofcrash,
59+
crashfile = 'crash-%s-%s-%s.pklz' % (timeofcrash,
5960
login_name,
6061
name)
6162
crashdir = node.config['execution']['crashdump_dir']
@@ -66,7 +67,8 @@ def report_crash(node, traceback=None, hostname=None):
6667
crashfile = os.path.join(crashdir, crashfile)
6768
logger.info('Saving crash info to %s' % crashfile)
6869
logger.info(''.join(traceback))
69-
np.savez(crashfile, node=node, traceback=traceback)
70+
savepkl(crashfile, dict(node=node, traceback=traceback))
71+
#np.savez(crashfile, node=node, traceback=traceback)
7072
return crashfile
7173

7274

@@ -590,16 +592,17 @@ def _get_args(self, node, keywords):
590592
value = getattr(self, "_" + keyword)
591593
if keyword == "template" and os.path.isfile(value):
592594
value = open(value).read()
593-
if hasattr(node, "plugin_args") and
594-
isinstance(node.plugin_args, dict) and keyword in node.plugin_args:
595-
if keyword == "template" and
596-
os.path.isfile(node.plugin_args[keyword]):
595+
if (hasattr(node, "plugin_args") and
596+
isinstance(node.plugin_args, dict) and
597+
keyword in node.plugin_args):
598+
if (keyword == "template" and
599+
os.path.isfile(node.plugin_args[keyword])):
597600
tmp_value = open(node.plugin_args[keyword]).read()
598601
else:
599602
tmp_value = node.plugin_args[keyword]
600603

601-
if 'overwrite' in node.plugin_args and
602-
node.plugin_args['overwrite']:
604+
if ('overwrite' in node.plugin_args and
605+
node.plugin_args['overwrite']):
603606
value = tmp_value
604607
else:
605608
value += tmp_value

nipype/utils/filemanip.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,30 +378,21 @@ def load_json(filename):
378378
fp.close()
379379
return data
380380

381-
382-
def loadflat(infile, *args):
383-
"""Load an npz file into a dict
384-
"""
385-
data = np.load(infile)
386-
out = {}
387-
if args:
388-
outargs = np.setdiff1d(args, data.files)
389-
if outargs:
390-
raise IOError('File does not contain variables: '+str(outargs))
391-
for k in data.files:
392-
if k in args or not args:
393-
out[k] = [f for f in data[k].flat]
394-
if len(out[k]) == 1:
395-
out[k] = out[k].pop()
396-
return out
397-
398-
399381
def loadcrash(infile, *args):
400382
if '.pkl' in infile:
401383
return loadpkl(infile)
384+
elif '.npz' in infile:
385+
DeprecationWarning(('npz files will be deprecated in the next '
386+
'release. you can use numpy to open them.'))
387+
data = np.load(infile)
388+
out = {}
389+
for k in data.files:
390+
out[k] = [f for f in data[k].flat]
391+
if len(out[k]) == 1:
392+
out[k] = out[k].pop()
393+
return out
402394
else:
403-
return loadflat(infile, *args)
404-
395+
raise ValueError('Only pickled crashfiles are supported')
405396

406397
def loadpkl(infile):
407398
"""Load a zipped or plain cPickled file

nipype/utils/tests/test_filemanip.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tempfile import mkstemp, mkdtemp
55

66
from nipype.testing import assert_equal, assert_true, assert_false
7-
from nipype.utils.filemanip import (save_json, load_json, loadflat,
7+
from nipype.utils.filemanip import (save_json, load_json,
88
fname_presuffix, fnames_presuffix,
99
hash_rename, check_forhash,
1010
copyfile, copyfiles,
@@ -143,23 +143,6 @@ def test_json():
143143
os.unlink(name)
144144
yield assert_equal, sorted(adict.items()), sorted(new_dict.items())
145145

146-
def test_loadflat():
147-
alist = [dict(a='one', c='three', b='two'),
148-
dict(a='one', c='three', b='two')]
149-
fd, name = mkstemp(suffix='.npz')
150-
np.savez(name,a=alist)
151-
aloaded = loadflat(name)['a']
152-
os.unlink(name)
153-
yield assert_equal, len(aloaded), 2
154-
yield assert_equal, sorted(aloaded[0].items()), sorted(alist[0].items())
155-
adict = dict(a='one', c='three', b='two')
156-
fd, name = mkstemp(suffix='.npz')
157-
np.savez(name,a=adict)
158-
aloaded = loadflat(name)['a']
159-
os.unlink(name)
160-
yield assert_true, isinstance(aloaded, dict)
161-
yield assert_equal, sorted(aloaded.items()), sorted(adict.items())
162-
163146
def test_related_files():
164147
file1 = '/path/test.img'
165148
file2 = '/path/test.hdr'

0 commit comments

Comments
 (0)