Skip to content
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

Clean paradigm #316

Merged
merged 3 commits into from Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions nipy/modalities/fmri/experimental_paradigm.py
Expand Up @@ -22,6 +22,7 @@
import numpy as np

from ...utils.compat3 import open4csv
import warnings

##########################################################
# Paradigm handling
Expand All @@ -48,14 +49,7 @@ def __init__(self, con_id=None, onset=None, amplitude=None):
self.amplitude = amplitude
if con_id is not None:
self.n_events = len(con_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this now? Need deprecation warning or informative error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still worried by backwards compatibility - I think previous behavior was:

import nipy.modalities.fmri.experimental_paradigm as ep
In [2]: ep.Paradigm([1, 2, 3]).con_id
Out[2]: 
array(['c1', 'c2', 'c3'], 
      dtype='|S2')

where behavior on this branch is:

In [3]: ep.Paradigm([1, 2, 3]).con_id
Out[3]: 
array(['1', '2', '3'], 
      dtype='|S1')

I can see that it's a good idea not to convert strings to ints then back to strings, but maybe preserve c prefix if condition names are integers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in general it is a bad idea to decide that the conditions cannot be named '1', '2' etc. and to change this for the user. Now, if you think that backward compatibility is more important, I can revert that one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK, I can see arguments both ways...

try:
# this is only for backward compatibility:
#if con_id were integers, they become a string
self.con_id = np.array(['c' + str(int(float(c)))
for c in con_id])
except:
self.con_id = np.ravel(np.array(con_id)).astype('str')

self.con_id = np.ravel(np.array(con_id)).astype('str')
if onset is not None:
if len(onset) != self.n_events:
raise ValueError(
Expand Down
8 changes: 8 additions & 0 deletions nipy/modalities/fmri/tests/test_paradigm.py
Expand Up @@ -11,6 +11,7 @@

from ..experimental_paradigm import (EventRelatedParadigm, BlockParadigm,
load_paradigm_from_csv_file)
from nose.tools import assert_true


def basic_paradigm():
Expand Down Expand Up @@ -77,6 +78,13 @@ def test_read_paradigm():
assert (read_paradigm.onset == paradigm.onset).all()


def test_paradigm_with_int_condition_ids():
paradigm1 = basic_paradigm()
conditions = [0, 0, 0, 1, 1, 1, 2, 2, 2]
paradigm2 = EventRelatedParadigm(conditions, paradigm1.onset)
assert_true((paradigm2.con_id == np.array(conditions).astype('str')).all())


if __name__ == "__main__":
import nose
nose.run(argv=['', __file__])