I calculated the wind direction using Metpy. How can I extract the values and use the values as input in another part of my program?
In the sample code below, I would like to display the direction as a numpy variable, so I can use it in my program.
import metpy.calc as mpcalc
import numpy as np
# Make some fake data for us to work with
np.random.seed(19990503) # So we all have the same data
u = np.random.randint(0, 15, 10) * units('m/s')
v = np.random.randint(0, 15, 10) * units('m/s')
direction = mpcalc.wind_direction(u, v)
print(direction)
To convert a metpy result from a wind calculation to a numpy array, simply use the numpy np.array
function.
import metpy.calc as mpcalc
from metpy.units import units
import numpy as np
np.random.seed(19990503)
u = np.random.randint(0, 15, 10)*units("m/s")
v = np.random.randint(0, 15, 10)*units("m/s")
direction = mpcalc.wind_direction(u, v)
direction_numpy = np.array(direction)