Пример #1
0
def detect_saccades(orientations, timestep):
    orientations = orientations[~numpy.isnan(orientations)]

    unwrappedOrientations = numpy.unwrap(orientations, 180)
    SMOOTH_TIME = 1
    smoothWindow = int(round(SMOOTH_TIME / timestep))
    smoothedOrientations = tools.smooth(unwrappedOrientations, smoothWindow)
    angSpds = abs(numpy.diff(smoothedOrientations)) / timestep
    MIN_PEAK_SPD = 30
    sacInds = tools.local_minima(-angSpds) & (angSpds > MIN_PEAK_SPD)
    sacSpds = angSpds[sacInds]

    MIN_SAC_SPD = 5
    inSac = angSpds > MIN_SAC_SPD
    startInds = pylab.find(numpy.diff(inSac.view(dtype=int8)) == 1)
    stopInds = pylab.find(numpy.diff(inSac.view(dtype=int8)) == -1)
    if stopInds[-1] < startInds[-1]:
        l = stopInds.tolist()
        l.append(len(inSac) - 1)
        stopInds = numpy.array(l)
    if startInds[0] > stopInds[0]:
        l = startInds.tolist()
        l.insert(0, 0)
        startInds = numpy.array(l)

    angDisp = numpy.zeros(len(angSpds))
    for i, startInd in enumerate(startInds):
        stopInd = stopInds[i]
        angDisp[startInd:stopInd] = smoothedOrientations[stopInd] - smoothedOrientations[startInd]

    sacAmps = angDisp[sacInds]
    return sacAmps
Пример #2
0
    def mapper(self, _, line):
        """ The mapper loads a track and yields its ramp factor """
        t = track.load_track(line)
        segments = t['segments']
        duration = t['duration']
        xdata = []
        ydata = []
        for i in xrange(len(segments)):
            seg = segments[i]
            sloudness = seg['loudness_max']
            sstart = seg['start'] + seg['loudness_max_time']
            xdata.append( sstart )
            ydata.append( sloudness )

        if duration > 20:
            idata = tools.interpolate(xdata, ydata, int(duration) * 10)
            smooth = tools.smooth(idata, 20)
            samp = tools.sample(smooth, self.SIZE)
            ndata = tools.rnormalize(samp, -60, 0)
            if self.DUMP:
                for i, (x, y) in enumerate(zip(self.MATCH, ndata)):
                    print i, x, y
            if self.VECTOR:
                yield (t['artist_name'], t['title'], t['track_id']), ndata
            else:
                distance = tools.distance(self.MATCH, ndata)
                yield (t['artist_name'], t['title'], t['track_id']), distance
Пример #3
0
    def mapper(self, _, line):
        """ The mapper loads a track and yields its ramp factor """
        t = track.load_track(line)
        segments = t['segments']
        duration = t['duration']
        xdata = []
        ydata = []
        for i in xrange(len(segments)):
            seg = segments[i]
            sloudness = seg['loudness_max']
            sstart = seg['start'] + seg['loudness_max_time']
            xdata.append(sstart)
            ydata.append(sloudness)

        if duration > 20:
            idata = tools.interpolate(xdata, ydata, int(duration) * 10)
            smooth = tools.smooth(idata, 20)
            samp = tools.sample(smooth, self.SIZE)
            ndata = tools.rnormalize(samp, -60, 0)
            if self.DUMP:
                for i, (x, y) in enumerate(zip(self.MATCH, ndata)):
                    print i, x, y
            if self.VECTOR:
                yield (t['artist_name'], t['title'], t['track_id']), ndata
            else:
                distance = tools.distance(self.MATCH, ndata)
                yield (t['artist_name'], t['title'], t['track_id']), distance
Пример #4
0
def get_normals(clines, lat, lon, ktop, kbot):

    # Smooth coastline
    window_len = 21
    clines2 = np.zeros((clines.shape[0], clines.shape[1]))
    for k in range(clines.shape[0]):
        tmp = tools.smooth(clines[k, :], window_len, "flat")
        clines2[k, :] = 1 * tmp[np.int64(window_len / 2 -
                                         1):np.int64(clines.shape[1] +
                                                     window_len / 2 - 1)]

    tangent = np.ones((clines.shape[0], clines.shape[1], 2))
    normal = np.ones((clines.shape[0], clines.shape[1], 2))
    for j in range(0, clines.shape[1] - 1):
        # the tangent component points northward
        # the normal component points towards the coast!!!
        tangent[:, j, 0] = 9900  # ty
        tangent[:, j, 1] = 10855 * (-clines2[:, j + 1] + clines2[:, j])  # tx
        normal[:, j, 0] = -1 * tangent[:, j, 1]  # ny
        normal[:, j, 1] = 1 * tangent[:, j, 0]  # nx

    #tangent[:,0,0] = 1*tangent[:,1,0]
    #tangent[:,0,1] = 1*tangent[:,1,1]
    tangent[:, clines.shape[1] - 1, 0] = 1 * tangent[:, clines.shape[1] - 2, 0]
    tangent[:, clines.shape[1] - 1, 1] = 1 * tangent[:, clines.shape[1] - 2, 1]

    #normal[:,0,0] = 1*normal[:,1,0]
    #normal[:,0,1] = 1*normal[:,1,1]
    normal[:, clines.shape[1] - 1, 0] = 1 * normal[:, clines.shape[1] - 2, 0]
    normal[:, clines.shape[1] - 1, 1] = 1 * normal[:, clines.shape[1] - 2, 1]

    #tangent_ = tangent.copy()

    # Normalize Vectors
    normal_ = np.zeros((normal.shape))
    tangent_ = np.zeros((tangent.shape))

    for j in range(clines.shape[1]):
        normal_[:, j, 0] = 1 * normal[:, j, 0] / np.sqrt(
            normal[:, j, 1] * normal[:, j, 1] +
            normal[:, j, 0] * normal[:, j, 0])
        normal_[:, j, 1] = 1 * normal[:, j, 1] / np.sqrt(
            normal[:, j, 1] * normal[:, j, 1] +
            normal[:, j, 0] * normal[:, j, 0])
        tangent_[:, j, 0] = 1 * tangent[:, j, 0] / np.sqrt(
            tangent[:, j, 1] * tangent[:, j, 1] +
            tangent[:, j, 0] * tangent[:, j, 0])
        tangent_[:, j, 1] = 1 * tangent[:, j, 1] / np.sqrt(
            tangent[:, j, 1] * tangent[:, j, 1] +
            tangent[:, j, 0] * tangent[:, j, 0])

    return tangent_, normal_
Пример #5
0
def detect_saccades0(orientations, timestep):
    orientations = orientations[~numpy.isnan(orientations)]

    unwrappedOrientations = numpy.unwrap(orientations, 180)
    SMOOTH_TIME = 0.5
    smoothWindow = int(round(SMOOTH_TIME / timestep))
    smoothedOrientations = tools.smooth(unwrappedOrientations, smoothWindow)
    angSpds = abs(numpy.diff(smoothedOrientations)) / timestep
    sacInds = tools.local_minima(-angSpds) & (angSpds > 10)
    saccades = angSpds[sacInds]
    # sacs = tools.zigzag(smoothedOrientations)
    # sacInds = abs(sacs) > 10
    # saccades = sacs[sacInds]
    return saccades
Пример #6
0
def new_change_times(sky):
    """record new change times
    
    arguments:      
    sky     sky dict
    """
    pylab.figure()
    pylab.plot(sky['times'],tools.smooth(sky['pixelMeans'],100))
    pylab.draw()
    pylab.title('click on points, center click when done')
    pylab.hold('on')
    pts = pylab.ginput(0,timeout=0)
    changeTimes = [pt[0] for pt in pts]
    y = [pt[1] for pt in pts]
    directions = []
    for cT in changeTimes:
        directions.append(input('direction after rotation at '+time.ctime(cT)+' '))
    sky['changeTimes'] = changeTimes
    sky['directions'] = directions
    return sky
	if cline_x[y] >= tmp:
		u_x.append(cline_x[y])
		u_y.append(cline_y[y])

for y in range(301,851):
	u_x.append(cline_x[y])
	u_y.append(cline_y[y])

u_p = interp1d(u_y,u_x, kind = 'cubic',bounds_error = False, fill_value=0.0)

for y in range(len(cline_x)):
    q_u[y] = u_p(cline_y[y])

window_len = 71

tmp = tools.smooth(q_u,window_len,"hanning")
smooth_x= tmp[window_len/2-1:cline_x.shape[0]+window_len/2-1]

smooth_x = np.around(smooth_x)
smooth_x = np.int64(smooth_x) # Now contains the x-positions of the coastline as integer

clines = np.zeros((60,851)) # 60 clines, because the first 20 are not considered
clines[0,:] = smooth_x

## NOW go on finding the other coastline, starting from smooth_x
coastlines = np.zeros((60,var.shape[0],var.shape[1]))
coastlines_ = np.zeros((60,var.shape[0],var.shape[1]))

for k in range(21,80):
#for k in range(20,80):
	var = vke[k,:,:].copy()
Пример #8
0
def get_normals_sophisticated(clines, lat, lon):
    clines_lat_ = np.zeros((60, clines.shape[1]))
    clines_lon_ = np.zeros((60, clines.shape[1]))
    clines_lat = np.zeros((60, clines.shape[1]))
    clines_lon = np.zeros((60, clines.shape[1]))

    for k in range(clines.shape[0]):
        for j in range(clines.shape[1]):
            clines_lat_[k, j] = lat[j, np.int64(clines[k, j])]
            clines_lon_[k, j] = lon[j, np.int64(clines[k, j])]

    # Smooth coastline
    window_len = 31
    for k in range(clines.shape[0]):
        tmp = tools.smooth(clines_lat_[k, :], window_len, "flat")
        clines_lat[k, :] = tmp[np.int64(window_len / 2 -
                                        1):np.int64(clines_lat_.shape[1] +
                                                    window_len / 2 - 1)]

        tmp = tools.smooth(clines_lon_[k, :], window_len, "flat")
        clines_lon[k, :] = tmp[np.int64(window_len / 2 -
                                        1):np.int64(clines_lon_.shape[1] +
                                                    window_len / 2 - 1)]

    tangent = np.ones((60, clines.shape[1], 2))
    normal = np.ones((60, clines.shape[1], 2))
    for j in range(1, clines.shape[1] - 1):
        tangent[:, j, 0] = -clines_lat[:, j + 1] + clines_lat[:, j]  # ty
        tangent[:, j, 1] = -clines_lon[:, j + 1] + clines_lon[:, j]  # tx
        normal[:, j, 0] = -tangent[:, j, 1]  # ny
        normal[:, j, 1] = tangent[:, j, 0]  # nx

    tangent[:, 0, 0] = tangent[:, 1, 0]
    tangent[:, 0, 1] = tangent[:, 1, 1]
    tangent[:, clines.shape[1] - 1, 0] = tangent[:, clines.shape[1] - 2, 0]
    tangent[:, clines.shape[1] - 1, 1] = tangent[:, clines.shape[1] - 2, 1]

    normal[:, 0, 0] = normal[:, 1, 0]
    normal[:, 0, 1] = normal[:, 1, 1]
    normal[:, clines.shape[1] - 1, 0] = normal[:, clines.shape[1] - 2, 0]
    normal[:, clines.shape[1] - 1, 1] = normal[:, clines.shape[1] - 2, 1]

    # Normalize Vectors
    normal_ = np.zeros((normal.shape))
    tangent_ = np.zeros((tangent.shape))

    for j in range(clines.shape[1]):
        normal_[:, j, 0] = 1 * normal[:, j, 0] / np.sqrt(
            normal[:, j, 1] * normal[:, j, 1] +
            normal[:, j, 0] * normal[:, j, 0])
        normal_[:, j, 1] = 1 * normal[:, j, 1] / np.sqrt(
            normal[:, j, 1] * normal[:, j, 1] +
            normal[:, j, 0] * normal[:, j, 0])
        tangent_[:, j, 0] = 1 * tangent[:, j, 0] / np.sqrt(
            tangent[:, j, 1] * tangent[:, j, 1] +
            tangent[:, j, 0] * tangent[:, j, 0])
        tangent_[:, j, 1] = 1 * tangent[:, j, 1] / np.sqrt(
            tangent[:, j, 1] * tangent[:, j, 1] +
            tangent[:, j, 0] * tangent[:, j, 0])

    return tangent_, normal_
Пример #9
0
def get_normals_dd(lat, lon, ktop, kbot, uko2, vke2):

    maxpos = np.zeros((kbot - ktop, uko2.shape[1]))
    tmp = vke2**2 + uko2**2
    for k in range(0, 18):
        ik = k + ktop
        for j in range(uko2.shape[1]):
            tmp1 = tmp[ik, j, :].max()
            tmp2 = np.where(tmp[ik, j, :] == tmp1)[0]
            maxpos[k, j] = 1 * tmp2[0]

    for k in range(18, kbot - ktop):
        maxpos[k, :] = 1 * maxpos[17, :]

    clines = 1 * maxpos
    # Smooth coastline
    window_len = 5
    clines2 = np.zeros((clines.shape[0], clines.shape[1]))
    for k in range(clines.shape[0]):
        tmp = tools.smooth(clines[k, :], window_len, "flat")
        clines2[k, :] = 1 * tmp[np.int64(window_len / 2 -
                                         1):np.int64(clines.shape[1] +
                                                     window_len / 2 - 1)]

    #clines2 = 1*clines

    tangent = np.ones((kbot - ktop, clines.shape[1], 2))
    normal = np.ones((kbot - ktop, clines.shape[1], 2))
    for j in range(0, clines.shape[1] - 1):
        # the tangent component points northward
        # the normal component points towards the coast!!!
        tangent[:, j, 0] = 9900  # ty
        tangent[:, j, 1] = 10855 * (-clines2[:, j + 1] + clines2[:, j])  # tx
        normal[:, j, 0] = -1 * tangent[:, j, 1]  # ny
        normal[:, j, 1] = 1 * tangent[:, j, 0]  # nx

    #tangent[:,0,0] = 1*tangent[:,1,0]
    #tangent[:,0,1] = 1*tangent[:,1,1]
    tangent[:, clines.shape[1] - 1, 0] = 1 * tangent[:, clines.shape[1] - 2, 0]
    tangent[:, clines.shape[1] - 1, 1] = 1 * tangent[:, clines.shape[1] - 2, 1]

    #normal[:,0,0] = 1*normal[:,1,0]
    #normal[:,0,1] = 1*normal[:,1,1]
    normal[:, clines.shape[1] - 1, 0] = 1 * normal[:, clines.shape[1] - 2, 0]
    normal[:, clines.shape[1] - 1, 1] = 1 * normal[:, clines.shape[1] - 2, 1]

    #tangent_ = tangent.copy()

    # Normalize Vectors
    normal_ = np.zeros((normal.shape))
    tangent_ = np.zeros((tangent.shape))

    for j in range(clines.shape[1]):
        normal_[:, j, 0] = 1 * normal[:, j, 0] / np.sqrt(
            normal[:, j, 1] * normal[:, j, 1] +
            normal[:, j, 0] * normal[:, j, 0])
        normal_[:, j, 1] = 1 * normal[:, j, 1] / np.sqrt(
            normal[:, j, 1] * normal[:, j, 1] +
            normal[:, j, 0] * normal[:, j, 0])
        tangent_[:, j, 0] = 1 * tangent[:, j, 0] / np.sqrt(
            tangent[:, j, 1] * tangent[:, j, 1] +
            tangent[:, j, 0] * tangent[:, j, 0])
        tangent_[:, j, 1] = 1 * tangent[:, j, 1] / np.sqrt(
            tangent[:, j, 1] * tangent[:, j, 1] +
            tangent[:, j, 0] * tangent[:, j, 0])

    return tangent_, normal_
import tools

data_dir = "/home/cs4li/Dev/end_to_end_visual_odometry/results/trajectory_results_1/"

losses_to_overlay = [
    (data_dir + "run_results_trajectory_results_1-tag-se3_losses.csv", {"linewidth": 1.0, "color": "r"}, "Training Loss"),
    (data_dir + "run_results_trajectory_results_1-tag-se3_losses_val.csv", {"linewidth": 1.0, "color": "b"}, "Validation Loss")
]

plt.figure(1)

loss_to_draw = losses_to_overlay[0]
data = np.loadtxt(loss_to_draw[0], skiprows=1, delimiter=",")
x = data[:, 1] / 797
y = data[:, 2]
y = tools.smooth(y, window_len=2000, window="hanning")
plt.plot(x, y[0: len(x)], **loss_to_draw[1], label=loss_to_draw[2])

loss_to_draw = losses_to_overlay[1]
data = np.loadtxt(loss_to_draw[0], skiprows=1, delimiter=",")
x = data[:, 1] / 24
y = data[:, 2]
y = tools.smooth(y, window_len=100, window="hanning")
plt.plot(x, y[0: len(x)], **loss_to_draw[1], label=loss_to_draw[2])

plt.xlabel("epochs")
plt.ylabel("SE(3) losses")
plt.ylim(0, 0.1)
plt.xlim(0, 151)
plt.title("SE(3) Training and Validation Losses")
plt.legend()
Пример #11
0
def analyze_directory(dirName):
    """pixel mean analysis
    
    arguments:      
    dirName     directory path to analyze
    
    example:
    analyze_directory('/home/cardini/data/fly07/')
    """ 
    filenames = os.listdir(dirName)
    skyFilenames = [f for f in filenames if f[:3] == 'sky' and f[-3:] == 'fmf']    
    skyFilenames.sort(compare_file_times)
    annotationFileExists = False
    for f, filename in enumerate(filenames):
        if filename[-4:] == '.txt':
            annotationFileExists = True
            annotationFilename = filename
        elif filename[:4] == 'aSky' and filename[-3:] == 'pkl': # not sure which will choose if >1 pkl file
            inPklFile = open(os.path.join(dirName,filename), 'rb')
            sky = pickle.load(inPklFile)
            inPklFile.close()
            break
    
    else:
        sky = {}
        if annotationFileExists:
            changeTimes, directions, stopStartTimes = read_annotation_file(os.path.join(dirName,annotationFilename))
            sky['dirName'], sky['fileName'] = dirName, filename
            sky['stopStartTimes']=stopStartTimes
            sky['changeTimes']=changeTimes
            sky['directions']=directions
        elif skyFilenames==[]:
            print 'no sky filenames'
            flyFilenames = [f for f in filenames if f[:3] == 'fly' and f[-3:] == 'fmf']
            flyFilenames.sort(compare_file_times)
            for f, filename in enumerate(flyFilenames):
                fmf = FMF.FlyMovie(os.path.join(dirName,filename))
                timestamps = fmf.get_all_timestamps()
                sky['dirName'], sky['fileName'] = dirName, filename
                sky['times'] = timestamps
                sky['changeTimes'] = []
                sky['directions'] = []
        else:
            for f, filename in enumerate(skyFilenames):
                pixelStats = get_pixel_stats(os.path.join(dirName,filename),1)
                pylab.figure()
                pylab.plot(pixelStats.t,tools.smooth(pixelStats.m,100))
                pylab.draw()
                pylab.title('click on points, center click when done')
                pylab.hold('on')
                pylab.plot(pixelStats.t,tools.smooth(pixelStats.s,100))
                pts = pylab.ginput(0,timeout=0)
                changeTimes = [pt[0] for pt in pts]
                y = [pt[1] for pt in pts]
                directions = []
                for cT in changeTimes:
                    directions.append(input('direction after rotation at '+time.ctime(cT)+' '))
                sky['dirName'], sky['fileName'] = dirName,filename
                sky['pixelMeans'] = pixelStats.m
                sky['pixelStds'] = pixelStats.s
                sky['times'] = pixelStats.t
                sky['changeTimes'] = changeTimes
                sky['directions'] = directions
        date_time = time.strftime("%Y%m%d_%H%M%S")
        pklFilename = 'aSky'+ date_time +'.pkl'
        sky['pklFileName'] = pklFilename
        outPklFile = open(os.path.join(dirName,pklFilename), 'wb')
        pickle.dump(sky, outPklFile)
        outPklFile.close()
    return sky