Description Usage Arguments Details Value Author(s) Examples
View source: R/DS.GCM.to.grid.R
need a function to downscale data to regular grid
1 2 | DS.GCM.to.grid(nc, lon = c(-180, 180), lat = c(-90, 90), cellsize = 0.2,
type = 2)
|
nc |
|
lon |
|
lat |
|
cellsize |
|
type |
nc should be from extend.global.data
Downscale Global GCM Models to a Regular Grid
Jeremy VanDerWal jjvanderwal@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## Not run:
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(nc,cellsize=0.2,type=2) {
#ensure nc is from retrieve.nc or similar
if (all(c('dat','tim','lat', 'lon') %in% names(nc))==FALSE)
stop('nc must have objects named dat, lat, lon and tim as from
retrieve.nc of clim.pact package, append.nc or extract.monthly.averages')
if (!(type %in% 1:3)) stop('type must be 1,2 or 3... see help file')
#do the work
lat = seq(-90+0.5*cellsize,90-0.5*cellsize,cellsize)
lon = seq(-180+05*cellsize,180-0.5*cellsize,cellsize)
out = array(0,dim=c(length(nc$tim),length(lat),length(lon)))
for (ii in 1:length(nc$tim)) { out[ii,,] =
interp2grid(nc$dat[ii,,],lon,lat,nc$lon,nc$lat,type=type) }
return(list(dat=out,lon=lon,lat=lat,tim=nc$tim))
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.