# frost package

## Prediction of minimum temperature for frost forecasting in agriculture

### Description

This package contains a compilation of empirical methods used by farmers and agronomic engineers to predict the minimum temperature to detect a frost event.

These functions use variables such as environmental temperature, relative humidity, and dew point.

### Installation

If you don’t have package devtools installed, run the following commands.

install.packages("devtools")

library(devtools)

To install the package from the GitHub repo, run

install_github("anadiedrichs/frost")

Load the library to start using the functions

library(frost)

## Dew point estimation

Given that several methods used dew point as an input variable, this package provides methods to estimate the dew point (in Celsius degree) given ambient temperature and relative humidity.

library(frost)

temp <- 25
rh <- 54

calcDewPoint(rh,temp,mode="A")
#> [1] 14.99222
calcDewPoint(rh,temp,mode="B")
#> [1] 24.07111
calcDewPoint(rh,temp,mode="C")
#> [1] 15.04884

## Temperature conversions

Most of the predictive methods use temperature in degree Celsius, so maybe you want to convert your temperature values to this unit. You can use the method convert.temperature to achieve this, and convert from/to Kelvin (K), Fahrenheit (F) or Celcius (C).

library(frost)

library(frost)
convert.temperature(from="K", to="C",350)
#> [1] 76.85
cels <- convert.temperature(from="F",to="C",c(120,80,134,110))
k <- convert.temperature(from="C", to="K",cels)

## Prediction of minimum temperature

### FAO approach

The empirical formula for estimating the minimum temperature is $$T_{min} = a * T + b * T_{dew} + c$$. For calculating the coefficientes $$a, b$$ and $$c$$ we call buildFAO(dw,temp,tmin).

library(frost)
# We create random data
x1 <- rnorm(100,mean=2,sd=5)
x2 <- rnorm(100,mean=1,sd=3)
y <- rnorm(100,mean=0,sd=2)
buildFAO(dw = x2,temp=x1,tmin=y)
#> An object of class "FAOFrostModel"
#> Slot "a":
#> [1] -0.0212634
#>
#> Slot "b":
#> [1] -0.0740061
#>
#> Slot "c":
#> [1] 0.001168745
#>
#> Slot "Tp":
#>   [1]  0.3317844864 -0.1203190410  0.1334290382 -0.3938878717 -0.2030806995
#>   [6] -0.2088475442  0.0804456769 -0.1744633209 -0.1957718598  0.0588446032
#>  [11]  0.2632287624 -0.2228468080  0.1215774881  0.4719427731 -0.1423961768
#>  [16] -0.1435656329 -0.0758006193  0.0345275459  0.1401422384  0.6020580379
#>  [21] -0.5073168322 -0.2820275982 -0.5226070432 -0.5769375646  0.1280641615
#>  [26] -0.3662330462  0.1391154147 -0.6708894581 -0.4895895194 -0.1722829655
#>  [31] -0.0695250598 -0.1756239850 -0.0872101766  0.1390127722 -0.0005958758
#>  [36]  0.2652138776 -0.0434716468  0.1967849373  0.2652703453 -0.1558650866
#>  [41] -0.1066094171  0.1745030187 -0.7380950223  0.1602548837  0.0720685542
#>  [46] -0.4800011487  0.0764527009 -0.1480798262 -0.5191671329 -0.3912491983
#>  [51] -0.1289594306 -0.2819242139  0.3713357002 -0.0125856482 -0.0406952249
#>  [56]  0.0654154839 -0.0351323419 -0.3376009628 -0.2372115041 -0.2859484620
#>  [61]  0.0035973849 -0.5202481760 -0.1018946862 -0.0354233941 -0.3291166095
#>  [66]  0.2196682326 -0.0292289184  0.0537502268 -0.0366203356 -0.2551508203
#>  [71]  0.2536956400 -0.2082472934 -0.1164544875 -0.4770960625  0.1605930654
#>  [76]  0.2770897280  0.2249430002  0.4600066331 -0.0378402288 -0.4587163548
#>  [81] -0.1986482800  0.0187932855 -0.4230999062  0.0080105413  0.2939677758
#>  [86] -0.3154599637 -0.4807873439  0.2103869843  0.2168626502  0.0633279822
#>  [91]  0.0230896725 -0.6855424752 -0.5377790054 -0.2349990500 -0.3839017339
#>  [96] -0.0287641200 -0.2677175810 -0.0748641863 -0.1884836957 -0.3402656205
#>
#> Slot "Rp":
#>   [1] -2.946754461 -2.990855346 -0.981263480  2.516562788  0.726690087
#>   [6] -0.086809612 -0.468997847 -1.123860170 -0.479698948 -3.427662377
#>  [11]  0.970614304 -0.879594924 -0.431102340 -0.869586682 -0.344517161
#>  [16] -0.920845110 -1.996718978 -1.804556714 -1.495413190  2.281998587
#>  [21]  2.257782594 -0.445316644 -2.028999346  0.035697483 -0.170255421
#>  [26] -2.445870245  4.393099644  3.463141584 -3.314101266  1.850888883
#>  [31]  3.111068006  2.562302716  0.026822201 -0.201477439 -1.355424433
#>  [36]  3.139400998 -1.547350607 -3.292997780  3.414485141  0.417355197
#>  [41] -1.806778415 -3.893292122  0.231301768 -0.893700052  2.927112424
#>  [46] -0.241529550 -2.354713082  1.400030592 -0.694058452  1.463345186
#>  [51]  1.117268406 -0.785009918  2.256686838  1.061800308  0.491175208
#>  [56] -0.666057978 -3.077604140  0.765013576  2.586458304  1.217978001
#>  [61]  1.673285916 -0.378955032 -2.131789410 -2.543909929 -0.500089643
#>  [66]  2.987069585 -0.413285515 -0.611616426 -2.077630309  0.341797510
#>  [71]  0.098434003 -0.319203250 -0.563209483 -0.594499335  0.001201451
#>  [76] -2.346730284 -0.291429626  2.904629142  1.681730634 -0.501577676
#>  [81]  0.672932394  0.099048611 -1.303365574  0.836510646  1.447024722
#>  [86] -1.750576402  0.264627862  1.243011567 -0.201711260  1.488691604
#>  [91]  1.398884790  3.505885395  1.197625026 -4.853958863  3.576546638
#>  [96] -0.621231481 -0.813832298 -0.261545322  0.460537194  0.977365835
#>
#> Slot "r2":
#> [1] 0.02121489
# data example taken from FAO Book
t0 <- c(3.2,0.8,0.2,2.6,4.4,5.2,2.7,1.2,4.5,5.6) # temperature 2 hours after sunset
td <- c(-4.2,-8.8,-6.5,-6.2,-6.1,2.6,-0.7,-1.7,-1.2,0.1) # dew point 2 hours after sunset
tn <- c(-3.1,-5,-6.3,-5.4,-4,-2.5,-4.8,-5,-4.4,-3.3)
out <- buildFAO(dw = td,temp=t0,tmin=tn)

# We use the results of the model to have the coefficients for the formula
current_temp <- 10
current_dw <- 2
ptmin <- predFAO(out,current_temp,current_dw)
cat("The predicte minimum temperature is ",ptmin," °C")
#> The predicte minimum temperature is  -0.7409219  °C

# We plot the temperature trend, we have 12 hours until sunrise
getTrend(Tmin = ptmin ,t2 = current_temp,n = 12,plot=TRUE) # in °C degress

#>     x          y
#> 1   3  6.6034223
#> 2   4  5.1965137
#> 3   5  4.1169548
#> 4   6  3.2068445
#> 5   7  2.4050213
#> 6   8  1.6801177
#> 7   9  1.0135000
#> 8  10  0.3930274
#> 9  11 -0.1897332
#> 10 12 -0.7409219

We can plot an estimated temperature trend during a frost night, calculated using the FAO recomendation.

library(frost)

getTrend(Tmin = 22.2,t2 = 33.7,n = 15) # in °F degress
#>     x        y
#> 1   3 30.51047
#> 2   4 29.18933
#> 3   5 28.17558
#> 4   6 27.32095
#> 5   7 26.56800
#> 6   8 25.88729
#> 7   9 25.26131
#> 8  10 24.67866
#> 9  11 24.13142
#> 10 12 23.61383
#> 11 13 23.12154
#> 12 14 22.65116
#> 13 15 22.20000
getTrend(Tmin = -5.45,t2 = 0.95,n = 15, plot=TRUE) # in °C degress
#>     x          y
#> 1   3 -0.8250406
#> 2   4 -1.5602865
#> 3   5 -2.1244606
#> 4   6 -2.6000813
#> 5   7 -3.0191115
#> 6   8 -3.3979438
#> 7   9 -3.7463161
#> 8  10 -4.0705731
#> 9  11 -4.3751219
#> 10 12 -4.6631713
#> 11 13 -4.9371438
#> 12 14 -5.1989211
#> 13 15 -5.4500000

We can use the output of plotTrend to plot using other libraries such as ggplot2.

library(frost)
var <- getTrend(Tmin = -5.45,t2 = 0.95,n = 15) # in °C degress
require(ggplot2)
# just plotting points
ggplot(var,aes(x=x,y=y)) + geom_point(color="blue")
ggplot(var,aes(x=x,y=y)) + geom_point() + geom_smooth(color="red")
#> geom_smooth() using method = 'loess' and formula 'y ~ x'

### Empirical formula used in Mendoza

The empirical formula for estimating the minimum temperature is $$T_{min} = \frac{T_{max} + T_{dew}}{2} - K$$. For calculating K, we call buildMdz function. Then for prediction we use predMdz.

# just an example
dw <- c(-2,-5,2,6,8)
tempMax <- c(10,20,30,25,29)
tmin <- c(-1,-2,3,5,10)
out <- buildMdz(dw,tempMax,tmin)
predMdz(dw = -3, tempMax = 15, out)
#> [1] 15.3