unitConv: Function: Unit conversion of a RasterLayer object

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

Description

Converts the cell values of a 'RasterLayer' from one unit to another.

Usage

1
unitConv(rasterLayer, u1, u2, decimalPlaces = 4)

Arguments

rasterLayer

A 'RasterLayer' object to be converted.

u1

An object of class 'character'. Unit of the input 'RasterLayer'.

u2

An object of class 'character'. Requested unit of the output 'RasterLayer'.

decimalPlaces

An object of class 'numeric'. Number of decimal places (default = 4).

Details

This function makes use of ud.convert from the package 'udunits2' to calculate a conversion factor which is applied to convert unit 'u1' of a 'RasterLayer' into the requested unit 'u2'.

A list of common units: "kelvin", "celsius", "mm/d", "mm/h", "mm/s", "cm/d", "cm/h", "cm/s", "m/d", "m/h", "m/s".

Value

Returns the converted 'RasterLayer'.

Author(s)

Alexander R. Groos (alexander.groos@giub.unibe.ch)

See Also

ud.convert

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
# Load the provided RasterLayer objects as exemplary
# input for the function
data(airTemperature_30m_daily, precip_30m_daily,
    package = "glacierSMBM")
# Individual RasterLayer objects should be loaded or
# created using the function raster()

# Convert air temperature from Kelvin to degree Celsius
output <- unitConv(airTemperature_30m_daily, "kelvin", "celsius")

# Plot output
plot(airTemperature_30m_daily, main = "Air Temperature [Kelvin]",
    legend.args=list(text='Temperature (K)', side=3, line=1.5))
plot(output, main = "Air Temperature [Celsius]",
    legend.args=list(text='Temperature (Celsius)',
    side=3, line=1.5))

# Convert precipitation from m d-1 to mm h-1
output <- unitConv(precip_30m_daily, "m/d", "mm/h")

# Plot output
plot(precip_30m_daily, main = "Precipitation [m/d]",
    legend.args=list(text='Precipitation (m/d)',
    side=3, line=1.5))
plot(output, main = "Precipitation [mm/h]",
    legend.args=list(text='Precipitation (mm/h)',
    side=3, line=1.5))

glacierSMBM documentation built on May 2, 2019, 3:42 a.m.