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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_gallery_southern-africa-gravity.py>`
        to download the full example code

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

.. _sphx_glr_gallery_southern-africa-gravity.py:


Gravity ground-based surveys of Southern Africa
-----------------------------------------------

This dataset is a compilation of several public domain ground measurements
of gravity from Southern Africa. The observations are the absolute gravity
values in mGal. The horizontal datum is not specified and heights are
referenced to "sea level", which we will interpret as the geoid (which
realization is likely not relevant since the uncertainty in the height is
probably larger than geoid model differences).

**Original source:** `NOAA NCEI
<https://ngdc.noaa.gov/mgg/geodas/trackline.html>`__

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

.. GENERATED FROM PYTHON SOURCE LINES 25-31

.. code-block:: Python


    import pandas as pd
    import pygmt

    import ensaio








.. GENERATED FROM PYTHON SOURCE LINES 32-33

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

.. GENERATED FROM PYTHON SOURCE LINES 33-36

.. code-block:: Python

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





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

 .. code-block:: none

    /home/runner/work/_temp/cache/ensaio/v1/southern-africa-gravity.csv.xz




.. GENERATED FROM PYTHON SOURCE LINES 37-38

Load the CSV formatted data with pandas

.. GENERATED FROM PYTHON SOURCE LINES 38-41

.. 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>longitude</th>
          <th>latitude</th>
          <th>height_sea_level_m</th>
          <th>gravity_mgal</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>18.34444</td>
          <td>-34.12971</td>
          <td>32.2</td>
          <td>979656.12</td>
        </tr>
        <tr>
          <th>1</th>
          <td>18.36028</td>
          <td>-34.08833</td>
          <td>592.5</td>
          <td>979508.21</td>
        </tr>
        <tr>
          <th>2</th>
          <td>18.37418</td>
          <td>-34.19583</td>
          <td>18.4</td>
          <td>979666.46</td>
        </tr>
        <tr>
          <th>3</th>
          <td>18.40388</td>
          <td>-34.23972</td>
          <td>25.0</td>
          <td>979671.03</td>
        </tr>
        <tr>
          <th>4</th>
          <td>18.41112</td>
          <td>-34.16444</td>
          <td>228.7</td>
          <td>979616.11</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>14354</th>
          <td>21.22500</td>
          <td>-17.95833</td>
          <td>1053.1</td>
          <td>978182.09</td>
        </tr>
        <tr>
          <th>14355</th>
          <td>21.27500</td>
          <td>-17.98333</td>
          <td>1033.3</td>
          <td>978183.09</td>
        </tr>
        <tr>
          <th>14356</th>
          <td>21.70833</td>
          <td>-17.99166</td>
          <td>1041.8</td>
          <td>978182.69</td>
        </tr>
        <tr>
          <th>14357</th>
          <td>21.85000</td>
          <td>-17.95833</td>
          <td>1033.3</td>
          <td>978193.18</td>
        </tr>
        <tr>
          <th>14358</th>
          <td>21.98333</td>
          <td>-17.94166</td>
          <td>1022.6</td>
          <td>978211.38</td>
        </tr>
      </tbody>
    </table>
    <p>14359 rows × 4 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 42-43

Make a PyGMT map with the data points colored by the gravity data.

.. GENERATED FROM PYTHON SOURCE LINES 43-65

.. code-block:: Python

    fig = pygmt.Figure()
    fig.basemap(
        region=[
            data.longitude.min() - 1,
            data.longitude.max() + 1,
            data.latitude.min() - 1,
            data.latitude.max() + 1,
        ],
        projection="M15c",
        frame=True,
    )
    pygmt.makecpt(cmap="viridis", series=[data.gravity_mgal.min(), data.gravity_mgal.max()])
    fig.plot(
        x=data.longitude,
        y=data.latitude,
        fill=data.gravity_mgal,
        cmap=True,
        style="c0.05c",
    )
    fig.colorbar(frame='af+l"gravity [mGal]"')
    fig.coast(shorelines=True, water="royalblue4", area_thresh=1e4)
    fig.show()



.. image-sg:: /gallery/images/sphx_glr_southern-africa-gravity_001.png
   :alt: southern africa gravity
   :srcset: /gallery/images/sphx_glr_southern-africa-gravity_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_gallery_southern-africa-gravity.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: southern-africa-gravity.ipynb <southern-africa-gravity.ipynb>`

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

      :download:`Download Python source code: southern-africa-gravity.py <southern-africa-gravity.py>`


.. only:: html

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

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