Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculating wind u- and v-components from direction and speed #19

Open
mpvginde opened this issue Jun 20, 2024 · 2 comments
Open

Calculating wind u- and v-components from direction and speed #19

mpvginde opened this issue Jun 20, 2024 · 2 comments

Comments

@mpvginde
Copy link

Hi,
I think there is a mistake in the calculation of the wind u- and v-components from wind speed and direction:

meteogrid/R/geowind.R

Lines 49 to 63 in 9da2345

wind.uv <- function(wspeed, wdir, fieldname=c("U","V"), rad=FALSE){
if (missing(wdir) && is.list(wspeed)){
wdir <- wspeed$wdir
wspeed <- wspeed$wspeed
}
if (!rad) wdir <- wdir*pi/180.
u <- wspeed*cos(wdir)
v <- wspeed*sin(wdir)
if (is.geofield(wdir)) {
attr(u, "info")$name <- fieldname[1]
attr(v, "info")$name <- fieldname[2]
}
if (is.vector(wspeed)) return(data.frame(U=u,V=v))
else return(list(U=u,V=v))
}

The cos and sin directly use the direction as angle.
But this is the direction the wind is blowing from (meteorological convection).
The true angle to be used for the cos and sin function should be:
270 - direction (rotate wind 180 degrees + 90 degrees to account for the fact that the N/S axis is used as reference in stead of E/W axis)

As it is now, if you apply wind.dirspeed and then again wind.uv the original u an v are swapped and have the opposite sign.

Michiel

@mpvginde
Copy link
Author

@adeckmyn

@adeckmyn
Copy link
Collaborator

Indeed, that is an error (or at the very least an inconsistency). The function is rarely used (I think), so it has been there for many years. Which of course means that changing this "long time behaviour" may actually cause a problem for a few users...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants