Skip to content

Instantly share code, notes, and snippets.

@kastman
Created February 4, 2015 03:45
Show Gist options
  • Save kastman/1e0f2c2c76946dad36dd to your computer and use it in GitHub Desktop.
Save kastman/1e0f2c2c76946dad36dd to your computer and use it in GitHub Desktop.
FIR or Standard Onset Creator Snippet
def _build_betacourse_regressors(self, timings, condition_code, durations_list=[]):
onsets=[];durations=[];conditions=[]
print timings.size, len(durations_list)
for i in range(timings.size):
onset = [timings[i]]
duration = [durations_list[i]] if len(durations_list) else [2]
name = "%s_%d" % (condition_code, i + 1)
onsets.append(onset)
durations.append(duration)
conditions.append(name)
return (onsets,durations,conditions)
def _build_standard_regressors(self, timings, condition_code, durations_list=[]):
'''Timings is a vector, condition code is a label.
For standard regressors, just make a list (to be extended)'''
onsets=[];durations=[];conditions=[]
onsets.append(timings)
if len(durations_list):
durations.append(durations_list)
else:
durations.append([2])
conditions.append(condition_code)
return (onsets,durations,conditions)
def _from_column_onsets(self, column_onsets_files):
info = dict(conditions=[],onsets=[],durations=[])
for onset_file in column_onsets_files:
timings = np.genfromtxt(onset_file)
condition_match = re.compile('run1(...)').search(onset_file)
if not condition_match:
raise RuntimeError("Couldn't introspect condition name from %s" % onset_file)
condition_code = condition_match.groups()[0]
cue_codes = ['a_q','o_q','x_q']; picture_codes = ['ofa','ofo','xfa','xfx']
stimtype = 'cue' if condition_code in cue_codes else 'picture'
if self.inputs.modeltype == 'betacourses' and stimtype == 'cue':
onsets, durations, conditions = self._build_betacourse_regressors(timings, condition_code)
else:
onsets, durations, conditions = self._bui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment