interp3d_bilinear: Bilinear interpolation for 3d array

Description Usage Arguments Note Examples

Description

Bilinear interpolation for 3d array

Usage

1
2
3
4
5
6
7
8
9
interp3d_bilinear(
  grid,
  z,
  range = c(70, 140, 15, 55),
  cellsize_x = 1,
  cellsize_y = cellsize_x,
  na.rm = FALSE,
  convertTo2d = TRUE
)

Arguments

grid

A list object with "lon", "lat".

  • lon numeric, with the length of nlon.

  • lat numeric, with the length of nlat.

  • ... other elements will be ignore

z

3d array (lon, lat, time), with the dimension of [nlon, nlat, ntime]. image(z[,,1]) should look normal.

range

A numeric vector, [lat_min, lat_max, lon_min, lon_max]

cellsize_x

Degree, cell size in the horizontal direction.

cellsize_y

Degree, cell size in the Vertical direction.

na.rm

If true, Na value in margin will be fixed.

Note

High resolution interpolating to low resolution will lead to unreliable result, if cellsize.new/cellsize.origin > 2.

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
library(CMIP5tools)
# library(rgdal)
# library(sp2)
library(maptools)

# polyline
read_polyline <- function(file, lwd = 0.5, ...){
    suppressWarnings(shp <- readShapeLines(file))
    proj4string(shp) <- prj84
    list("sp.lines", shp, first = FALSE, lwd = lwd, ...) # china poly    
}
# sp_arc_world <- read_polyline("G:/ArcGIS/continent.shp") # sp_arc_world
# sp_arc_CH <- read_polyline(system.file("extdata/shp", "bou1_4l_sml.shp", package = "CMIP5tools"))

range <- c(70, 140, 15, 55)
# MAIN SCRIPTS ------------------------------------------------------------
x <- readRDS(system.file("extdata", "tasmax_Threshold_ACCESS1-0.RDS", package = "CMIP5tools"))

class(x) <- "raster2"
plot(x)

x_interp <- interp3d_bilinear(x$grid, x$TRS, range, cellsize_x = 1.5) 
x_clip <- clip_raster2(x, range)

plot(x_interp)
plot(x_clip) # , sp.layout = sp_arc_CH

kongdd/CMIP5tools documentation built on Dec. 17, 2020, 11:03 a.m.