downscale: Downscale a precipitation field

Description Usage Arguments Value Author(s) Examples

View source: R/downscale.R

Description

Downscales an input precipitation matrix using a metagaussian spectral field f previously generated with initmetagauss(). The target resolution is defined by the dimensions of f. An optional weights array can be specified.

Usage

1
downscale(r, f, weights = 1, fglob = FALSE, fsmooth = TRUE)

Arguments

r

matrix of precipitation data to downscale.

f

matrix containing a complex spectrum generated by the initmetagauss() function.

weights

matrix with climatological weights generated with the rfweights() function.

fglob

logical to conserve global average over domain.

fsmooth

logical to use smoothing for conservation. If neither option is set precipitation is conserved over each coarse box.

Value

The downscaled field, with the same dimensions as f.

Author(s)

Jost von Hardenberg, j.vonhardenberg@isac.cnr.it

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Make some sample synthetic rainfall data
r <- exp(rnorm(4 * 4))
dim(r) <- c(4, 4)
r
#           [,1]      [,2]      [,3]      [,4]
# [1,] 1.8459816 1.8536550 2.1600665 1.3102116
# [2,] 1.3851011 1.4647348 0.2708219 0.4571810
# [3,] 0.2492451 0.8227134 0.4790567 1.9320403
# [4,] 0.5985922 3.3065678 2.1282795 0.6849944
# Create help field `f` with logarithmic slope 1.7
# with `dim(f) = c(8 * 4 ,8 * 4)`
f <- initmetagauss(1.7, 8 * 4)
rd <- downscale(r, f, fsmooth=FALSE) 
# Verify that downscaled data maintained original box averages
agg(rd, 4) 
#           [,1]      [,2]      [,3]      [,4]
# [1,] 1.8459816 1.8536550 2.1600665 1.3102116
# [2,] 1.3851011 1.4647348 0.2708219 0.4571810
# [3,] 0.2492451 0.8227134 0.4790567 1.9320403
# [4,] 0.5985922 3.3065678 2.1282795 0.6849944

Example output

          [,1]      [,2]      [,3]      [,4]
[1,] 2.2676967 0.4273860 0.7686228 0.3194689
[2,] 3.3215916 1.4116466 0.8829614 0.2197174
[3,] 1.3797779 0.9283591 0.1731589 1.2174686
[4,] 0.3621563 0.3576194 1.1012999 4.3324394
          [,1]      [,2]      [,3]      [,4]
[1,] 2.2676967 0.4273860 0.7686228 0.3194689
[2,] 3.3215916 1.4116466 0.8829614 0.2197174
[3,] 1.3797779 0.9283591 0.1731589 1.2174686
[4,] 0.3621563 0.3576194 1.1012999 4.3324394

rainfarmr documentation built on May 1, 2019, 8:02 p.m.