imucal.CalibrationInfo#

class imucal.CalibrationInfo(acc_unit: str | None = None, gyr_unit: str | None = None, from_acc_unit: str | None = None, from_gyr_unit: str | None = None, comment: str | None = None)[source]#

Abstract BaseClass for all Calibration Info objects.

Note

All CalibrationInfo subclasses implement a CAL_TYPE attribute. If the calibration is exported into any format, this information is stored as well. If imported, all constructor methods intelligently infer the correct CalibrationInfo subclass based on this parameter.

>>> json_string = "{cal_type: 'Ferraris', ...}"
>>> CalibrationInfo.from_json(json_string)
<FerrarisCalibrationInfo ...>
Attributes:
CAL_TYPE
acc_unit
comment
from_acc_unit
from_gyr_unit
gyr_unit

Methods

calibrate(acc, gyr, acc_unit, gyr_unit)

Abstract method to perform a calibration on both acc and gyro.

calibrate_df(df, acc_unit, gyr_unit[, ...])

Apply the calibration to data stored in a dataframe.

find_subclass_from_cal_type(cal_type)

Get a SensorCalibration subclass that handles the specified calibration type.

from_hdf5(path)

Read calibration data stored in hdf5 fileformat (created by CalibrationInfo.save_to_hdf5).

from_json(json_str)

Create a calibration object from a json string (created by CalibrationInfo.to_json).

from_json_file(path)

Create a calibration object from a valid json file (created by CalibrationInfo.to_json_file).

to_hdf5(path)

Save calibration matrices to hdf5 file format.

to_json()

Convert all calibration matrices into a json string.

to_json_file(path)

Dump acc calibration matrices into a file in json format.

__init__(acc_unit: str | None = None, gyr_unit: str | None = None, from_acc_unit: str | None = None, from_gyr_unit: str | None = None, comment: str | None = None) None#
calibrate(acc: ndarray, gyr: ndarray, acc_unit: str | None, gyr_unit: str | None) Tuple[ndarray, ndarray][source]#

Abstract method to perform a calibration on both acc and gyro.

This absolutely needs to implement by any daughter class. It is further recommended to call self._validate_units in the overwritten calibrate method, to check if the input units are as expected.

Parameters:
acc

3D acceleration

gyr

3D gyroscope values

acc_unit

The unit of the acceleration data

gyr_unit

The unit of the gyroscope data

calibrate_df(df: DataFrame, acc_unit: str | None, gyr_unit: str | None, acc_cols: Iterable[str] = ('acc_x', 'acc_y', 'acc_z'), gyr_cols: Iterable[str] = ('gyr_x', 'gyr_y', 'gyr_z')) DataFrame[source]#

Apply the calibration to data stored in a dataframe.

This calls calibrate for the respective columns and returns a copy of the df with the respective columns replaced by their calibrated counter-part.

See the calibrate method for more information.

Parameters:
df

6 column dataframe (3 acc, 3 gyro)

acc_cols

The name of the 3 acceleration columns in order x,y,z.

gyr_cols

The name of the 3 acceleration columns in order x,y,z.

acc_unit

The unit of the acceleration data

gyr_unit

The unit of the gyroscope data

Returns:
cal_df

A copy of df with the calibrated data.

classmethod find_subclass_from_cal_type(cal_type)[source]#

Get a SensorCalibration subclass that handles the specified calibration type.

classmethod from_hdf5(path: str | Path)[source]#

Read calibration data stored in hdf5 fileformat (created by CalibrationInfo.save_to_hdf5).

Parameters:
path

Path to the hdf5 file

Returns:
cal_info

A CalibrationInfo object. The exact child class is determined by the cal_type key in the json string.

classmethod from_json(json_str: str) CalInfo[source]#

Create a calibration object from a json string (created by CalibrationInfo.to_json).

Parameters:
json_str

valid json string object

Returns:
cal_info

A CalibrationInfo object. The exact child class is determined by the cal_type key in the json string.

classmethod from_json_file(path: str | Path) CalInfo[source]#

Create a calibration object from a valid json file (created by CalibrationInfo.to_json_file).

Parameters:
path

Path to the json file

Returns:
cal_info

A CalibrationInfo object. The exact child class is determined by the cal_type key in the json string.

to_hdf5(path: str | Path)[source]#

Save calibration matrices to hdf5 file format.

Parameters:
path

Path to the hdf5 file

to_json() str[source]#

Convert all calibration matrices into a json string.

to_json_file(path: str | Path)[source]#

Dump acc calibration matrices into a file in json format.

Parameters:
path

path to the json file

Examples using imucal.CalibrationInfo#

Custom Calibration Info Subclass

Custom Calibration Info Subclass