-
Notifications
You must be signed in to change notification settings - Fork 575
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
[ENH] Handle GLM designs with null or nan durations / onsets #3943
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3c6cd72
manual "rebase"
Remi-Gau 2967afb
make functions public
Remi-Gau 4a23b6b
throw errors for nan values
Remi-Gau a6b848a
refactor
Remi-Gau 1190043
plot null duration events
Remi-Gau 3b773c4
fix link in doc
Remi-Gau f8500a1
update example
Remi-Gau 75c031c
ignore results
Remi-Gau 26a793d
revert useless change
Remi-Gau 2422c55
rm useless code
Remi-Gau fa72f75
update changelog
Remi-Gau 42c71a8
rm :func: from changelog
Remi-Gau File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,10 @@ | |
|
||
print(__doc__) | ||
|
||
######################################################################### | ||
# %% | ||
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. |
||
# Define the onset times in seconds. These are typically extracted from | ||
# the stimulation software used, but we will use hardcoded values in this | ||
# example. | ||
import numpy as np | ||
|
||
# fmt: off | ||
onsets = [ | ||
|
@@ -37,9 +36,8 @@ | |
264.0, 266.7, 269.7, 275.4, 278.4, 284.4, 288.0, 291.0, 293.4, 296.7, | ||
] | ||
# fmt: on | ||
onsets = np.array(onsets) | ||
|
||
######################################################################### | ||
# %% | ||
# Associated trial types: these are numbered between 0 and 9, hence | ||
# corresponding to 10 different conditions. | ||
|
||
|
@@ -51,9 +49,8 @@ | |
7, 1, 0, 0, 4, 1, 9, 8, 4, 9, 9 | ||
] | ||
# fmt: on | ||
trial_type_idx = np.array(trial_type_idx) | ||
|
||
######################################################################### | ||
# %% | ||
# We may want to map these indices to explicit condition names. | ||
# For that, we define a list of 10 strings. | ||
condition_ids = [ | ||
|
@@ -71,13 +68,21 @@ | |
|
||
trial_types = [condition_ids[i] for i in trial_type_idx] | ||
|
||
######################################################################### | ||
# %% | ||
# We must also define a duration (required by :term:`BIDS` conventions). | ||
# In this case, all trials lasted one second. | ||
|
||
durations = np.ones_like(onsets) | ||
|
||
######################################################################### | ||
# In this case, all trials lasted one second, | ||
# except for button response | ||
# that are modeled as events with instantaneous duration (0 second). | ||
|
||
null_duration_trials = [2, 3, 4, 5] | ||
durations = [] | ||
for i in trial_type_idx: | ||
if i in null_duration_trials: | ||
durations.append(0) | ||
else: | ||
durations.append(1) | ||
bthirion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# %% | ||
# Form a pandas DataFrame from this information. | ||
import pandas as pd | ||
|
||
|
@@ -89,11 +94,11 @@ | |
} | ||
) | ||
|
||
######################################################################### | ||
# %% | ||
# Take a look at the new DataFrame | ||
events | ||
|
||
######################################################################### | ||
# %% | ||
# Export them to a tsv file. | ||
from pathlib import Path | ||
|
||
|
@@ -104,7 +109,7 @@ | |
events.to_csv(tsvfile, sep="\t", index=False) | ||
print(f"The event information has been saved to {tsvfile}") | ||
|
||
######################################################################### | ||
# %% | ||
# Optionally, the events can be visualized using the | ||
# :func:`~nilearn.plotting.plot_event` function. | ||
import matplotlib.pyplot as plt | ||
|
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
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.
:func:
~glm.first_level.experimental_paradigm.check_events
and
:func:
~glm.first_level.check_events
give me the same doc build error.
Am I missing something obvious?
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.
check_events
is not exposed in the docs so there is nothing to link to. I'm not sure if it is supposed to be part of the public API or not. If so, it would need to be added todoc/modules/glm.rst
first before you can use that roleThere 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 wouldn't put it in the public API.
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.
Then we just refer to it with the backticks without the func role
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.
Wait... Just to make sure I understand.
What is the rationale of saying it is not in the public API but check_design_matrix is when both of them are found this init file?
https://github.com/nilearn/nilearn/blob/main/nilearn/glm/first_level/__init__.py#L24
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.
As the codebase stands I wouldn't take what is in the init file for what is in the public API and supposed to be exposed to users since we know there is heterogeneity in the way "private" functions are written and also, we can have public API of a private module so that would be ok to include in the init. I agree though that given the refactoring we are doing regarding this, check_events should either be in a file named with a leading underscore or, since it is only used in design_matrix.py, it can be moved there and renamed with a leading underscore. I don't see that, following this convention, it would then be a problem if it is imported in a module's init file since it'll be clear from the import statement, which would then have a leading underscore, that it is private. This is what I understand from PEP8, though we may also want to make a decision on that aspect if it's confusing.
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.
OK thanks for the clarification.
OK so for the moment it really feels the public API is whatever the doc days is in the public API. Hopefully things should get clearer once we clean things up.
For now I will use the backticks without the func role.