R/small_funs.R
spherical.Rd
Transform a longitude or latitude interval into the equivalent in meters depending on latitude.
dlon(dx, lat, a = 6731000)
dlat(dy, a = 6731000)
dx(dlon, lat, a = 6731000)
dy(dlat, a = 6731000)
library(data.table)
data(geopotential)
geopotential <- geopotential[date == date[1]]
# Geostrophic wind
geopotential[, c("u", "v") := GeostrophicWind(gh, lon, lat)] # in meters/second
#> lon lat lev gh date u v
#> <num> <num> <int> <num> <Date> <num> <num>
#> 1: 0.0 -22.5 700 3163.839 1990-01-01 NA 1.08181190
#> 2: 2.5 -22.5 700 3162.516 1990-01-01 NA 0.55189199
#> 3: 5.0 -22.5 700 3162.226 1990-01-01 NA 0.06625043
#> 4: 7.5 -22.5 700 3162.323 1990-01-01 NA -0.29800162
#> 5: 10.0 -22.5 700 3163.097 1990-01-01 NA -0.75064329
#> ---
#> 4028: 347.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000
#> 4029: 350.0 -90.0 700 2715.936 1990-01-01 NA 0.00000000
#> 4030: 352.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000
#> 4031: 355.0 -90.0 700 2715.936 1990-01-01 NA 0.00000000
#> 4032: 357.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000
geopotential[, c("dlon", "dlat") := .(dlon(u, lat), dlat(v))] # in degrees/second
#> lon lat lev gh date u v dlon
#> <num> <num> <int> <num> <Date> <num> <num> <num>
#> 1: 0.0 -22.5 700 3163.839 1990-01-01 NA 1.08181190 NA
#> 2: 2.5 -22.5 700 3162.516 1990-01-01 NA 0.55189199 NA
#> 3: 5.0 -22.5 700 3162.226 1990-01-01 NA 0.06625043 NA
#> 4: 7.5 -22.5 700 3162.323 1990-01-01 NA -0.29800162 NA
#> 5: 10.0 -22.5 700 3163.097 1990-01-01 NA -0.75064329 NA
#> ---
#> 4028: 347.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4029: 350.0 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4030: 352.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4031: 355.0 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4032: 357.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> dlat
#> <num>
#> 1: 9.208625e-06
#> 2: 4.697828e-06
#> 3: 5.639385e-07
#> 4: -2.536657e-06
#> 5: -6.389644e-06
#> ---
#> 4028: 0.000000e+00
#> 4029: 0.000000e+00
#> 4030: 0.000000e+00
#> 4031: 0.000000e+00
#> 4032: 0.000000e+00
geopotential[, c("u2", "v2") := .(dx(dlon, lat), dy(dlat))] # again in degrees/second
#> lon lat lev gh date u v dlon
#> <num> <num> <int> <num> <Date> <num> <num> <num>
#> 1: 0.0 -22.5 700 3163.839 1990-01-01 NA 1.08181190 NA
#> 2: 2.5 -22.5 700 3162.516 1990-01-01 NA 0.55189199 NA
#> 3: 5.0 -22.5 700 3162.226 1990-01-01 NA 0.06625043 NA
#> 4: 7.5 -22.5 700 3162.323 1990-01-01 NA -0.29800162 NA
#> 5: 10.0 -22.5 700 3163.097 1990-01-01 NA -0.75064329 NA
#> ---
#> 4028: 347.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4029: 350.0 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4030: 352.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4031: 355.0 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> 4032: 357.5 -90.0 700 2715.936 1990-01-01 NA 0.00000000 NA
#> dlat u2 v2
#> <num> <num> <num>
#> 1: 9.208625e-06 NA 1.08181190
#> 2: 4.697828e-06 NA 0.55189199
#> 3: 5.639385e-07 NA 0.06625043
#> 4: -2.536657e-06 NA -0.29800162
#> 5: -6.389644e-06 NA -0.75064329
#> ---
#> 4028: 0.000000e+00 NA 0.00000000
#> 4029: 0.000000e+00 NA 0.00000000
#> 4030: 0.000000e+00 NA 0.00000000
#> 4031: 0.000000e+00 NA 0.00000000
#> 4032: 0.000000e+00 NA 0.00000000