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.

import metpy.calc as mpcalc
from metpy.units import units

Create a test value of an angle

angle_deg = 70 * units('degree')
print(angle_deg)

Out:

70 degree

Now throw that angle into the function to get the corresponding direction

Out:

ENE

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.

Out:

('N', 'N', 'N')

If you want the unabbrieviated version, input full=True

Out:

['North', 'North', 'North']

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

Gallery generated by Sphinx-Gallery