Skip to content

Commit

Permalink
FIX: error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Oct 20, 2017
1 parent 85876a5 commit cbe115b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NiBetaSeries/workflows/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def check_imgs_length(nifti_lst):
import nibabel as nib
# remove nifti from list if it's less than 3 volumes in the 4th dimension
# can't do correlations with less than 3 volumes
return [nifti for nifti in nifti_lst if nib.load(nifti).shape[3] > 2]
return [nifti for nifti in nifti_lst if len(nib.load(nifti).shape) == 4 and nib.load(nifti).shape[3] > 2]

# mixes the rois and betaseries_files so I can run all combinations
def cart(rois, bsfiles):
Expand Down
37 changes: 19 additions & 18 deletions NiBetaSeries/workflows/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def trial_events_iterator(events):
verbose=1, n_jobs=n_jobs)

events_df = pd.read_csv(events, sep='\t', index_col=None)
num_events = len(events_df)

# initialize trial type tracker
t_type_prev = 0
Expand All @@ -59,19 +60,6 @@ def trial_events_iterator(events):
betaseries_files = []
beta_path = os.getcwd()
for t_ev_idx, (t_ev, t_type, t_idx) in enumerate(trial_events_iterator(events_df)):
# if we have collected all betas for a trial type...
if t_type_prev != t_type and t_type_prev != 0:
# concatenate and save the 4d betaseries
betaseries = nib.funcs.concat_images(beta_list)
betaseries_file = os.path.join(
beta_path, 'trialtype-{}_betaseries.nii.gz'.format(t_type_prev))
print('betaseries: {}'.format(betaseries_file))
nib.save(betaseries, betaseries_file)
# add the 4d betaseries to the output list
betaseries_files.append(betaseries_file)
beta_list = []

t_type_prev = t_type
if not os.path.exists(beta_path):
os.makedirs(beta_path)

Expand All @@ -88,12 +76,25 @@ def trial_events_iterator(events):
else:
model.refit_run_design(bold, t_ev, None) # had to remove conf

beta = model.compute_contrast(t_type, output_type='effect_size')
beta_list.append(beta)
# nib.save(beta, beta_file)
beta = model.compute_contrast(t_type, output_type='effect_size')
if t_type_prev != t_type and t_type_prev != 0 or t_ev_idx == (num_events-1):
if t_ev_idx == (num_events-1):
beta_list.append(beta)
# concatenate and save the 4d betaseries
betaseries = nib.funcs.concat_images(beta_list)
betaseries_file = os.path.join(
beta_path, 'trialtype-{}_betaseries.nii.gz'.format(t_type_prev))
print('betaseries: {}'.format(betaseries_file))
nib.save(betaseries, betaseries_file)
# add the 4d betaseries to the output list
betaseries_files.append(betaseries_file)
beta_list = []

t_type_prev = t_type
beta_list.append(beta)
# nib.save(beta, beta_file)

print('Done in %d seconds' %
(time.time() - start_time))
print('Done in %d seconds' % (time.time() - start_time))

# return the 4d betaseries files
print("all betaseries_files: {}".format(betaseries_files))
Expand Down

0 comments on commit cbe115b

Please sign in to comment.