code/vexptoolbox/experiment.py
def addTrialsFromCSV(self, file_name=None, sep=None, repeat=1, block=None,
                         block_col=None, params={}, num_rows=None):
        """ Read a list of trials from a CSV file, adding the columns
        as parameter values to each trial (one trial per row). If no file is 
        specified, show Vizard file selection dialog.

        Args:
            file_name (str): name of CSV file to read, or None to show selection dialog
            sep (str): column separator (default: tab)
            repeat (int): Number of times to repeat each trial read from the file
            block (int): Block number to assign to trials (overrides block_col)
            block_col (str): Column name to use for block numbering
            params (dict): Parameter values to set in all trials
                (Caution: Will override identically named columns from input file!)
            num_rows (int): How many trials to read (at least 1, default: all)
        """
        if file_name is None:
            file_name = vizinput.fileOpen(filter=[('Trial files', '*.csv;*.tsv;*.dat;*.txt')])

        if sep is None:
            ext = os.path.splitext(file_name)[1]
            if ext.upper() in ['.TSV']:
                sep='\t'
            else:
                sep=';'

        trial_no = 0
        with open(file_name, 'r') as tf:
            reader = csv.DictReader(tf, delimiter=sep)
            if len(reader.fieldnames) == 1:
                m = 'Warning: Only a single column read from trial file. Is the field separator set correctly (e.g., sep=";")?\n'
                print(m)

            for row in reader:
                cparams = {}
                for h in reader.fieldnames:

                    # Convert numeric values
                    data = row[h]
                    try:
                        cparams[h] = int(data)
                    except ValueError:
                        try:
                            cparams[h] = float(data)
                        except ValueError:
                            cparams[h] = data

                if block is None:
                    if block_col is not None:
                        # Use column if no block number specified
                        if block_col not in cparams.keys():
                            s = 'addTrialsFromCSV: Block variable "{:s}" not found in input file!'
                            raise ValueError(s.format(block_col))
                        else:
                            bl = int(cparams[block_col])

                    elif block_col is None:
                        # Nothing specified, use default (0)
                        bl = 0
                else:
                    # Use block argument if present (overrides column)
                    bl = int(block)

                # Add any other params specified in function call
                cparams.update(params)

                for rep in range(0, repeat):
                    self.trials.append(Trial(params=cparams, block=bl))
                    trial_no += 1

                if num_rows is not None:
                    if trial_no >= num_rows:
                        break

        self._updateTrialIndices()
        self._updateBlocks()

        if '_trial_input_files' not in self.config:
            self.config['_trial_input_files'] = []
        self.config['_trial_input_files'].append(file_name)
        self._dlog('Adding {:d} trials from file: {:s}'.format(trial_no, file_name))
 Read a list of trials from a CSV file, adding the columns
        as parameter values to each trial (one trial per row). If no file is 
        specified, show Vizard file selection dialog.

        Args:
            file_name (str): name of CSV file to read, or None to show selection dialog
            sep (str): column separator (default: tab)
            repeat (int): Number of times to repeat each trial read from the file
            block (int): Block number to assign to trials (overrides block_col)
            block_col (str): Column name to use for block numbering
            params (dict): Parameter values to set in all trials
                (Caution: Will override identically named columns from input file!)
            num_rows (int): How many trials to read (at least 1, default: all)
        
Read a list of trials from a CSV file, adding the columns
as parameter values to each trial (one trial per row). If no file is
specified, show Vizard file selection dialog.
Read a list of trials from a CSV file adding the columns as parameter values to each trial ( one trial per row ) . If no file is specified show Vizard file selection dialog .
def addTrialsFromCSV(self, file_name=None, sep=None, repeat=1, block=None,
                         block_col=None, params={}, num_rows=None):
        if file_name is None:
            file_name = vizinput.fileOpen(filter=[('Trial files', '*.csv;*.tsv;*.dat;*.txt')])
        if sep is None:
            ext = os.path.splitext(file_name)[1]
            if ext.upper() in ['.TSV']:
                sep='\t'
            else:
                sep=';'
        trial_no = 0
        with open(file_name, 'r') as tf:
            reader = csv.DictReader(tf, delimiter=sep)
            if len(reader.fieldnames) == 1:
                m = 'Warning: Only a single column read from trial file. Is the field separator set correctly (e.g., sep=";")?\n'
                print(m)
            for row in reader:
                cparams = {}
                for h in reader.fieldnames:
                    data = row[h]
                    try:
                        cparams[h] = int(data)
                    except ValueError:
                        try:
                            cparams[h] = float(data)
                        except ValueError:
                            cparams[h] = data
                if block is None:
                    if block_col is not None:
                        if block_col not in cparams.keys():
                            s = 'addTrialsFromCSV: Block variable "{:s}" not found in input file!'
                            raise ValueError(s.format(block_col))
                        else:
                            bl = int(cparams[block_col])
                    elif block_col is None:
                        bl = 0
                else:
                    bl = int(block)
                cparams.update(params)
                for rep in range(0, repeat):
                    self.trials.append(Trial(params=cparams, block=bl))
                    trial_no += 1
                if num_rows is not None:
                    if trial_no >= num_rows:
                        break
        self._updateTrialIndices()
        self._updateBlocks()
        if '_trial_input_files' not in self.config:
            self.config['_trial_input_files'] = []
        self.config['_trial_input_files'].append(file_name)
        self._dlog('Adding {:d} trials from file: {:s}'.format(trial_no, file_name))
def addTrialsFromCSV ( self , file_name = None , sep = None , repeat = 1 , block = None , block_col = None , params = { } , num_rows = None ) : if file_name is None : file_name = vizinput . fileOpen ( filter = [ ( 'Trial files' , '*.csv;*.tsv;*.dat;*.txt' ) ] ) if sep is None : ext = os . path . splitext ( file_name ) [ 1 ] if ext . upper ( ) in [ '.TSV' ] : sep = '\t' else : sep = ';' trial_no = 0 with open ( file_name , 'r' ) as tf : reader = csv . DictReader ( tf , delimiter = sep ) if len ( reader . fieldnames ) == 1 : m = 'Warning: Only a single column read from trial file. Is the field separator set correctly (e.g., sep=";")?\n' print ( m ) for row in reader : cparams = { } for h in reader . fieldnames : data = row [ h ] try : cparams [ h ] = int ( data ) except ValueError : try : cparams [ h ] = float ( data ) except ValueError : cparams [ h ] = data if block is None : if block_col is not None : if block_col not in cparams . keys ( ) : s = 'addTrialsFromCSV: Block variable "{:s}" not found in input file!' raise ValueError ( s . format ( block_col ) ) else : bl = int ( cparams [ block_col ] ) elif block_col is None : bl = 0 else : bl = int ( block ) cparams . update ( params ) for rep in range ( 0 , repeat ) : self . trials . append ( Trial ( params = cparams , block = bl ) ) trial_no += 1 if num_rows is not None : if trial_no >= num_rows : break self . _updateTrialIndices ( ) self . _updateBlocks ( ) if '_trial_input_files' not in self . config : self . config [ '_trial_input_files' ] = [ ] self . config [ '_trial_input_files' ] . append ( file_name ) self . _dlog ( 'Adding {:d} trials from file: {:s}' . format ( trial_no , file_name ) )
Read a list of trials from a CSV file, adding the columns
as parameter values to each trial (one trial per row).
Read a list of trials from a CSV file adding the columns as parameter values to each trial ( one trial per row ) .
""" Read a list of trials from a CSV file, adding the columns
        as parameter values to each trial (one trial per row). If no file is 
        specified, show Vizard file selection dialog.

        Args:
            file_name (str): name of CSV file to read, or None to show selection dialog
            sep (str): column separator (default: tab)
            repeat (int): Number of times to repeat each trial read from the file
            block (int): Block number to assign to trials (overrides block_col)
            block_col (str): Column name to use for block numbering
            params (dict): Parameter values to set in all trials
                (Caution: Will override identically named columns from input file!)
            num_rows (int): How many trials to read (at least 1, default: all)
        """ # Convert numeric values # Use column if no block number specified # Nothing specified, use default (0) # Use block argument if present (overrides column) # Add any other params specified in function call
self
file_name
name of CSV file to read, or None to show selection dialog
name of CSV file to read or None to show selection dialog
sep
column separator (default: tab)
column separator ( default : tab )
repeat
Number of times to repeat each trial read from the file
Number of times to repeat each trial read from the file
block
Block number to assign to trials (overrides block_col)
Block number to assign to trials ( overrides block_col )
block_col
Column name to use for block numbering
Column name to use for block numbering
params
Parameter values to set in all trials
(Caution: Will override identically named columns from input file!)
Parameter values to set in all trials ( Caution : Will override identically named columns from input file! )
num_rows
None