.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Angle_to_Direction.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_examples_calculations_Angle_to_Direction.py: ================== Angle to Direction ================== Demonstrate how to convert angles to direction strings. The code below shows how to convert angles into directional text. It also demonstrates the function's flexibility. .. GENERATED FROM PYTHON SOURCE LINES 14-17 .. code-block:: Python import metpy.calc as mpcalc from metpy.units import units .. GENERATED FROM PYTHON SOURCE LINES 18-19 Create a test value of an angle .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python angle_deg = 70 * units('degree') print(angle_deg) .. rst-class:: sphx-glr-script-out .. code-block:: none 70 degree .. GENERATED FROM PYTHON SOURCE LINES 23-25 Now throw that angle into the function to get the corresponding direction .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python dir_str = mpcalc.angle_to_direction(angle_deg) print(dir_str) .. rst-class:: sphx-glr-script-out .. code-block:: none ENE .. GENERATED FROM PYTHON SOURCE LINES 29-32 The function can also handle array of angles, rounding to the nearest direction, handling angles > 360, and defaulting to degrees if no units are specified. .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python angle_deg_list = [0, 361, 719] dir_str_list = mpcalc.angle_to_direction(angle_deg_list) print(dir_str_list) .. rst-class:: sphx-glr-script-out .. code-block:: none ['N' 'N' 'N'] .. GENERATED FROM PYTHON SOURCE LINES 37-38 If you want the unabbrieviated version, input full=True .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python full_dir_str_list = mpcalc.angle_to_direction(angle_deg_list, full=True) print(full_dir_str_list) .. rst-class:: sphx-glr-script-out .. code-block:: none ['North' 'North' 'North'] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.004 seconds) .. _sphx_glr_download_examples_calculations_Angle_to_Direction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Angle_to_Direction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Angle_to_Direction.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_