Beispiel #1
0
def dataset_synced():
    master = TEST_SYNCED_DATA / "NilsPodX-7FAD_20190430_0933.bin"
    slave1 = TEST_SYNCED_DATA / "NilsPodX-922A_20190430_0933.bin"
    slave2 = TEST_SYNCED_DATA / "NilsPodX-323C_20190430_0933.bin"
    return {
        # We only need a timezone on the master. The other timezones are ignored anyway
        "master": (Dataset.from_bin_file(master, tz="Europe/Berlin"), master),
        "slave1": (Dataset.from_bin_file(slave1), slave1),
        "slave2": (Dataset.from_bin_file(slave2), slave2),
    }
def test_inplace(simple_header, simple_calibration):
    sensors = ("acc", "gyro")
    simple_header.enabled_sensors = sensors

    dataset = Dataset({k: np.ones((100, 3))
                       for k in sensors}, np.arange(100), simple_header)
    # default: inplace = False
    cal_ds = dataset.calibrate_imu(simple_calibration)
    assert id(cal_ds) != id(dataset)
    for sensor in sensors:
        assert id(getattr(cal_ds, sensor)) != id(getattr(dataset, sensor))

    dataset = Dataset({k: np.ones((100, 3))
                       for k in sensors}, np.arange(100), simple_header)
    cal_ds = dataset.calibrate_imu(simple_calibration, inplace=True)
    assert id(cal_ds) == id(dataset)
    for sensor in sensors:
        assert id(getattr(cal_ds, sensor)) == id(getattr(dataset, sensor))

    dataset = Dataset({k: np.ones((100, 3))
                       for k in sensors}, np.arange(100), simple_header)
    cal_ds = dataset.calibrate_imu(simple_calibration, inplace=False)
    assert id(cal_ds) != id(dataset)
    for sensor in sensors:
        assert id(getattr(cal_ds, sensor)) != id(getattr(dataset, sensor))
def test_repeated_cal_error(simple_header, simple_calibration):
    sensors = ("acc", "gyro")
    simple_header.enabled_sensors = sensors

    dataset = Dataset({k: np.ones((100, 3))
                       for k in sensors}, np.arange(100), simple_header)
    cal_ds = dataset.calibrate_imu(simple_calibration)

    with pytest.raises(RepeatedCalibrationError) as e:
        cal_ds.calibrate_imu(simple_calibration)
    assert sensors[0] in str(e.value)
def test_non_existent_warning(simple_header, simple_calibration):
    sensors = ("acc", "gyro")
    simple_header.enabled_sensors = sensors

    dataset = Dataset({}, np.arange(100), simple_header)
    with pytest.warns(UserWarning) as warn:
        dataset.calibrate_imu(simple_calibration)

    assert len(warn) == 2
    for m in warn:
        assert any(s in str(m) for s in sensors)
        assert "calibration" in str(m)
def test_imu_cal(simple_header, simple_calibration):
    simple_header.enabled_sensors = ("acc", "gyro")

    dataset = Dataset({
        "acc": np.ones((100, 3)),
        "gyro": np.ones((100, 3))
    }, np.arange(100), simple_header)
    cal_ds = dataset.calibrate_imu(simple_calibration)
    assert np.all(cal_ds.gyro.data == factory_calibrate_sensors_dict["gyro"] /
                  3)
    assert np.all(cal_ds.acc.data == factory_calibrate_sensors_dict["acc"] / 2)
    assert cal_ds.gyro.is_factory_calibrated is True
    assert cal_ds.acc.is_factory_calibrated is True
    assert cal_ds.gyro.is_calibrated is True
    assert cal_ds.acc.is_calibrated is True
Beispiel #6
0
    def from_file_paths(cls: Type[T],
                        paths: Iterable[path_t],
                        legacy_support: str = "error",
                        tz: Optional[str] = None) -> T:
        """Create a new session from a list of files pointing to valid .bin files.

        Parameters
        ----------
        paths :
            List of paths pointing to files to be included
        legacy_support :
            This indicates how to deal with old firmware versions.
            If `error`: An error is raised, if an unsupported version is detected.
            If `warn`: A warning is raised, but the file is parsed without modification
            If `resolve`: A legacy conversion is performed to load old files. If no suitable conversion is found,
            an error is raised. See the `legacy` package and the README to learn more about available
            conversions.
        tz
            Optional timezone str of the recording.
            This can be used to localize the start and end time.
            Note, this should not be the timezone of your current PC, but the timezone relevant for the specific
            recording.

        """
        ds = (Dataset.from_bin_file(p, legacy_support=legacy_support, tz=tz)
              for p in paths)
        return cls(ds)
def test_factory_cal(simple_header, sensor, calval):
    """Test that all sensors are factory calibrated by default on init."""
    simple_header.enabled_sensors = (sensor, )

    dataset = Dataset({sensor: np.ones(100)}, np.arange(100), simple_header)
    assert np.all(getattr(dataset, sensor).data == calval)
    assert getattr(dataset, sensor).is_factory_calibrated is True
    assert getattr(dataset, sensor).is_calibrated is False
def test_repeated_cal_error_factory_cal(simple_header, sensor):
    """Test that we can not apply factory calibration twice.

    Note: This should never happen, as factory cal methods are private.
    """
    simple_header.enabled_sensors = (sensor, )

    dataset = Dataset({sensor: np.ones(100)}, np.arange(100), simple_header)

    with pytest.raises(RepeatedCalibrationError) as e:
        getattr(dataset,
                "_factory_calibrate_" + sensor)(getattr(dataset, sensor))
    assert sensor in str(e.value)
    assert "factory-calibrate" in str(e.value)
def test_imu_factory_cal(simple_header, ):
    simple_header.enabled_sensors = ("acc", "gyro")

    dataset = Dataset({
        "acc": np.ones(100),
        "gyro": np.ones(100) * 2
    }, np.arange(100), simple_header)

    assert np.all(dataset.acc.data == factory_calibrate_sensors_dict["acc"])
    assert np.all(dataset.gyro.data == factory_calibrate_sensors_dict["gyro"] *
                  2)
    assert dataset.acc.is_calibrated is False
    assert dataset.acc.is_calibrated is False
    assert dataset.acc.is_factory_calibrated is True
    assert dataset.acc.is_factory_calibrated is True
Beispiel #10
0
def _dataset_master_simple():
    path = TEST_SESSION_DATA / "NilsPodX-6F13_20210109_162824.bin"
    return Dataset.from_bin_file(path=path, tz="Europe/Berlin"), path