code/vexptoolbox/experiment.py
def saveTrialDataToCSV(self, file_name=None, sep='\t', rec_data='single'):
        """ Saves trial parameters and results to CSV file

        Args:
            file_name (str): Name of CSV file to write to
            sep (str): Field separator string (default: Tab)
            rec_data: How to save sample and event data if recorded:
                - 'single': One large file with all samples (default)
                - 'separate' Or True: one sample file per trial
                - 'none' or False: Do not save sample data
        """
        if file_name is None:
            file_name = '{:s}.tsv'.format(self.output_file_name)

        if type(rec_data) == bool:
            if rec_data: 
                rec_data = 'single'
            else: 
                rec_data = 'none'

        # Trial data
        self._dlog('Saving trial data...')
        all_keys = []
        tdicts = []
        for t in self.trials:
            td = dict(t.params)
            td.update(dict(t.results))
            td['_trial_index'] = t.index
            td['_trial_number'] = t.number
            td['_start_tick'] = t._start_tick
            td['_end_tick'] = t._end_tick
            td['_start_time'] = t._start_time
            td['_end_time'] = t._end_time

            # Collect superset of all param and result keys
            for key in list(td.keys()):
                if key not in all_keys:
                    all_keys.append(key)
            tdicts.append(td)

        all_keys.sort()
        with open(file_name, 'w') as of:
            writer = csv.DictWriter(of, delimiter=sep, lineterminator='\n', 
                                    fieldnames=all_keys)
            writer.writeheader()
            for td in tdicts:
                writer.writerow(td)

        # Sample and event data
        if rec_data.lower() == 'single' and self._recorder is not None:
            file_name_s = '{:s}_samples.tsv'.format(os.path.splitext(file_name)[0])
            file_name_e = '{:s}_events.tsv'.format(os.path.splitext(file_name)[0])

            first = True
            for t in self.trials:
                # Write all trials to same file, but ensure not to append to old data
                if first:
                    self.recorder.saveRecording(sample_file=file_name_s, event_file=file_name_e, _append=False,
                                                _data=(t.samples, t.events), meta_cols={'trial_number': t.number})
                    first = False
                else:
                    self.recorder.saveRecording(sample_file=file_name_s, event_file=file_name_e, _append=True,
                                                _data=(t.samples, t.events), meta_cols={'trial_number': t.number})

        elif rec_data.lower() == 'separate' and self._recorder is not None:
            for t in self.trials:
                try:
                    file_name_s = '{:s}_samples_{:d}.tsv'.format(os.path.splitext(file_name)[0], t.number)
                    file_name_e = '{:s}_events_{:d}.tsv'.format(os.path.splitext(file_name)[0], t.number)
                    if os.path.isfile(file_name_s) and os.path.isfile(file_name_e):
                        continue # This is called on each trial, so skip existing files
                    
                    self.recorder.saveRecording(sample_file=file_name_s, event_file=file_name_e, 
                                                _data=(t.samples, t.events), meta_cols={'trial_number': t.number})
                
                except AttributeError:
                    pass
 Saves trial parameters and results to CSV file

        Args:
            file_name (str): Name of CSV file to write to
            sep (str): Field separator string (default: Tab)
            rec_data: How to save sample and event data if recorded:
                - 'single': One large file with all samples (default)
                - 'separate' Or True: one sample file per trial
                - 'none' or False: Do not save sample data
        
Saves trial parameters and results to CSV file
Saves trial parameters and results to CSV file
def saveTrialDataToCSV(self, file_name=None, sep='\t', rec_data='single'):
        if file_name is None:
            file_name = '{:s}.tsv'.format(self.output_file_name)
        if type(rec_data) == bool:
            if rec_data: 
                rec_data = 'single'
            else: 
                rec_data = 'none'
        self._dlog('Saving trial data...')
        all_keys = []
        tdicts = []
        for t in self.trials:
            td = dict(t.params)
            td.update(dict(t.results))
            td['_trial_index'] = t.index
            td['_trial_number'] = t.number
            td['_start_tick'] = t._start_tick
            td['_end_tick'] = t._end_tick
            td['_start_time'] = t._start_time
            td['_end_time'] = t._end_time
            for key in list(td.keys()):
                if key not in all_keys:
                    all_keys.append(key)
            tdicts.append(td)
        all_keys.sort()
        with open(file_name, 'w') as of:
            writer = csv.DictWriter(of, delimiter=sep, lineterminator='\n', 
                                    fieldnames=all_keys)
            writer.writeheader()
            for td in tdicts:
                writer.writerow(td)
        if rec_data.lower() == 'single' and self._recorder is not None:
            file_name_s = '{:s}_samples.tsv'.format(os.path.splitext(file_name)[0])
            file_name_e = '{:s}_events.tsv'.format(os.path.splitext(file_name)[0])
            first = True
            for t in self.trials:
                if first:
                    self.recorder.saveRecording(sample_file=file_name_s, event_file=file_name_e, _append=False,
                                                _data=(t.samples, t.events), meta_cols={'trial_number': t.number})
                    first = False
                else:
                    self.recorder.saveRecording(sample_file=file_name_s, event_file=file_name_e, _append=True,
                                                _data=(t.samples, t.events), meta_cols={'trial_number': t.number})
        elif rec_data.lower() == 'separate' and self._recorder is not None:
            for t in self.trials:
                try:
                    file_name_s = '{:s}_samples_{:d}.tsv'.format(os.path.splitext(file_name)[0], t.number)
                    file_name_e = '{:s}_events_{:d}.tsv'.format(os.path.splitext(file_name)[0], t.number)
                    if os.path.isfile(file_name_s) and os.path.isfile(file_name_e):
                        continue 
                    self.recorder.saveRecording(sample_file=file_name_s, event_file=file_name_e, 
                                                _data=(t.samples, t.events), meta_cols={'trial_number': t.number})
                except AttributeError:
                    pass
def saveTrialDataToCSV ( self , file_name = None , sep = '\t' , rec_data = 'single' ) : if file_name is None : file_name = '{:s}.tsv' . format ( self . output_file_name ) if type ( rec_data ) == bool : if rec_data : rec_data = 'single' else : rec_data = 'none' self . _dlog ( 'Saving trial data...' ) all_keys = [ ] tdicts = [ ] for t in self . trials : td = dict ( t . params ) td . update ( dict ( t . results ) ) td [ '_trial_index' ] = t . index td [ '_trial_number' ] = t . number td [ '_start_tick' ] = t . _start_tick td [ '_end_tick' ] = t . _end_tick td [ '_start_time' ] = t . _start_time td [ '_end_time' ] = t . _end_time for key in list ( td . keys ( ) ) : if key not in all_keys : all_keys . append ( key ) tdicts . append ( td ) all_keys . sort ( ) with open ( file_name , 'w' ) as of : writer = csv . DictWriter ( of , delimiter = sep , lineterminator = '\n' , fieldnames = all_keys ) writer . writeheader ( ) for td in tdicts : writer . writerow ( td ) if rec_data . lower ( ) == 'single' and self . _recorder is not None : file_name_s = '{:s}_samples.tsv' . format ( os . path . splitext ( file_name ) [ 0 ] ) file_name_e = '{:s}_events.tsv' . format ( os . path . splitext ( file_name ) [ 0 ] ) first = True for t in self . trials : if first : self . recorder . saveRecording ( sample_file = file_name_s , event_file = file_name_e , _append = False , _data = ( t . samples , t . events ) , meta_cols = { 'trial_number' : t . number } ) first = False else : self . recorder . saveRecording ( sample_file = file_name_s , event_file = file_name_e , _append = True , _data = ( t . samples , t . events ) , meta_cols = { 'trial_number' : t . number } ) elif rec_data . lower ( ) == 'separate' and self . _recorder is not None : for t in self . trials : try : file_name_s = '{:s}_samples_{:d}.tsv' . format ( os . path . splitext ( file_name ) [ 0 ] , t . number ) file_name_e = '{:s}_events_{:d}.tsv' . format ( os . path . splitext ( file_name ) [ 0 ] , t . number ) if os . path . isfile ( file_name_s ) and os . path . isfile ( file_name_e ) : continue self . recorder . saveRecording ( sample_file = file_name_s , event_file = file_name_e , _data = ( t . samples , t . events ) , meta_cols = { 'trial_number' : t . number } ) except AttributeError : pass
Saves trial parameters and results to CSV file
Saves trial parameters and results to CSV file
""" Saves trial parameters and results to CSV file

        Args:
            file_name (str): Name of CSV file to write to
            sep (str): Field separator string (default: Tab)
            rec_data: How to save sample and event data if recorded:
                - 'single': One large file with all samples (default)
                - 'separate' Or True: one sample file per trial
                - 'none' or False: Do not save sample data
        """ # Trial data # Collect superset of all param and result keys # Sample and event data # Write all trials to same file, but ensure not to append to old data # This is called on each trial, so skip existing files
self
file_name
Name of CSV file to write to
Name of CSV file to write to
sep
Field separator string (default: Tab)
Field separator string ( default : Tab )
rec_data
None