File: Angle_to_Direction.py

package info (click to toggle)
metpy 1.7.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,584 kB
  • sloc: python: 41,853; makefile: 111; javascript: 57
file content (39 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright (c) 2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""
==================
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)

###########################################
# Now throw that angle into the function to
# get the corresponding direction
dir_str = mpcalc.angle_to_direction(angle_deg)
print(dir_str)

###########################################
# 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.
angle_deg_list = [0, 361, 719]
dir_str_list = mpcalc.angle_to_direction(angle_deg_list)
print(dir_str_list)

###########################################
# If you want the unabbrieviated version, input full=True
full_dir_str_list = mpcalc.angle_to_direction(angle_deg_list, full=True)
print(full_dir_str_list)