.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_self_calibration.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_self_calibration.py: How to use self calibration module ================================== The magnetic field read by the sensors inside km3net DOM are sending a measurement in cartesian referential. When a DOM is placed under an uniform magnetic field, rotating it should only results in a modification of the magnetic field direction. However, the natural coordinates system is often not centered on (0,0,0), which raise the need to perform a calibration before using converting the magnetic field data in a direction measurement. This script is an example on how use the ``calib_self_sphere`` class on acceptance tests data in order to estimate the point around which the magnetic field is revolving, allowing a calibration directly computed on data. .. GENERATED FROM PYTHON SOURCE LINES 18-21 .. code-block:: default import km3compass as kc import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 22-25 Loading some data ~~~~~~~~~~~~~~~~~ Initialising is a simple as this: .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: default filename = "../tests/DOM_0801.csk" reader = kc.readerCSK(filename) print(reader.module_IDs) .. rst-class:: sphx-glr-script-out .. code-block:: none File loaded, 2508 rows 1 module(s) - 817302522 Number of measurements after removing duplicates : 252 [817302522] .. GENERATED FROM PYTHON SOURCE LINES 30-36 Loading the module ~~~~~~~~~~~~~~~~~~ The ``calib_self_sphere`` will fit a sphere to the raw magnetic field data, and will then correct the data from the estimated center. .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: default calib = kc.calib_self_sphere(reader, 817302522) .. GENERATED FROM PYTHON SOURCE LINES 39-44 Print fit results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here, we print the center and radius reconstructed by the fit. We also display a plot that summarize the calibration results. .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. code-block:: default print("Center : {}".format(calib.center.flatten())) print("Radius : {}".format(calib.radius)) calib.plot_results() .. image-sg:: /auto_examples/images/sphx_glr_plot_self_calibration_001.png :alt: plot self calibration :srcset: /auto_examples/images/sphx_glr_plot_self_calibration_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Center : [ 0.0736884 -0.10788356 -0.37211751] Radius : [0.21029674] .. GENERATED FROM PYTHON SOURCE LINES 50-54 Comparing data before and after calibration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To do so, we will use the ``kc.plot_raw_results`` function, that works for both raw and calibrated data : .. GENERATED FROM PYTHON SOURCE LINES 54-61 .. code-block:: default kc.plot_raw_results(reader.df, title="Data before calibration") kc.plot_raw_results(calib.df, title="Data after applying self calibration") plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_self_calibration_002.png :alt: Data before calibration :srcset: /auto_examples/images/sphx_glr_plot_self_calibration_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_self_calibration_003.png :alt: Data after applying self calibration :srcset: /auto_examples/images/sphx_glr_plot_self_calibration_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.001 seconds) .. _sphx_glr_download_auto_examples_plot_self_calibration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_self_calibration.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_self_calibration.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_