Skip to content

Commit 9ece6ae

Browse files
committed
Change the log-/events-tables from property to method to express their cost
1 parent ed4c563 commit 9ece6ae

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

bidscoin/bidseditor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,12 +1506,12 @@ def run2data(self) -> tuple:
15061506
events_data['columns'].append([{'value': value, 'editable': True}, {'value': key, 'editable': key not in ('onset','duration')}])
15071507

15081508
# Set up the data for the events table
1509-
df = self.events.logtable
1509+
df = self.events.logtable()
15101510
events_data['log_table'] = [[{'value': name, 'editable': False} for name in df]] if len(df) else []
15111511
for i in range(len(df)):
15121512
events_data['log_table'].append([{'value': value, 'editable': False} for value in df.iloc[i]])
15131513

1514-
df = self.events.eventstable
1514+
df = self.events.eventstable()
15151515
events_data['table'] = [[{'value': name, 'editable': False} for name in df]] if len(df) else []
15161516
for i in range(len(df)):
15171517
events_data['table'].append([{'value': value, 'editable': False} for value in df.iloc[i]])
@@ -1657,7 +1657,7 @@ def events_time2run(self, rowindex: int, colindex: int):
16571657
elif key == 'start':
16581658
value = ast.literal_eval(value) # Convert stringified dict back to dict
16591659
for column in value.copy():
1660-
if column not in self.events.logtable:
1660+
if column not in self.events.logtable():
16611661
newcol = self.get_input_column(column)
16621662
if newcol == column:
16631663
raise KeyError
@@ -1710,7 +1710,7 @@ def events_rows2run(self, rowindex: int, colindex: int):
17101710
mapping = ast.literal_eval(mapping) # Convert stringified dict back to dict
17111711
for column, pattern in mapping.copy().items():
17121712
re.compile(str(pattern) if colindex==0 else '')
1713-
if colindex == 0 and column not in self.events.logtable:
1713+
if colindex == 0 and column not in self.events.logtable():
17141714
newcol = self.get_input_column(column)
17151715
if newcol == column: # The user cancelled the dialogue
17161716
raise KeyError
@@ -1749,7 +1749,7 @@ def events_columns2run(self, rowindex: int, colindex: int, _input: str=''):
17491749
if colindex == 0 and input and not output:
17501750
output = input
17511751

1752-
if not input or input in self.events.logtable:
1752+
if not input or input in self.events.logtable():
17531753
LOGGER.verbose(f"User sets the events column to: '{input}: {output}' for {self.target_run}")
17541754
if output: # Evaluate and store the data
17551755
if rowindex == nrows - 1:
@@ -1772,7 +1772,7 @@ def get_input_column(self, input: str) -> str:
17721772
"""Ask the user to pick an input column from the log table"""
17731773

17741774
# Get column names
1775-
columns = self.events.logtable.columns.tolist()
1775+
columns = self.events.logtable().columns.tolist()
17761776
column, ok = QInputDialog.getItem(self, 'Input error', f"Your '{input}' input column does not exist, please choose one of the existing columns:", columns, 0, False)
17771777

17781778
return column if ok else input
@@ -2126,7 +2126,7 @@ def run2data(runitem: RunItem) -> tuple:
21262126
events_data = []
21272127
events = runitem.events()
21282128
if events:
2129-
df = events.eventstable
2129+
df = events.eventstable()
21302130
events_data.append([*df.columns])
21312131
for i in range(len(df)):
21322132
events_data.append([*df.iloc[i]])

bidscoin/plugins/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self, sourcefile: Path, data: dict, options: dict):
210210
for key, val in {'parsing': {}, 'columns': [{'onset':''}, {'duration':''}], 'rows': [{}], 'time': {}}.items():
211211
if key not in data: data[key] = val
212212
self._data = data
213-
self.time # Add all required data['time'] keys
213+
self.time # Initialize all required data['time'] keys
214214

215215
self.sourcefile = Path(sourcefile)
216216
self.options = options
@@ -227,17 +227,15 @@ def __str__(self):
227227

228228
return f"{self.sourcefile}"
229229

230-
@property
231230
@abstractmethod
232231
def logtable(self) -> pd.DataFrame:
233232
"""Returns the source logging data"""
234233

235-
@property
236234
def eventstable(self) -> pd.DataFrame:
237235
"""Returns the target events.tsv data"""
238236

239237
# Check the parser's data structure
240-
logtable = self.logtable
238+
logtable = self.logtable()
241239
if not len(logtable):
242240
return pd.DataFrame(columns=['onset', 'duration'])
243241
if not self.isvalid:
@@ -347,7 +345,7 @@ def is_float(s):
347345
valid = False
348346

349347
# Check if the logtable has existing and unique column names
350-
columns = self.logtable.columns
348+
columns = self.logtable().columns
351349
for name in set([name for item in self.columns for name in item.values()] +
352350
[name for item in self.rows for name in (item.get('condition') or {}).keys()] + [*self.time.start.keys()]):
353351
if name and name not in columns:
@@ -363,7 +361,7 @@ def write(self, targetfile: Path):
363361
"""Write the eventstable to a BIDS events.tsv file"""
364362

365363
LOGGER.verbose(f"Saving events to: {targetfile}")
366-
self.eventstable.to_csv(targetfile, sep='\t', index=False)
364+
self.eventstable().to_csv(targetfile, sep='\t', index=False)
367365

368366
def rename_duplicates(self, columns: Iterable[str]) -> List[str]:
369367
"""

bidscoin/plugins/events2bids.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ def __init__(self, sourcefile: Path, data: dict, options: dict):
311311
LOGGER.debug(f"Cannot read/parse {sourcefile}")
312312
self._sourcetable = pd.DataFrame()
313313

314-
@property
315314
def logtable(self) -> pd.DataFrame:
316315
"""Returns the Psychopy log-table"""
317316

0 commit comments

Comments
 (0)