# Path: sensbiotk/algorithms/basic.py
# def find_peaks(sig_raw, min_peak_height, min_peak_distance, max_peak_distance):
# def find_static_periods(sig_raw, static_threshold, min_sample_duration):
# def find_static_periods_3D(sig_raw, static_threshold, min_sample_duration):
# def cut_signal(sig_time, sig_raw, time0, timef):
# def lowpass_filter(sig_raw, cuttoff_freq, samp_freq):
# def lowpass_filter2(sig_raw, cuttoff_freq, samp_freq):
# def window_mean(sig_time, sig_raw, time0, timef):
# def moving_average(sig_raw, fen):
# def moving_average2(sig_raw, fen):
# def search_maxpeak(sig_raw):
# def threshold_signal(sig_time, sig_raw, threshold):
# def threshold_under_signal(sig_time, sig_raw, threshold):
# def compute_norm(sig_raw):
# 
# Path: sensbiotk/calib/calib_acc.py
# SEP = ";"
# def scale_fit(data, constant):
# def scale_fit_norm(data, constant):
# def compute(data):
# def errorf(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac1(v_x, v_y, v_z, mxx, mxy, mxz, b_x, b_y, b_z):
# def jac2(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, b_x, b_y, b_z):
# def jac3(v_x, v_y, v_z, mxx, mxy, mxz, myz, mzz, b_x, b_y, b_z):
# def jac4(v_x, v_y, v_z, mxy, myy, myz, b_x, b_y, b_z):
# def jac5(v_x, v_y, v_z, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac6(v_x, v_y, v_z, mxz, myz, mzz, b_x, b_y, b_z):
# def jac7(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac8(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac9(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def compute_simple(data):
# 
# Path: sensbiotk/calib/calib_mag.py
# SEP = ";"
# def unit_sphere_fit(data):
# def compute(data):
# 
# Path: sensbiotk/calib/calib_gyr.py
# def offset_fit(data):
# def compute(data):


import numpy as np
    import pylab as py
from sensbiotk.algorithms import basic as algo
from sensbiotk.calib import calib_acc as calib_acc
from sensbiotk.calib import calib_mag as calib_mag
from sensbiotk.calib import calib_gyr as calib_gyr
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io import viz
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io.uigetfile import uigetfile
    from sensbiotk.algorithms.basic import find_static_periods_3D
    from sensbiotk.io.iofox import load_foxcsvfile
    from os.path import split
    print "\t", params_acc[2]
    print "\t", params_acc[3]
    print "Magnetometers"
    print "Scale=", params_mag[0]
    print "Offset=\t", params_mag[1]
    print "\t", params_mag[2]
    print "\t", params_mag[3]
    print "Gyrometers"
    print "Scale=", params_gyr[0]
    print "Offset=\t", params_gyr[1]
    print "\t", params_gyr[2]
    print "\t", params_gyr[3]

    return

FILETEST = "../../tests/data/imu08.csv"


def test1():
    """ Test1
    """

    print "Test Calibration"
    [time, acc, mag, gyr] = fox.load_foximu_csvfile(FILETEST)
    viz.plot_imu(0, "calib", time[:, 1], acc, mag, gyr)

    acc_motionless = acc[5500:7500]
    gyr_motionless = gyr[5500:7500]
    mag_motion = mag[8000:18000]


# Path: sensbiotk/algorithms/basic.py
# def find_peaks(sig_raw, min_peak_height, min_peak_distance, max_peak_distance):
# def find_static_periods(sig_raw, static_threshold, min_sample_duration):
# def find_static_periods_3D(sig_raw, static_threshold, min_sample_duration):
# def cut_signal(sig_time, sig_raw, time0, timef):
# def lowpass_filter(sig_raw, cuttoff_freq, samp_freq):
# def lowpass_filter2(sig_raw, cuttoff_freq, samp_freq):
# def window_mean(sig_time, sig_raw, time0, timef):
# def moving_average(sig_raw, fen):
# def moving_average2(sig_raw, fen):
# def search_maxpeak(sig_raw):
# def threshold_signal(sig_time, sig_raw, threshold):
# def threshold_under_signal(sig_time, sig_raw, threshold):
# def compute_norm(sig_raw):
# 
# Path: sensbiotk/calib/calib_acc.py
# SEP = ";"
# def scale_fit(data, constant):
# def scale_fit_norm(data, constant):
# def compute(data):
# def errorf(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac1(v_x, v_y, v_z, mxx, mxy, mxz, b_x, b_y, b_z):
# def jac2(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, b_x, b_y, b_z):
# def jac3(v_x, v_y, v_z, mxx, mxy, mxz, myz, mzz, b_x, b_y, b_z):
# def jac4(v_x, v_y, v_z, mxy, myy, myz, b_x, b_y, b_z):
# def jac5(v_x, v_y, v_z, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac6(v_x, v_y, v_z, mxz, myz, mzz, b_x, b_y, b_z):
# def jac7(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac8(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def jac9(v_x, v_y, v_z, mxx, mxy, mxz, myy, myz, mzz, b_x, b_y, b_z):
# def compute_simple(data):
# 
# Path: sensbiotk/calib/calib_mag.py
# SEP = ";"
# def unit_sphere_fit(data):
# def compute(data):
# 
# Path: sensbiotk/calib/calib_gyr.py
# def offset_fit(data):
# def compute(data):


# Path: sensbiotk/calib/calib.py
import numpy as np
    import pylab as py
from sensbiotk.algorithms import basic as algo
from sensbiotk.calib import calib_acc as calib_acc
from sensbiotk.calib import calib_mag as calib_mag
from sensbiotk.calib import calib_gyr as calib_gyr
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io import viz
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io.uigetfile import uigetfile
    from sensbiotk.algorithms.basic import find_static_periods_3D
    from sensbiotk.io.iofox import load_foxcsvfile
    from os.path import split

    print "\t", params_acc[2]
    print "\t", params_acc[3]
    print "Magnetometers"
    print "Scale=", params_mag[0]
    print "Offset=\t", params_mag[1]
    print "\t", params_mag[2]
    print "\t", params_mag[3]
    print "Gyrometers"
    print "Scale=", params_gyr[0]
    print "Offset=\t", params_gyr[1]
    print "\t", params_gyr[2]
    print "\t", params_gyr[3]

    return

FILETEST = "../../tests/data/imu08.csv"


def test1():
    """ Test1
    """

    print "Test Calibration"
    [time, acc, mag, gyr] = fox.load_foximu_csvfile(FILETEST)
    viz.plot_imu(0, "calib", time[:, 1], acc, mag, gyr)

    acc_motionless = acc[5500:7500]
    gyr_motionless = gyr[5500:7500]
    mag_motion = mag[8000:18000]


    scale, offset = calib_acc.compute_simple(acc_motionless)