-
Notifications
You must be signed in to change notification settings - Fork 45
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
Make heuristics a simple set of "if .. elif .. else" statements and use a dictionary instead of variables. #209
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cd55bf0
Start from 1 in run numeration
38a7142
Delete heur_ex and heur
c4e62b8
Restructure heuristics to use info dictionary
2f9146a
Adapt use_heuristic to accept new heuristics and use info dictionary
fbc30fd
Update heuristics for tutorial and tests
28570e8
Update documentation
7abb36e
Correct folder path
bd46897
Update tests to match new heuristic (run-00→01)
447c176
Change dictionary name from 'info' to 'bids_keys'
a7cf2c6
Add pytest parametrisation not to loose coverage
e21c138
Change file link for deleted file
c9a54e1
Update phys2bids/phys2bids.py
0ba2ec5
Update phys2bids/phys2bids.py
8158e41
Update docs/heuristic.rst
c0d9954
Update phys2bids/phys2bids.py
4eecc21
Remove logger from heuristic, initialise dictionary internally rather…
6c94afe
Add logger that was in the heuristics before, update dictionary inste…
ebe5614
Merge remote-tracking branch 'origin/enh/heuristic_refactor' into enh…
34fa496
Tiny parenthesis matter
2d64201
Update documentations
3387c34
It's always the whitespaces. Always.
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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,88 @@ | ||
import fnmatch | ||
|
||
|
||
def heur(physinfo): | ||
""" | ||
Set of if .. elif statements to fill BIDS names. | ||
|
||
It requires the user (you!) to adjust it accordingly! | ||
It needs an ``if`` or ``elif`` statement for each file that | ||
needs to be processed. | ||
The statement will test if the ``physinfo``: | ||
- is similar to a string (first case), or | ||
- exactly matches a string (second case). | ||
|
||
Parameters | ||
---------- | ||
physinfo: str | ||
Name of an input file that should be bidsified (See Notes) | ||
|
||
Returns | ||
------- | ||
info: dictionary of str | ||
Dictionary containing BIDS keys | ||
|
||
Notes | ||
----- | ||
The `if ..` structure should always be similar to | ||
``` | ||
if physinfo == 'somepattern': | ||
info['var'] = 'somethingelse' | ||
``` | ||
or, in case it's a partial match | ||
``` | ||
if fnmatch.fnmatchcase(physinfo, '*somepattern?'): | ||
info['var'] = 'somethingelse' | ||
``` | ||
Where: | ||
- `physinfo` and `info` are dedicated keywords, | ||
- 'somepattern' is the name of the file, | ||
- 'var' is a bids key in the list below | ||
- 'somethingelse' is the value of the key | ||
""" | ||
info = {} | ||
# ################################# # | ||
# ## Modify here! ## # | ||
# ## ## # | ||
# ## Possible variables are: ## # | ||
# ## -info['task'] (required) ## # | ||
# ## -info['run'] ## # | ||
# ## -info['rec'] ## # | ||
# ## -info['acq'] ## # | ||
# ## -info['dir'] ## # | ||
# ## ## # | ||
# ## Remember that they are ## # | ||
# ## dictionary keys ## # | ||
# ## See example below ## # | ||
# ################################# # | ||
|
||
if physinfo == 'origfilename1': | ||
info['task'] = 'newname1' | ||
elif physinfo == 'origfilename2': | ||
info['task'] = 'newname2' | ||
info['run'] = 'runnum' | ||
elif physinfo == 'BH4': | ||
info['task'] = 'breathhold' | ||
elif fnmatch.fnmatchcase(physinfo, 'MOTOR?'): | ||
info['task'] = 'motor' | ||
elif fnmatch.fnmatchcase(physinfo, 'LOCALIZER?'): | ||
info['task'] = 'pinel' | ||
elif fnmatch.fnmatchcase(physinfo, 'SIMON?'): | ||
info['task'] = 'simon' | ||
elif physinfo == 'RS1': | ||
info['task'] = 'rest' | ||
info['run'] = '01' | ||
elif physinfo == 'RS2': | ||
info['task'] = 'rest' | ||
info['run'] = '02' | ||
elif physinfo == 'RS3': | ||
info['task'] = 'rest' | ||
info['run'] = '03' | ||
elif physinfo == 'RS4': | ||
info['task'] = 'rest' | ||
info['run'] = '04' | ||
|
||
# ############################## # | ||
# ## Don't modify below this! ## # | ||
# ############################## # | ||
return info |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
I assume this one is an example?
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.
Yep, why not.
it's the one used for a dataset that will be shared at a certain point.