---
title: "EnvironmentalAnalysis"
author: Willyan Junior Adorian Bandeira
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{EnvironmentalAnalysis}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```
#Procedures for estimating environmental variables

In addition to functions for estimating parameters for genotype selection, the EstimateBreed package also offers functions for measuring and estimating environmental variables.

##Accumulated Thermal Sum

The calculation of thermal sum is crucial for understanding plant growth and development. It helps predict the onset of key growth stages, optimize planting schedules, and assess climate impacts on crop yields, ultimately enhancing agricultural planning and productivity.

The accumulated thermal sum during a given growing cycle can be obtained with the `atsum()` function.
```{r}
library(EstimateBreed)

data("clima")
clima <- get("clima")[1:150, ]

with(clima,atsum(TMED,crop="maize"))

#Adjusting lower basal temperature manually
with(clima,atsum(TMED,crop="maize",lbt=12))
```

## Soybean plastochron

The plastochron of soybean represents the time interval between leaf initiation. Understanding its influence on growth is key to optimizing crop management, improving yield prediction, and adapting practices to environmental conditions for better productivity. 

The `plast()` function estimates the air temperature required for leaf expansion and node emission in soybean crops, as described by Porta et al (2024).

```{r  echo = TRUE, fig.height = 5, fig.width = 10, fig.align = "center", message = F, warning = F}
library(EstimateBreed)
data("pheno")

with(pheno, plast(GEN,TMED,EST,NN,habit="ind",plot=TRUE))
```


#Predict ∆T to determine the ideal times to apply agricultural pesticides.

Delta T, the difference between air temperature and dew point, is crucial for agrochemical application. The `tdelta()` function performs forecasting or retrospective analysis of climate data to understand the best time for application.

```{r, eval = FALSE}
# This function requires an internet connection to access the weather API.
library(EstimateBreed)

# Forecasting application conditions
forecast <- tdelta(-53.6969,-28.0638,type=1,days=10)
forecast

# Retrospective analysis of application conditions
retrosp <- tdelta(-53.6969,-28.0638,type=2,days=10,
                 dates=c("2023-01-01","2023-05-01"),
                 details=TRUE)
retrosp
```

##Stress indicators from agronomic traits

The `stind()` function estimates several stress indicators based on the productivity of a given crop subjected or not to stressful conditions, as described by Ghazvini et al(2024).

```{r}
library(EstimateBreed)

data("aveia")

#General
with(aveia,stind(GEN,MC,MG,index = "ALL",bygen=TRUE))

#Only the desired index
with(aveia,stind(GEN,MC,MG,index = "STI",bygen=TRUE))
```

##Risk of Disease Occurrence in Soybeans

Predicting the occurrence of Asian soybean rust is critical for timely disease management. Early detection allows for targeted interventions, such as fungicide application, minimizing crop losses and reducing the spread of the disease. 

This can be estimated with the `risk`() function, based on the methodology proposed by Engers et al. (2024), which uses temperature and relative humidity to define the potential risk of the disease occurring.

```{r}

library(EstimateBreed)

# Rust Risk Prediction
data("clima")
with(clima, risk(DY, MO, TMED, RH, disease = "rust"))
```
