Speed up wind shear calculation
ews-ffarella opened this issue · 1 comments
Hi!
Great repo. Have you considered using np.polynomial.polynomial.polyfit
to speed up the wind shear calculations?
In my benchmarks (ok, they may be be a bit old), it is faster. Below a solution using dask
(we have big datasets), but
polyfit = np.polynomial.polynomial.polyfit
heights = df.columns.to_series().values.astype("float")
logh = np.log(heights)
vals = np.log(df.values)
def regr(v):
return polyfit(logh[~np.isnan(v)], v[~np.isnan(v)], 1)[1]
with warnings.catch_warnings():
warnings.simplefilter("ignore")
shear = dask.bag.from_sequence(vals).map(regr).compute(schedulder=schedulder, num_workers=num_workers)
Also for wind veer and/or wind direction difference we use
def calculate_angle_shift(inf, sup):
diff = np.radians(sup) - np.radians(inf)
return np.degrees(np.arctan2(np.sin(diff), np.cos(diff)))
It might be faster than this
Hi @ews-ffarella,
Thanks!
We use
coeffs = np.polyfit(log_heights, log_wspds, deg=1) # get coefficients of linear best fit to log distribution
brightwind/brightwind/analyse/shear.py
Line 847 in 5f20fd2
Is that the same function as you are suggesting?
There is also a bit of prepping of the data like getting concurrent wind speeds before averaging them which can take time. Calculating the time series of shear can take time so am interested to know how this could be speeded up.
Please feel free to create a branch and implement your suggestion and then we can test the speed difference.
Cheers,