In [11]:
import os
import numpy as np
import nibabel as nib
import nilearn.image as nimg
import nipype.interfaces.spm as spm
import pandas as pd
%matplotlib inline
import warnings
warnings.filterwarnings("ignore", category=FutureWarning, module="matplotlib")
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

In [8]:
os.chdir("..")

In [12]:
print(os.path.abspath(os.curdir))


/home/tg/Projects/ML

In [4]:
os.chdir("data/train")

In [13]:
"""
plot 3D brain scan as voxelgrid

"""
#TODO check path is */ML

#rand file to load
rnd = np.random.randint(1,278)

#load file
file_path = "data/train/train_" + str(rnd) + ".nii"
img = nib.load(file_path)
img_data = img.get_data()
vox = img_data[:,:,:,0]

#load age
targets = pd.read_csv("data/targets.csv", header=None)
age = "Called file : {0}       Age is : {1}".format(rnd, targets.at[rnd-1,0])
print(age)


Called file : 72       Age is : 87

In [14]:
fastr = fsl.FAST()
fastr.inputs.in_files = example_data(file_path)
out = fastr.run()


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-14-353b11cec715> in <module>()
      1 seg = spm.Segment()
      2 seg.inputs.data = file_path
----> 3 seg.run()

/usr/lib/python3.5/site-packages/nipype/interfaces/base.py in run(self, **inputs)
   1041                         version=self.version)
   1042         try:
-> 1043             runtime = self._run_wrapper(runtime)
   1044             outputs = self.aggregate_outputs(runtime)
   1045             runtime.endTime = dt.isoformat(dt.utcnow())

/usr/lib/python3.5/site-packages/nipype/interfaces/base.py in _run_wrapper(self, runtime)
    998             runtime.environ['DISPLAY'] = ':%d' % vdisp_num
    999 
-> 1000         runtime = self._run_interface(runtime)
   1001 
   1002         if self._redirect_x:

/usr/lib/python3.5/site-packages/nipype/interfaces/spm/base.py in _run_interface(self, runtime)
    309         self.mlab.inputs.script = self._make_matlab_command(
    310             deepcopy(self._parse_inputs()))
--> 311         results = self.mlab.run()
    312         runtime.returncode = results.runtime.returncode
    313         if self.mlab.inputs.uses_mcr:

/usr/lib/python3.5/site-packages/nipype/interfaces/base.py in run(self, **inputs)
   1041                         version=self.version)
   1042         try:
-> 1043             runtime = self._run_wrapper(runtime)
   1044             outputs = self.aggregate_outputs(runtime)
   1045             runtime.endTime = dt.isoformat(dt.utcnow())

/usr/lib/python3.5/site-packages/nipype/interfaces/base.py in _run_wrapper(self, runtime)
   1658 
   1659     def _run_wrapper(self, runtime):
-> 1660         runtime = self._run_interface(runtime)
   1661         return runtime
   1662 

/usr/lib/python3.5/site-packages/nipype/interfaces/matlab.py in _run_interface(self, runtime)
    139     def _run_interface(self, runtime):
    140         self.inputs.terminal_output = 'allatonce'
--> 141         runtime = super(MatlabCommand, self)._run_interface(runtime)
    142         try:
    143             # Matlab can leave the terminal in a barbbled state

/usr/lib/python3.5/site-packages/nipype/interfaces/base.py in _run_interface(self, runtime, correct_return_codes)
   1684         if not exist_val:
   1685             raise IOError("command '%s' could not be found on host %s" %
-> 1686                           (self.cmd.split()[0], runtime.hostname))
   1687         setattr(runtime, 'command_path', cmd_path)
   1688         setattr(runtime, 'dependencies', get_dependencies(executable_name,

OSError: command 'matlab' could not be found on host tg-arch
Interface MatlabCommand failed to run. 
Interface Segment failed to run. 

In [ ]:
fig1 = plt.figure(1,figsize=(8, 10))
ax1 = fig1.add_subplot(1,1,1, projection='3d')
ax1.set_title(age)
ax1.scatter(vox[:,0], vox[:,1], vox[:,2])