Experiment Data File

For an example that uses creating an experiment data file see VisualSearch- VisualSearch1_SingleObject

Here's  how you can add an experiment data file to save the results of your Experiment. You can find this example under ExampleScripts-VisualSearch-VisualSearch_SingleObject. See the Visual Search page for more information on that example, but it serves well for demonstrating adding an experiment data file. In most cases you would define the independent variable you are manipulating in a STIM file, then list this condition per trial along with any dependent variables you are measuring.  

Key Components of Code

Import CSV

The csv module in Python is imported to facilitate reading and writing operations with .csv files.

import csv

File Name

The filename is generated dynamically based on the participant's ID, first name, and last name. These details are fetched from the sightlab object. Change"PathToYourDataFolder" to wherever you want to save this data file (usually in a folder next to your main script, or can use utils/data. Can rename "experiment_data" to whatever you want to call this file. 

filename = ('PathToYourDataFolder\\experiment_data_{0}_{1}_{2}.csv'.format(sightlab.participant.id,sightlab.participant.firstName,sightlab.participant.lastName))

File Writing

Here we open a .csv file in write mode and initialize the csv.writer object. The first row of the file is the header row, specifying the columns. Change these to the names of the columns you wish to use. Make sure the rest of your trial block is indented to run inside of this file being open. 

with open(filename, 'w', newline='') as csvfile:

    writer = csv.writer(csvfile)

    writer.writerow(['Trial', 'Object Size', 'Time to Find Target', 'Position'])


Data Writing

During the experiment, data for each trial is saved to the file using writer.writerow() method. The row will contain the following columns:

You can add your own conditions, but these are usually read from the STIM file to keep track of what independent variable is bein modified for each trial, then you can add the dependent variables you are measuring. 

writer.writerow([i + 1, CONDITION, time_to_find_target, positionTuple])

Steps to Add an Experiment Data File

Modifying the Code

You can modify this code to save additional data columns. To do so:

writer.writerow(['Trial', 'Object Size', 'Time to Find Target', 'Position', 'New_Column'])

writer.writerow([i + 1, CONDITION, time_to_find_target, positionTuple, new_data_point])