extend.global.data: Extend Extents of Global Data to Interpolate Spherical Data

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/extend.global.data.R

Description

a function to extend the extents of a GCM in preparation for bilinear downscaling

Usage

1

Arguments

nc

~~Describe nc here~~

Details

inputs are from retrieve.nc, append.nc or extract.monthly.averages

Value

...

Note

~~further notes~~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## 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) {
	#ensure nc1 & nc2 are from retrieve.nc
	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')
	#do the work
	#assuming this is a global model, we need to buffer the edges to interpolate
	#adjust the latitude
	nc$lat = c(nc$lat[1]-mean(diff(nc$lat),na.rm=T),
  nc$lat,nc$lat[length(nc$lat)]+mean(diff(nc$lat),na.rm=T))
	if(min(nc$lat,na.rm=T)>-90) nc$lat[nc$lat==min(nc$lat,na.rm=T)] = -90
	if(max(nc$lat,na.rm=T)<90) nc$lat[nc$lat==max(nc$lat,na.rm=T)] = 90
	#adjust the longitude
	nc$lon = c(nc$lon[1]-mean(diff(nc$lon),na.rm=T),
  nc$lon,nc$lon[length(nc$lon)]+mean(diff(nc$lon),na.rm=T))
	if(min(nc$lon,na.rm=T)>-180) nc$lon[nc$lon==min(nc$lon,na.rm=T)] = -180
	if(max(nc$lon,na.rm=T)<180) nc$lon[nc$lon==max(nc$lon,na.rm=T)] = 180
	#populate a new set of outa with new dim of lat & lon
	out = array(0,dim=c(length(nc$tim),length(nc$lat),length(nc$lon)))
	out[1:dim(nc$dat)[1],1:dim(nc$dat)[2]+1,1:dim(nc$dat)[3]+1] = nc$dat[,,]
	#adjust the latitude data
	tmid = ceiling(dim(nc$dat)[3] / 2)
	out[,1,] = cbind(NA,nc$dat[,1,tmid:dim(nc$dat)[3]],nc$dat[,1,1:(tmid-1)],NA)
	out[,dim(out)[2],] = cbind(NA,nc$dat[,dim(nc$dat)[2],tmid:dim(nc$dat)[3]],
  nc$dat[,dim(nc$dat)[2],1:(tmid-1)],NA)
	#adjust the longitude information... appending ends from other side of globe
	out[,,1] = out[,,dim(out)[3]-1]
	out[,,dim(out)[3]] = out[,,2]
	#return the extended outa
	return(list(dat=out,lon=nc$lon,lat=nc$lat,tim=nc$tim))
  }

## End(Not run)

jjvanderwal/climates documentation built on May 19, 2019, 11:41 a.m.