Skip to content
Prev Previous commit
Next Next commit
Implemented _read_csv, and several changes following testing
  • Loading branch information
arokem committed Sep 29, 2010
commit a1aa5543ffcf01dd2af9f27d9ec37c615b425906
6 changes: 6 additions & 0 deletions nipype/interfaces/nitime/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

from nipype.interfaces.nitime.analysis import (CoherenceAnalyzerInputSpec,
CoherenceAnalyzerOutputSpec,
CoherenceAnalyzer)
32 changes: 22 additions & 10 deletions nipype/interfaces/nitime/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@

"""


from nipype.utils.misc import package_check
package_check('nitime')
package_check('matplotlib')


from nipype.interfaces.base import (TraitedSpec, File, InputMultiPath,
OutputMultiPath, Undefined, traits,
BaseInterface)

from nitime.analysis import CoherenceAnalyzer
from nitime.timeseries import TimeSeries

package_check('nitime')
package_check('matplotlib')

from matplotlib.mlab import csv2rec

class CoherenceAnalyzerInputSpec(TraitedSpec):

#Input either csv file, or time-series object and use _xor_inputs to
#discriminate
_xor_inputs('in_file','in_TS')
_xor_inputs=('in_file','in_TS')
in_file = File(desc=('csv file with ROIs on the columns and ',
'time-points on the rows. ROI names at the top row'),
exists=True,
requires=('sampling_rate'))
requires=('TR',))

#If you gave just a file name, you need to specify the sampling_rate:
TR = traits.Float(desc=('The TR used to collect the data',
Expand Down Expand Up @@ -79,16 +81,21 @@ class CoherenceAnalyzerOutputSpec(TraitedSpec):
class CoherenceAnalyzer(BaseInterface):

input_spec = CoherenceAnalyzerInputSpec
output_spec = CoherenceAnayzerOutputSpec
output_spec = CoherenceAnalyzerOutputSpec

def _read_csv(self):
#Check that input conforms to expectations:
first_row = open(self.inputs.in_file).readline()
if not first_row[1].isalpha():
raise ValueError("First row of in_file should contain ROI names as strings of characters")

return roi_labels,TS
rec_array=csv2rec(self.inputs.in_file)
return rec_array

#Rewrite _run_interface, but not run
def _run_interface(self,runtime):
lb, ub = self.inputs.frequency_range
if


#Rewrite _list_outputs (look at BET)

Expand All @@ -97,10 +104,15 @@ def _list_outputs(self):
return outputs

class GetTimeSeriesInputSpec():
pass
class GetTimeSeriesOutputSpec():
pass
class GetTimeSeries():

pass
class CoherenceVizInputSpec():
pass
class CoherenceVizOutputSpec():
pass
class CoherenceViz():
pass

17 changes: 12 additions & 5 deletions nipype/interfaces/nitime/tests/test_nitime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
import os
import tempfile
import shutil
from matplotlib import mlab.csv2rec as csv2rec

from nipype.testing import (assert_equal, assert_not_equal, assert_raises,
with_setup, TraitError, parametric, skipif)

from nipype.testing import example_data

import nipype.interfaces.nitime as nitime

def test_read_csv():
"""Test that reading the data from csv file gives you back a reasonable
time-series object """

#XXX need to finish this:
data_rec = csv2rec('data/fmri_timeseries.csv')


CA = nitime.CoherenceAnalyzer()
CA.inputs.TR = 1.89 # bogus value just to pass traits test
CA.inputs.in_file = example_data('fmri_timeseries_nolabels.csv')
yield assert_raises,ValueError,CA._read_csv

CA.inputs.in_file = example_data('fmri_timeseries.csv')
rec_array = CA._read_csv()
yield assert_equal, rec_array['wm'][0],10125.9