def whenSelected():

    if getSelection():
        if pcol.get() or p3d.get():
            if (checkValidInt(sf, 0) and checkValidInt(ws, 1)
                    and checkValidInt(ch, 2) and checkBandPass(hi, lo)):
                for file in files:
                    freqs, time, data = stft.main(params, file)
                    #                    print(data.shape)
                    if pcol.get():
                        plotting.plotPColor(data, file, params[2], freqs, time)
                    if p3d.get():
                        plotting.plot3D(data, file, params[2], freqs, time)
        else:
            mbox.showerror("No graph type selected", errors[-1])
示例#2
0
# if(constants.URL.__contains__('sonar')) :
#     best_fitness = output(best_fitness)

# print("BEST FITNESS ::",output(best_fitness))
print("BEST FITNESS ::", (best_fitness))

print("labelled :: \n", labelled)

##############################

####   FMEASURE
if (constants.URL.__contains__('ionosphere')
        or constants.URL.__contains__('iris')
        or constants.URL.__contains__('wine')
        or constants.URL.__contains__('parkinsons')
        or constants.URL.__contains__('sonar')
        or constants.URL.__contains__('segmentation')
        or constants.URL.__contains__('glass')):
    # classdata = pd.read_csv(constants.cURL)
    classdata = np.array(y_dataset_glob)
    #print(classdata)
    fmeasure(labelled, classdata)
##############################

if constants.URL.__contains__('random2'):
    plot2D(got_back[best_index], pop_distri)

if constants.URL.__contains__('random3'):
    plot3D(got_back[best_index], pop_distri)
示例#3
0
    bkgTauMin, bkgAMin, sortedTimes,
    meanSigma)  #Calculating pdf function with background
area2 = trapz(pdf2,
              sortedTimes)  #Calculating area of new pdf using trapezium rule
#Calculating errors
TauAErrors = minim.bkgError(bkgTaus, bkgAs, bkgTauMin, bkgAMin, bkgNllMin,
                            funcs.bkgNll)
meanTauError = np.mean([TauAErrors[0], TauAErrors[1]])
meanAError = np.mean([TauAErrors[2], TauAErrors[3]])

### CREATING AND DISPLAYING PLOTS ###
pt.plotContour(bkgTaus,
               bkgAs,
               funcs.bkgNll,
               levels=np.arange(bkgNllMin + 0.5, bkgNllMin + 0.5 + 100, 10))
pt.plot3D(bkgTaus, bkgAs, funcs.bkgNll)
intersect, m, c = pt.plotErrorsVSReadings(sizes, sizeErrors)
pt.plotNLL(taus, likelihoods, tauMin, nllMin)
pt.plotHist(times, bins=100, sortedTimes=sortedTimes, pdfs=[pdf, pdf2])

### PRINTING RESULTS ###
print "Area under initial PDF (without background):", area
print "Area under refined PDF (with background):", area2
print "NLL at Minimum 1D:", nllMin
print "Tau at Minimum 1D:", tauMin, "picoseconds"
print "Positive Tau Error 1D:", posError, "picoseconds"
print "Negative Tau Error 1D:", negError, "picoseconds"
print "Mean Tau Error 1D:", meanError, "picoseconds"
print "Last Parabolic Estimate Error of Tau:", parabError, "picoseconds"
print "Intersect of extrapolation of gradient", m, "and intercept", c, "gives approximately", int(
    10**intersect[0]), "readings required for accuracy of 0.001ps"
示例#4
0
 def test_plot3d(self):
     data = dict([(i, dict([(j, random.random()) for j in range(10)]))
                  for i in range(5)])
     plot3D(data)
     plt.show()
示例#5
0
labelled = fitness.get_pop_distri_label(file, centroid, constants.K)

print("labelled :: \n", labelled)

##############################

####   FMEASURE
if (constants.URL.__contains__('ionosphere')
        or constants.URL.__contains__('iris')
        or constants.URL.__contains__('wine')
        or constants.URL.__contains__('parkinsons')
        or constants.URL.__contains__('sonar')
        or constants.URL.__contains__('segmentation')
        or constants.URL.__contains__('glass')):
    # classdata = pd.read_csv(constants.cURL)
    classdata = np.array(y_dataset)
    #print(classdata)
    fmeasure(labelled, classdata)
##############################

if constants.URL.__contains__('random2'):
    plot2D(centroid, pop_distri)

if constants.URL.__contains__('random3'):
    plot3D(centroid, pop_distri)
#data = np.array(data)
#print(dist(centroids[0],data[0]),dist(centroids[1],data[0]),dist(centroids[2],data[0]))
#print(dist(centroids[0],data[55]),dist(centroids[1],data[55]),dist(centroids[2],data[55]))
#print(dist(centroids[0],data[127]),dist(centroids[1],data[127]),dist(centroids[2],data[127]))
示例#6
0
def run():
    global pts3
    global pts4

    if simulation and view:
        plot.plot3D(data3D, 'Original 3D Data')

    if view:
        plot.plot2D(pts1_raw, name='First Statics (Noise not shown)')
        plot.plot2D(pts2_raw, name='Second Statics (Noise not shown)')

    # FUNDAMENTAL MATRIX
    F = getFundamentalMatrix(pts1, pts2)

    # ESSENTIAL MATRIX (HZ 9.12)
    E, w, u, vt = getEssentialMatrix(F, K1, K2)

    # PROJECTION/CAMERA MATRICES from E (HZ 9.6.2)
    P1, P2 = getNormalisedPMatrices(u, vt)
    P1_mat = np.mat(P1)
    P2_mat = np.mat(P2)

    # FULL PROJECTION MATRICES (with K) P = K[Rt]
    KP1 = K1 * P1_mat
    KP2 = K2 * P2_mat

    print "\n> KP1:\n", KP1
    print "\n> KP2:\n", KP2

    # SYNCHRONISATION + CORRECTION
    if rec_data and simulation is False:
        print "---Synchronisation---"
        pts3, pts4 = synchroniseGeometric(pts3, pts4, F)

        pts3 = pts3.reshape((1, -1, 2))
        pts4 = pts4.reshape((1, -1, 2))
        newPoints3, newPoints4 = cv2.correctMatches(F, pts3, pts4)
        pts3 = newPoints3.reshape((-1, 2))
        pts4 = newPoints4.reshape((-1, 2))

    elif simulation:
        print "> Simulation: Use whole point set for reconstruction"
        pts3 = pts1
        pts4 = pts2

    # Triangulate the trajectory
    p3d = triangulateCV(KP1, KP2, pts3, pts4)

    # Triangulate goalposts
    if simulation is False:
        goalPosts = triangulateCV(KP1, KP2, postPts1, postPts2)

    # SCALING AND PLOTTING
    if simulation:
        if view:
            plot.plot3D(p3d, 'Simulation Reconstruction')
        reprojectionError(K1, P1_mat, K2, P2_mat, pts3, pts4, p3d)
        p3d = simScale(p3d)
        if view:
            plot.plot3D(p3d, 'Scaled Simulation Reconstruction')

    else:
        # add the post point data into the reconstruction for context
        if len(postPts1) == 4:
            print "> Concatenate goal posts to trajectory"
            pts3_gp = np.concatenate((postPts1, pts3), axis=0)
            pts4_gp = np.concatenate((postPts2, pts4), axis=0)
            p3d_gp = np.concatenate((goalPosts, p3d), axis=0)

        scale = getScale(goalPosts)

        scaled_gp_only = [[a * scale for a in inner] for inner in goalPosts]
        scaled_gp = [[a * scale for a in inner] for inner in p3d_gp]
        scaled = [[a * scale for a in inner] for inner in p3d]

        if view:
            plot.plot3D(scaled_gp, 'Scaled 3D Reconstruction')
        reprojectionError(K1, P1_mat, K2, P2_mat, pts3_gp, pts4_gp, p3d_gp)

        getMetrics(scaled, scaled_gp_only)
        scaled_gp = transform(scaled_gp)
        if view:
            plot.plot3D(scaled_gp, 'Final (Reorientated) 3D Reconstruction')
        if ground_truth_provided:
            reconstructionError(data3D, scaled_gp)

        # write X Y Z to file
        outfile = open('sessions/' + clip + '/3d_out.txt', 'w')
        for p in scaled_gp:
            p0 = round(p[0], 2)
            p1 = round(p[1], 2)
            p2 = round(p[2], 2)
            string = str(p0) + ' ' + str(p1) + ' ' + str(p2)
            outfile.write(string + '\n')
        outfile.close()
示例#7
0
def main():

    path = sys.argv[1]
    folder = os.path.dirname(path)

    data_3d = getData(path)

    data_3d = np.array(data_3d, dtype='float32')

    # Artificial cameras - both have the same intrinsics
    K = tools.CalibArray(1000, 640, -360)
    dist = (0, 0, 0, 0)

    # Some numbers we use a lot
    rt2 = math.sqrt(2)
    rt2on2 = rt2 / 2

    # Lots of rotation matrices...
    # naming: z45cc = 45deg counter-clockwise rotation about z

    z45cc = np.mat([[1 / rt2, -1 / rt2, 0], [1 / rt2, 1 / rt2, 0], [0, 0, 1]],
                   dtype='float32')

    nothing = np.mat([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='float32')

    z90cc = np.mat([[0, -1, 0], [1, 0, 0], [0, 0, 1]], dtype='float32')
    z90cw = np.mat([[0, 1, 0], [-1, 0, 0], [0, 0, 1]], dtype='float32')

    z180 = np.mat([[-1, 0, 0], [0, -1, 0], [0, 0, 1]], dtype='float32')
    x180 = np.mat([[1, 0, 0], [0, -1, 0], [0, 0, -1]], dtype='float32')
    y180 = np.mat([[-1, 0, 0], [0, 1, 0], [0, 0, -1]], dtype='float32')

    x90cw = np.mat([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype='float32')
    x90cc = np.mat([[1, 0, 0], [0, 0, -1], [0, 1, 0]], dtype='float32')

    y90cc = np.mat([[0, 0, 1], [0, 1, 0], [-1, 0, 0]], dtype='float32')
    y90cw = np.mat([[0, 0, -1], [0, 1, 0], [1, 0, 0]], dtype='float32')

    z90cc_vec, jacobian = cv2.Rodrigues(z90cc)
    z90cc_vec, jacobian = cv2.Rodrigues(z90cc)
    y90cc_vec, jacobian = cv2.Rodrigues(y90cc)
    x90cc_vec, jacobian = cv2.Rodrigues(x90cc)

    y45cc = np.mat([[rt2on2, 0, rt2on2], [0, 1, 0], [-rt2on2, 0, rt2on2]],
                   dtype='float32')

    y45cw = np.mat([[rt2on2, 0, -rt2on2], [0, 1, 0], [rt2on2, 0, rt2on2]],
                   dtype='float32')

    # cameras have different poses
    tvec1 = (-5, 1, 14)
    tvec2 = (5, 1, 13)

    # Project the model into each camera
    img_pts1 = project(data_3d, K, y45cc, tvec1)
    img_pts2 = project(data_3d, K, y45cw, tvec2)

    img_pts1 = np.reshape(img_pts1, (len(img_pts1), 2, 1))
    img_pts2 = np.reshape(img_pts2, (len(img_pts2), 2, 1))

    # Plot the model and images
    plot.plot3D(data_3d)
    plotImagePoints(img_pts1)
    plotImagePoints(img_pts2)

    # Add noise to the image data if desired
    try:
        noise = sys.argv[2]
        img_pts1 = addNoise(float(noise), img_pts1)
        img_pts2 = addNoise(float(noise), img_pts2)
    except indexError:
        continue

    writeData(folder, img_pts1, img_pts2)
示例#8
0
 def test_plot3d(self):
     data =  dict([(i, dict([(j, random.random())for j in range(10)])) for i in range(5)])
     plot3D(data)
     plt.show()
示例#9
0
def main():

    path = sys.argv[1]
    folder = os.path.dirname(path)

    data_3d = getData(path)

    data_3d = np.array(data_3d, dtype='float32')

    # Artificial cameras - both have the same intrinsics
    K = tools.CalibArray(1000, 640, -360)
    dist = (0, 0, 0, 0)

    # Some numbers we use a lot
    rt2 = math.sqrt(2)
    rt2on2 = rt2 / 2

    # Lots of rotation matrices...
    # naming: z45cc = 45deg counter-clockwise rotation about z

    z45cc = np.mat([[1 / rt2, -1 / rt2, 0],
                    [1 / rt2, 1 / rt2, 0],
                    [0, 0, 1]], dtype='float32')

    nothing = np.mat([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='float32')

    z90cc = np.mat([[0, -1, 0], [1, 0, 0], [0, 0, 1]], dtype='float32')
    z90cw = np.mat([[0, 1, 0], [-1, 0, 0], [0, 0, 1]], dtype='float32')

    z180 = np.mat([[-1, 0, 0], [0, -1, 0], [0, 0, 1]], dtype='float32')
    x180 = np.mat([[1, 0, 0], [0, -1, 0], [0, 0, -1]], dtype='float32')
    y180 = np.mat([[-1, 0, 0], [0, 1, 0], [0, 0, -1]], dtype='float32')

    x90cw = np.mat([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype='float32')
    x90cc = np.mat([[1, 0, 0], [0, 0, -1], [0, 1, 0]], dtype='float32')

    y90cc = np.mat([[0, 0, 1], [0, 1, 0], [-1, 0, 0]], dtype='float32')
    y90cw = np.mat([[0, 0, -1], [0, 1, 0], [1, 0, 0]], dtype='float32')

    z90cc_vec, jacobian = cv2.Rodrigues(z90cc)
    z90cc_vec, jacobian = cv2.Rodrigues(z90cc)
    y90cc_vec, jacobian = cv2.Rodrigues(y90cc)
    x90cc_vec, jacobian = cv2.Rodrigues(x90cc)

    y45cc = np.mat([[rt2on2, 0, rt2on2],
                    [0, 1, 0],
                    [-rt2on2, 0, rt2on2]], dtype='float32')

    y45cw = np.mat([[rt2on2, 0, -rt2on2],
                    [0, 1, 0],
                    [rt2on2, 0, rt2on2]], dtype='float32')

    # cameras have different poses
    tvec1 = (-5, 1, 14)
    tvec2 = (5, 1, 13)

    # Project the model into each camera
    img_pts1 = project(data_3d, K, y45cc, tvec1)
    img_pts2 = project(data_3d, K, y45cw, tvec2)

    img_pts1 = np.reshape(img_pts1, (len(img_pts1), 2, 1))
    img_pts2 = np.reshape(img_pts2, (len(img_pts2), 2, 1))

    # Plot the model and images
    plot.plot3D(data_3d)
    plotImagePoints(img_pts1)
    plotImagePoints(img_pts2)

    # Add noise to the image data if desired
    try:
        noise = sys.argv[2]
        img_pts1 = addNoise(float(noise), img_pts1)
        img_pts2 = addNoise(float(noise), img_pts2)
    except indexError:
        continue

    writeData(folder, img_pts1, img_pts2)
示例#10
0
def run():
    global pts3
    global pts4

    if simulation and view:
        plot.plot3D(data3D, 'Original 3D Data')

    if view:
        plot.plot2D(pts1_raw, name='First Statics (Noise not shown)')
        plot.plot2D(pts2_raw, name='Second Statics (Noise not shown)')

    # FUNDAMENTAL MATRIX
    F = getFundamentalMatrix(pts1, pts2)

    # ESSENTIAL MATRIX (HZ 9.12)
    E, w, u, vt = getEssentialMatrix(F, K1, K2)

    # PROJECTION/CAMERA MATRICES from E (HZ 9.6.2)
    P1, P2 = getNormalisedPMatrices(u, vt)
    P1_mat = np.mat(P1)
    P2_mat = np.mat(P2)

    # FULL PROJECTION MATRICES (with K) P = K[Rt]
    KP1 = K1 * P1_mat
    KP2 = K2 * P2_mat

    print "\n> KP1:\n", KP1
    print "\n> KP2:\n", KP2

    # SYNCHRONISATION + CORRECTION
    if rec_data and simulation is False:
        print "---Synchronisation---"
        pts3, pts4 = synchroniseGeometric(pts3, pts4, F)

        pts3 = pts3.reshape((1, -1, 2))
        pts4 = pts4.reshape((1, -1, 2))
        newPoints3, newPoints4 = cv2.correctMatches(F, pts3, pts4)
        pts3 = newPoints3.reshape((-1, 2))
        pts4 = newPoints4.reshape((-1, 2))

    elif simulation:
        print "> Simulation: Use whole point set for reconstruction"
        pts3 = pts1
        pts4 = pts2

    # Triangulate the trajectory
    p3d = triangulateCV(KP1, KP2, pts3, pts4)

    # Triangulate goalposts
    if simulation is False:
        goalPosts = triangulateCV(KP1, KP2, postPts1, postPts2)

    # SCALING AND PLOTTING
    if simulation:
        if view:
            plot.plot3D(p3d, 'Simulation Reconstruction')
        reprojectionError(K1, P1_mat, K2, P2_mat, pts3, pts4, p3d)
        p3d = simScale(p3d)
        if view:
            plot.plot3D(p3d, 'Scaled Simulation Reconstruction')

    else:
        # add the post point data into the reconstruction for context
        if len(postPts1) == 4:
            print "> Concatenate goal posts to trajectory"
            pts3_gp = np.concatenate((postPts1, pts3), axis=0)
            pts4_gp = np.concatenate((postPts2, pts4), axis=0)
            p3d_gp = np.concatenate((goalPosts, p3d), axis=0)

        scale = getScale(goalPosts)

        scaled_gp_only = [[a * scale for a in inner] for inner in goalPosts]
        scaled_gp = [[a * scale for a in inner] for inner in p3d_gp]
        scaled = [[a * scale for a in inner] for inner in p3d]

        if view:
            plot.plot3D(scaled_gp, 'Scaled 3D Reconstruction')
        reprojectionError(K1, P1_mat, K2, P2_mat, pts3_gp, pts4_gp, p3d_gp)

        getMetrics(scaled, scaled_gp_only)
        scaled_gp = transform(scaled_gp)
        if view:
            plot.plot3D(scaled_gp, 'Final (Reorientated) 3D Reconstruction')
        if ground_truth_provided:
            reconstructionError(data3D, scaled_gp)

        # write X Y Z to file
        outfile = open('sessions/' + clip + '/3d_out.txt', 'w')
        for p in scaled_gp:
            p0 = round(p[0], 2)
            p1 = round(p[1], 2)
            p2 = round(p[2], 2)
            string = str(p0) + ' ' + str(p1) + ' ' + str(p2)
            outfile.write(string + '\n')
        outfile.close()