if (FALSE) {
library(RNCEP)
###############################################################
###############################################################
## The function can be applied to interpolate a single variable
## to a single point in space and time ##
## Interpolate temperature from the 850 mb pressure level ##
wx.interp <- NCEP.interp(variable='air', level=850, lat=55.1,
lon=11.3, dt='2006-10-12 17:23:12',
interp='linear')
## Interpolate precipitable water (for the entire atmosphere, but
## described in reference to the surface)
wx.interp <- NCEP.interp(variable='pr_wtr.eatm', level='surface',
lat=55.1, lon=11.3, dt='2006-10-12 17:23:12',
interp='linear')
## Interpolate specific humidity (at the surface, but in
## reference to a T62 Gaussian grid) using the IDW interpolation
wx.interp <- NCEP.interp(variable='shum.2m', level='gaussian',
lat=55.1, lon=11.3, dt='2006-10-12 17:23:12',
interp='IDW', p=1)
###################################################################
###################################################################
## The function can also be applied to interpolate several variables,
## locations, datetimes, and/or methods of interpolation in a single
## function call ##
## Interpolate temperature from the 850 and 700 mb pressure levels ##
## for the same time and location ##
wx.interp <- NCEP.interp(variable='air', level=c(850,700), lat=55.1,
lon=11.3, dt='2006-10-12 17:23:12',
interp='linear')
## Interpolate temperature and relative humidity from the 1000 mb
## pressure level ##
wx.interp <- NCEP.interp(variable=c('air','rhum'), level=1000,
lat=55.1, lon=11.3, dt='2006-10-12 17:23:12', interp='linear')
## Interpolate temperature and relative humidity
## from the 1000 and 700 mb pressure levels, respectively
## for the same datetime ##
wx.interp <- NCEP.interp(variable=c('air','rhum'),
level=c(1000,700), lat=55.1, lon=11.3,
dt='2006-10-12 17:23:12', interp='linear')
## Interpolate temperature and relative humidity
## from the 1000 and 700 mb pressure levels, respectively
## for different datetimes ##
wx.interp <- NCEP.interp(variable=c('air','rhum'), level=c(1000,700), lat=55.1,
lon=11.3, dt=c('2006-10-12 17:23:12', '2006-10-12 18:05:31'),
interp='linear')
## Interpolate geopotential height using 'linear', 'IDW', and
## 'nearest neighbor' interpolation ##
wx.interp <- NCEP.interp(variable='hgt', level=700, lat=55.1,
lon=11.3, dt='2006-10-12 17:23:12',
interp=c('linear','IDW','IDW'),
interpolate.space=c(TRUE,TRUE,FALSE))
###############################################################
###############################################################
## Alternatively the function can be applied to interpolate a
## weather variable to multiple datetime and point locations
## in a single function call ##
## In this example, we use datetime and locational data obtained
## from a GPS device attached to a lesser black-backed gull.
## We interpolate wind information to to each point in the dataset
data(gull)
## Take a subset of the data based on the datetime of
## the measurement ##
ss <- subset(gull, format(gull$datetime, "%Y-%m-%d %H:%M:%S") >=
"2008-09-19 16:00:00" & format(gull$datetime,
"%Y-%m-%d %H:%M:%S") <= "2008-09-19 19:30:00")
## Now collect wind information for each point in the subset ##
uwind <- NCEP.interp(variable='uwnd', level=925,
lat=ss$latitude, lon=ss$longitude, dt=ss$datetime,
reanalysis2=TRUE, keep.unpacking.info=TRUE)
vwind <- NCEP.interp(variable='vwnd', level=925,
lat=ss$latitude, lon=ss$longitude, dt=ss$datetime,
reanalysis2=TRUE, keep.unpacking.info=TRUE)
## Now calculate the tailwind component from the U and V
## wind components assuming that the bird's preferred
## direction is 225 degrees
tailwind <- (sqrt(uwind^2 + vwind^2)*cos(((atan2(uwind,vwind)*
(180/pi))-225)*(pi/180)))
## Now visualize the subset of the GPS track using color
## to indicate the tailwind speed ##
NCEP.vis.points(wx=tailwind, lats=ss$latitude, lons=ss$longitude,
cols=rev(heat.colors(64)),
title.args=list(main='Lesser black-backed gull'),
image.plot.args=list(legend.args=list(text='Tailwind m/s',
adj=0, padj=-2, cex=1.15)),
map.args=list(xlim=c(-7,4), ylim=c(40,50)))
}
Run the code above in your browser using DataLab