[pymvpa] Rapid ER design

Jeffrey Bloch jeffreybloch1 at gmail.com
Mon Mar 30 19:01:18 UTC 2015


Dear Michael,

I really appreciate your time getting back to me.  You comments were indeed
helpful, at least conceptually.  :)   I've spent the past 5 hours trying to
get this to work, but it seems there are still some problems.  Getting
pretty frustrated, so I thought I'd reply and hope you aren't too annoyed.
My apologies if I've repeated myself below, I just want to be sure I'm
understanding you.


>>> ds1 = fmri_dataset(samples=bold_fname, targets=attr.targets,
> chunks=attr.chunks)

The culprit is in the last line. You are trying to assign conditions to
a dataset where samples are fmri volumnes, but, as you said, you cannot
do that -- so don't ;-) Leave out the `targets=attr.targets`


*          Good point.  :)   Should I also remove chunks?  Regardless, even
when I load the dataset without any attributes
(ds1=fmri_dataset(bold_fname), the 179 volumes of the time_series still
causes me some problems (see below).  *

Even if your dataset has no 'time_coords' (for whatever reason), just
add them:  ds.sa['time_coords'] = np.arange(0,???, 2.0) or something like
that.







*             When I set up my time_coords with np.arange, it still wants
179 time points (even though I only want to model 110 events).
          >>> ds1 = fmri_dataset(bold_fname)            >>> ds1.sa
<http://ds1.sa>['time_coords'] = np.arange(20,339,2.9)
ValueError: Collectable 'time_coords' with length [110] does not match the
required length [179] of collection '<SampleAttributesCollection:
time_coords,time_indices>'.*



*               As you can see, I want my events to be 2.9s apart.  If I
put 2.0 instead of 2.9, my events will be 2s apart (which is the TR).Here's
an example of some time points when I complied with the 179 volumes and
allowed 2.9s.  Of course, my time_attr went up to 520 in this case.*



*>>> ds1.sa <http://ds1.sa>['time_coords'] =
np.arange(0,518,2.9){'duration': 1, 'onset': 1, 'time_attr':
2.8999999999999999}{'duration': 1, 'onset': 2, 'time_attr':
5.7999999999999998}{'duration': 1, 'onset': 3, 'time_attr':
8.6999999999999993}*

With 'time_coords' properly set, the 'onset' property of an event is
interpreted as onset in $(unit of your time_coords attribute). Things
will just work as you want them after this change.

          *How can I build an event list from only a time_coords file?  I'm
not sure where the other items in the dictionary come from.*


If they aren't correct -- just make them ;-)




*Even if I build my events by hand, the time_coords necessary for
eventrelated_dataset won't match up with the events or the dataset.  Is
there an easy way to make dictionaries from attribute lists?  Or, is
find_event the only way?  *
The key is to NOT have an attributes file. Just build the list of dicts
you show above with the correct values from your design.









*How do I get information from my dicts into the event list?  Are they
attributes of something?  I'm not sure what to put for "condition_attr" if
I don't have any attributes with the dataset from the outset.  The file
loaded below with ColumnData has 5 columns with each data on of the
parameters I'm interested in.  >>> events =
ColumnData('/home/bloch/data_for_Jeff/sub001/BOLD/Attributes_All.txt',
header=True)>>> print(events)ColumnData 220 rows, 5 columns [subcat chunk
oddball word cat]>>> print len(events)5*


*evds =
eventrelated_dataset(ds1,                                                 *



*> ...
 events,                                                        [list of
110 events] > ...                             model='hrf', > ...
                 time_attr='time_coords'                              >
...                             condition_attr=('X', 'Y'))*
*[e.g., 'subcat', 'chunk']*



Cheers,
Jeff

On Mon, Mar 30, 2015 at 8:05 AM, Michael Hanke <mih at debian.org> wrote:

> Hi,
>
> On Sun, Mar 29, 2015 at 03:53:53PM -0400, Jeffrey Bloch wrote:
> > MAKING THE DATASET
> > >>> path = os.path.join('/home/bloch/data_for_Jeff')
> > >>> bold_fname = os.path.join(path, 'sub001', 'BOLD', 'task001_run001',
> > 'bold.nii.gz')
> > >>> attr_fname = os.path.join(path, 'sub001', 'BOLD', 'task001_run001',
> > 'Attributes_by_volume.txt'
> > >>> attr = SampleAttributes(attr_fname)
> > >>> ds1 = fmri_dataset(samples=bold_fname, targets=attr.targets,
> > chunks=attr.chunks)
> >
> > [Attribute list above has 179 items.  If I try to give it only the 110
> > events with associated time stamps, it fails]
>
> Ah code, no need for long descriptions if you have code...
>
> The culprit is in the last line. You are trying to assign conditions to
> a dataset where samples are fmri volumnes, but, as you said, you cannot
> do that -- so don't ;-) Leave out the `targets=attr.targets`
>
> Given your code it is strange that your dataset doesnt not contain a
> time_coords attribute. Do you NIfTI files have the pixdim[4] value set
> properly?
>
> > >>> evds = eventrelated_dataset(ds1,
> > ...                             events,
> > ...                             model='hrf',
> > ...                             time_attr='time_coords'
> > ...                             condition_attr=('targets', 'chunks'))
> >
> > [I'm not able to give appropriate time coords here -- for 110 events.
> > Also, the information about the included events is not accurate due to
> > timing]
>
> Even if your dataset has no 'time_coords' (for whatever reason), just
> add them:
>
> ds.sa['time_coords'] = np.arange(0,???, 2.0) or something like that.
>
>
> > EXAMPLE OF EVENTS:
> > {'chunks': 0.0, 'duration': 5.8, 'onset': 20.0, 'targets': 'Monkey'}
> > {'chunks': 0.0, 'duration': 8.7, 'onset': 24.0, 'targets': 'Wrench'}
> > {'chunks': 0.0, 'duration': 2.9, 'onset': 30.0, 'targets': 'Monkey'}
> > {'chunks': 0.0, 'duration': 5.8, 'onset': 32.0, 'targets': 'Screwdriver'}
> > {'chunks': 0.0, 'duration': 8.7, 'onset': 36.0, 'targets': 'Elephant'}
> > {'chunks': 0.0, 'duration': 5.8, 'onset': 42.0, 'targets': 'Hammer'}
> >
> > [The onsets/durations above aren't correct.  I had to guess how long they
> > would be by extrapolating my 110 events into the 179 volumes.  E.G.,
> there
> > was only 1 monkey stimulus, but in my attribute file I put it twice two
> > "cover" the TRs during which it occurred.  Find_events interprets this
> as 2
> > events, and thus doubles the duration time I give it.  The onsets
> > themselves take on multiples of TR value, which in itself is incorrect]
>
> If they aren't correct -- just make them ;-)
>
> With 'time_coords' properly set, the 'onset' property of an event is
> interpreted as onset in $(unit of your time_coords attribute). Things
> will just work as you want them after this change.
>
> The key is to NOT have an attributes file. Just build the list of dicts
> you show above with the correct values from your design.
>
> HTH,
>
> Michael
>
> _______________________________________________
> Pkg-ExpPsy-PyMVPA mailing list
> Pkg-ExpPsy-PyMVPA at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-exppsy-pymvpa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pkg-exppsy-pymvpa/attachments/20150330/eefa71ab/attachment.html>


More information about the Pkg-ExpPsy-PyMVPA mailing list