-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' of github.com:SantanderMetGroup/drought4R into d…
…evel
- Loading branch information
Showing
21 changed files
with
485 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,23 @@ Imports: | |
transformeR(>= 1.4.4), | ||
utils, | ||
abind, | ||
magrittr | ||
magrittr, | ||
geosphere | ||
Suggests: | ||
loadeR, | ||
visualizeR, | ||
convertR | ||
Type: Package | ||
Title: A climate4R package for drought assessment <http://www.meteo.unican.es/climate4R> | ||
Version: 0.2.0 | ||
Date: 2019-04-24 | ||
Title: A climate4R package for PET estimation and drought assessment <http://www.meteo.unican.es/climate4R> | ||
Version: 0.3.0 | ||
Date: 2019-06-17 | ||
Authors@R: as.person(c( | ||
"Santander Meteorology Group <http://meteo.unican.es> [cph]", | ||
"Joaquín Bedia <[email protected]> [aut, cre]", | ||
"Maialen Iturbide <[email protected]> [aut]")) | ||
BugReports: https://github.com/SantanderMetGroup/drought4R/issues | ||
URL: https://github.com/SantanderMetGroup/transformeR/wiki | ||
Description: Evapotranspiration routines and drought index calculation using the climate4R framework <http://www.meteo.unican.es/climate4R>. | ||
Description: Potential evapotranspiration methods and drought index calculation using the climate4R framework <http://www.meteo.unican.es/climate4R>. | ||
License: file LICENSE | ||
LazyData: true | ||
Encoding: UTF-8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## effectiveTemp.R Calculation of the effective temperature for improving the Thornthwaite's ET0 estimation method | ||
## | ||
## Copyright (C) 2019 Santander Meteorology Group (http://www.meteo.unican.es) | ||
## | ||
## This program is free software: you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 3 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## This program is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
## You should have received a copy of the GNU General Public License | ||
## along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#' @title Effective temperature | ||
#' @description Calculation of the \dQuote{effective temperature} for improving the Thornthwaite's ET0 estimation method | ||
#' @param tasmax Grid of maximum monthly temperature (degC) | ||
#' @param tasmin Grid of minimum monthly temperature (degC) | ||
#' @param k Calibration coefficient. Default to 0.69, as proposed by Pereira and Pruitt (2004) | ||
#' @references \itemize{ | ||
#' \item de Camargo, A.P., Marin, F.R., Sentelhas, P. C., Picini, A.G., 1999. Adjust of the Thornthwaite’s method to estimate the potential evapotranspiration for arid and superhumid climates, based on daily temperature amplitude. Revista Brasileira de Agrometeorologia 7. | ||
#' \item Pereira, A.R., Pruitt, W.O., 2004. Adaptation of the Thornthwaite scheme for estimating daily reference evapotranspiration. Agricultural Water Management 66, 251–257. https://doi.org/10.1016/j.agwat.2003.11.003 | ||
#' } | ||
#' @details The function is internally used by \code{\link{petGrid}} when the Thornthwaite's method with calibration coefficient k is chosen. | ||
#' @seealso \code{\link{petGrid}} | ||
#' @author J. Bedia | ||
#' @export | ||
|
||
effectiveTempGrid <- function(tasmin = NULL, tasmax = NULL, k = 0.69) { | ||
if (is.null(tasmin) | is.null(tasmax)) { | ||
stop("Both \'tasmin\' and \'tasmax\' arguments are required for effective temperature computation", call. = FALSE) | ||
} | ||
if (is.null(k)) stop("A calibration factor \'k\' is required", call. = FALSE) | ||
checkDim(tasmin, tasmax, dimensions = c("time", "lat", "lon")) | ||
checkTemporalConsistency(tasmin, tasmax) | ||
if ((getTimeResolution(tasmax) != "DD" | getTimeResolution(tasmin) != "DD")) stop("Daily data are required for effective temperature computation", call. = FALSE) | ||
message("[", Sys.time(), "] Calculating effective temperature...") | ||
tasmin <- gridArithmetics(tasmax, 3, tasmin, operator = c("*", "-")) %>% gridArithmetics(., 0.5 * k, operator = "*") | ||
tasmax <- NULL | ||
tasmin$Variable$varName <- "Effective_temperature" | ||
attr(tasmin$Variable, "description") <- "effective temperature for Thorthwaite's method calibration" | ||
attr(tasmin$Variable, "longname") <- "effective_temperature" | ||
attr(tasmin, "R_package_desc") <- paste0("drought4R-v", packageVersion("drought4R")) | ||
attr(tasmin, "R_package_URL") <- "https://github.com/SantanderMetGroup/drought4R" | ||
attr(tasmin, "R_package_ref") <- "http://dx.doi.org/10.1016/j.envsoft.2018.09.009" | ||
return(tasmin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
## photoperiod.R Compute photoperiod (daylength) as a funtion of latitude and date | ||
## | ||
## Copyright (C) 2019 Santander Meteorology Group (http://www.meteo.unican.es) | ||
## | ||
## This program is free software: you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 3 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## This program is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
## You should have received a copy of the GNU General Public License | ||
## along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#' @title Photoperiod | ||
#' @description Compute photoperiod (daylength) as a funtion of latitude and date | ||
#' @param c4r.obj climate4R object. Note that this is independent of the variable stored, as it will use only the calendar | ||
#' an geographical information of the object to compute the photoperiod | ||
#' @importFrom geosphere daylength | ||
#' @importFrom transformeR getRefDates getCoordinates getShape redim subsetGrid mat2Dto3Darray bindGrid | ||
#' @importFrom magrittr %>% %<>% | ||
#' @details This is just a wrapper from the \code{\link[geosphere]{daylength}} function of package \pkg{geosphere}. | ||
#' @export | ||
#' @author J. Bedia | ||
#' @examples | ||
#' require(transformeR) | ||
#' data("tasmin.eobs.iberia.daily") | ||
#' daylength <- photoperiodGrid(tasmin.eobs.iberia.daily) | ||
#' lat <- range(getCoordinates(daylength)[["y"]]) | ||
#' lat.ranges <- seq(from = lat[1], to = tail(lat, 1), length.out = 5) | ||
#' lat.list <- lapply(1:(length(lat.ranges) - 1), function(x) { | ||
#' subsetGrid(daylength, latLim = c(lat.ranges[x], lat.ranges[x + 1]), outside = TRUE) | ||
#' }) | ||
#' require(visualizeR) | ||
#' temporalPlot(lat.list, xyplot.custom = list(main = "Photoperiod as a function of latitude", | ||
#' ylab = "Daylight hours", | ||
#' xlab = "Date", | ||
#' key = list(corner = c(1,.5), | ||
#' lines = list(col = 1:4), | ||
#' horizontal = TRUE, | ||
#' text = list(c("37ºN","39ºN","41ºN","43ºN"))))) | ||
|
||
photoperiodGrid <- function(c4r.obj) { | ||
message("[", Sys.time(), "] Calculating photoperiod...") | ||
j <- getRefDates(c4r.obj) %>% as.POSIXlt() %>% format(format = "%j") %>% as.integer() | ||
coords <- getCoordinates(c4r.obj) | ||
lats <- expand.grid(coords$y, coords$x)[2:1][,2] | ||
c4r.obj %<>% redim(member = TRUE) | ||
nmem <- getShape(c4r.obj, "member") | ||
aux.list <- lapply(1:nmem, function(x) { | ||
ref <- subsetGrid(c4r.obj, members = x) %>% redim(member = FALSE) | ||
ref$Data <- vapply(lats, FUN = geosphere::daylength, j, FUN.VALUE = numeric(length(j))) %>% mat2Dto3Darray(x = coords$x, y = coords$y) | ||
return(ref) | ||
}) | ||
c4r.obj <- suppressWarnings(bindGrid(aux.list, dimension = "member")) | ||
aux.list <- NULL | ||
c4r.obj$Variable$varName <- "photoperiod" | ||
attr(c4r.obj$Variable, "description") <- "daylength" | ||
attr(c4r.obj$Variable, "longname") <- "photoperiod_length" | ||
attr(c4r.obj$Variable, "units") <- "hours.day-1" | ||
attr(c4r.obj, "R_package_desc") <- paste0("drought4R-v", packageVersion("drought4R")) | ||
attr(c4r.obj, "R_package_URL") <- "https://github.com/SantanderMetGroup/drought4R" | ||
attr(c4r.obj, "R_package_ref") <- "http://dx.doi.org/10.1016/j.envsoft.2018.09.009" | ||
return(c4r.obj) | ||
} |
Oops, something went wrong.