.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Parse_Angles.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_Parse_Angles.py: ============ Parse angles ============ Demonstrate how to convert direction strings to angles. The code below shows how to parse directional text into angles. It also demonstrates the function's flexibility in handling various string formatting. .. GENERATED FROM PYTHON SOURCE LINES 15-17 .. code-block:: default import metpy.calc as mpcalc .. GENERATED FROM PYTHON SOURCE LINES 18-19 Create a test value of a directional text .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: default dir_str = 'SOUTH SOUTH EAST' print(dir_str) .. rst-class:: sphx-glr-script-out .. code-block:: none SOUTH SOUTH EAST .. GENERATED FROM PYTHON SOURCE LINES 23-25 Now throw that string into the function to calculate the corresponding angle .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: default angle_deg = mpcalc.parse_angle(dir_str) print(angle_deg) .. rst-class:: sphx-glr-script-out .. code-block:: none 157.5 degree .. GENERATED FROM PYTHON SOURCE LINES 29-31 The function can also handle arrays of strings with different abbreviations and capitalizations .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: default dir_str_list = ['ne', 'NE', 'NORTHEAST', 'NORTH_EAST', 'NORTH east'] angle_deg_list = mpcalc.parse_angle(dir_str_list) print(angle_deg_list) .. rst-class:: sphx-glr-script-out .. code-block:: none (, , , , ) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.002 seconds) .. _sphx_glr_download_examples_calculations_Parse_Angles.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Parse_Angles.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Parse_Angles.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_