예제 #1
0
def lineto (x1,y1,x2,y2,offset,samples,timeInterval):
	l = []
	t = (float(timeInterval) / float(samples))
	xv = (x2 - x1) / float(samples)
	yv = (y2 - y1) / float(samples)

	p = Sample(offset,timeInterval * offset,x1,y1)
	l.append(p)

	for i in range(0,samples):
		p = Sample(i+offset,timeInterval * (offset + i), p.x+xv, p.y+yv)
		l.append(p)
	
	return l
예제 #2
0
파일: test.py 프로젝트: sarmadm/eventdetect
def fixate(x, y, offset, samples, timeInterval):
    l = []

    for i in range(0, samples):
        p = Sample(i + offset, timeInterval * (offset + i), x, y)
        l.append(p)

    return l
예제 #3
0
def plot_IDT_thresh_results(df, window_sizes, threshes):

    try:
        fig, ax = plt.subplots(len(threshes),len(window_sizes), figsize=(4*len(window_sizes),4*len(threshes)))
    except:
        raise Exception("window_sizes and threshes must be larger than length 1")

    nrow = 0
    ncol = 0
    for window_size in window_sizes:
        for thresh in threshes:
            samples = [Sample(ind=i, time=df.time[i], x=df.x[i], y=df.y[i]) for i in range(len(df))]
            stream = ListSampleStream(samples)
            fixes = Dispersion(sampleStream = stream, windowSize = window_size, threshold = thresh)
            centers = []
            num_samples = []
            starts = []
            ends = []
            for f in fixes:
                centers.append(f.get_center())
                num_samples.append(f.get_num_samples())
                starts.append(f.get_start())
                ends.append(f.get_end())

            # label the fixations in the dataframe
            df['event'] = 'other'
            count = 0
            for i in range(len(starts)):
                df.loc[starts[i]:ends[i], ("event")] = 'fix'
                # if the end of the data is all fixations
                if i == len(starts)-1:
                    df.loc[starts[i]:len(starts), ("event")] = 'fix'
                # if there are only 1 or 2 samples between fixations, combine them
                elif starts[i+1]-ends[i] <= 2:
                    count += 1
                    df.loc[ends[i]:starts[i+1], ("event")] = 'fix'

            centers = np.array(centers)
            ax[nrow][ncol].scatter(df.x[df.event !='fix'], df.y[df.event!='fix'], s=0.5,label='other')
            ax[nrow][ncol].scatter(df.x[df.event =='fix'], df.y[df.event =='fix'], color='r', s=0.5, label='fix')
            # ax[nrow][ncol].scatter(df.x[df.event =='sac'], df.y[df.event =='sac'], color='orange', s=0.5, label='sac')
            # for i in range(len(centers)):
            #     plots.circle(centers[i], radius=num_samples[i]*0.5+10)
            #plt.scatter(centers[:,0], centers[:,1], c='None', edgecolors='r')
            ax[nrow][ncol].set_title('[I-DT] Window: '+str(window_size)+' Thresh: '+str(thresh))
            ax[nrow][ncol].set_xlabel('x pixel')
            ax[nrow][ncol].set_ylabel('y pixel')
            ax[nrow][ncol].legend()

            nrow += 1
        nrow = 0
        ncol += 1
    plt.legend()
    plt.show()
예제 #4
0
def label_fixes(df, eye, ws=0, thresh=0, method='IDT'):

    samples = [
        Sample(ind=i, time=df.time[i], x=df.x[i], y=df.y[i])
        for i in range(len(df))
    ]
    stream = ListSampleStream(samples)

    if method == 'IDT':
        fixes = Dispersion(sampleStream=stream,
                           windowSize=ws,
                           threshold=thresh)
    elif method == 'IVT':
        fixes = Velocity(sampleStream=IntersampleVelocity(stream),
                         threshold=thresh)
    else:
        raise Exception('method should be either "IDT" or "IVT"')

    centers = []
    num_samples = []
    starts = []
    ends = []
    for f in fixes:
        centers.append(f.get_center())
        num_samples.append(f.get_num_samples())
        starts.append(f.get_start())
        ends.append(f.get_end())
        #print(f)

    # label the fixations in the dataframe
    df['event'] = 'other'
    count = 0
    for i in range(len(starts)):
        df.loc[starts[i]:ends[i], ('event')] = 'fix'
        # if the end of the data is all fixations
        if i == len(starts) - 1:
            df.loc[starts[i]:len(starts), ('event')] = 'fix'
        # if there are only 1 or 2 samples between fixations, combine them
        elif starts[i + 1] - ends[i] <= 2:
            count += 1
            df.loc[ends[i]:starts[i + 1], ('event')] = 'fix'

    # plot classification
    plots.plot_vs_time(df, label='', eye=eye, classify=True, method=method)

    return df
예제 #5
0
# KEEP ROW ONLY WITH STIMULUS != 0
#index_zero_stimulus = degreesTb[degreesTb['current_stimulus'] == 0].index
#degreesTb.drop(index_zero_stimulus, inplace=True)
#print('-----------------------Done removing!----------------------')

# -----------------------DISPERSION ALGORITHM-----------------------
sampleFields = [
    'timestamp_milis', 'degrees_right_horizontal', 'degrees_right_vertical'
]
gazeSamples = []
stdFixations = []
# Store gaze sample data in 'Sample' format, i.e. {index, time, x, y}
for i in degreesTb.index:
    p = Sample(i, degreesTb.at[i, 'timestamp_milis'],
               degreesTb.at[i, 'new_degrees_RIGHT_horizontal_1'],
               degreesTb.at[i, 'new_degrees_LEFT_horizontal_1'])
    #p = Sample(i, degreesTb.at[i, 'timestamp_milis'], degreesTb.at[i, 'degrees_right_horizontal'], degreesTb.at[i, 'degrees_right_vertical'])
    gazeSamples.append(p)
    #print('this many')

# Dispersion algorithm:
windowSize = 10  #unit = samples
threshold = 1.5

#initialize Dispersion
stream = ListSampleStream(gazeSamples)
d = Dispersion(stream, windowSize, threshold)
print('before dispersion')
if True:
    Efixation = []
예제 #6
0
def saccto (x1,y1,x2,y2,offset,samples,timeInterval):
	""" Construct a fake saccade-like set of samples.
	
	    We work in polar coordinates, because it's easier.

	    We first compute the average velocity for half the displacement:
	    (i.e., to the mid-point)
	    v = 0.5r / t
	    Then acceleration:
	    a = 2v / t
	    Then we can iterate over the time range:
	    d(i) = (a * i) * interval
	"""
	l = []

	p = Sample(offset,timeInterval * offset,x1,y1)
	l.append(p)

	r = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
	theta = math.atan2(y2-y1, x2-x1)

	print "R: " + str(r) + " theta: " + str(theta)

	vAve = r / float(samples)

	print "vAve: " + str(vAve)

	a = (2*vAve) / float(samples / 2)

	v = 0
	xo = x1
	yo = y1

	for i in range(1,1 + (samples / 2)):
		v = v + a

		x = v * math.cos(theta)
		y = v * math.sin(theta)
		xo = xo + x
		yo = yo + y

		print "V: " + str(v / timeInterval)
	
		p = Sample(i+offset,timeInterval * (offset + i), xo, yo)
		l.append(p)
	
	# Reverse acceleration direction
	a = -a
	offset = offset + (samples / 2) + 1

	for i in range(0,(samples / 2)-1):
		v = v + a

		x = v * math.cos(theta)
		y = v * math.sin(theta)
		xo = xo + x
		yo = yo + y

		print "V: " + str(v)
		
		p = Sample(i+offset,timeInterval * (offset + i), xo, yo)
		l.append(p)

		
	
	return l
예제 #7
0
		
	
	return l

<<<<<<< HEAD
# Q: What's offset?
def fixate(x,y,offset,samples,timeInterval):
=======

def fixate (x,y,offset,samples,timeInterval):
>>>>>>> parent of e9456f2 (hmm)
	l = []

	for i in range(0,samples):
		p = Sample(i+offset,timeInterval * (offset + i), x, y)
		l.append(p)
	
	return l

testPath = fixate(250,250,0,49,0.001)
testPath.extend(saccto(250,250,550,550,50,100,0.001))
testPath.extend(fixate(550,550,151,99,0.001))
testPath.extend(saccto(550,550,350,150,251,99,0.001))
testPath.extend(fixate(350,150,251,49,0.001))

<<<<<<< HEAD
print("============= I-DT test ===============")
=======
print "============= I-DT test ==============="
>>>>>>> parent of e9456f2 (hmm)