-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntroduction.Rmd
141 lines (99 loc) · 3.94 KB
/
Introduction.Rmd
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
title: "frost package"
author: "Ana Laura Diedrichs"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
% \VignetteDepends{ggplot2}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
## 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) ``
<img src="logo-frost.png" width="250">
## 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.
```{r}
library(frost)
temp <- 25
rh <- 54
calcDewPoint(rh,temp,mode="A")
calcDewPoint(rh,temp,mode="B")
calcDewPoint(rh,temp,mode="C")
```
## 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).
```{r}
library(frost)
library(frost)
convert.temperature(from="K", to="C",350)
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)`.
```{r}
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)
# 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")
# We plot the temperature trend, we have 12 hours until sunrise
getTrend(Tmin = ptmin ,t2 = current_temp,n = 12,plot=TRUE) # in °C degress
```
We can plot an estimated temperature trend during a frost night, calculated using the FAO recomendation.
```{r, fig.show='hold'}
library(frost)
getTrend(Tmin = 22.2,t2 = 33.7,n = 15) # in °F degress
getTrend(Tmin = -5.45,t2 = 0.95,n = 15, plot=TRUE) # in °C degress
```
We can use the output of `plotTrend` to plot using other libraries such as ggplot2.
```{r, fig.show='hold'}
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")
# add trend line
ggplot(var,aes(x=x,y=y)) + geom_point() + geom_smooth(color="red")
```
### 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`.
```{r}
# 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)
```