|
13 | 13 | LOGGER = logging.getLogger(__name__) |
14 | 14 |
|
15 | 15 | # The default/fallback options that are set when installing/using the plugin |
16 | | -OPTIONS = Plugin({'meta': ['.json', '.tsv']}) # The file extensions of the equally named metadata sourcefiles that are copied over as BIDS sidecar files |
| 16 | +OPTIONS = Plugin({'table': 'event', 'meta': ['.json', '.tsv']}) # The file extensions of the equally named metadata sourcefiles that are copied over as BIDS sidecar files |
17 | 17 |
|
18 | 18 |
|
19 | 19 | def test(options: Plugin=OPTIONS) -> int: |
@@ -228,28 +228,47 @@ def bidscoiner_plugin(session: Path, bidsmap: BidsMap, bidsses: Path) -> None: |
228 | 228 | class PresentationEvents(EventsParser): |
229 | 229 | """Parser for Presentation (Neurobs) logfiles""" |
230 | 230 |
|
231 | | - def __init__(self, sourcefile: Path, _data): |
| 231 | + def __init__(self, sourcefile: Path, _data: dict, options: dict): |
232 | 232 | """ |
233 | 233 | Reads the event table from the Presentation logfile |
234 | 234 |
|
235 | 235 | :param sourcefile: The full filepath of the logfile |
236 | 236 | :param data: The run['events'] data (from a bidsmap) |
| 237 | + :param options: The plugin options |
237 | 238 | """ |
238 | 239 |
|
239 | | - super().__init__(sourcefile, _data) |
| 240 | + super().__init__(sourcefile, _data, options) |
240 | 241 |
|
241 | | - # Read the event table from the Presentation logfile |
242 | | - self.sourcetable = df = pd.read_csv(self.sourcefile, sep='\t', skiprows=3, skip_blank_lines=True) |
243 | | - """The Presentation event table (https://www.neurobs.com/pres_docs/html/03_presentation/07_data_reporting/01_logfiles/index.html)""" |
244 | | - |
245 | | - # Drop the stimulus, video and survey tables |
246 | | - endoftable = df['Subject'].isin(['Event Type', 'filename', 'Time']).idxmax() |
247 | | - if endoftable: |
248 | | - LOGGER.bcdebug(f"Dropping sourcetable data at row: {endoftable}") |
249 | | - self.sourcetable = df.iloc[:endoftable] |
| 242 | + # Read the log-tables from the Presentation logfile |
| 243 | + self._sourcetable = pd.read_csv(self.sourcefile, sep='\t', skiprows=3, skip_blank_lines=True) |
| 244 | + """The Presentation log-tables (https://www.neurobs.com/pres_docs/html/03_presentation/07_data_reporting/01_logfiles/index.html)""" |
250 | 245 |
|
251 | 246 | @property |
252 | 247 | def logtable(self) -> pd.DataFrame: |
253 | | - """Returns the source logging data""" |
| 248 | + """Returns a Presentation log-table""" |
| 249 | + |
| 250 | + nrows = len(self._sourcetable) |
| 251 | + stimulus_start = (self._sourcetable.iloc[:, 0] == 'Event Type').idxmax() or nrows |
| 252 | + video_start = (self._sourcetable.iloc[:, 0] == 'filename').idxmax() or nrows |
| 253 | + survey_start = (self._sourcetable.iloc[:, 0] == 'Time').idxmax() or nrows |
| 254 | + |
| 255 | + # Drop the stimulus, video and survey tables |
| 256 | + if self.options['table'] == 'event': |
| 257 | + begin = 0 |
| 258 | + end = min(stimulus_start, video_start, survey_start) |
| 259 | + elif self.options['table'] == 'stimulus': |
| 260 | + self._sourcetable.columns = self._sourcetable.iloc[stimulus_start] |
| 261 | + begin = stimulus_start + 1 |
| 262 | + end = min(video_start, survey_start) |
| 263 | + elif self.options['table'] == 'video': |
| 264 | + self._sourcetable.columns = self._sourcetable.iloc[video_start] |
| 265 | + begin = video_start + 1 |
| 266 | + end = survey_start |
| 267 | + else: |
| 268 | + begin = 0 |
| 269 | + end = nrows |
| 270 | + LOGGER.error(f"NOT IMPLEMENTED TABLE: {self.options['table']}") |
| 271 | + |
| 272 | + LOGGER.bcdebug(f"Slicing '{self.options['table']}' sourcetable[{begin}:{end}]") |
254 | 273 |
|
255 | | - return self.sourcetable |
| 274 | + return self._sourcetable.iloc[begin:end] |
0 commit comments