def test_batch_apply(points_1): c = Calibraxis(verbose=False) c.add_points(points_1) c.calibrate_accelerometer() out = c.batch_apply(points_1) normed = np.sqrt((np.array(out) ** 2).sum(axis=1)) np.testing.assert_array_almost_equal(normed, 1.0, 2)
def test_add_points_4(points_2): c = Calibraxis(verbose=False) points = points_2 / ((2 ** 15) / 8.) c.add_points(points.tolist()) np.testing.assert_almost_equal(np.linalg.norm(np.array(c._calibration_points) - points), 0.0, 6) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_batch_apply(points_1): c = Calibraxis(verbose=False) c.add_points(points_1) c.calibrate_accelerometer() out = c.batch_apply(points_1) normed = np.sqrt((np.array(out)**2).sum(axis=1)) np.testing.assert_array_almost_equal(normed, 1.0, 2)
def test_verbose_prints_progress(points_2, capsys): c = Calibraxis(verbose=True) c.add_points(points_2) c.calibrate_accelerometer() out, err = capsys.readouterr() for row in filter(None, out.split('\n')): assert re.match('^([0-9]+):\s([0-9\-\.e]+)\s*(\([0-9\s\-\.e,]+\))$', row)
def test_add_points_4(points_2): c = Calibraxis(verbose=False) points = points_2 / ((2**15) / 8.) c.add_points(points.tolist()) np.testing.assert_almost_equal( np.linalg.norm(np.array(c._calibration_points) - points), 0.0, 6) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_add_points_3(points_1): c = Calibraxis(verbose=False) points = points_1 / ((2 ** 15) / 8.) for p in points: c.add_points(tuple(p)) np.testing.assert_almost_equal(np.linalg.norm(np.array(c._calibration_points) - points), 0.0, 6) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_add_points_3(points_1): c = Calibraxis(verbose=False) points = points_1 / ((2**15) / 8.) for p in points: c.add_points(tuple(p)) np.testing.assert_almost_equal( np.linalg.norm(np.array(c._calibration_points) - points), 0.0, 6) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_recalibration_points_2(points_2): c = Calibraxis(verbose=False) points = points_2 / ((2 ** 15) / 16.) for p in points[:-1, :]: c.add_points(p) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2) c.add_points(points[-1, :]) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_recalibration_points_2(points_2): c = Calibraxis(verbose=False) points = points_2 / ((2**15) / 16.) for p in points[:-1, :]: c.add_points(p) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2) c.add_points(points[-1, :]) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
import numpy as np from calibraxis import Calibraxis c = Calibraxis() points = np.array([[-4772.38754098, 154.04459016, -204.39081967], [3525.0346179, -68.64924886, -34.54604833], [-658.17681729, -4137.60248854, -140.49377865], [-564.18562092, 4200.29150327, -130.51895425], [-543.18289474, 18.14736842, -4184.43026316], [-696.62532808, 15.70209974, 3910.20734908], [406.65271419, 18.46827992, -4064.61085677], [559.45926413, -3989.69513798, -174.71879106], [597.22629169, -3655.54153041, -1662.83257031], [1519.02616089, -603.82472204, 3290.58469588]]) # Add points to calibration object's storage. c.add_points(points) # Run the calibration parameter optimization. c.calibrate_accelerometer() # Applying the calibration parameters to the calibration data. c.apply(points[0:]) c.batch_apply(points)
def test_calibration_points_2_scaled(points_2): c = Calibraxis(verbose=False) c.add_points(points_2 / ((2 ** 15) / 16.)) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_calibration_points_1(points_1): c = Calibraxis(verbose=False) c.add_points(points_1) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)
def test_apply(points_1): c = Calibraxis(verbose=False) c.add_points(points_1) c.calibrate_accelerometer() np.testing.assert_almost_equal(np.linalg.norm(c.apply(points_1[0, :])), 1.0, 2)
def test_error_to_few_points(points_2): c = Calibraxis(verbose=False) for p in points_2[:5, :]: c.add_points(p) with pytest.raises(ValueError): c.calibrate_accelerometer()
def test_calibration_points_2_scaled(points_2): c = Calibraxis(verbose=False) c.add_points(points_2 / ((2**15) / 16.)) c.calibrate_accelerometer() np.testing.assert_almost_equal(c._calibration_errors[-1], 0.0, 2)