Skip to content

Commit

Permalink
Normalize wind direction angles
Browse files Browse the repository at this point in the history
Correctly find the differences between measured angles
  • Loading branch information
tsundvoll authored and Jens Gåsemyr Magnus committed May 21, 2021
1 parent 9896a8d commit c58a523
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion camille/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,15 @@ double veer(double dir_upr,
double dir_lwr,
double hgt_upr,
double hgt_lwr) noexcept {
using std::atan2;
using std::sin;
using std::cos;
double a = dir_upr - dir_lwr;

// Normalize angular difference
double n = atan2(sin(a), cos(a));

return (dir_upr - dir_lwr) / (hgt_upr - hgt_lwr);
return n / (hgt_upr - hgt_lwr);
}

static const auto planar_windspeed_docstring = R"(
Expand Down
6 changes: 4 additions & 2 deletions camille/lidar.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def extrapolate_winddirection(df, height):
pandas.Series
Wind direction at target height
"""
hwd = df.dir + df.veer * (height - df.height)
return hwd

hwd = df.dir.values + df.veer.values * (height - df.height.values)
hwd = np.arcsin(np.sin(hwd)) # Normalize direction
return pd.Series(hwd, index=df.index)


def windfield_desc(df, dist, hub_height, lidar_height_offset):
Expand Down
2 changes: 1 addition & 1 deletion tests/process/test_lidar.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def test(args):
p = np.array([dist, 0, lidar_hgt])
for _, row in processed.iterrows():
assert row.hws == ref_speed(windfield, p)
assert row.hwd == ref_direction(windfield)
assert row.shear == ref_shear(windfield)
assert row.veer == ref_veer(windfield)
assert row.hwd == ref_direction(windfield)
return test


Expand Down

0 comments on commit c58a523

Please sign in to comment.