Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized parse_angle() for long list of directional strings. Move "from operator import itemgetter" up one line. Revise how DIR_DICT is initialized; will use BASE_DEGREE_MULTIPLIER more in another PR. Remove print in test_tools Add back extra line... Handle np.array and pd.Series for parse_angle() and add new angle_to_dir() Fix example heading section Add full=True example Imperative Mood and newline between import group Update templates doc Fix CI Add back year
- Loading branch information
Showing
5 changed files
with
309 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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 numpy as np | ||
|
||
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_dir(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_dir(angle_deg_list) | ||
print(dir_str_list) | ||
|
||
########################################### | ||
# If you want the unabbrieviated version, input full=True | ||
full_dir_str_list = mpcalc.angle_to_dir(angle_deg_list, full=True) | ||
print(full_dir_str_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.