Skip to content

Commit 23f1e8b

Browse files
committed
More robust handling of events input data
1 parent 1ebae7d commit 23f1e8b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

bidscoin/plugins/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __init__(self, sourcefile: Path, eventsdata: dict, options: dict):
164164
:param options: The plugin options
165165
"""
166166

167-
self.sourcefile = sourcefile
167+
self.sourcefile = Path(sourcefile)
168168
self._data = eventsdata
169169
self.options = options
170170

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

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

bidscoin/plugins/events2bids.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __init__(self, sourcefile: Path, _data: dict, options: dict):
179179
super().__init__(sourcefile, _data, options)
180180

181181
# Read the log-tables from the Presentation log file
182-
self._sourcetable = pd.read_csv(self.sourcefile, sep='\t', skiprows=options.get('skiprows',3), skip_blank_lines=True)
182+
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()
183183
"""The Presentation log-tables (https://www.neurobs.com/pres_docs/html/03_presentation/07_data_reporting/01_logfiles/index.html)"""
184184
self._sourcecols = self._sourcetable.columns
185185
"""Store the original column names"""
@@ -188,13 +188,16 @@ def __init__(self, sourcefile: Path, _data: dict, options: dict):
188188
def logtable(self) -> pd.DataFrame:
189189
"""Returns a Presentation log-table"""
190190

191-
df = self._sourcetable
192-
nrows = len(df)
191+
df = self._sourcetable
192+
if not (nrows := len(df)):
193+
return df
194+
195+
# Get the row indices to slice the event, stimulus, video or survey table
193196
stimulus_header = (df.iloc[:, 0] == 'Event Type').idxmax() or nrows
194197
video_header = (df.iloc[:, 0] == 'filename').idxmax() or nrows
195198
survey_header = (df.iloc[:, 0] == 'Time').idxmax() or nrows
196199

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

0 commit comments

Comments
 (0)