Synthetic Data Generation

Creates a synthetic dataset using a constant magnetic vector that is randomly rotated in three different degrees of motion: low, mid, and high. The created data is saved in the folderPath directory as a pickle (.pkl) file. The file's name uses the date of its creation as: yyyymmdd_hhmm.pkl

The data provided is: magnetic field (m), magnetic field with added noise (mt), magnetic field with HSI (mm), magnetic field with HSI and noise (mmt), angular rates (w), angular rates with noise (wt), angular rates with gyroscope bias (wm), angular rate with gyroscope bias and noise (wmt), attitude (rph), time (t), ground truth magnetic vector (m0), soft iron (si), hard iron (hi), and gyroscope bias (wb).

For each level of movement the data is provided as a multi-dimensional array, where the shape is: (simulation, samples, 3).

If not random, the soft iron, hard iron, and gyroscope biases are fixed as follows:

\[ SI = \begin{bmatrix} 1.10 & 0.10 & 0.04 \\ 0.10 & 0.88 & 0.02 \\ 0.04 & 0.02 & 1.22 \end{bmatrix} \]
\[ HI = \begin{bmatrix} 0.020 & 0.120 & 0.090 \end{bmatrix}^T \]
\[ WB = \begin{bmatrix} 0.004 & -0.005 & 0.002 \end{bmatrix}^T \]

Parameters:

Name Type Description Default
folder_path Path

Folder to save the data as a pickle (.pkl) file.

required
niter int

Number of simulations per motion level, by default 100

100
nsamples int

Number of samples per simulation, by default 10000

10000
frequency float

Simulated sensor frequency, by default 25

25.0
mag_noise_G float

Noise for the magnetic measurements in G.

0.01
gyro_noise_rad_s float

Noise for the gyroscope measurements in rad/s

0.005
random bool

If True, the soft iron, hard iron, and gyroscope biases are randomly generated. If False, the soft iron, hard iron, and gyroscope biases are fixed, by default False.

False
scale_factor float

Scale factor for the SI, HI, and WB matrices, by default 1.0

1.0
Source code in magyc/sim_data/generate_data.py
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def create_synthetic_dataset(folder_path: Path, niter: int = 100, nsamples: int = 10000, frequency: float = 25.0,
                             mag_noise_G: float = 0.01, gyro_noise_rad_s: float = 0.005, random: bool = False,
                             scale_factor: float = 1.0) -> None:
    """
    Creates a synthetic dataset using a constant magnetic vector that is
    randomly rotated in three different degrees of motion: low, mid, and high.
    The created data is saved in the folderPath directory as a pickle (.pkl)
    file. The file's name uses the date of its creation as: yyyymmdd_hhmm.pkl

    The data provided is: magnetic field (m), magnetic field with added noise
    (mt), magnetic field with HSI (mm), magnetic field with HSI and noise (mmt),
    angular rates (w), angular rates with noise (wt), angular rates with gyroscope
    bias (wm), angular rate with gyroscope bias and noise (wmt), attitude (rph),
    time (t), ground truth magnetic vector (m0), soft iron (si), hard iron (hi),
    and gyroscope bias (wb).

    For each level of movement the data is provided as a multi-dimensional array,
    where the shape is: (simulation, samples, 3).

    If not random, the soft iron, hard iron, and gyroscope biases are fixed as
    follows:

    \\[ SI = \\begin{bmatrix} 1.10 & 0.10 & 0.04 \\\\
                              0.10 & 0.88 & 0.02 \\\\
                              0.04 & 0.02 & 1.22 \\end{bmatrix} \\]

    \\[ HI = \\begin{bmatrix} 0.020 & 0.120 & 0.090 \\end{bmatrix}^T \\]

    \\[ WB = \\begin{bmatrix} 0.004 & -0.005 & 0.002 \\end{bmatrix}^T \\]

    Args:
        folder_path (Path): Folder to save the data as a pickle (.pkl) file.
        niter (int): Number of simulations per motion level, by default 100
        nsamples (int): Number of samples per simulation, by default 10000
        frequency (float): Simulated sensor frequency, by default 25
        mag_noise_G (float): Noise for the magnetic measurements in G.
        gyro_noise_rad_s (float): Noise for the gyroscope measurements in rad/s
        random (bool): If True, the soft iron, hard iron, and gyroscope biases
            are randomly generated. If False, the soft iron, hard iron, and
            gyroscope biases are fixed, by default False.
        scale_factor (float): Scale factor for the SI, HI, and WB matrices, by
            default 1.0
    """
    if not random:
        # Adimensional and positive definite symmetric (PDS) matrix
        SI = np.array([[1.10, 0.10, 0.04],
                       [0.10, 0.88, 0.02],
                       [0.04, 0.02, 1.22]])
        SI = scale_factor * SI
        # G
        HI = np.array([[0.020],
                       [0.120],
                       [0.090]])
        HI = scale_factor * HI
        # rad/s
        WB = np.array([[0.004],
                       [-0.005],
                       [0.002]])
        WB = scale_factor * WB

    # Check if folder is a directory
    if not isdir(folder_path):
        raise ValueError("The provided folder is not a directory in the system")

    # Create dataset generator object
    sd = _SyntheticData(niter=niter, nsamples=nsamples, frequency=frequency, mag_noise_G=mag_noise_G,
                        gyro_noise_rad_s=gyro_noise_rad_s)

    # Set calibration parameters
    if random:
        sd.random_parameters()
    else:
        sd.fixed_parameters(SI, HI, WB)

    # Generate Dataset
    sd.generate_data(folder_path)