I have this NetCDF file (about 130 kb size). I want to get for each day (layer) the wind direction (in meteorological or geographical directions) at every cell.


I tried:


u <- brick("uv_comp.nc", varname = "u10")
v <- brick("uv_comp.nc", varname = "v10")

dirs <- atan2(v[[1]], u[[1]]) / (2*3.14159265) + (0.5 * 360) # for the first layer

However, I am not very sure that this method is the correct one. Can anyone confirm, please?


atan2 gives you a direction in radians, so to convert to degrees you wouldn't do:

dirs <- atan2(v[[1]], u[[1]]) / (2*3.14159265) + (0.5 * 360) 

you do:

dirs <- 180 * atan2(v, u) / pi

Note here I'm doing all layers at once, using pi instead of spelling it out, and multiplying by 180 rather than adding 180 (=0.5*360). This gives degrees from -180 to 180, so maybe you added 180 to get 0 to 360, in which case:

dirs = 180 + 180 * atan2(v,u) / pi

will give directions from 0 to 360.

You should check the directions are as expected in case you have got u and v the wrong way round. We've all done it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.