示例#1
0
    def read_all_data(self, all_file):
        """Returns a list of "Datapoint"s read from an data file.

        Args:
            all_file:A string containing the name of the data file output by the Tobii software.

        Returns:
            a list of "Datapoint"s
        """
        all_data = []
        with open(all_file, 'r') as f:
            reader = csv.DictReader(f, delimiter="\t")
            last_pupil_left = -1
            last_pupil_right = -1
            last_time = -1

            for row in reader:
                if row["MediaName"] != 'ScreenRec':  # ignore non-recording data point
                    continue
                if not row["ValidityLeft"] or not row[
                        "ValidityRight"]:  #ignore data point with no validity information
                    continue
                pupil_left = EMDAT_core.utils.cast_float(row["PupilLeft"], -1)
                pupil_right = EMDAT_core.utils.cast_float(
                    row["PupilRight"], -1)
                distance_left = EMDAT_core.utils.cast_float(
                    row["DistanceLeft"], -1)
                distance_right = EMDAT_core.utils.cast_float(
                    row["DistanceRight"], -1)
                timestamp = EMDAT_core.utils.cast_int(
                    row["RecordingTimestamp"])
                data = {
                    "timestamp":
                    timestamp,
                    "pupilsize":
                    EMDAT_core.Recording.get_pupil_size(
                        pupil_left, pupil_right),
                    "pupilvelocity":
                    EMDAT_core.Recording.get_pupil_velocity(
                        last_pupil_left, last_pupil_right, pupil_left,
                        pupil_right, (timestamp - last_time)),
                    "distance":
                    EMDAT_core.Recording.get_distance(distance_left,
                                                      distance_right),
                    "is_valid":
                    EMDAT_core.utils.cast_int(row["ValidityRight"]) < 2
                    or EMDAT_core.utils.cast_int(row["ValidityLeft"]) < 2,
                    "stimuliname":
                    row["MediaName"],
                    "fixationindex":
                    EMDAT_core.utils.cast_int(row["FixationIndex"]),
                    "gazepointxleft":
                    EMDAT_core.utils.cast_float(row["GazePointLeftX (ADCSpx)"])
                }
                all_data.append(Datapoint(data))
                last_pupil_left = pupil_left
                last_pupil_right = pupil_right
                last_time = timestamp

        return all_data
示例#2
0
    def read_all_data(self, all_file):
        """Returns a list of "Datapoint"s read from an "All-Data" file.

        Args:
            all_file:A string containing the name of the 'All-Data.tsv' file output by the Tobii software.

        Returns:
            a list of "Datapoint"s
        """
        all_data = []
        with open(all_file, 'r') as f:
            for _ in xrange(params.ALLDATAHEADERLINES +
                            params.NUMBEROFEXTRAHEADERLINES - 1):
                next(f)
            reader = csv.DictReader(f, delimiter="\t")
            last_pupil_left = -1
            last_pupil_right = -1
            last_time = -1

            for row in reader:
                if not row["Number"]:  # ignore invalid data point
                    continue
                pupil_left = cast_float(row["PupilLeft"], -1)
                pupil_right = cast_float(row["PupilRight"], -1)
                distance_left = cast_float(row["DistanceLeft"], -1)
                distance_right = cast_float(row["DistanceRight"], -1)
                timestamp = cast_int(row["Timestamp"])
                data = {
                    "timestamp":
                    timestamp,
                    "pupilsize":
                    get_pupil_size(pupil_left, pupil_right),
                    "pupilvelocity":
                    get_pupil_velocity(last_pupil_left, last_pupil_right,
                                       pupil_left, pupil_right,
                                       (timestamp - last_time)),
                    "distance":
                    get_distance(distance_left, distance_right),
                    "is_valid":
                    cast_int(row["ValidityRight"]) < 2
                    or cast_int(row["ValidityLeft"]) < 2,
                    "stimuliname":
                    row["StimuliName"],
                    "fixationindex":
                    cast_int(row["FixationIndex"]),
                    "gazepointxleft":
                    cast_float(row["GazePointXLeft"])
                }
                all_data.append(Datapoint(data))
                last_pupil_left = pupil_left
                last_pupil_right = pupil_right
                last_time = timestamp

        return all_data
    def read_all_data(self, all_file):
        """Returns a list of "Datapoint"s read from an data file.

        Args:
            all_file:A string containing the name of the data file output by the Tobii software.

        Returns:
            a list of "Datapoint"s
        """
        all_data = []
        with open(all_file, 'r') as f:
            reader = csv.DictReader(f, delimiter=";")
            last_pupil_left = -1
            last_pupil_right = -1
            last_time = -1
            currentfix = 0
            for row in reader:
                if not row["left_gaze_origin_validity"] or not row["right_gaze_origin_validity"]: #ignore data point with no validity information
                    continue
                right_gaze = list(map(lambda point: EMDAT_core.utils.cast_float(point, -1),
                                      row["right_gaze_point_on_display_area"].strip("()").split(",")))
                left_gaze = list(map(lambda point: EMDAT_core.utils.cast_float(point, -1),
                                     row["left_gaze_point_on_display_area"].strip("()").split(",")))
                gaze_point_x = EMDAT_core.utils.cast_float((left_gaze[0] + right_gaze[0])/2, -1)
                gaze_point_y = EMDAT_core.utils.cast_float((left_gaze[1] + right_gaze[1])/2, -1)
                pupil_left = EMDAT_core.utils.cast_float(row["left_pupil_diameter"], -1)
                pupil_right = EMDAT_core.utils.cast_float(row["right_pupil_diameter"], -1)
                timestamp = EMDAT_core.utils.cast_int(EMDAT_core.utils.cast_float(row["system_time_stamp"]))
                data = {"timestamp": timestamp,
                        "pupilsize": EMDAT_core.Recording.get_pupil_size(pupil_left, pupil_right),
                        "pupilvelocity": EMDAT_core.Recording.get_pupil_velocity(last_pupil_left, last_pupil_right, pupil_left, pupil_right, (timestamp-last_time) ),
                        "distance": -1,
                        "is_valid": EMDAT_core.utils.cast_int(row["right_gaze_origin_validity"]) == 1 or EMDAT_core.utils.cast_int(row["left_gaze_origin_validity"]) == 1,
                        "is_valid_blink": EMDAT_core.utils.cast_int(row["right_gaze_origin_validity"]) == 1 and EMDAT_core.utils.cast_int(row["left_gaze_origin_validity"]) == 1,
                        "fixationindex": currentfix,
                        "gazepointx": gaze_point_x,
                        "gazepointy": gaze_point_y}
                all_data.append(Datapoint(data))
                last_pupil_left = pupil_left
                last_pupil_right = pupil_right
                last_time = timestamp
                currentfix += 1

        return all_data
示例#4
0
    def read_all_data(self, all_file):
        all_data = []
        with open(all_file, 'r') as f:
            for i in xrange(params.RAW_HEADER_LINE):
                if i is (params.RAW_HEADER_LINE - 1):  # read the row of the table header for fixations
                    data_header = next(f).strip().split(',')
                else:
                    next(f)
		
            reader = csv.DictReader(f, fieldnames=data_header)
            last_pupil_left = -1
            last_pupil_right = -1
            last_time = -1
			
            for row in reader:
                if row["L Event Info"] != "Fixation":  # ignore data points other than fixations (gaze points)
                    continue
                pupil_left = EMDAT_core.utils.cast_float(row["L Pupil Diameter [mm]"])
                pupil_right = EMDAT_core.utils.cast_float(row["R Pupil Diameter [mm]"])
                distance_left = EMDAT_core.utils.cast_float(row["L EPOS Z"], -1)
                distance_right = EMDAT_core.utils.cast_float(row["R EPOS Z"], -1)
                timestamp = EMDAT_core.utils.cast_int(row["Time"])
                data = {"timestamp": timestamp,
                        "pupilsize": EMDAT_core.Recording.get_pupil_size(pupil_left, pupil_right),
                        "pupilvelocity": EMDAT_core.Recording.get_pupil_velocity(last_pupil_left, last_pupil_right, pupil_left, pupil_right, (timestamp-last_time) ),
                        "distance": EMDAT_core.Recording.get_distance(distance_left, distance_right),
                        "is_valid": (EMDAT_core.utils.cast_float(row["L POR X [px]"], -1) > 0 and EMDAT_core.utils.cast_float(row["L POR Y [px]"], -1) > 0 )
                                              or (EMDAT_core.utils.cast_float(row["R POR X [px]"], -1) > 0 and EMDAT_core.utils.cast_float(row["R POR Y [px]"], -1) > 0),
                        "stimuliname": "Screen",  # temporarily set to the same stimuli
                        "fixationindex": EMDAT_core.utils.cast_int(row["Time"]),
                        "gazepointxleft": EMDAT_core.utils.cast_float(row["L POR X [px]"]),
                        "gazepointxlright": EMDAT_core.utils.cast_float(row["R POR X [px]"])}
                all_data.append(Datapoint(data))
                last_pupil_left = pupil_left
                last_pupil_right = pupil_right
                last_time = timestamp

        return all_data