Open icarmel opened 1 year ago
Hi Idit,
If you'd like to propose a change to neurotic, the preferred method is the following:
I understand this may seem very complicated if you have never done it before. The advantage is that GitHub will automatically run neurotic's test suite, and I can more easily check that the proposed changes work. This off-loads work from me. Presently, I do really have time that I can devote to this.
Without actually testing your code, but just reading it, it looks to me like this is not a good change in its present form. The writable_epoch_source
is needed for the Epoch Encoder, which is a separate widget panel from the annotations table that I know Miryam wants to export data from. So, the change you make may allow the annotations table to be exported, but it will break the Epoch Encoder. I think a different approach would be needed here.
Have you seen the script I provided to Miryam for exporting the contents of the annotations table? I will copy its contents below. I know a script is not as convenient as a button click in the application, but it should be able to export the table's contents.
import os
from pathlib import Path
import pandas as pd
import neurotic
################################################################################
# Change these values for your needs
metadata_file = 'metadata.yml'
dataset_list = [
'IN VIVO / JG12 / 2019-05-10 / 002',
]
################################################################################
for dataset in dataset_list:
print('Dataset:', dataset)
metadata = neurotic.MetadataSelector(file=metadata_file)
metadata.select(dataset)
output_file = Path(metadata['data_file']).stem + ' TABLE.csv'
output_file = Path(metadata['data_dir']) / output_file
if output_file.exists():
print('ATTENTION: The output file already exists:')
print(' ', output_file)
overwrite = input('Do you want to overwrite it? [y/n] ')
if overwrite != 'y':
print('OK, aborting')
exit()
exclude_epoch_encoder = input('Do you want to exclude epoch encoder entries from the output? [y/n] ')
print('Loading data and generating table...')
blk = neurotic.load_dataset(metadata, lazy=False)
seg = blk.segments[0]
epochs = seg.epochs
print('Saving table...')
df_list = []
for ep in epochs:
if exclude_epoch_encoder == 'y':
ep = ep[ep.labels != '(from epoch encoder file)'];
df_list.append(pd.DataFrame({
'Start (s)': ep.times.rescale('s').round(4),
'End (s)': (ep.times + ep.durations).rescale('s').round(4),
'Duration (s)': ep.durations.rescale('s').round(4),
'Type': ep.name,
'Label': ep.labels,
}))
df_all = pd.concat(df_list).sort_values(['Start (s)', 'End (s)', 'Type', 'Label'])
df_all.to_csv(output_file, index=False)
print('Table successfully written to:')
print(' ', output_file)
print()
Thank you, Jeff! I've heard excellent feedback from my mom and team in the lab, who hold you in high regard and greatly appreciate your work and efforts. The fix I did was a workaround to pass the source in constructor as WritableEpochSource values (represented by self instance) were empty. I'll follow up with her regarding the attached script, and she'll take it from there.
Hello Jeff, My name is Idit and I'm Miryam Levy's daughter (from BIU). In the BIU lab, they are using neurotic version 1.5.0 and unable to save the data displayed to a CSV file. It generated only the headers. I debugged it a bit and it seems that the NeuroticWritableEpochSource is missing a source. I'd like to propose a fix but have no permission to push a Pull Request. Please find the patch diff. Thanks, Idit