-
Notifications
You must be signed in to change notification settings - Fork 4
Statescript #115
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
base: main
Are you sure you want to change the base?
Statescript #115
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Pull Request Overview
This PR introduces statescript parsing tools by updating the documentation and function signatures in the behavioral events processing code.
- Updated the docstring in _get_channel_name_map to reflect a nested dictionary structure.
- Provides clarification on the expected mapping between hardware events and their human-readable names.
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.
Pull Request Overview
This PR adds statescript parsing tools with an updated conversion function to support detailed metadata definitions.
- Updated the return type of _get_channel_name_map to a nested dictionary.
- Modified the docstring to include the new key structure with "name" and "comments".
Comments suppressed due to low confidence (1)
src/trodes_to_nwb/convert_dios.py:12
- The function now returns a nested dictionary instead of a flat mapping. Update the docstring summary to clearly reflect that each hardware event maps to a dictionary with 'name' and 'comments' keys.
def _get_channel_name_map(metadata: dict) -> dict[str, dict[str, str]]:
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #115 +/- ##
==========================================
- Coverage 89.32% 87.05% -2.28%
==========================================
Files 12 13 +1
Lines 1471 1769 +298
==========================================
+ Hits 1314 1540 +226
- Misses 157 229 +72 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR refactors the log parsing module for StateScript by enhancing the metadata mapping for behavioral events.
- Updated the return type of _get_channel_name_map to a nested dictionary structure.
- Clarified the documentation to accurately reflect the updated mapping format.
samuelbray32
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.
Can this PR include something like add_coverted_statescript(file, nwb) that uses these to add a DynamicTable to the nwb file?
| ) | ||
|
|
||
|
|
||
| def _parse_int(s: str) -> Optional[int]: |
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.
Would it make more sense to name this function _is_int and return a True/False value? converting to int in the function where it's called is straightforward and the current name doesn't communicate as clearly how it's being used below
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.
The function is still parsing a string to an int though right?
| df["timestamp"].astype(float) / self.MILLISECONDS_PER_SECOND | ||
| ) | ||
| # Ensure original timestamp remains integer | ||
| df["timestamp"] = df["timestamp"].astype(int) |
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.
A more useful conversion might be getting to unix time since nwb conversion makes a link between trodes timestamps and that already
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.
Yeah, the timestamp_sync column is the converted timestamps. You need to run calculate_time_offset to align it to a specific DIO.
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 might be confused. Are these timestamps not the same as the trodes timestamps we're using in convert position?
Co-authored-by: Samuel Bray <[email protected]>
Co-authored-by: Samuel Bray <[email protected]>
I guess the question is whether we want to make these specific behavioral events or if we want to just dump the whole thing into a table. |
StateScript log parsing and processing module.
This module provides tools for parsing, interpreting, and processing
.stateScriptLogfiles generated by Trodes (https://docs.spikegadgets.com/en/latest/basic/StateScript.html). It handles the conversion of Trodes timestamps, alignment with external time sources, interpretation of Digital Input/Output (DIO) or analog states, and processing of various common log line formats.A main task for the user is to convert their trodes time to a more precise time using a DIO reference. This is accomplished using the
calculate_time_offsetmethod to align a statescript event to a DIO. Theget_events_dataframemethod then outputs a dataframe withtimestamp_syncand the events parsed into different types.No NWB conversion yet but there might be a simple way to do this.
Not sure where this would go? It is a time series of events so perhaps using https://github.com/rly/ndx-events? @rly ?
One challenge is technically the user can print anything but there tend to be common formats explained below:
Notes
Source Files:
- Log files parsed by this module typically have the
.stateScriptLogextension.- These files are generated by Trodes during data acquisition sessions.
Timestamp Information:
- The primary timestamp (
<timestamp_int>) found in these logs is a 64-bit integer.- It represents the number of milliseconds elapsed since the start of the
Trodes recording session.
- This is often referred to as the 'Trodes timestamp'.
Log Line Formats:
.stateScriptLogfiles usually contain lines adhering to several common formats.The module aims to parse lines matching these structures:
Component Definitions:
-
<timestamp_int>: 64-bit integer; milliseconds since session start (Trodes timestamp).-
<int>: Integer value; often used as a bitwise mask for DIO pin states.-
<str>: String value; can represent an event name, variable name, message component, etc.-
<str...>: Denotes one or more space-separated strings.Example log file snippet:
Sample dataframe output
To-Do