Calibration data JSONΒΆ

The preferred format for calibration data is JSON file. Howeer, they are not always as easy to handwrite, so it is possible to use txt/ASCII calibration files too.

from pathlib import Path
import json
import plotly
from resistics.time import ChanMetadata
from resistics.calibrate import SensorCalibrationJSON

Define the calibration data path. This is dependent on where the data is stored.

cal_data_path = Path("..", "..", "data", "calibration", "example.json")

Inspect the contents of the calibration file

with cal_data_path.open("r") as f:
    file_contents = json.load(f)
print(json.dumps(file_contents, indent=4, sort_keys=True))

Out:

{
    "file_info": {
        "created_on_local": "2021-07-04T17:20:47.042892",
        "created_on_utc": "2021-07-04T16:20:47.042892",
        "version": "1.0.0a3"
    },
    "file_path": "calibration_ascii\\example.txt",
    "frequency": [
        0.00011,
        0.0011,
        0.011,
        0.021,
        0.03177,
        0.048062,
        0.072711,
        0.11,
        0.13249,
        0.15959,
        0.19222,
        0.23153,
        0.27888,
        0.3359,
        0.40459,
        0.48733,
        0.58698,
        0.70702,
        0.8516,
        1.0257,
        1.2355,
        1.4881,
        1.7925,
        2.159,
        2.6005,
        3.1323,
        3.7728,
        4.5443,
        5.4736,
        6.5929,
        7.9411,
        9.5649,
        11.521,
        13.877,
        16.715,
        20.132,
        24.249,
        29.208,
        35.181,
        42.375,
        51.041,
        61.478,
        74.05,
        89.192,
        107.43,
        129.4,
        155.86,
        187.73,
        226.12,
        272.36,
        328.06,
        395.14,
        475.95,
        573.28,
        690.5,
        831.71,
        1001.8
    ],
    "magnitude": [
        0.01,
        0.1,
        1.0,
        1.903,
        2.903,
        4.339,
        6.565,
        9.935,
        12.02,
        14.2,
        17.24,
        20.82,
        24.53,
        29.38,
        34.21,
        40.3,
        47.34,
        53.8,
        61.1,
        68.05,
        75.0,
        80.45,
        85.4,
        89.25,
        92.2,
        94.4,
        96.2,
        97.3,
        98.1,
        98.65,
        99.05,
        99.35,
        99.75,
        99.75,
        99.8,
        99.95,
        99.95,
        99.95,
        100.0,
        100.0,
        100.2,
        100.0,
        100.0,
        100.0,
        99.8,
        99.8,
        99.7,
        99.6,
        99.3,
        98.8,
        98.0,
        96.0,
        92.7,
        87.55,
        80.8,
        74.5,
        70.7
    ],
    "magnitude_unit": "mV/nT",
    "n_samples": 57,
    "phase": [
        1.5707963267948966,
        1.5707963267948966,
        1.5533430342749532,
        1.546065011294137,
        1.5428361521779475,
        1.526971109277319,
        1.505398839722669,
        1.4724295701524963,
        1.4491817845159316,
        1.4238046971919343,
        1.402913106045562,
        1.3795780539463978,
        1.3431181258722362,
        1.2771446801468507,
        1.2277693156079312,
        1.1700861838295185,
        1.0909355022515757,
        1.0088177609452424,
        0.9242216521010773,
        0.827041719350033,
        0.7294952674560699,
        0.6388428661074844,
        0.5498136209632537,
        0.46968555500419407,
        0.3926641751136843,
        0.32766811376941546,
        0.270246781378802,
        0.21961477977844648,
        0.17517869702267086,
        0.13625436404469332,
        0.10112263153129945,
        0.06969099703213358,
        0.04107981460419053,
        0.013366778609323771,
        -0.01522921945412692,
        -0.04212177616763115,
        -0.07138396640656808,
        -0.10302329508672128,
        -0.1383801750736224,
        -0.1780235837034216,
        -0.21912608758788807,
        -0.2792875869041326,
        -0.3439869422755624,
        -0.42004839107747527,
        -0.5115036438819781,
        -0.6197664173831864,
        -0.7506312046977213,
        -0.9091245540713263,
        -1.1008838789879434,
        -1.3337282544965068,
        -1.616262153809349,
        -1.9645426060448175,
        -2.384294291149454,
        -2.8906143071530086,
        2.784672821556953,
        2.030865117620602,
        0.8973959414979245
    ],
    "sensor": "lemi120",
    "serial": 710,
    "static_gain": 1.0
}

Read the data using the appropriate calibration data reader. As calibration data can be dependent on certain sensor parameters, channel metadata needs to be passed to the method.

chan_metadata = ChanMetadata(name="Hx", chan_type="magnetic", data_files=[])
cal_data = SensorCalibrationJSON().read_calibration_data(cal_data_path, chan_metadata)

Plot the calibration data.

fig = cal_data.plot(color="maroon")
fig.update_layout(height=700)
plotly.io.show(fig)

Total running time of the script: ( 0 minutes 0.263 seconds)

Gallery generated by Sphinx-Gallery