We describe a method for the in-orbit calibration of body-mounted magnetometers
based on the CHAOS-7 geomagnetic field model. The code is designed to find the true
calibration parameters autonomously by using only the onboard magnetometer data and the
corresponding CHAOS outputs. As the model output and satellite data have different
coordinate systems, they are first transformed to a Star Tracker Coordinate (STC). Then,
non-linear optimization processes are run to minimize the differences between the
CHAOS-7 model and satellite data in the STC. The process finally searches out a suite of
calibration parameters that can maximize the model-data agreement. These parameters
include the instrument gain, offset, axis orthogonality, and Euler rotation matrices
between the magnetometer frame and the STC. To validate the performance of the Python
code, we first produce pseudo satellite data by convoluting CHAOS-7 model outputs with a
prescribed set of the ‘true’ calibration parameters. Then, we let the code autonomously
undistort the pseudo satellite data through optimization processes, which ultimately
track down the initially prescribed calibration parameters. The reconstructed parameters
are in good agreement with the prescribed (true) ones, which demonstrates that the code
can be used for actual instrument data calibration. This study is performed using Python
3.8.5, NumPy 1.19.2, SciPy 1.6, AstroPy 4.2, SpacePy 0.2.1, and ChaosmagPy 0.5 including
the CHAOS-7.6 geomagnetic field model. This code will be utilized for processing
NextSat-1 and Small scale magNetospheric and Ionospheric Plasma Experiment (SNIPE) data
in the future.