-
Notifications
You must be signed in to change notification settings - Fork 159
Omitted stimuli bug #1623
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
Omitted stimuli bug #1623
Conversation
Keys for the name of stimulus are different between eceephys and behavior ophys. This adds in a small function to get the key represented in each data type and raise an exception if one key is not found. This was added to allow ophys behavior experiments to write to nwb files.
I updated the function to be more generic and removed specific case verbaige. I also fixed the failing tests on Linux and Mac. The regex for the tests was returning an error on Linux and Mac.
This function had to be added as the omitted stimuli did not by design have an ending timestamp. These stimuli therfore could not be written to NWB files as the interval data object in PyNWB requires an ending time. This commit adds a function that adds a stop_time to a omitted row that is based off the known time that omitted stimuli are shown. This allows for omitted stimuli types to be written to NWB intervals.
I added documentation for the functions in stimulus_presentations.py that I have touched during investigation. These functions are get_stimulus_presentations and get_visual_stimuli_df. I added doc strings to better explain what is happening in the code.
5613eb8 to
a0604ce
Compare
Corrected import name problem, function name changed and I didn't change it.
Codecov Report
@@ Coverage Diff @@
## address-behavior-ophys-NWB-failures #1623 +/- ##
=======================================================================
+ Coverage 35.58% 35.61% +0.03%
=======================================================================
Files 344 345 +1
Lines 33568 33586 +18
=======================================================================
+ Hits 11946 11963 +17
- Misses 21622 21623 +1
Continue to review full report at Codecov.
|
|
|
||
| # if there is no stop time in the stimuli it is an 'omitted' stimuli | ||
| # row and therefore by design has no stop_time, we must add this in. | ||
| if 'stop_time' not in row.keys(): |
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 don't think this is the right place to set omitted stop times. The add_stimulus_presentations function is also used by the Ecephys Neuropixels project and it may not be correct (and probably wrong) to add a stop time if an Ecephys Neuropixels stimulus_presentation table row lacked a stop time.
A better place to set omitted stop times would be when loading the presentation table for ophys+behavior.
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 moved the function call to the behavior_ophys_nwb_api module where whole stimulus table is now passed!
Moved logic of checking for omitted stimulus stop_times to behavior_ophys_nwb_api.
Added debug statements to the code.
Fixed small bug used pandas iterrows iterable
Changed debug statements
added further debug statements
added anohter debug statement.
Changed to work on indices of original dataframe and removed debug statements.
small typo
| # All of the omitted stimuli have a duration of 250ms as defined | ||
| # by the Visual Behavior team. For questions about duration contact that | ||
| # team. | ||
| omitted_stimuli_duration = 0.250 |
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.
This should probably be a default argument to set_omitted_stop_time. e.g.
def set_omitted_stop_time(stimulus_table_row: dict, omitted_stimuli_duration: float = 0.250):
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.
Set it to default and removed module global.
I changed the input for the omitted stimuli stop time setting function to be the whole DataFrame. I updated the tests and confirmed that the function passes the stimuli table writing.
Removed module global variable defining omitted stimuli time in favour of default function arguement.
|
@njmei just an FYI the commits look ugly but it's just for you to see the history, I'm going to squash merge when you approve so they won't be carried into the feature branch. |
| def test_set_omitted_stop_time(stimulus_table, expected_stop_time): | ||
| stimulus_table = pd.DataFrame.from_dict(data=stimulus_table) | ||
| nwb_utils.set_omitted_stop_time(stimulus_table) | ||
| assert stimulus_table.iloc[0]['stop_time'] == expected_stop_time |
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 would prefer this test check that the entire stimulus table is 'correct' rather than checking that the row 0 stop_time is correct.
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.
Updated to test if expected table is equal to created table.
Updated testting to test entire pd dataframe and not specific elements.
njmei
left a comment
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.
LGTM
f489520
into
address-behavior-ophys-NWB-failures
* Added function to set the stop_time for omitted stimuli for writing NWB This function had to be added as the omitted stimuli did not by design have an ending timestamp. These stimuli therfore could not be written to NWB files as the interval data object in PyNWB requires an ending time. This commit adds a function that adds a stop_time to a omitted row that is based off the known time that omitted stimuli are shown. This allows for omitted stimuli types to be written to NWB intervals. * Added doc strings to stimulus_presentations.py I added documentation for the functions in stimulus_presentations.py that I have touched during investigation. These functions are get_stimulus_presentations and get_visual_stimuli_df. I added doc strings to better explain what is happening in the code.
* Added function to set the stop_time for omitted stimuli for writing NWB This function had to be added as the omitted stimuli did not by design have an ending timestamp. These stimuli therfore could not be written to NWB files as the interval data object in PyNWB requires an ending time. This commit adds a function that adds a stop_time to a omitted row that is based off the known time that omitted stimuli are shown. This allows for omitted stimuli types to be written to NWB intervals. * Added doc strings to stimulus_presentations.py I added documentation for the functions in stimulus_presentations.py that I have touched during investigation. These functions are get_stimulus_presentations and get_visual_stimuli_df. I added doc strings to better explain what is happening in the code.
* Added function to set the stop_time for omitted stimuli for writing NWB This function had to be added as the omitted stimuli did not by design have an ending timestamp. These stimuli therfore could not be written to NWB files as the interval data object in PyNWB requires an ending time. This commit adds a function that adds a stop_time to a omitted row that is based off the known time that omitted stimuli are shown. This allows for omitted stimuli types to be written to NWB intervals. * Added doc strings to stimulus_presentations.py I added documentation for the functions in stimulus_presentations.py that I have touched during investigation. These functions are get_stimulus_presentations and get_visual_stimuli_df. I added doc strings to better explain what is happening in the code.
Overview:
Currently Omitted Stimuli exist in Behavior Ophys experiments, these stimuli represent when a experiment subject is being shown a gray screen. These stimuli by design have no ending frame or ending timestamp, they always last for 750ms however. Currently these cannot be written as an NWB interval because the datatype requires an ending timestamp, leaving this information out is not a good idea.
Solution:
The proposed solution that the Visual Behavior team agrees with is to take the starting timestamp, which is present in the omitted stimuli data, and add the standard duration time to get the stop time. This fixes the error where NWB intervals require a stop time, the stop_time is now created and saved in the stimulus table row.
Validation:
The solution has been validated by running through four Behavior Ophys experiments and successfully running the function
add_stimulus_presentations, with the inclusion of #1619. The test cases cover the cases where stop_time is not found in a row, any additional testing coverage suggestions would be much appreciated.Notes:
stimulus_processing.pyas work was done in this file understanding the omitted stimuli data.