Esempio n. 1
0
def calibration_combination(data):
    min_magno = np.array([float("inf"), float("inf"), float("inf")])
    max_magno = -np.array([float("inf"), float("inf"), float("inf")])
    for vec in data:
        min_magno = np.minimum(min_magno, vec)
        max_magno = np.maximum(max_magno, vec)

    magno_sf = 2 / (max_magno - min_magno)
    magno_bias = (max_magno + min_magno) / 2

    calibrated_initial = (data - magno_bias) * magno_sf

    data2 = data_regularize(calibrated_initial)

    center, (a, b, c), evecs, v = ellipsoid_fit(data2)
    D = np.array([[1 / a, 0., 0.], [0., 1 / b, 0.], [0., 0., 1 / c]])


    transform = np.dot(np.diag(magno_sf),evecs.dot(D).dot(evecs.T))
    offset = center.T + magno_bias

    calibrated = transform.dot((data - offset).T).T
    plot_scatter(calibrated, "Combination Calibration", 100)
    eval = eval_calibrated(calibrated)
    print("Combination Calibration (Transform - {}, Offset - {} Eval - {})".format(
        np.array_str(transform),
        np.array_str(offset),
        str(eval)))
Esempio n. 2
0
def _monte_carlo_identity():
    '''Generate the default params that don't affect readings by fitting to a unit sphere'''
    # create points randomly distributed on the unit sphere
    npoints = 25000
    vec = np.random.randn(3, npoints)
    vec /= np.linalg.norm(vec, axis=0)
    # use those to fit
    regularized = data_regularize(vec.T, divs=8)
    return ellipsoid_fit(regularized)
def calibration_ellipsoid(file='magcalib.txt'):

    data = read_mag_file(file)
    data = data_regularize(data)

    center, evecs, radii = ellipsoid_fit(data)

    a, b, c = radii
   #r = (a * b * c) ** (1. / 3.)
    D = np.array([[1/a, 0., 0.], [0., 1/b, 0.], [0., 0., 1/c]])
  
    transformation = evecs@[email protected]

    return center.T,transformation
Esempio n. 4
0
def calibration_ellipsoid(data):
    data2 = data_regularize(data)

    plot_scatter(data2, "Regularized Data", 1)

    center, (a, b, c), evecs, v = ellipsoid_fit(data2)
    D = np.array([[1 / a, 0., 0.], [0., 1 / b, 0.], [0., 0., 1 / c]])
    transform = evecs.dot(D).dot(evecs.T)


    calibrated = transform.dot((data - center.T).T).T
    plot_scatter(calibrated, "Calibrated ADIS16405 Magnetometer Data", 100)
    eval = eval_calibrated(calibrated)

    print("Ellipsoid Calibration (Transform - {}, Offset - {} Eval - {})".format(
        np.array_str(transform),
        np.array_str(center.T),
        str(eval)))
    return transform
import numpy as np
from ellipsoid_fit import ellipsoid_fit as ellipsoid_fit, data_regularize


if __name__=='__main__':

    data = np.loadtxt("mag_out.txt")
    data2 = data_regularize(data)

    center, radii, evecs, v = ellipsoid_fit(data2)

    a,b,c = radii
    r = (a*b*c)**(1./3.)
    D = np.array([[r/a,0.,0.],[0.,r/b,0.],[0.,0.,r/c]])
    TR = evecs.dot(D).dot(evecs.T)
    
    print
    print 'center: ',center
    print 'transformation:'
    print TR
    
    np.savetxt('magcal_ellipsoid.txt', np.vstack((center.T, TR)))

import numpy as np
from ellipsoid_fit import ellipsoid_fit as ellipsoid_fit, data_regularize

if __name__ == '__main__':

    data = np.loadtxt("mag_out.txt")
    data2 = data_regularize(data)

    center, radii, evecs, v = ellipsoid_fit(data2)

    a, b, c = radii
    r = (a * b * c)**(1. / 3.)
    D = np.array([[r / a, 0., 0.], [0., r / b, 0.], [0., 0., r / c]])
    TR = evecs.dot(D).dot(evecs.T)

    print('')
    print('center: ', center)
    print('transformation:')
    print(TR)

    np.savetxt('magcal_ellipsoid.txt', np.vstack((center.T, TR)))
Esempio n. 7
0
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from ellipsoid_fit import ellipsoid_fit, ellipsoid_plot, data_regularize

if __name__ == '__main__':

    data = np.loadtxt("mag_out.txt")
    data2 = data_regularize(data, divs=8)

    center, radii, evecs, v = ellipsoid_fit(data2)

    dataC = data - center.T
    dataC2 = data2 - center.T

    a, b, c = radii
    r = (a * b * c)**(1. / 3.)  #preserve volume?
    D = np.array([[r / a, 0., 0.], [0., r / b, 0.], [0., 0., r / c]])
    #http://www.cs.brandeis.edu/~cs155/Lecture_07_6.pdf
    #affine transformation from ellipsoid to sphere (translation excluded)
    TR = evecs.dot(D).dot(evecs.T)
    dataE = TR.dot(dataC2.T).T

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    #hack  for equal axes
    ax.set_aspect('equal')
    MAX = 200
    for direction in (-1, 1):
        for point in np.diag(direction * MAX * np.array([1, 1, 1])):
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from ellipsoid_fit import ellipsoid_fit, ellipsoid_plot, data_regularize


if __name__=='__main__':

    data = np.loadtxt("mag_out.txt")
    data2 = data_regularize(data, divs=8)

    center, radii, evecs, v = ellipsoid_fit(data2)

    dataC = data - center.T
    dataC2 = data2 - center.T

    a,b,c = radii
    r = (a*b*c)**(1./3.)#preserve volume?
    D = np.array([[r/a,0.,0.],[0.,r/b,0.],[0.,0.,r/c]])
    #http://www.cs.brandeis.edu/~cs155/Lecture_07_6.pdf
    #affine transformation from ellipsoid to sphere (translation excluded)
    TR = evecs.dot(D).dot(evecs.T)
    dataE = TR.dot(dataC2.T).T

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    

    #hack  for equal axes
    ax.set_aspect('equal')
    MAX = 200
Esempio n. 9
0
 def calibrate(self, raw_mag):
     #not sure what regularizing does but the ellipsoid_fit example uses it...
     regularized = data_regularize(raw_mag, divs=8)
     center, radii, evecs, v = ellipsoid_fit(regularized)
     self.params = center, radii, evecs, v