Skip to content

[ENH] Refactor VTK and tvtk -based interfaces #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 80 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
420fa76
Added ets.toolkit configuration to initialization
oesteban Oct 21, 2014
559e698
remove ets.toolkit config in mesh (#972)
oesteban Oct 21, 2014
1f9372f
Merge branch 'master' into enh/ETSConfigTookit
oesteban Feb 23, 2015
545f8c5
Merge branch 'master' into enh/ETSConfigTookit
oesteban Mar 3, 2015
1231a5e
add new import under traits as failback for enthougth
oesteban Mar 3, 2015
dda44ba
Merge branch 'master' into enh/ETSConfigTookit
oesteban Apr 9, 2015
a72fd34
remove error, add config to docs
oesteban Apr 9, 2015
d53ab22
setting ETS_TOOLKIT
oesteban Sep 16, 2015
485c44d
insert here new TVTKBaseInterface
oesteban Sep 18, 2015
bfb0002
Merge branch 'fix/TVTKPolyDataWriter' into enh/ETSConfigTookit
oesteban Sep 18, 2015
21b86ac
ETS_TOOLKIT settings in algorithms.mesh
oesteban Sep 18, 2015
e144fd2
Merge branch 'fix/TVTKPolyDataWriter' into enh/ETSConfigTookit
oesteban Sep 18, 2015
90f27bd
search all tvtk imports and fix ETS_TOOLKIT
oesteban Sep 18, 2015
f8f2bed
Merge branch 'master' into enh/ETSConfigTookit
oesteban Nov 18, 2015
f79aaad
Merge branch 'master' into enh/ETSConfigTookit
oesteban Dec 14, 2015
6416e5b
add autotest file for TVTKBaseInterface
oesteban Dec 14, 2015
befd2db
Merge branch 'master' into enh/ETSConfigTookit
oesteban Dec 15, 2015
a0f4a7e
Merge branch 'master' into enh/ETSConfigTookit
oesteban Jan 25, 2016
c6bb4e3
removed NotImplementedError in method with implementation
oesteban Jan 25, 2016
fa93796
Merge branch 'master' into enh/ETSConfigTookit
oesteban Jan 27, 2016
b757cf8
improved code quality, added comments
oesteban Jan 27, 2016
a3bad0a
added dependencies to testing frameworks
oesteban Jan 27, 2016
df17a3d
added neurodebian in all travis builds
oesteban Jan 27, 2016
b9287f4
added dependency (Pillow) and fixed numpy installation
oesteban Jan 27, 2016
30b0323
fixed numpy installation -> moved from circle to travis
oesteban Jan 27, 2016
9ce6bce
replaced Pillow by PIL
oesteban Jan 27, 2016
4ee2119
added PIL from url
oesteban Jan 27, 2016
2416371
added PIL from url also for circle
oesteban Jan 27, 2016
fa6e263
fixed PIL installation
oesteban Jan 27, 2016
02ea69b
added missing etsproxy
oesteban Jan 27, 2016
70036b4
added python-vtk
oesteban Jan 27, 2016
a52e3d9
fixed vtk installation in travis
oesteban Jan 27, 2016
9a6728e
fixed mayavi in travis and python-vtk in circle
oesteban Jan 27, 2016
db3ac3e
added xvfbwrapper requirement, fixing vtk in ci
oesteban Jan 27, 2016
92d98bc
fixed syntax error in travis file
oesteban Jan 27, 2016
ffd1d40
fixed errors, added conditional doctest
oesteban Jan 27, 2016
cbea5b0
fixing travis for python 3.0, minor in circle
oesteban Jan 27, 2016
db08c4f
updated doctests for the case vtk is not installed (typically python …
oesteban Jan 27, 2016
7c7b719
fixed doctests
oesteban Jan 28, 2016
8938187
removed doctests, added exception testing when vtk is unavailable
oesteban Jan 28, 2016
b68c66a
Merge branch 'master' into enh/ETSConfigTookit
oesteban Jan 28, 2016
a9c039e
fixed mesh tests
oesteban Jan 28, 2016
6b08b02
added base for two regression tests
oesteban Jan 28, 2016
602dea4
Merge branch 'fix/CircleCI/FslFeeds' into enh/ETSConfigTookit
oesteban Jan 28, 2016
5760a0e
Merge branch 'master' into enh/ETSConfigTookit
oesteban Jan 28, 2016
c738be6
Merge branch 'master' into enh/ETSConfigTookit
oesteban Jan 28, 2016
a94158b
added xvfbwrapper to requirements, improved vtk handling
oesteban Jan 28, 2016
8baba45
improved VTK version parsing
oesteban Jan 28, 2016
5396852
Merge branch 'master' into enh/ETSConfigTookit
oesteban Jan 28, 2016
9339e5f
encapsulated VTK Info in class
oesteban Jan 29, 2016
b7ba47f
use tvtk appropriate tools whenever possible
oesteban Jan 29, 2016
9cafde5
refactored vtk/tvtk use and ETSConfigToolkit
oesteban Jan 29, 2016
774906a
Merge branch 'master' into enh/ETSConfigTookit
oesteban Feb 1, 2016
90ad893
fixed outdated code based on xvfbwrapper
oesteban Feb 1, 2016
0dbe8bb
Merge branch 'master' into enh/ETSConfigTookit
oesteban Feb 1, 2016
1ce6850
fixing lint problems
oesteban Feb 2, 2016
01bd281
fixing output_spec is not callable
oesteban Feb 3, 2016
edf906e
revert codacy fixes
oesteban Feb 4, 2016
7e12be8
Merge branch 'master' into enh/ETSConfigTookit
oesteban Feb 4, 2016
69cf3aa
Merge branch 'master' into enh/ETSConfigTookit
oesteban Feb 5, 2016
94eeea2
update travis
Feb 10, 2016
a6ec41e
remove empty line before docstring
Feb 10, 2016
a17422e
add multiverse for ubuntu
Feb 10, 2016
c9968ae
travis set to pin libvtk6-dev from trusty
Feb 10, 2016
807708b
fix error in travis
Feb 10, 2016
39b84f7
fix error in travis
Feb 10, 2016
f809b41
trying to fix travis
Feb 10, 2016
76e64cc
add trusty-updates-
Feb 10, 2016
bf8192d
still fixing VTK6 installation in travis
Feb 10, 2016
5843591
fixed command as sudo
Feb 10, 2016
b9e051d
use ubuntu trusty
Feb 10, 2016
62a23e2
modify the neurodebian script for travis
Feb 10, 2016
664a839
remove ubuntu pinning
Feb 10, 2016
4a778c8
remove python-vtk from travis
Feb 11, 2016
3cd40e1
Merge branch 'master' into enh/ETSConfigTookit
Feb 11, 2016
0087bd9
added disable flag in codacy errors
Feb 11, 2016
a2e52ee
revert back travis
Feb 12, 2016
618fb23
Merge branch 'master' into enh/ETSConfigTookit
Feb 12, 2016
2448821
add disable flag for codacy
Feb 12, 2016
3c75d63
Merge branch 'master' into enh/ETSConfigTookit
Feb 13, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
search all tvtk imports and fix ETS_TOOLKIT
  • Loading branch information
oesteban committed Sep 18, 2015
commit 90f27bd08ba811c44c90ec09cf07c68cc7132b6c
5 changes: 0 additions & 5 deletions doc/users/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ Execution
*xvfb_max_wait*
Maximum time (in seconds) to wait for Xvfb to start, if the _redirect_x parameter of an Interface is True.

*ets_toolkit*
This sets the backend for the Enthought traits (should be ``'null'`` in headless
settings).


Example
~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

oldets = os.getenv('ETS_TOOLKIT')
have_tvtk = False

try:
os.environ['ETS_TOOLKIT'] = 'null'
from tvtk.api import tvtk
Expand Down
11 changes: 10 additions & 1 deletion nipype/algorithms/tests/test_mesh_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@

from nipype.algorithms import mesh as m

notvtk = True
import platform

notvtk = True
if 'darwin' not in platform.system().lower():
oldets = os.getenv('ETS_TOOLKIT')
have_tvtk = False
try:
os.environ['ETS_TOOLKIT'] = 'null'
from tvtk.api import tvtk
notvtk = False
except ImportError:
pass

if oldets is not None:
os.environ['ETS_TOOLKIT'] = oldets
else:
del os.environ['ETS_TOOLKIT']

@skipif(notvtk)
def test_ident_distances():
tempdir = mkdtemp()
Expand Down
18 changes: 18 additions & 0 deletions nipype/interfaces/fsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,11 +1854,20 @@ def _parse_inputs(self, skip=None):
return first_args + [ second_args ]

def _vtk_to_coords(self, in_file, out_file=None):
import os
import os.path as op

oldets = os.getenv('ETS_TOOLKIT')
try:
os.environ['ETS_TOOLKIT'] = 'null'
from tvtk.api import tvtk
except ImportError:
raise ImportError('This interface requires tvtk to run.')
finally:
if oldets is not None:
os.environ['ETS_TOOLKIT'] = oldets
else:
del os.environ['ETS_TOOLKIT']

reader = tvtk.PolyDataReader(file_name=in_file+'.vtk')
reader.update()
Expand All @@ -1871,11 +1880,20 @@ def _vtk_to_coords(self, in_file, out_file=None):
return out_file

def _coords_to_vtk(self, points, out_file):
import os
import os.path as op

oldets = os.getenv('ETS_TOOLKIT')
try:
os.environ['ETS_TOOLKIT'] = 'null'
from tvtk.api import tvtk
except ImportError:
raise ImportError('This interface requires tvtk to run.')
finally:
if oldets is not None:
os.environ['ETS_TOOLKIT'] = oldets
else:
del os.environ['ETS_TOOLKIT']

reader = tvtk.PolyDataReader(file_name=self.inputs.in_file)
reader.update()
Expand Down
70 changes: 32 additions & 38 deletions nipype/pipeline/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def report_crash(node, traceback=None, hostname=None):
timeofcrash = strftime('%Y%m%d-%H%M%S')
login_name = getpass.getuser()
crashfile = 'crash-%s-%s-%s.pklz' % (timeofcrash,
login_name,
name)
login_name,
name)
crashdir = node.config['execution']['crashdump_dir']
if crashdir is None:
crashdir = os.getcwd()
Expand Down Expand Up @@ -106,10 +106,10 @@ def create_pyscript(node, updatehash=False, store_exception=True):
pkl_file = os.path.join(batch_dir, 'node_%s.pklz' % suffix)
savepkl(pkl_file, dict(node=node, updatehash=updatehash))
mpl_backend = node.config["execution"]["matplotlib_backend"]
ets_toolkit = node.config["execution"]["ets_toolkit"]
# create python script to load and trap exception
cmdstr = """import os
import sys

can_import_matplotlib = True #Silently allow matplotlib to be ignored
try:
import matplotlib
Expand All @@ -118,8 +118,6 @@ def create_pyscript(node, updatehash=False, store_exception=True):
can_import_matplotlib = False
pass

os.environ['ETS_TOOLKIT'] = '%s'

from nipype import config, logging
from nipype.utils.filemanip import loadpkl, savepkl
from socket import gethostname
Expand All @@ -133,12 +131,9 @@ def create_pyscript(node, updatehash=False, store_exception=True):
from collections import OrderedDict
config_dict=%s
config.update_config(config_dict)

## Only configure matplotlib if it was successfully imported, matplotlib is
## an optional component to nipype
## Only configure matplotlib if it was successfully imported, matplotlib is an optional component to nipype
if can_import_matplotlib:
config.update_matplotlib()
config.update_ets()
logging.update_logging(config)
traceback=None
cwd = os.getcwd()
Expand Down Expand Up @@ -170,8 +165,7 @@ def create_pyscript(node, updatehash=False, store_exception=True):
report_crash(info['node'], traceback, gethostname())
raise Exception(e)
"""
cmdstr = cmdstr % (mpl_backend, ets_toolkit, pkl_file,
batch_dir, node.config, suffix)
cmdstr = cmdstr % (mpl_backend, pkl_file, batch_dir, node.config, suffix)
pyscript = os.path.join(batch_dir, 'pyscript_%s.py' % suffix)
fp = open(pyscript, 'wt')
fp.writelines(cmdstr)
Expand All @@ -180,7 +174,6 @@ def create_pyscript(node, updatehash=False, store_exception=True):


class PluginBase(object):

"""Base class for plugins"""

def __init__(self, plugin_args=None):
Expand All @@ -195,7 +188,6 @@ def run(self, graph, config, updatehash=False):


class DistributedPluginBase(PluginBase):

"""Execute workflow with a distribution engine
"""

Expand Down Expand Up @@ -238,7 +230,7 @@ def run(self, graph, config, updatehash=False):
# setup polling - TODO: change to threaded model
notrun = []
while np.any(self.proc_done == False) | \
np.any(self.proc_pending == True):
np.any(self.proc_pending == True):
toappend = []
# trigger callbacks for any pending results
while self.pending_tasks:
Expand Down Expand Up @@ -316,7 +308,7 @@ def _submit_mapnode(self, jobid):
self.procs.extend(mapnodesubids)
self.depidx = ssp.vstack((self.depidx,
ssp.lil_matrix(np.zeros(
(numnodes, self.depidx.shape[1])))),
(numnodes, self.depidx.shape[1])))),
'lil')
self.depidx = ssp.hstack((self.depidx,
ssp.lil_matrix(
Expand Down Expand Up @@ -365,23 +357,23 @@ def _send_procs_to_workers(self, updatehash=False, graph=None):
self.proc_pending[jobid] = True
# Send job to task manager and add to pending tasks
logger.info('Executing: %s ID: %d' %
(self.procs[jobid]._id, jobid))
(self.procs[jobid]._id, jobid))
if self._status_callback:
self._status_callback(self.procs[jobid], 'start')
continue_with_submission = True
if str2bool(self.procs[jobid].config['execution']
['local_hash_check']):
['local_hash_check']):
logger.debug('checking hash locally')
try:
hash_exists, _, _, _ = self.procs[
jobid].hash_exists()
logger.debug('Hash exists %s' % str(hash_exists))
if (hash_exists and
(self.procs[jobid].overwrite == False or
(self.procs[jobid].overwrite == None and
not self.procs[jobid]._interface.always_run)
)
):
(self.procs[jobid].overwrite == False or
(self.procs[jobid].overwrite == None and
not self.procs[jobid]._interface.always_run)
)
):
continue_with_submission = False
self._task_finished_cb(jobid)
self._remove_node_dirs()
Expand Down Expand Up @@ -473,7 +465,6 @@ def _remove_node_dirs(self):


class SGELikeBatchManagerBase(DistributedPluginBase):

"""Execute workflow with SGE/OGE/PBS like batch system
"""

Expand Down Expand Up @@ -536,7 +527,7 @@ def _get_result(self, taskid):
'seconds. Batch dir contains crashdump file '
'if node raised an exception.\n'
'Node working directory: ({2}) '.format(
taskid, timeout, node_dir))
taskid,timeout,node_dir) )
raise IOError(error_message)
except IOError, e:
result_data['traceback'] = format_exc()
Expand Down Expand Up @@ -583,7 +574,6 @@ def _clear_task(self, taskid):


class GraphPluginBase(PluginBase):

"""Base class for plugins that distribute graphs to workflows
"""

Expand Down Expand Up @@ -613,19 +603,19 @@ def _get_args(self, node, keywords):
if keyword == "template" and os.path.isfile(value):
value = open(value).read()
if (hasattr(node, "plugin_args") and
isinstance(node.plugin_args, dict) and
keyword in node.plugin_args):
if (keyword == "template" and
os.path.isfile(node.plugin_args[keyword])):
tmp_value = open(node.plugin_args[keyword]).read()
else:
tmp_value = node.plugin_args[keyword]

if ('overwrite' in node.plugin_args and
node.plugin_args['overwrite']):
value = tmp_value
else:
value += tmp_value
isinstance(node.plugin_args, dict) and
keyword in node.plugin_args):
if (keyword == "template" and
os.path.isfile(node.plugin_args[keyword])):
tmp_value = open(node.plugin_args[keyword]).read()
else:
tmp_value = node.plugin_args[keyword]

if ('overwrite' in node.plugin_args and
node.plugin_args['overwrite']):
value = tmp_value
else:
value += tmp_value
values += (value, )
return values

Expand All @@ -636,13 +626,16 @@ def _submit_graph(self, pyfiles, dependencies, nodes):
"""
raise NotImplementedError



def _get_result(self, taskid):
if taskid not in self._pending:
raise Exception('Task %d not found' % taskid)
if self._is_pending(taskid):
return None
node_dir = self._pending[taskid]


logger.debug(os.listdir(os.path.realpath(os.path.join(node_dir,
'..'))))
logger.debug(os.listdir(node_dir))
Expand All @@ -663,3 +656,4 @@ def _get_result(self, taskid):
result_out['result'] = result_data

return result_out

19 changes: 7 additions & 12 deletions nipype/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
keep_inputs = false
local_hash_check = true
matplotlib_backend = Agg
ets_toolkit = null
plugin = Linear
remove_node_directories = false
remove_unnecessary_outputs = true
Expand Down Expand Up @@ -71,7 +70,6 @@ def mkdir_p(path):


class NipypeConfig(object):

"""Base nipype config class
"""

Expand All @@ -84,12 +82,12 @@ def __init__(self, *args, **kwargs):
# To be deprecated in two releases
if os.path.exists(old_config_file):
if os.path.exists(new_config_file):
msg = ("Detected presence of both old (%s, used by versions "
"< 0.5.2) and new (%s) config files. This version will "
"proceed with the new one. We advise to merge settings "
"and remove old config file if you are not planning to "
"use previous releases of nipype.") % (old_config_file,
new_config_file)
msg=("Detected presence of both old (%s, used by versions "
"< 0.5.2) and new (%s) config files. This version will "
"proceed with the new one. We advise to merge settings "
"and remove old config file if you are not planning to "
"use previous releases of nipype.") % (old_config_file,
new_config_file)
warn(msg)
else:
warn("Moving old config file from: %s to %s" % (old_config_file,
Expand Down Expand Up @@ -167,10 +165,7 @@ def update_matplotlib(self):
import matplotlib
matplotlib.use(self.get('execution', 'matplotlib_backend'))

def update_ets(self):
import os
os.environ['ETS_TOOLKIT'] = '%s' % self.get('execution', 'ets_toolkit')

def enable_provenance(self):
self._config.set('execution', 'write_provenance', 'true')
self._config.set('execution', 'hash_method', 'content')