How can extrapolate data from 10 to 50 meters using the NetCDF file in R software?

HI @KHAN1
Since you also wanted to be able to write out back to a netcdf file, I found that the terra package did a better job without creating bands in the wrong order when I saved to a netcdf file (at least when I looked at the file in the panoply app.)

library("terra")

u10 <- rast("~/Downloads/ERA5_monthlyWindSpeed.nc", drivers = "NETCDF")

#https://en.wikipedia.org/wiki/Wind_profile_power_law
u_calc <- function(ur, zr, z, a = 0.143) {
  ur * ((z / zr) ^ a)
}

# Calculate windspeed at height z = 50
u50 <- u_calc(u10, zr = 10, z = 50)

writeCDF(u50, filename = "~/Downloads/u50.nc", varname = "sfcWind",
  unit = "m/s", zname = "time", prec = "float")
1 Like