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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_generated_gallery_vector_data_true_winds.py>`
        to download the full example code.

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

.. _sphx_glr_generated_gallery_vector_data_true_winds.py:


True Winds (Foreign Grid)
-------------------------

This example demonstrates how to render "true" winds, when attached to data points
given in a non-standard Coordinate Reference System (CRS).

📋 Summary
^^^^^^^^^^

The example constructs sample points on a North Polar Stereographic grid, and assigns
synthetic vector values to them, representing wind data. These data are presented as
"true" winds, i.e., eastward (``U``) and northward (``V``) vector components, therefore
not related to the foreign sample points grid. This is a fairly typical real world
use case.

A synthetic eastward wind with a constant ``4.0 ms-1`` is generated everywhere,
so the final effect is clearly visible.

We use the :meth:`geovista.bridge.Transform.from_points` method, passing the
winds to the ``vectors`` keyword, and specifying the different CRS of both the
sample points (``crs``) and the vectors (``vectors_crs``).

.. tags::

    experimental 🧪,
    component: graticule, component: texture, component: vectors,
    domain: meteorology,
    filter: glyph,
    version: 0.6.0

----

.. GENERATED FROM PYTHON SOURCE LINES 41-101







.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /generated/gallery/vector_data/images/sphx_glr_true_winds_001.png
        :alt: true winds
        :srcset: /generated/gallery/vector_data/images/sphx_glr_true_winds_001.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/geovista-ja/checkouts/latest/geovista/docs/src/generated/gallery/vector_data/images/sphx_glr_true_winds_001.vtksz






.. code-block:: Python


    from __future__ import annotations

    import cartopy.crs as ccrs
    import numpy as np
    import pyvista as pv

    import geovista as gv


    def main() -> None:
        """Plot vectors on different CRS from points.

        Notes
        -----
        .. versionadded:: 0.6.0

        """
        # Create a stereographic CRS (foreign grid) for the sample points.
        crs_polar = ccrs.NorthPolarStereo()

        # Create a geographic (latitude/longitude) CRS for the vectors.
        crs_latlon = ccrs.Geodetic()

        # Create the polar grid points.
        x = np.linspace(-5.0e6, 5.0e6, 20)
        y = np.linspace(-4.0e6, 2.0e6, 20)
        xs, ys = np.meshgrid(x, y)

        # Create the eastward (us) and northward (vs) wind vector components.
        xs, ys = xs.flatten(), ys.flatten()
        us, vs = 4.0 * np.ones_like(xs), np.zeros_like(ys)

        # Create the point cloud mesh with attached wind vectors.
        mesh = gv.Transform.from_points(
            xs, ys, vectors=(us, vs), crs=crs_polar, vectors_crs=crs_latlon
        )

        # Generate a mesh containing arrow glyphs from the wind vectors.
        arrows = mesh.glyph(factor=0.02)

        # Now render the plotter scene.
        p = gv.GeoPlotter()
        p.add_mesh(arrows, color="red")
        p.add_base_layer(texture=gv.natural_earth_hypsometric())
        p.add_graticule()

        # Define a specific camera position and orientation.
        cpos = pv.CameraPosition(
            position=(0.60371, -0.01103, 3.06958),
            focal_point=(0.0, 0.0, 0.00289),
            viewup=(-0.98099, -0.01998, 0.19304),
        )

        p.add_axes()
        p.show(cpos=cpos)


    if __name__ == "__main__":
        main()


.. _sphx_glr_download_generated_gallery_vector_data_true_winds.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: true_winds.ipynb <true_winds.ipynb>`

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

      :download:`Download Python source code: true_winds.py <true_winds.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: true_winds.zip <true_winds.zip>`


.. only:: html

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

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