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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_gallery_alps-gps-velocity.py>`
        to download the full example code

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

.. _sphx_glr_gallery_alps-gps-velocity.py:


GPS velocities (3-component) for the Alps
-----------------------------------------

This is a compilation of 3D GPS velocities for the Alps. The horizontal
velocities are reference to the Eurasian frame. All velocity components and
even the position have error estimates, which is very useful and rare to find
in a lot of datasets.

**Original source:**
`Sánchez et al. (2018) <https://doi.org/10.1594/PANGAEA.886889>`__

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

.. GENERATED FROM PYTHON SOURCE LINES 24-31

.. code-block:: Python


    import numpy as np
    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_alps_gps(version=1)
    print(fname)





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

 .. code-block:: none

    /home/runner/work/_temp/cache/ensaio/v1/alps-gps-velocity.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>station_id</th>
          <th>longitude</th>
          <th>latitude</th>
          <th>height_m</th>
          <th>velocity_east_mmyr</th>
          <th>velocity_north_mmyr</th>
          <th>velocity_up_mmyr</th>
          <th>longitude_error_m</th>
          <th>latitude_error_m</th>
          <th>height_error_m</th>
          <th>velocity_east_error_mmyr</th>
          <th>velocity_north_error_mmyr</th>
          <th>velocity_up_error_mmyr</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>ACOM</td>
          <td>13.514900</td>
          <td>46.547935</td>
          <td>1774.682</td>
          <td>0.2</td>
          <td>1.2</td>
          <td>1.1</td>
          <td>0.0005</td>
          <td>0.0009</td>
          <td>0.001</td>
          <td>0.1</td>
          <td>0.1</td>
          <td>0.1</td>
        </tr>
        <tr>
          <th>1</th>
          <td>AFAL</td>
          <td>12.174517</td>
          <td>46.527144</td>
          <td>2284.085</td>
          <td>-0.7</td>
          <td>0.9</td>
          <td>1.3</td>
          <td>0.0009</td>
          <td>0.0009</td>
          <td>0.001</td>
          <td>0.1</td>
          <td>0.2</td>
          <td>0.2</td>
        </tr>
        <tr>
          <th>2</th>
          <td>AGDE</td>
          <td>3.466427</td>
          <td>43.296383</td>
          <td>65.785</td>
          <td>-0.2</td>
          <td>-0.2</td>
          <td>0.1</td>
          <td>0.0009</td>
          <td>0.0018</td>
          <td>0.002</td>
          <td>0.1</td>
          <td>0.3</td>
          <td>0.3</td>
        </tr>
        <tr>
          <th>3</th>
          <td>AGNE</td>
          <td>7.139620</td>
          <td>45.467942</td>
          <td>2354.600</td>
          <td>0.0</td>
          <td>-0.2</td>
          <td>1.5</td>
          <td>0.0009</td>
          <td>0.0036</td>
          <td>0.004</td>
          <td>0.2</td>
          <td>0.6</td>
          <td>0.5</td>
        </tr>
        <tr>
          <th>4</th>
          <td>AIGL</td>
          <td>3.581261</td>
          <td>44.121398</td>
          <td>1618.764</td>
          <td>0.0</td>
          <td>0.1</td>
          <td>0.7</td>
          <td>0.0009</td>
          <td>0.0009</td>
          <td>0.002</td>
          <td>0.1</td>
          <td>0.5</td>
          <td>0.5</td>
        </tr>
        <tr>
          <th>...</th>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
          <td>...</td>
        </tr>
        <tr>
          <th>181</th>
          <td>WLBH</td>
          <td>7.351299</td>
          <td>48.415171</td>
          <td>819.069</td>
          <td>0.0</td>
          <td>-0.2</td>
          <td>-2.8</td>
          <td>0.0005</td>
          <td>0.0009</td>
          <td>0.001</td>
          <td>0.1</td>
          <td>0.2</td>
          <td>0.2</td>
        </tr>
        <tr>
          <th>182</th>
          <td>WTZR</td>
          <td>12.878911</td>
          <td>49.144199</td>
          <td>666.025</td>
          <td>0.1</td>
          <td>0.2</td>
          <td>-0.1</td>
          <td>0.0005</td>
          <td>0.0005</td>
          <td>0.001</td>
          <td>0.1</td>
          <td>0.1</td>
          <td>0.1</td>
        </tr>
        <tr>
          <th>183</th>
          <td>ZADA</td>
          <td>15.227590</td>
          <td>44.113177</td>
          <td>64.307</td>
          <td>0.2</td>
          <td>3.1</td>
          <td>-0.3</td>
          <td>0.0018</td>
          <td>0.0036</td>
          <td>0.004</td>
          <td>0.2</td>
          <td>0.4</td>
          <td>0.4</td>
        </tr>
        <tr>
          <th>184</th>
          <td>ZIMM</td>
          <td>7.465278</td>
          <td>46.877098</td>
          <td>956.341</td>
          <td>-0.1</td>
          <td>0.4</td>
          <td>1.0</td>
          <td>0.0005</td>
          <td>0.0009</td>
          <td>0.001</td>
          <td>0.1</td>
          <td>0.1</td>
          <td>0.1</td>
        </tr>
        <tr>
          <th>185</th>
          <td>ZOUF</td>
          <td>12.973553</td>
          <td>46.557221</td>
          <td>1946.508</td>
          <td>0.1</td>
          <td>1.0</td>
          <td>1.3</td>
          <td>0.0005</td>
          <td>0.0009</td>
          <td>0.001</td>
          <td>0.1</td>
          <td>0.1</td>
          <td>0.1</td>
        </tr>
      </tbody>
    </table>
    <p>186 rows × 13 columns</p>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 42-44

To plot the vectors with PyGMT, we need to convert the horizontal components
into angle (azimuth) and length.

.. GENERATED FROM PYTHON SOURCE LINES 44-47

.. code-block:: Python

    angle = np.degrees(np.arctan2(data.velocity_north_mmyr, data.velocity_east_mmyr))
    length = np.hypot(data.velocity_north_mmyr, data.velocity_east_mmyr)








.. GENERATED FROM PYTHON SOURCE LINES 48-50

Now we can make a PyGMT map with the horizontal velocity vectors and vertical
velocities encoded as colored points.

.. GENERATED FROM PYTHON SOURCE LINES 50-110

.. code-block:: Python


    # West, East, South, North boundaries of the map
    region = [-5, 20, 40, 55]

    fig = pygmt.Figure()
    with fig.subplot(
        nrows=1,
        ncols=2,
        figsize=("35c", "15c"),
        sharey="l",  # shared y-axis on the left side
        frame="WSrt",
    ):
        with fig.set_panel(0):
            fig.basemap(region=region, projection="M?", frame="af")
            fig.coast(area_thresh=1e4, land="#eeeeee")
            scale_factor = 2 / length.max()
            fig.plot(
                x=data.longitude,
                y=data.latitude,
                direction=[angle, length * scale_factor],
                style="v0.15c+e",
                fill="blue",
                pen="1p,blue",
            )
            # Plot a quiver caption
            fig.plot(
                x=-4,
                y=42,
                direction=[[0], [1 * scale_factor]],
                style="v0.15c+e",
                fill="blue",
                pen="1p,blue",
            )
            fig.text(
                x=-4,
                y=42.2,
                text="1 mm/yr",
                justify="BL",
                font="10p,Helvetica,blue",
            )
        with fig.set_panel(1):
            fig.basemap(region=region, projection="M?", frame="af")
            fig.coast(area_thresh=1e4, land="#eeeeee")
            pygmt.makecpt(
                cmap="polar",
                series=[data.velocity_up_mmyr.min(), data.velocity_up_mmyr.max()],
            )
            fig.plot(
                x=data.longitude,
                y=data.latitude,
                fill=data.velocity_up_mmyr,
                style="c0.2c",
                cmap=True,
                pen="0.5p,black",
            )
            fig.colorbar(
                frame='af+l"vertical velocity [mm/yr]"',
                position="jTL+w7c/0.3c+h+o1/1",
            )
    fig.show()



.. image-sg:: /gallery/images/sphx_glr_alps-gps-velocity_001.png
   :alt: alps gps velocity
   :srcset: /gallery/images/sphx_glr_alps-gps-velocity_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_gallery_alps-gps-velocity.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: alps-gps-velocity.ipynb <alps-gps-velocity.ipynb>`

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

      :download:`Download Python source code: alps-gps-velocity.py <alps-gps-velocity.py>`


.. only:: html

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

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