-
Notifications
You must be signed in to change notification settings - Fork 141
Fix gen design #381
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
Merged
Merged
Fix gen design #381
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2b8116a
add a check in utils.gen_design so that when there is no event, an al…
d944873
add test for the changes
71cc6df
add the example stimulus timing file of AFNI style
32dc6c3
remove the printing test line
b24cc4d
removed the conditional clause in generate_stimfunction of fmrisim.py…
4daa70a
fix whitespace
1c5d20b
changed two `floor` to `round` in utils.gen_design, because in princi…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -427,10 +427,10 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL', | |
| n_C = len(stimtime_files) # number of conditions | ||
| n_S = np.size(scan_duration) # number of scans | ||
| if n_S > 1: | ||
| design = [np.empty([int(np.floor(duration / TR)), n_C]) | ||
| design = [np.empty([int(np.round(duration / TR)), n_C]) | ||
| for duration in scan_duration] | ||
| else: | ||
| design = [np.empty([int(np.floor(scan_duration / TR)), n_C])] | ||
| design = [np.empty([int(np.round(scan_duration / TR)), n_C])] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense |
||
| scan_onoff = np.insert(np.cumsum(scan_duration), 0, 0) | ||
| if style == 'FSL': | ||
| design_info = _read_stimtime_FSL(stimtime_files, n_C, n_S, scan_onoff) | ||
|
|
@@ -445,21 +445,24 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL', | |
| # generate design matrix | ||
| for i_s in range(n_S): | ||
| for i_c in range(n_C): | ||
| stimfunction = generate_stimfunction( | ||
| onsets=design_info[i_s][i_c]['onset'], | ||
| event_durations=design_info[i_s][i_c]['duration'], | ||
| total_time=scan_duration[i_s], | ||
| weights=design_info[i_s][i_c]['weight'], | ||
| temporal_resolution=1.0/temp_res) | ||
| hrf = _double_gamma_hrf(response_delay=response_delay, | ||
| undershoot_delay=undershoot_delay, | ||
| response_dispersion=response_disp, | ||
| undershoot_dispersion=undershoot_disp, | ||
| undershoot_scale=undershoot_scale, | ||
| temporal_resolution=1.0/temp_res) | ||
| design[i_s][:, i_c] = convolve_hrf( | ||
| stimfunction, TR, hrf_type=hrf, scale_function=0, | ||
| temporal_resolution=1.0 / temp_res).transpose() * temp_res | ||
| if len(design_info[i_s][i_c]['onset']) > 0: | ||
| stimfunction = generate_stimfunction( | ||
| onsets=design_info[i_s][i_c]['onset'], | ||
| event_durations=design_info[i_s][i_c]['duration'], | ||
| total_time=scan_duration[i_s], | ||
| weights=design_info[i_s][i_c]['weight'], | ||
| temporal_resolution=1.0/temp_res) | ||
| hrf = _double_gamma_hrf(response_delay=response_delay, | ||
| undershoot_delay=undershoot_delay, | ||
| response_dispersion=response_disp, | ||
| undershoot_dispersion=undershoot_disp, | ||
| undershoot_scale=undershoot_scale, | ||
| temporal_resolution=1.0/temp_res) | ||
| design[i_s][:, i_c] = convolve_hrf( | ||
| stimfunction, TR, hrf_type=hrf, scale_function=False, | ||
| temporal_resolution=1.0 / temp_res).transpose() * temp_res | ||
| else: | ||
| design[i_s][:, i_c] = 0.0 | ||
| # We multiply the resulting design matrix with | ||
| # the temporal resolution to normalize it. | ||
| # We do not use the internal normalization | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -10.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,7 +101,8 @@ def test_gen_design(): | |
| import os.path | ||
| files = {'FSL1': 'example_stimtime_1_FSL.txt', | ||
| 'FSL2': 'example_stimtime_2_FSL.txt', | ||
| 'AFNI1': 'example_stimtime_1_AFNI.txt'} | ||
| 'AFNI1': 'example_stimtime_1_AFNI.txt', | ||
| 'AFNI2': 'example_stimtime_2_AFNI.txt'} | ||
| for key in files.keys(): | ||
| files[key] = os.path.join(os.path.dirname(__file__), files[key]) | ||
| design1 = gen_design(stimtime_files=files['FSL1'], scan_duration=[48, 20], | ||
|
|
@@ -130,6 +131,11 @@ def test_gen_design(): | |
| scan_duration=[48, 20], TR=2, style='AFNI') | ||
| assert np.all(np.isclose(design1, design6)), ( | ||
| 'design matrices generated from AFNI style and FSL style do not match') | ||
| design7 = gen_design(stimtime_files=[files['AFNI2']], | ||
| scan_duration=[48], TR=2, style='AFNI') | ||
| assert np.all(design7 == 0.0), ( | ||
| 'A negative stimulus onset of AFNI style should result in an all-zero' | ||
| + ' design matrix') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good extra test to have |
||
|
|
||
|
|
||
| def test_center_mass_exp(): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this is unnecessary as you say