Skip to content

Commit

Permalink
More robust handling of events input data
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Feb 12, 2025
1 parent 1ebae7d commit 23f1e8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion bidscoin/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, sourcefile: Path, eventsdata: dict, options: dict):
:param options: The plugin options
"""

self.sourcefile = sourcefile
self.sourcefile = Path(sourcefile)
self._data = eventsdata
self.options = options

Expand Down Expand Up @@ -192,6 +192,8 @@ def eventstable(self) -> pd.DataFrame:
"""Returns the target events.tsv data"""

# Check the parser's data structure
if not len(self.logtable):
return pd.DataFrame(columns=['onset', 'duration'])
if not self.isvalid:
pass

Expand Down
11 changes: 7 additions & 4 deletions bidscoin/plugins/events2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def __init__(self, sourcefile: Path, _data: dict, options: dict):
super().__init__(sourcefile, _data, options)

# Read the log-tables from the Presentation log file
self._sourcetable = pd.read_csv(self.sourcefile, sep='\t', skiprows=options.get('skiprows',3), skip_blank_lines=True)
self._sourcetable = pd.read_csv(self.sourcefile, sep='\t', skiprows=options.get('skiprows',3), skip_blank_lines=True) if self.sourcefile.is_file() else pd.DataFrame()
"""The Presentation log-tables (https://www.neurobs.com/pres_docs/html/03_presentation/07_data_reporting/01_logfiles/index.html)"""
self._sourcecols = self._sourcetable.columns
"""Store the original column names"""
Expand All @@ -188,13 +188,16 @@ def __init__(self, sourcefile: Path, _data: dict, options: dict):
def logtable(self) -> pd.DataFrame:
"""Returns a Presentation log-table"""

df = self._sourcetable
nrows = len(df)
df = self._sourcetable
if not (nrows := len(df)):
return df

# Get the row indices to slice the event, stimulus, video or survey table
stimulus_header = (df.iloc[:, 0] == 'Event Type').idxmax() or nrows
video_header = (df.iloc[:, 0] == 'filename').idxmax() or nrows
survey_header = (df.iloc[:, 0] == 'Time').idxmax() or nrows

# Get the row indices to slice the event, stimulus, video or survey table
# Get the first and last row index of the table of interest
df.columns = self._sourcecols
if self.options['table'].lower() == 'event':
begin = 0
Expand Down

0 comments on commit 23f1e8b

Please sign in to comment.