Beispiel #1
0
def printQueriedEventsDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    #
    experiment_data = ExperimentDataAccessUtility('..\hdf5_files',
                                                  'events.hdf5')

    # Retrieve the 'time','device_time','event_id','delay','category','text'
    # attributes from the Message Event table, where the event time is between
    # the associated trials condition variables TRIAL_START and TRIAL_END
    # value.
    # i.e. only get message events sent during each trial of the eperiment, not any
    #      sent between trials.
    #
    event_results = experiment_data.getEventAttributeValues(
        EventConstants.MESSAGE,
        ['time', 'device_time', 'event_id', 'delay', 'category', 'text'],
        conditionVariablesFilter=None,
        startConditions={'time': ('>=', '@TRIAL_START@')},
        endConditions={'time': ('<=', '@TRIAL_END@')})

    for trial_events in event_results:
        print '==== TRIAL DATA START ======='
        print "Trial Condition Values:"
        for ck, cv in trial_events.condition_set._asdict().iteritems():
            print "\t{ck} : {cv}".format(ck=ck, cv=cv)
        print

        trial_events.query_string
        print "Trial Query String:\t"
        print trial_events.query_string
        print

        event_value_arrays = [
            (cv_name, cv_value)
            for cv_name, cv_value in trial_events._asdict().iteritems()
            if cv_name not in ('query_string', 'condition_set')
        ]
        print "Trial Event Field Data:"
        for field_name, field_data in event_value_arrays:
            print "\t" + field_name + ': ' + str(field_data)
            print
        print '===== TRIAL DATA END ========'

    experiment_data.close()
Beispiel #2
0
def loadEventFile(data_folder_path, file_name, session_name):
    global dataAccessUtil
    dataAccessUtil = ExperimentDataAccessUtility(
        data_folder_path,  #IOHUB_DATA_FOLDER_PATH,
        file_name,  #IOHUB_DATA_FILE_NAME,
        experimentCode=None,
        sessionCodes=[
            session_name,
        ])  #SESSION_CODE,])
def printExperimentMetaDataDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    # 
    experiment_data=ExperimentDataAccessUtility('..\hdf5_files' , 'events.hdf5')
    
    # Access the Experiment Meta Data for the first Experiment found in the file.
    # Note that currently only one experiment's data can be saved in each hdf5 file 
    # created. However multiple sessions / runs of the same experiment are all
    # saved in one file.
    #
    exp_md=experiment_data.getExperimentMetaData()[0]
    
    printExperimentMetaData(exp_md)
    
    # Close the HDF5 File
    #
    experiment_data.close()
def printEventTypesWithDataDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    # 
    experiment_data=ExperimentDataAccessUtility('..\hdf5_files' , 'events.hdf5')
    
    # Get any event tables that have >=1 event saved in them
    #
    events_by_type=experiment_data.getEventsByType()
    
    # print out info on each table
    #
    for event_id, event_gen in events_by_type.iteritems():
        event_constant=EventConstants.getName(event_id)
        print "{0} ({1}): {2}".format(event_constant,event_gen.table.nrows,event_gen)

    # Close the HDF5 File
    #
    experiment_data.close()
def printExperimentMetaDataDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    #
    experiment_data = ExperimentDataAccessUtility('..\hdf5_files',
                                                  'events.hdf5')

    # Access the Experiment Meta Data for the first Experiment found in the file.
    # Note that currently only one experiment's data can be saved in each hdf5 file
    # created. However multiple sessions / runs of the same experiment are all
    # saved in one file.
    #
    exp_md = experiment_data.getExperimentMetaData()[0]

    printExperimentMetaData(exp_md)

    # Close the HDF5 File
    #
    experiment_data.close()
def printEventTypesWithDataDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    # 
    experiment_data=ExperimentDataAccessUtility('..\hdf5_files' , 'events.hdf5')
    
    # Get any event tables that have >=1 event saved in them
    #
    events_by_type=experiment_data.getEventsByType()
    
    # print out info on each table
    #
    for event_id, event_gen in events_by_type.iteritems():
        event_constant=EventConstants.getName(event_id)
        print "{0} ({1}): {2}".format(event_constant,event_gen.table.nrows,event_gen)

    # Close the HDF5 File
    #
    experiment_data.close()
def printQueriedEventsDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    # 
    experiment_data=ExperimentDataAccessUtility('..\hdf5_files' , 'events.hdf5')
    
    # Retrieve the 'time','device_time','event_id','delay','category','text'
    # attributes from the Message Event table, where the event time is between
    # the associated trials condition variables TRIAL_START and TRIAL_END
    # value.
    # i.e. only get message events sent during each trial of the eperiment, not any
    #      sent between trials.
    #
    event_results=experiment_data.getEventAttributeValues(EventConstants.MESSAGE,
                        ['time','device_time','event_id','delay','category','text'], 
                        conditionVariablesFilter=None, 
                        startConditions={'time':('>=','@TRIAL_START@')},
                        endConditions={'time':('<=','@TRIAL_END@')})

    
    for trial_events in event_results:    
        print '==== TRIAL DATA START ======='
        print "Trial Condition Values:"
        for ck,cv in trial_events.condition_set._asdict().iteritems():
            print "\t{ck} : {cv}".format(ck=ck,cv=cv)
        print
        
        trial_events.query_string
        print "Trial Query String:\t"
        print trial_events.query_string
        print 
        
        event_value_arrays=[(cv_name,cv_value) for cv_name,cv_value in trial_events._asdict().iteritems() if cv_name not in ('query_string','condition_set')]
        print "Trial Event Field Data:"
        for field_name,field_data in event_value_arrays:
            print "\t"+field_name+': '+str(field_data)
            print
        print '===== TRIAL DATA END ========'

    experiment_data.close()
def printExperimentConditionVariableDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    # 
    experiment_data=ExperimentDataAccessUtility('..\hdf5_files' , 'events.hdf5')
    
    # Here we are accessing the condition values saved.
    # A list is returned, with each element being the condition variable data 
    # for a trial of the experiment, in the order the trials 
    # were run for the given session.    
    #    
    condition_variables=experiment_data.getConditionVariables()

    print "Experiment Condition Variable values:"
    print 
    
    for variable_set in condition_variables:
        pprint(dict(variable_set._asdict()))
        print
    # Close the HDF5 File
    #
    experiment_data.close()
def printExperimentConditionVariableDemo():
    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes.
    #
    experiment_data = ExperimentDataAccessUtility('..\hdf5_files',
                                                  'events.hdf5')

    # Here we are accessing the condition values saved.
    # A list is returned, with each element being the condition variable data
    # for a trial of the experiment, in the order the trials
    # were run for the given session.
    #
    condition_variables = experiment_data.getConditionVariables()

    print "Experiment Condition Variable values:"
    print

    for variable_set in condition_variables:
        pprint(dict(variable_set._asdict()))
        print
    # Close the HDF5 File
    #
    experiment_data.close()
#SAVE_EVENT_TYPE = EventConstants.BINOCULAR_EYE_SAMPLE
#SAVE_EVENT_FIELDS = ['time', 'left_gaze_x', 'left_gaze_y', 'left_pupil_measure1',
#                     'right_gaze_x', 'right_gaze_y', 'right_pupil_measure1', 'status']

if __name__ == '__main__':
    # Select the hdf5 file to process.
    data_file_path = displayDataFileSelectionDialog(
        os.path.dirname(os.path.abspath(__file__)))
    if data_file_path is None:
        print("File Selection Cancelled, exiting...")
        sys.exit(0)
    data_file_path = data_file_path[0]
    dpath, dfile = os.path.split(data_file_path)

    datafile = ExperimentDataAccessUtility(dpath, dfile)

    events_by_trial = datafile.getEventAttributeValues(
        SAVE_EVENT_TYPE,
        SAVE_EVENT_FIELDS,
        startConditions={'time': ('>=', '@TRIAL_START@')},
        endConditions={'time': ('<=', '@TRIAL_END@')})

    ecount = 0

    # Open a file to save the tab delimited output to.
    #
    output_file_name = "%s.txt" % (dfile[:-5])
    with open(output_file_name, 'w') as output_file:
        print('Writing Data to %s:\n' % (output_file_name))
        column_names = events_by_trial[0].condition_set._fields[
Beispiel #11
0
def createTrialDataStreams():
    trial_data_streams = []

    # Get the filtered event data.
    # We will use right eye data only for the testing..
    #
    dataAccessUtil = ExperimentDataAccessUtility(
        "../hdf5_files", "remote_data.hdf5", experimentCode=None, sessionCodes=[]
    )

    event_type = EventConstants.BINOCULAR_EYE_SAMPLE
    retrieve_attributes = ("time", "right_gaze_x", "right_gaze_y", "right_pupil_measure1", "status")
    trial_event_data = dataAccessUtil.getEventAttributeValues(
        event_type,
        retrieve_attributes,
        conditionVariablesFilter=None,
        startConditions={"time": (">=", "@TRIAL_START@")},
        endConditions={"time": ("<=", "@TRIAL_END@")},
    )

    dataAccessUtil.close()

    for t, trial_data in enumerate(trial_event_data):
        # Create a mask to be used to define periods of missing data in a data trace (eye tracker dependent)
        #
        invalid_data_mask = trial_data.status % 10 >= 2

        time = trial_data.time
        pupil = trial_data.right_pupil_measure1
        # Get x, y eye position traces (in pixels), setting sample positions where there is track loss
        # to NaN.
        xpix_cleared = trial_data.right_gaze_x.copy()
        ypix_cleared = trial_data.right_gaze_y.copy()
        processSampleEventGaps(xpix_cleared, ypix_cleared, pupil, invalid_data_mask, "clear")

        # Get x, y eye position traces (in pixels), setting sample positions
        # where there is track loss to be linearly interpolated using each
        # missing_sample_start-1 and missing_sample_end+1 as the points to
        # interpolate between.
        #
        xpix_linear = trial_data.right_gaze_x.copy()
        ypix_linear = trial_data.right_gaze_y.copy()

        # valid_data_periods is a list of array slice objects giving the start,end index of each non missing
        # period of in the data stream.
        #
        valid_data_periods = processSampleEventGaps(xpix_linear, ypix_linear, pupil, invalid_data_mask, "linear")

        # Convert from pixels to visual angle coordinates
        calibration_area_info = dict(
            display_size_mm=(340, 280.0), display_res_pix=(1280.0, 1024.0), eye_distance_mm=590.0
        )
        vac = VisualAngleCalc(**calibration_area_info)
        xdeg, ydeg = vac.pix2deg(xpix_linear, ypix_linear)

        # Create Filtered versions of the x and y degree data traces
        # We'll use the Median Filter...
        #
        xdeg_filtered = scipy.signal.medfilt(xdeg, SPATIAL_FILTER_WINDOW_SIZE)
        ydeg_filtered = scipy.signal.medfilt(ydeg, SPATIAL_FILTER_WINDOW_SIZE)

        # Create the velocity stream
        #
        xvel = calculateVelocity(time, xdeg_filtered)
        yvel = calculateVelocity(time, ydeg_filtered)

        # Filter the velocity data
        #
        FILTER_ORDER = 2
        Wn = 0.3
        b, a = scipy.signal.butter(FILTER_ORDER, Wn, "low")
        ffunc = scipy.signal.filtfilt
        xvel_filtered = ffunc(b, a, xvel)
        yvel_filtered = ffunc(b, a, yvel)

        #        xvel_filtered=savitzky_golay(xvel,window_size=VELOCITY_FILTER_WINDOW_SIZE,order=2)
        #        yvel_filtered=savitzky_golay(yvel,window_size=VELOCITY_FILTER_WINDOW_SIZE,order=2)
        #        xvel_filtered=gaussian_filter1d(xvel,VELOCITY_FILTER_WINDOW_SIZE)
        #        yvel_filtered=gaussian_filter1d(yvel,VELOCITY_FILTER_WINDOW_SIZE)
        #        xvel_filtered=scipy.signal.medfilt(xvel,VELOCITY_FILTER_WINDOW_SIZE)
        #        yvel_filtered=scipy.signal.medfilt(yvel,VELOCITY_FILTER_WINDOW_SIZE)

        velocity = np.sqrt(xvel * xvel + yvel * yvel)
        velocity_filtered = np.sqrt(xvel_filtered * xvel_filtered + yvel_filtered * yvel_filtered)

        # Create a data trace dictionary for all the different types
        #  of data traces created for the trial
        #
        trial_data = {}
        trial_data["time"] = time
        trial_data["xpix_cleared"] = xpix_cleared
        trial_data["ypix_cleared"] = ypix_cleared
        trial_data["xpix_linear"] = xpix_linear
        trial_data["xpix_linear"] = xpix_linear
        trial_data["xdeg"] = xdeg
        trial_data["ydeg"] = ydeg
        trial_data["xdeg_filtered"] = xdeg_filtered
        trial_data["ydeg_filtered"] = ydeg_filtered
        trial_data["pupil"] = pupil
        trial_data["velocity"] = velocity
        trial_data["velocity_filtered"] = velocity_filtered
        trial_data["valid_data_periods"] = valid_data_periods
        trial_data["missing_data_mask"] = invalid_data_mask
        # Add the data trace dictionary to a list
        #
        trial_data_streams.append(trial_data)
    return trial_data_streams
Beispiel #12
0
        psychopy.iohub.module_directory(writeOutputFileHeader))
    if data_file_path is None:
        print("File Selection Cancelled, exiting...")
        sys.exit(0)
    dpath, dfile = os.path.split(data_file_path)

    # Lets time how long processing takes
    #
    start_time = getTime()

    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes, as well
    # as access the experiment session metadata saved with each session run.
    dataAccessUtil = ExperimentDataAccessUtility(dpath,
                                                 dfile,
                                                 experimentCode=None,
                                                 sessionCodes=[])

    # Get a dict of all event types -> DataStore table info
    #   for the selected DataStore file.
    eventTableMappings = dataAccessUtil.getEventMappingInformation()

    # Get event tables that have data...
    #
    events_with_data = dataAccessUtil.getEventsByType()

    duration = getTime() - start_time

    # Select which event table to output by displaying a list of
    #   Event Class Names that have data available to the user...
    event_class_selection = displayEventTableSelectionDialog(
Beispiel #13
0
    if data_file_path is None:
        print("File Selection Cancelled, exiting...")
        sys.exit(0)

    dpath, dfile = os.path.split(data_file_path)

    # Lets time how long it takes to read and save to .txt format
    #
    start_time = getTime()

    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes, as well
    # as access the experiment session metadata saved with each session run.
    dataAccessUtil = ExperimentDataAccessUtility(dpath,
                                                 dfile,
                                                 experimentCode=None,
                                                 sessionCodes=[])

    duration = getTime() - start_time

    dvs_selected = displayTimeRangeVariableSelectionDialog(dataAccessUtil)

    # restart processing time calculation...
    #
    start_time = getTime()

    # Read the session metadata table for all sessions saved to the file.
    #
    session_metadata = dataAccessUtil.getSessionMetaData()
    sesion_meta_data_dict = dict()
    # Create a session_id -> session metadata mapping for use during
Beispiel #14
0
# Enter the eye tracker setup used for the data collection.
#
calibration_area_info=dict(display_size_mm=(340,280.0),
                   display_res_pix=(1280.0,1024.0),
                   eye_distance_mm=590.0)


##### STEP A. #####
# Retrieve a subset of the BINOCULAR_EYE_SAMPLE event attributes, for events that occurred
# between each time period defined by the TRIAL_START and TRIAL_END trial variables of each entry
# in the trial_conditions data table.
#
# Load an ioDataStore file containing 120 Hz sample data from a
# remote eye tracker that was recording both eyes. In the plotting example
#
dataAccessUtil=ExperimentDataAccessUtility('../hdf5_files','remote_data.hdf5', 
                                           experimentCode=None,sessionCodes=[])
# Get the filtered event data.
#
event_type=EventConstants.BINOCULAR_EYE_SAMPLE
retrieve_attributes=('time','left_gaze_x','left_gaze_y','left_pupil_measure1',
            'right_gaze_x','right_gaze_y','right_pupil_measure1','status')
trial_event_data=dataAccessUtil.getEventAttributeValues(event_type,
            retrieve_attributes,
            conditionVariablesFilter=None,
            startConditions={'time':('>=','@TRIAL_START@')},
            endConditions={'time':('<=','@TRIAL_END@')},
            )

trial_data=trial_event_data[TRIAL_INDEX]

time=trial_data.time
Beispiel #15
0
    if data_file_path is None:
        print("File Selection Cancelled, exiting...")
        sys.exit(0)

    dpath,dfile=os.path.split(data_file_path)

    # Lets time how long it takes to read and save to .txt format
    #
    start_time=getTime()

    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes, as well
    # as access the experiment session metadata saved with each session run.
    dataAccessUtil=ExperimentDataAccessUtility(dpath,dfile,
                                               experimentCode=None,
                                               sessionCodes=[])

    duration=getTime()-start_time

    dvs_selected = displayTimeRangeVariableSelectionDialog(dataAccessUtil)

    # restart processing time calculation...
    #
    start_time=getTime()

    # Read the session metadata table for all sessions saved to the file.
    #
    session_metadata=dataAccessUtil.getSessionMetaData()
    sesion_meta_data_dict=dict()
    # Create a session_id -> session metadata mapping for use during
Beispiel #16
0
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility
from psychopy.iohub import EventConstants

import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from matplotlib.font_manager import FontProperties

from common_workshop_functions import processSampleEventGaps

import numpy as np

# Load an ioDataStore file containing 120 Hz sample data from a
# remote eye tracker that was recording both eyes. In the plotting example
dataAccessUtil = ExperimentDataAccessUtility('../hdf5_files',
                                             'remote_data.hdf5',
                                             experimentCode=None,
                                             sessionCodes=[])

##### STEP A. #####
# Retrieve a subset of the BINOCULAR_EYE_SAMPLE event attributes, for events that occurred
# between each time period defined by the TRIAL_START and TRIAL_END trial variables of each entry
# in the trial_conditions data table.
#
event_type = EventConstants.BINOCULAR_EYE_SAMPLE
retrieve_attributes = ('time', 'left_gaze_x', 'left_gaze_y',
                       'left_pupil_measure1', 'right_gaze_x', 'right_gaze_y',
                       'right_pupil_measure1', 'status')
trial_event_data = dataAccessUtil.getEventAttributeValues(
    event_type,
    retrieve_attributes,
    conditionVariablesFilter=None,
Beispiel #17
0
    def convertToText(self, dir, name, localtime):
        # Select the hdf5 file to process.
        #data_file_path= displayDataFileSelectionDialog(psychopy.iohub.module_directory(writeOutputFileHeader))
        print(' this is dir')
        print(dir)
        data_file_path = dir + '\events.hdf5'
        if data_file_path is None:
            print("File Selection Cancelled, exiting...")
            sys.exit(0)
        dpath, dfile = os.path.split(data_file_path)
        print('dpath')
        print(dpath)
        print('dfile')
        print(dfile)
        # Lets time how long processing takes
        #
        start_time = getTime()

        # Create an instance of the ExperimentDataAccessUtility class
        # for the selected DataStore file. This allows us to access data
        # in the file based on Device Event names and attributes, as well
        # as access the experiment session metadata saved with each session run.
        dataAccessUtil = ExperimentDataAccessUtility(dpath,
                                                     dfile,
                                                     experimentCode=None,
                                                     sessionCodes=[])
        print('this is dataaccessutil:')
        print(dataAccessUtil)

        # Get a dict of all event types -> DataStore table info
        #   for the selected DataStore file.
        eventTableMappings = dataAccessUtil.getEventMappingInformation()

        # Get event tables that have data...
        #
        events_with_data = dataAccessUtil.getEventsByType()

        duration = getTime() - start_time

        # Select which event table to output by displaying a list of
        #   Event Class Names that have data available to the user...
        #event_class_selection=displayEventTableSelectionDialog("Select Event Type to Save", "Event Type:",
        #            [eventTableMappings[event_id].class_name for event_id in events_with_data.keys()])
        event_class_selection = 'BinocularEyeSampleEvent'
        print('event_class_selection')
        print(event_class_selection)
        if event_class_selection == None:
            print("Event table Selection Cancelled, exiting...")
            dataAccessUtil.close()
            sys.exit(0)

        # restart processing time calculation...
        #
        start_time = getTime()

        # Lookup the correct event iterator fiven the event class name selected.
        #
        event_iterator_for_output = []
        for event_id, mapping_info in eventTableMappings.items():
            if mapping_info.class_name == event_class_selection:
                event_iterator_for_output = events_with_data[event_id]
                break

        # Read the session metadata table for all sessions saved to the file.
        #
        session_metadata = dataAccessUtil.getSessionMetaData()

        print('this is dataaccessutil getsession metadata')
        print(session_metadata)
        sesion_meta_data_dict = dict()

        # Create a session_id -> session metadata mapping for use during
        # file writing.
        #
        session_metadata_columns = []
        if len(session_metadata):
            session_metadata_columns = list(session_metadata[0]._fields[:-1])
            session_uservar_columns = list(
                session_metadata[0].user_variables.keys())
            for s in session_metadata:
                sesion_meta_data_dict[s.session_id] = s

        # Open a file to save the tab delimited ouput to.
        #
        #log_file_name="%s.%s.txt"%(dfile[:-5],event_class_selection)
        log_file_name = name + '_EyeSample' + localtime + '.txt'
        with open(dir + '\\Exp Results\\' + log_file_name, 'w') as output_file:

            # write column header
            #
            writeOutputFileHeader(
                output_file, session_metadata_columns,
                dataAccessUtil.getEventTable(
                    event_class_selection).cols._v_colnames[3:])

            print('Writing Data to %s:\n' % (dir + log_file_name)),
            i = 0
            for i, event in enumerate(event_iterator_for_output):
                # write out each row of the event data with session
                # data as prepended columns.....
                #
                writeDataRow(output_file,
                             sesion_meta_data_dict[event['session_id']],
                             session_uservar_columns, event[:][3:])

                if i % 100 == 0: print('.'),

        duration = duration + (getTime() - start_time)
        #print
        print(
            '\nOutput Complete. %d Events Saved to %s in %.3f seconds (%.2f events/seconds).\n'
            % (i, log_file_name, duration, i / duration))
        print('%s will be in the same directory as the selected .hdf5 file' %
              (log_file_name))
Beispiel #18
0
    data_file_path= displayDataFileSelectionDialog(psychopy.iohub.module_directory(writeOutputFileHeader))
    if data_file_path is None:
        print("File Selection Cancelled, exiting...")
        sys.exit(0)
    data_file_path = data_file_path[0]
    dpath,dfile=os.path.split(data_file_path)

    # Lets time how long processing takes
    #
    start_time=getTime()

    # Create an instance of the ExperimentDataAccessUtility class
    # for the selected DataStore file. This allows us to access data
    # in the file based on Device Event names and attributes, as well
    # as access the experiment session metadata saved with each session run.
    dataAccessUtil=ExperimentDataAccessUtility(dpath,dfile, experimentCode=None,sessionCodes=[])

    # Get a dict of all event types -> DataStore table info
    #   for the selected DataStore file.
    eventTableMappings=dataAccessUtil.getEventMappingInformation()

    # Get event tables that have data...
    #
    events_with_data=dataAccessUtil.getEventsByType()

    duration=getTime()-start_time
    # Select which event table to output by displaying a list of
    #   Event Class Names that have data available to the user...
    event_class_selection=displayEventTableSelectionDialog("Select Event Type to Save", "Event Type:",
                [eventTableMappings[event_id].class_name.decode('utf-8') for event_id in list(events_with_data.keys())])
    if event_class_selection is None:
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility

# Create an instance of the ExperimentDataAccessUtility class
# for the selected DataStore file. This allows us to access data
# in the file based on Device Event names and attributes.
#
experiment_data = ExperimentDataAccessUtility('.\hdf5_files', 'events.hdf5')

# Print the HDF5 Structure for the given ioDataStore file.
#
experiment_data.printHubFileStructure()

# Close the HDF5 File
#
experiment_data.close()
def createTrialDataStreams():
    trial_data_streams=[]

    # Get the filtered event data.
    # We will use right eye data only for the testing..
    #
    dataAccessUtil=ExperimentDataAccessUtility('../hdf5_files','remote_data.hdf5', 
                                           experimentCode=None,sessionCodes=[])

    event_type=EventConstants.BINOCULAR_EYE_SAMPLE
    retrieve_attributes=('time','right_gaze_x','right_gaze_y','right_pupil_measure1','status')
    trial_event_data=dataAccessUtil.getEventAttributeValues(event_type,
                retrieve_attributes,
                conditionVariablesFilter=None,
                startConditions={'time':('>=','@TRIAL_START@')},
                endConditions={'time':('<=','@TRIAL_END@')},
                )
 
    dataAccessUtil.close()
    
    for t,trial_data in enumerate(trial_event_data):
        #Create a mask to be used to define periods of missing data in a data trace (eye tracker dependent)
        #
        invalid_data_mask=trial_data.status%10>=2
        
        time=trial_data.time
        pupil=trial_data.right_pupil_measure1
        # Get x, y eye position traces (in pixels), setting sample positions where there is track loss
        # to NaN.
        xpix_cleared=trial_data.right_gaze_x.copy()
        ypix_cleared=trial_data.right_gaze_y.copy()
        processSampleEventGaps(xpix_cleared,ypix_cleared,pupil,invalid_data_mask,'clear')
    
        # Get x, y eye position traces (in pixels), setting sample positions 
        # where there is track loss to be linearly interpolated using each 
        # missing_sample_start-1 and missing_sample_end+1 as the points to
        # interpolate between.
        #
        xpix_linear=trial_data.right_gaze_x.copy()
        ypix_linear=trial_data.right_gaze_y.copy()
    
        # valid_data_periods is a list of array slice objects giving the start,end index of each non missing 
        # period of in the data stream.
        #
        valid_data_periods=processSampleEventGaps(xpix_linear,ypix_linear,pupil,invalid_data_mask,'linear')
     
        # Convert from pixels to visual angle coordinates
        calibration_area_info=dict(display_size_mm=(340,280.0),
                           display_res_pix=(1280.0,1024.0),
                           eye_distance_mm=590.0)
        vac=VisualAngleCalc(**calibration_area_info)      
        xdeg,ydeg=vac.pix2deg(xpix_linear,ypix_linear)
    
        # Create Filtered versions of the x and y degree data traces
        # We'll use the Median Filter...
        #
        xdeg_filtered = scipy.signal.medfilt(xdeg,SPATIAL_FILTER_WINDOW_SIZE)
        ydeg_filtered = scipy.signal.medfilt(ydeg,SPATIAL_FILTER_WINDOW_SIZE)
        
        # Create the velocity stream
        #
        xvel=calculateVelocity(time,xdeg_filtered)
        yvel=calculateVelocity(time,ydeg_filtered)

        # Filter the velocity data
        #
        FILTER_ORDER=2
        Wn=0.3
        b, a = scipy.signal.butter(FILTER_ORDER, Wn, 'low')
        ffunc=scipy.signal.filtfilt
        xvel_filtered = ffunc(b, a, xvel)
        yvel_filtered = ffunc(b, a, yvel)

#        xvel_filtered=savitzky_golay(xvel,window_size=VELOCITY_FILTER_WINDOW_SIZE,order=2)
#        yvel_filtered=savitzky_golay(yvel,window_size=VELOCITY_FILTER_WINDOW_SIZE,order=2)
#        xvel_filtered=gaussian_filter1d(xvel,VELOCITY_FILTER_WINDOW_SIZE)
#        yvel_filtered=gaussian_filter1d(yvel,VELOCITY_FILTER_WINDOW_SIZE)
#        xvel_filtered=scipy.signal.medfilt(xvel,VELOCITY_FILTER_WINDOW_SIZE)
#        yvel_filtered=scipy.signal.medfilt(yvel,VELOCITY_FILTER_WINDOW_SIZE)

        velocity=np.sqrt(xvel*xvel+yvel*yvel)
        velocity_filtered=np.sqrt(xvel_filtered*xvel_filtered+yvel_filtered*yvel_filtered)

        # Create a data trace dictionary for all the different types
        #  of data traces created for the trial
        #
        trial_data={}
        trial_data['time']=time
        trial_data['xpix_cleared']=xpix_cleared
        trial_data['ypix_cleared']=ypix_cleared
        trial_data['xpix_linear']=xpix_linear
        trial_data['xpix_linear']=xpix_linear
        trial_data['xdeg']=xdeg
        trial_data['ydeg']=ydeg
        trial_data['xdeg_filtered']=xdeg_filtered
        trial_data['ydeg_filtered']=ydeg_filtered
        trial_data['pupil']=pupil
        trial_data['velocity']=velocity
        trial_data['velocity_filtered']=velocity_filtered
        trial_data['valid_data_periods']=valid_data_periods
        trial_data['missing_data_mask']=invalid_data_mask
        # Add the data trace dictionary to a list
        #
        trial_data_streams.append(trial_data)
    return trial_data_streams
from psychopy.iohub.datastore.util import ExperimentDataAccessUtility         

# Create an instance of the ExperimentDataAccessUtility class
# for the selected DataStore file. This allows us to access data
# in the file based on Device Event names and attributes.
#
experiment_data=ExperimentDataAccessUtility('.\hdf5_files' , 'events.hdf5')

# Print the HDF5 Structure for the given ioDataStore file.
#
experiment_data.printHubFileStructure()

# Close the HDF5 File
#
experiment_data.close()