Skip to content

Commit

Permalink
Version 0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Carm1r committed Oct 17, 2020
1 parent 4a60249 commit b18a930
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 60 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: fruclimadapt
Type: Package
Title: Evaluation Tools for Assessing Climate Adaptation of Fruit Tree Species
Version: 0.4.3.9000
Version: 0.4.4
Author: Carlos Miranda
Maintainer: Carlos Miranda <carlos.miranda@unavarra.es>
Description: Climate is a critical component limiting growing range of plant species, which
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(DTR)
export(ET_penman)
export(ET_penman_monteith)
export(GDD_linear)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# fruclimadapt 0.4.4
## New features
* New function (DTR) to calculate the mean diurnal temperature range
* color_potential now allows to define the evaluation period
* russet now allows to define the critical relative humidity and the evaluation period
* coolness_index now allows to define the evaluation period

# fruclimadapt 0.4.3
## Bug fixes
* Changed a reference in DESCRIPTION with a wrong doi for other referencing the same method.
Expand Down
62 changes: 62 additions & 0 deletions R/DTR.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#' Calculation of the diurnal temperature range (DTR)
#'
#' This function calculates the mean diurnal temperature range (DTR) for
#' a custom period. Mean DTR is obtained by subtracting the daily minimum
#' temperature (Tmin) from daily maximum temperature (Tmax) and then
#' averaged for the period defined by the user, provided as the initial
#' (init) and end (end) date expressed as days of the year. The function
#' requires the initial and end dates to be in the same year.
#'
#' @param climdata a dataframe with daily maximum and minimum temperatures.
#' Must contain the columns Year, Month, Day, Tmax, Tmin.
#' @param init_d the initial date (as day of the year) of the evaluation period
#' @param end_d the end date (as day of the year) of the evaluation period
#' @return dataframe with the value of DTR for each year in the series.
#' It contains the columns Year, First_d, Last_d, DTR
#' @author Carlos Miranda, \email{carlos.miranda@@unavarra.es}
#' @examples
#'
#' # Select the appropiate columns from the Tudela_DW example dataset,
#' # and estimate the mean DTR for July on each year in the dataset.
#' library(tidyverse)
#' Weather <- Tudela_DW %>%
#' select(Year, Month, Day, Tmax, Tmin)
#' DTR_July <- DTR(Weather, 182, 212)
#'
#' @export DTR
#' @import data.table tidyverse zoo
#' @importFrom lubridate make_date

DTR <- function(climdata, init_d, end_d)
{
climdata <- select(climdata,"Year","Month","Day","Tmax","Tmin") %>%
mutate(Date = make_date(Year, Month, Day),
DOY = yday(Date), DTR_d=Tmax-Tmin)

seasons <- unique(climdata$Year)

indices_cn <- c("Year","First_d","Last_d","DTR")
indices.df <-data.frame(matrix(ncol=4, nrow=0, byrow=FALSE))
colnames(indices.df) <- indices_cn

for (sea in 1:length(seasons)){
Anno <- as.numeric(seasons[sea])
climdata_fil <- climdata %>%
filter(climdata$Year==Anno)

DTR <- climdata_fil %>%
filter(climdata_fil$DOY>=(init_d) & climdata_fil$DOY<=end_d) %>%
summarise(DTR_a=mean(DTR_d)) %>%
select(DTR_a) %>%
unlist(use.names=FALSE)

new.row.df <- data.frame(Anno,init_d,end_d) %>%
cbind(DTR)

indices.df <-rbind(indices.df,new.row.df)

}
indices.df <- indices.df %>% rename(Year=Anno)
return(indices.df)
}

22 changes: 12 additions & 10 deletions R/color_potential.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
#'
#' This function estimates the number of days that can be
#' considered as highly favorable or unfavorable for anthocyanin
#' accumulation in the skin of red apple cultivars during the
#' month (30 days) before harvest. A highly favorable day (Cool
#' day) is considered when the daily maximum temperature is below
#' 26ºC, a highly unfavorable day (Hot day) when the minimum
#' temperature is above 20ºC (Lin-Wang et al, 2011). The average
#' of maximum and minimum temperatures during the same period is
#' also provided. The function allows testing for several harvest
#' dates.
#' accumulation in the skin of red apple cultivars during a
#' user defined pre-harvest period (30 days by default).
#' A highly favorable day (Cool day) is considered when the daily
#' maximum temperature is below 26ºC, a highly unfavorable day (Hot day)
#' when the minimum temperature is above 20ºC (Lin-Wang et al, 2011).
#' The average of maximum and minimum temperatures during the same
#' period is also provided. The function allows testing for several
#' harvest dates.
#'
#' @param climdata a dataframe with daily maximum and minimum temperatures.
#' Must contain the columns Year, Month, Day, Tmax, Tmin.
#' @param harvest a vector with expected harvest days
#' (expressed as day of the year)
#' @param span the period (in days) before harvest that will be analyzed. By
#' default, this parameter is set in 30 days.
#' @return dataframe with the number of highly favorable (Cool_d)
#' and unfavorable (Hot_d) days for apple red color, as well as the
#' average of the maximum (Tmax_avg) and minimum (Tmin_avg)
Expand Down Expand Up @@ -43,7 +45,7 @@
#' @import data.table tidyverse zoo
#' @importFrom lubridate make_date

color_potential <- function(climdata, harvest)
color_potential <- function(climdata, harvest, span=30)
{
climdata <- select(climdata,"Year","Month","Day","Tmax","Tmin") %>%
mutate(Date = make_date(Year, Month, Day),
Expand All @@ -63,7 +65,7 @@ color_potential <- function(climdata, harvest)
for (nharv in 1:length(harvest)){
Day_h <- as.numeric(harvest[nharv])
evacol_fil <- climdata_fil %>%
filter(climdata_fil$DOY>(Day_h-30) & climdata_fil$DOY<=Day_h) %>%
filter(climdata_fil$DOY>(Day_h-span) & climdata_fil$DOY<=Day_h) %>%
summarise(Cool_d=sum(Cool),Hot_d=sum(Hot),Tmax_avg=mean(Tmax),Tmin_avg=mean(Tmin)) %>%
select(Cool_d,Hot_d,Tmax_avg,Tmin_avg)
new.row.df <- data.frame(Anno,Day_h) %>%
Expand Down
15 changes: 9 additions & 6 deletions R/cool_night_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
#' Cool Night index of Tonietto (1999). Instead of calculating
#' the mean of minimum temperatures in September/March (Northern
#' or Southern hemispheres, respectively), this function allows
#' to define the harvest date, and calculates the mean of minimum
#' temperatures in the previous 30 days. The function allows
#' testing for several harvest dates simultaneously.
#' to define the harvest date and the number of days that will be
#' analyzed (by default, 30 days), and calculates the mean of minimum
#' temperatures in the in the specified period of days before harvest.
#' The function allows testing for several harvest dates simultaneously.
#'
#' @param climdata a dataframe with daily maximum and minimum temperatures.
#' Must contain the columns Year, Month, Day, Tmax, Tmin.
#' @param harvest a vector with expected harvest days
#' (expressed as day of the year)
#' @param span the period (in days) before harvest that will be analyzed. By
#' default, this parameter is set in 30 days.
#' @return dataframe with the values of the indices. It contains the
#' columns Year, Harvest, Coolness
#' @author Carlos Miranda, \email{carlos.miranda@@unavarra.es}
Expand All @@ -26,7 +29,7 @@
#'
#' # Select the appropiate columns from the Tudela_DW example dataset,
#' # create a vector or harvest dates and estimate the coolness index
#' # for each year in the dataset.
#' # for the 30 days prior to harvest on each year in the dataset.
#' library(tidyverse)
#' Weather <- Tudela_DW %>%
#' select(Year, Month, Day, Tmax, Tmin)
Expand All @@ -37,7 +40,7 @@
#' @import data.table tidyverse zoo
#' @importFrom lubridate make_date

coolness_index <- function(climdata, harvest)
coolness_index <- function(climdata, harvest, span=30)
{
climdata <- select(climdata,"Year","Month","Day","Tmax","Tmin") %>%
mutate(Date = make_date(Year, Month, Day),
Expand All @@ -56,7 +59,7 @@ coolness_index <- function(climdata, harvest)
for (nharv in 1:length(harvest)){
Day_h <- as.numeric(harvest[nharv])
coolnight <- climdata_fil %>%
filter(climdata_fil$DOY>(Day_h-30) & climdata_fil$DOY<=Day_h) %>%
filter(climdata_fil$DOY>(Day_h-span) & climdata_fil$DOY<=Day_h) %>%
summarise(Cool_n=mean(Tmin)) %>%
select(Cool_n) %>%
unlist(use.names=FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ globalVariables(c("%>%","BEDD_day","Chill","Cool","Cool_d","Cool_n","DOY","DTR",
"bind_cols","bind_rows","day","delt","everything","filter",
"ftmprt","group_by","h_russ","h_wind","h_wpol","if_else","m_lat",
"make_datetime","mutate","rename","right_join","select","slice",
"sr","summarise","summarise_all","tail","windh","wpol","case_when"))
"sr","summarise","summarise_all","tail","windh","wpol","case_when","DTR_a","DTR_d"))
47 changes: 32 additions & 15 deletions R/russet.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
#' Estimation of the russet risk for apple and pear fruits
#'
#' This function assesses the risk of russet in apple and pear
#' fruits by estimating the number of hours with relative
#' humidity above 75\% in the critical period (between 12
#' and 30 days after full bloom, DAFB). The function requires
#' hourly temperatures and humidity, if only daily data is
#' available, the function hourly_RH can be used to estimate them.
#' This function assesses the risk of russet in fruit skins. The
#' risk is defined by the number of hours with the relative humidity (RH)
#' above a threshold during a given period. For reference, in 'Conference'
#' pear the risk is defined by the number of hours with RH> 75\% from
#' 12 to 30 days after full bloom (Alegre, 2013). In 'Golden' apple,
#' the risk is defined by the number of hours with RH> 55\% from
#' 30 to 34 days after full bloom (Barcelo-Vidal et al., 2013).
#' The function requires hourly temperatures and humidity,
#' if only daily data is available, the function hourly_RH can be
#' used to estimate them.
#'
#' @param climdata a dataframe with hourly temperature and RH
#' data. Required columns are Date, Year, Month, Day, DOY (julian day),
#' Hour and RH.
#' @param fendata a dataframe with julian day of occurrence of the full
#' bloom (F2) phenological stage.
#' Must contain the columns Year and Fday in that order.
#' @return data frame with the number of hours with RH>75\%
#' between 12 and 30 DAFB (Russet_h) each year in the series.
#' @param RH_crit the relative humidity threshold
#' @param init_d the initial date (as days after full bloom) of the sensitive period
#' @param end_d the end date (as days after full bloom) of the sensitive period
#' @return data frame with the number of risk hours (Russet_hours)
#' in the sensitive period for each year in the series.
#' @author Carlos Miranda, \email{carlos.miranda@@unavarra.es}
#' @references
#'
#' Alegre S. 2013. Tecnicas de cultivo. In. VII Foro INIA "adaptacion a
#' cambio climatico en la produccion fruticola de hueso y pepita". Madrid,
#' Spain, pp 1-18
#' Barcelo-Vidal C, Bonany J, Martin-Fernandez JA and Carbo J. 2013.
#' Modelling of weather parameters to predict russet on 'Golden Delicious'
#' apple. J. Hort. Sci. Biotech. 88: 624-630.
#'
#' @examples
#'
#' # Select the appropiate columns from the example dataset
Expand All @@ -28,22 +44,23 @@
#' rename(Fday=sbloom)
#' # Obtain estimated hourly RH from the example dataset Tudela_DW
#' RH_h <- hourly_RH(Tudela_DW, 42.13132)
#' # Estimate the number of russet-inducing days for each season
#' Russet_Risk <-russet(RH_h,Bloom)
#' # Estimate the number of russet-inducing days for a RH>55\%
#' # between 30 to 34 days after full bloom for each season
#' Russet_Risk <-russet(RH_h,Bloom,55,30,34)
#'
#' @export russet
#' @import data.table tidyverse zoo
#' @importFrom lubridate make_date

russet <- function(climdata, fendata)
russet <- function(climdata, fendata, RH_crit, init_d, end_d)
{
climdata <- climdata %>%
group_by(Date) %>%
summarise(h_russ= sum(RH>=75)) %>%
summarise(h_russ= sum(RH>=RH_crit)) %>%
mutate(Year=year(Date),Month=month(Date),Day=day(Date), DOY=yday(Date)) %>%
select(-h_russ,h_russ)
Seasons <- unique(fendata$Year)
russrisks_cn <- c("Year","Russ_h")
russrisks_cn <- c("Year","Russ_hours")
russrisk.df <-data.frame(matrix(ncol=2, nrow=0, byrow=FALSE))
colnames(russrisk.df) <- russrisks_cn
for (sea in 1:(length(Seasons))){
Expand All @@ -52,14 +69,14 @@ russet <- function(climdata, fendata)
Fday <- as.numeric(Fdate[2])
fendata_fil <- fendata %>% filter(fendata$Year==Anno)
russhours_fil <- climdata %>%
filter(climdata$Year==Anno & climdata$DOY>=Fday+12 & climdata$DOY<=Fday+30)
filter(climdata$Year==Anno & climdata$DOY>=Fday+init_d & climdata$DOY<=Fday+end_d)
russhours_fil <- select(russhours_fil, h_russ)
russhours<- sum(unlist(russhours_fil, use.names=FALSE))
new.row.df <- data.frame(Anno,russhours)
russrisk.df <-rbind(russrisk.df,new.row.df)
}
russrisk.df <- russrisk.df %>%
rename(Year=Anno, Russet_h=russhours)
rename(Year=Anno, Russet_hours=russhours)
return(russrisk.df)
}

8 changes: 6 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Resubmission
This is a resubmission. In this version I have:
* Modified a reference with a problematic DOI encoding for other describing the same methodology.
This is a resubmission. In this version I have added some new features.
* New function (DTR) to calculate the mean diurnal temperature range
* color_potential now allows to define the evaluation period
* russet now allows to define the critical relative humidity and the evaluation period
* coolness_index now allows to define the evaluation period

## Test environments
* local OS X install, R 4.0.0
* ubuntu 16.04 (on travis-ci, devel and release), R 4.0.0
Expand Down
41 changes: 41 additions & 0 deletions man/DTR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions man/color_potential.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b18a930

Please sign in to comment.