if (FALSE) {
library(RNCEP)
## In this example, we use datetime and locational data
## obtained from a GPS device attached to a lesser
## black-backed gull.
data(gull, package='RNCEP')
## First, visualize the entire track representing altitude
## with the point colors ##
## Note the specification of the title
## Also, note the specification of the legend label
## and adjustment of its placement
NCEP.vis.points(wx=gull$altitude, lats=gull$latitude,
lons=gull$longitude, cols=topo.colors(64),
title.args=list(main='Lesser black-backed gull'),
image.plot.args=list(legend.args=list(text='Altitude',
adj=-1, cex=1.25)))
## 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 cloud cover, temperature, and wind
## information for each point in the subset ##
cloud <- NCEP.interp(variable='tcdc.eatm', level='gaussian',
lat=ss$latitude, lon=ss$longitude, dt=ss$datetime,
reanalysis2=TRUE, keep.unpacking.info=TRUE)
temp <- NCEP.interp(variable='air.sig995', level='surface',
lat=ss$latitude, lon=ss$longitude, dt=ss$datetime,
reanalysis2=FALSE, keep.unpacking.info=TRUE)
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 visualize the subset of the GPS track using color
## to indicate the cloud cover ##
## Note the adjustment to the color of the basemap
## And the setting of the map range ##
## And the explicit placement of the colorbar legend
## using the smallplot argument
NCEP.vis.points(wx=cloud, lats=ss$latitude, lons=ss$longitude,
cols=rev(heat.colors(64)),
map.args=list(col='darkgreen',xlim=c(-7,4), ylim=c(40,50)),
title.args=list(main='Lesser black-backed gull'),
image.plot.args=list(legend.args=list(text='Cloud Cover %',
adj=-.1, padj=-.5, cex=1),
smallplot=c(.83,.86,.15,.85)))
## Now visualize the subset of the GPS track using color
## to indicate the temperature ##
## Note the adjustment of point size
NCEP.vis.points(wx=temp, lats=ss$latitude, lons=ss$longitude,
cols=rev(heat.colors(64)),
points.args=list(cex=1.25),
title.args=list(main='Lesser black-backed gull'),
image.plot.args=list(legend.args=list(text='Kelvin',
adj=-.4, padj=-.5, cex=1.15)),
map.args=list(xlim=c(-7,4), ylim=c(40,50)))
## 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 ##
## Note the adjustment of grid and axis properties
NCEP.vis.points(wx=tailwind, lats=ss$latitude, lons=ss$longitude,
cols=rev(heat.colors(64)),
axis.args=list(las=2), grid.args=list(lty=1),
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