2

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.

https://drive.google.com/open?id=1UxYGJK1-gIgXWZT6tE10bavmiNEpsVx3

I tried:

library(raster)

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?

2

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.