Skip to main content

Tool to create calibration matrix allowing to correct for magneto-resistance in resisitive sensors.

Project description

Simple tool to generate a calibration correction matrix for resistive sensors in a magnetic field.

Installation

pip install MagnetoResistance-tool or pip install --user MagnetoResistance-tool.

Usage

MRcalib [-h] [-o FILE_OUT] [-p] [-B FIELD_ORDER] [-T TEMP_ORDER] [-v] file_in

Fit magneto-resistance data and create calibration matrix.

positional arguments:
file_in               input file defining the measurement data

options:
-h, --help            show this help message and exit
-o FILE_OUT, --out FILE_OUT
calibration matrix output file
-p, --plot            plot the data and fits
-B FIELD_ORDER, --field FIELD_ORDER
order of polynomial to use for fitting with respect to the magnetic field
-T TEMP_ORDER, --temperature TEMP_ORDER
order of polynomial to use for fitting with respect to the measured temperature
-v, --verbose         print values while calculating

The input file file_in describes the data files to use. It should be a tab delimited file specifying first the path of the data file to use, next the names of the field and temperature columns to use, and finally the parameters for the outlier rejection algorithm. Here's an example:

SD-3-7_V1-1-5_V2-20-6_BSweep_1,33K.001.dat	Field	Probe_Temp	 0	0	0	0
SD-3-7_V1-1-5_V2-20-6_BSweep_2,17K.001.dat	Field	Probe_Temp	 0	0	0	0
SD-3-7_V1-1-5_V2-20-6_BSweep-1,3K.001.dat	Field	Probe_Temp	 0	0	0	0
SD-3-7_V1-1-5_V2-20-6_BSweep-1,89K.001.dat	Field	Probe_Temp	 50	5	50	0.04
SD-3-7_V1-1-5_V2-20-6_BSweep-2,6K.001.dat	Field	Probe_Temp	 25	0.8	0	0
d3_mag_sweep_4p2K.001.dat	B	T-A-K	 0	0	150	0.5
d3_mag_sweep_10K.001.dat	B	T-A-K	 0	0	20	0.04
d3_mag_sweep_15K.001.dat	B	T-A-K	 0	0	20	0.06
d3_mag_sweep_20K.002.dat	B	T-A-K	 0	0	20	0.06
d3_mag_sweep_25K.001.dat	B	T-A-K	 0	0	30	0.06

The outlier rejection algorithm takes a rolling median of the data and rejects any points outside of this rolling median. The first two parameters control the outlier rejection in terms of field, the second set of two parameters does the same in terms of temperature. In each set the first parameter specifies the size of the window to take the rolling median over, and the second specifies how big the difference has to be for a point to be considered an outlier. Setting either of these two parameters to zero disables outlier rejection for this variable. To summarize, the syntax of the input file is:

<PATH>	<FIELD COLUMN NAME>	<TEMPERATURE COLUMN NAME> <FIELD ROLLING MEDIAN WINDOW> <FIELD REJECTION THRESHOLD> <TEMPERATURE ROLLING MEDIAN WINDOW> <TEMPERATURE REJECTION THERSHOLD>

Once the input file is created the calibration matrix creation tool can be called:

MRcalib <PATH TO INPUT FILE>

All data is sliced up in slices of equal field. For each field the actual temperature is fitted against the measured temperature using the order specified by the --temperature or -T argument (defaults to 1 if unspecified). Next each of these fitting parameters is fitted against field using the order specified by the --field or -B argument (defaults to 3 if unspecified). The optional arguments --verbose (-v) and --plot (-p) allow to check and visualize each step. Plotting requires matplotlib.

When plotting is enabled the first set of plots visualizes which points are accepted by the outlier rejection algorithm and which ones are rejected. This allows to fine tune the parameters of the algorithm to achieve the desired result. The second set of plots visualizes the first round of fitting (actual temperature versus measured temperature) for a maximum of 10 different fields. The final plot allows for performing a sanity check. The calculated correction is applied to the initial set of input files. This should create a series of more or less flat lines since the actual temperature for each input data file is the same. If this is not the case than this can indicate that the actual temperature was drifting in one of the input data files. Increasing or decreasing the order of the fitting polynomials (--field) and (--temperature) can help to achieve a better result. In general higher is better, but requires more computation and therefore more time and the improvement return tends to diminish the higher the order becomes.

The generated calibration matrix is written as calib.txt into the same directory as the input file was read from. This can be overridden using the --out or -o argument.

To apply the calculated calibration matrix to your actual data, call the correction function from your python data analysis script as follows:

from MRcalib import MRcorrect

<YOUR CODE GOES HERE>

MRcorrect(<PATH TO CALIBRATION FILE>, <FIELD DATA>, <TEMPERATURE DATA>)

<YOUR CODE GOES HERE>

This function will return the actual temperature and its uncertainty for a given field and measured temperature. The field and temperature data can be provided as an integer, float, list, numpy array, pandas dataframe or pandas series.

Bugs and contributions

If you found a problem, please open a new ticket in the issues pane of our GitLab page. And if you want to contribute than merge requests are also welcome on our GitLab page.

License

The code in this repository is licensed under the GPL-3+ license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magnetoresistance_tool-0.0.4.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

MagnetoResistance_tool-0.0.4-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file magnetoresistance_tool-0.0.4.tar.gz.

File metadata

  • Download URL: magnetoresistance_tool-0.0.4.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for magnetoresistance_tool-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d51124013babd4bf52f3b615d8f011fce1a20718231c1cd08b416ef8de3fb89b
MD5 f27b9fc4502fa9cb2cc25cc12caadad3
BLAKE2b-256 6257972f49a41a809ec945e2580d62ab31f9fbfba2e0b6b0d58133cfca25d1a0

See more details on using hashes here.

File details

Details for the file MagnetoResistance_tool-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for MagnetoResistance_tool-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e8a1b0554f6b96e6007346620c4b7524a21fe62157274cba2cd887fa1fcc131f
MD5 1bb121434d4b6a9c4704a95199cf7426
BLAKE2b-256 eaf9ec9b607c989516badcd8839288fb257f384fed939abffdeabdfb64f46ae2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page