
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/britain-magnetic.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_britain-magnetic.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_britain-magnetic.py:


Magnetic airborne survey of Britain
-----------------------------------

This is a digitization of an airborne magnetic survey of Britain. Data are
sampled where flight lines crossed contours on the archive maps. Contains
only the total field magnetic anomaly, not the magnetic field intensity
measurements or corrections.

Unfortunately, the exact date of measurements is not available (only the year).

Contains British Geological Survey materials © UKRI 2021.

**Original source:**
`British Geological Survey
<https://www.bgs.ac.uk/datasets/gb-aeromagnetic-survey/>`__

**Pre-processing:** `Source code for preparation of the original dataset for
redistribution in Ensaio <https://github.com/fatiando-data/britain-magnetic>`__

.. GENERATED FROM PYTHON SOURCE LINES 28-35

.. code-block:: Python


    import numpy as np
    import pandas as pd
    import pygmt

    import ensaio








.. GENERATED FROM PYTHON SOURCE LINES 36-37

Download and cache the data and return the path to it on disk

.. GENERATED FROM PYTHON SOURCE LINES 37-40

.. code-block:: Python

    fname = ensaio.fetch_britain_magnetic(version=1)
    print(fname)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /home/runner/work/_temp/cache/ensaio/v1/britain-magnetic.csv.xz




.. GENERATED FROM PYTHON SOURCE LINES 41-42

Load the CSV formatted data with pandas

.. GENERATED FROM PYTHON SOURCE LINES 42-45

.. code-block:: Python

    data = pd.read_csv(fname)
    data






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>line_and_segment</th>
          <th>year</th>
          <th>longitude</th>
          <th>latitude</th>
          <th>height_m</th>
          <th>total_field_anomaly_nt</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>FL1-1</td>
          <td>1955</td>
          <td>-1.74162</td>
          <td>53.48164</td>
          <td>792</td>
          <td>62</td>
        </tr>
        <tr>
          <th>1</th>
          <td>FL1-1</td>
          <td>1955</td>
          <td>-1.70122</td>
          <td>53.48352</td>
          <td>663</td>
          <td>56</td>
        </tr>
        <tr>
          <th>2</th>
          <td>FL1-1</td>
          <td>1955</td>
          <td>-1.08051</td>
          <td>53.47677</td>
          <td>315</td>
          <td>30</td>
        </tr>
        <tr>
          <th>3</th>
          <td>FL1-1</td>
          <td>1955</td>
          <td>-1.07471</td>
          <td>53.47672</td>
          <td>315</td>
          <td>31</td>
        </tr>
        <tr>
          <th>4</th>
          <td>FL1-1</td>
          <td>1955</td>
          <td>-1.01763</td>
          <td>53.47586</td>
          <td>321</td>
          <td>44</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>541503</th>
          <td>FL-3(TL10-24)-1</td>
          <td>1965</td>
          <td>-4.68843</td>
          <td>58.26786</td>
          <td>1031</td>
          <td>64</td>
        </tr>
        <tr>
          <th>541504</th>
          <td>FL-3(TL10-24)-1</td>
          <td>1965</td>
          <td>-4.68650</td>
          <td>58.26786</td>
          <td>1045</td>
          <td>74</td>
        </tr>
        <tr>
          <th>541505</th>
          <td>FL-3(TL10-24)-1</td>
          <td>1965</td>
          <td>-4.68535</td>
          <td>58.26790</td>
          <td>1035</td>
          <td>94</td>
        </tr>
        <tr>
          <th>541506</th>
          <td>FL-3(TL10-24)-1</td>
          <td>1965</td>
          <td>-4.68419</td>
          <td>58.26787</td>
          <td>1024</td>
          <td>114</td>
        </tr>
        <tr>
          <th>541507</th>
          <td>FL-3(TL10-24)-1</td>
          <td>1965</td>
          <td>-4.68274</td>
          <td>58.26790</td>
          <td>1011</td>
          <td>120</td>
        </tr>
      </tbody>
    </table>
    <p>541508 rows × 6 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 46-48

Make a PyGMT map with the data points colored by the total field magnetic
anomaly.

.. GENERATED FROM PYTHON SOURCE LINES 48-64

.. code-block:: Python


    fig = pygmt.Figure()
    scale = np.percentile(data.total_field_anomaly_nt, 95)
    pygmt.makecpt(cmap="polar", series=[-scale, scale])
    fig.plot(
        x=data.longitude,
        y=data.latitude,
        style="c0.02c",
        fill=data.total_field_anomaly_nt,
        cmap=True,
        projection="M15c",
    )
    fig.colorbar(frame='af+l"nT"', position="jBL+h+w7c/0.2c+o1/2")
    fig.coast(shorelines=True)
    fig.basemap(frame="afg")
    fig.show()



.. image-sg:: /gallery/images/sphx_glr_britain-magnetic_001.png
   :alt: britain magnetic
   :srcset: /gallery/images/sphx_glr_britain-magnetic_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_gallery_britain-magnetic.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: britain-magnetic.ipynb <britain-magnetic.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: britain-magnetic.py <britain-magnetic.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
