# unitConv-method: Method: Unit conversion of a RasterLayer object In glacierSMBM: Glacier Surface Mass Balance Model

## Description

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

## 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)

`ud.convert`
 ``` 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)) ```