bidsaid.events.PresentationEventExtractor
- class bidsaid.events.PresentationEventExtractor(log_or_df, trial_types, scanner_event_type, scanner_trigger_code, trial_column_name='Code', convert_to_seconds=None, initial_column_headers=('Trial', 'Event Type'), n_discarded_volumes=0, tr=None)[source]
Extract onsets, durations, trial types, reaction times, and responses from Presentation logs using an event design.
Parameters
- log_or_df
str,Path,pandas.DataFrame The Presentation log as a file path or the Presentation DataFrame returned by
bidsaid.parsers.load_presentation_log.Important
If a text file is used, data are assumed to have at least one element that is an digit or float during parsing.
- trial_types
Iterable[str] The names of the trial types (i.e “congruentleft”, “seen”). Regex can be used.
Note
If your block design does not include a rest block or crosshair code, include the code immediately after the final block.
- scanner_event_type
str The event type in the “Event Type” column the scanner trigger is listed under (e.g., “Pulse”, “Response”, “Picture”, etc).
- scanner_trigger_code
str Code listed under “Code” for the scanner start (e.g., “54”, “99”, “trigger). Used with
scanner_event_typeto compute the onset times of the trials relative to the scanner start time then clip the dataframe to ensure that no trials before the start of the scanner is initiated.Note
Uses the first index of the rows in the dataframe with values provided for
scanner_event_typeandscanner_trigger_code.- trial_column_name
str, default=”Code” Name of the column containing the trial types.
- convert_to_seconds
list[str]orNone, default=None Convert the time resolution of the specified columns from 0.1 ms to seconds. See Presentation Timing.
Important
Recommend time resolution of the “Time” column and “Duration” column to be converted.
- initial_column_headers
Iterable[str], default=(“Trial”, “Event Type”) The initial column headers for data. Only used when
log_or_dfis a file path.- n_discarded_volumes
int, default=0 Number of non-steady state scans discarded by the scanner at the start of the sequence.
Important
Only used when
trigger_column_nameis specified.Only set this parameter if scanner trigger is sent before these volumes are acquired so that the start time of the first retained volume is shifted forward by (
n_discarded_volumes * tr). If the scanner sends trigger after discarding the volumes, do not set this parameter. Explanation from Neurostars.
- tr
float,int, orNone, default=None The repetition time provided in seconds if data was converted to seconds or in ten thousand seconds if not converted.
Attributes
- df
pandas.DataFrame DataFrame containing the log data. If the scanner trigger is identified using
scanner_event_typeandscanner_trigger_code, then rows preceeding the first scanner are dropped and the index is reset.- trial_types
list[str] The names of the trial types.
- scanner_event_type
str Event type of scanner trigger.
- scanner_trigger_code
str Code for the scanner trigger.
- trial_column_name
str Name of column containing the trial types.
- n_discarded_scans
int Number of non-steady state scans discarded by scanner.
- tr
float,int, orNone The repetition time.
- scanner_start_time
floatorNone Time when scanner sends the pulse. If
n_discarded_volumesis not 0 andtris specified, then this time will be shifted forward (``scanner_start_time = scanner_start_time + n_discarded_volumes * tr ``) to reflect the time when the first steady state volume was retained. Otherwise, the time extracted from the log data is assumed to be the time when the first steady state volume was retained.- event_trial_indices
list[int] The indices of when each trial event of interest (specified by
trial_types) begins.
Example
>>> import pandas as pd >>> from bidsaid.events import PresentationEventExtractor >>> extractor = PresentationEventExtractor( ... log_file, ... trial_types=("congruentleft", "congruentright", "incongruentleft", "incongruentright", "nogo"), ... scanner_event_type="Pulse", ... scanner_trigger_code="99", ... convert_to_seconds=["Time"], ... ) >>> events = {} >>> events["onset"] = extractor.extract_onsets() >>> events["duration"] = extractor.extract_durations() >>> events["trial_type"] = extractor.extract_trial_types() >>> events["reaction_time"] = extractor.extract_reaction_times() >>> events["response"] = extractor.extract_responses() >>> events["accuracy"] = extractor.extract_responses(response_map={"hit": 1, "miss": 0}) >>> df = pd.DataFrame(events)
Methods
extract_accuracies(response_map)Extract the accuracy (correct or incorrect) for each event.
Extract the duration for each event.
extract_onsets([scanner_start_time])Extract the onset times for each event.
Extract the reaction time for each event.
Extract the response for each event.
Extract the trial type for each event.
- log_or_df