Skip to content

Unable to save Table data to csv #335

@icarmel

Description

@icarmel

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

commit 1335f505b6f9e3117352ec3db4ec476fdcbeea22
Author: Idit Levy Carmel <[email protected]>
Date:   Wed Oct 4 09:50:28 2023 +0300

    change DataFrame table source in NeuroticWritableEpochSource

diff --git a/neurotic/gui/config.py b/neurotic/gui/config.py
index cc916cd..3e7377c 100644
--- a/neurotic/gui/config.py
+++ b/neurotic/gui/config.py
@@ -675,6 +675,20 @@ class EphyviewerConfigurator():
             epoch_view.params['xratio'] = self.metadata.get('past_fraction', 0.3)
             epoch_view.params['label_size'] = ui_scales[ui_scale]['channel_label_size']
 
+        ########################################################################
+        # DATAFRAME
+
+        self.annotations_dataframe = _neo_epoch_to_dataframe(seg.epochs, exclude_epoch_encoder_epochs=True)
+        if self.is_shown('data_frame') and len(self.annotations_dataframe) > 0:
+
+            data_frame_view = ephyviewer.DataFrameView(source = self.annotations_dataframe, name = 'Table')
+            if 'Events' in win.viewers:
+                win.add_view(data_frame_view, tabify_with = 'Events')
+            elif 'Video' in win.viewers:
+                win.add_view(data_frame_view, split_with = 'Video')
+            else:
+                win.add_view(data_frame_view, location = 'bottom', orientation = 'horizontal')
+
         ########################################################################
         # EPOCH ENCODER
 
@@ -693,6 +707,7 @@ class EphyviewerConfigurator():
             writable_epoch_source = NeuroticWritableEpochSource(
                 filename = _abs_path(self.metadata, 'epoch_encoder_file'),
                 possible_labels = possible_labels,
+                source = self.annotations_dataframe
             )
 
             epoch_encoder = ephyviewer.EpochEncoder(source = writable_epoch_source, name = 'Epoch encoder')
@@ -769,19 +784,6 @@ class EphyviewerConfigurator():
             else:
                 win.add_view(event_list, location = 'bottom', orientation = 'horizontal')
 
-        ########################################################################
-        # DATAFRAME
-
-        annotations_dataframe = _neo_epoch_to_dataframe(seg.epochs, exclude_epoch_encoder_epochs=True)
-        if self.is_shown('data_frame') and len(annotations_dataframe) > 0:
-
-            data_frame_view = ephyviewer.DataFrameView(source = annotations_dataframe, name = 'Table')
-            if 'Events' in win.viewers:
-                win.add_view(data_frame_view, tabify_with = 'Events')
-            elif 'Video' in win.viewers:
-                win.add_view(data_frame_view, split_with = 'Video')
-            else:
-                win.add_view(data_frame_view, location = 'bottom', orientation = 'horizontal')
 
         ########################################################################
         # FINAL TOUCHES
diff --git a/neurotic/gui/epochencoder.py b/neurotic/gui/epochencoder.py
index daa5503..04ae113 100644
--- a/neurotic/gui/epochencoder.py
+++ b/neurotic/gui/epochencoder.py
@@ -22,12 +22,13 @@ class NeuroticWritableEpochSource(WritableEpochSource):
     custom CSV column formatting and automatic file backup.
     """
 
-    def __init__(self, filename, possible_labels, color_labels=None, channel_name='', backup=True):
+    def __init__(self, filename, possible_labels, source=None, color_labels=None, channel_name='', backup=True):
         """
         Initialize a new NeuroticWritableEpochSource.
         """
 
         self.filename = filename
+        self.source = source
         self.backup = backup
 
         WritableEpochSource.__init__(self, epoch=None, possible_labels=possible_labels, color_labels=color_labels, channel_name=channel_name)
@@ -76,8 +77,13 @@ class NeuroticWritableEpochSource(WritableEpochSource):
             shutil.copy2(self.filename, backup_filename)
 
         df = pd.DataFrame()
-        df['Start (s)'] = np.round(self.ep_times, 6)                   # round to nearest microsecond
-        df['End (s)'] = np.round(self.ep_times + self.ep_durations, 6) # round to nearest microsecond
-        df['Type'] = self.ep_labels
+        if self.source:
+            df['Start (s)'] = np.round(self.source['Start (s)'], 6)                   # round to nearest microsecond
+            df['End (s)'] = np.round(self.source['End (s)'] + self.source['Duration (s)'], 6) # round to nearest microsecond
+            df['Type'] = self.source['Type'] 
+        else: 
+            df['Start (s)'] = np.round(self.ep_times, 6)                   # round to nearest microsecond
+            df['End (s)'] = np.round(self.ep_times + self.ep_durations, 6) # round to nearest microsecond
+            df['Type'] = self.ep_labels
         df.sort_values(['Start (s)', 'End (s)', 'Type'], inplace=True)
         df.to_csv(self.filename, index=False)



Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions