From 7186c71c676727f99591865cdd33496cfe7b0ebe Mon Sep 17 00:00:00 2001 From: Joaquin Bedia Date: Wed, 19 Jul 2017 12:03:14 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5d79b3..5f18115 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ What is fireDanger? `fireDanger` is an R package for the Implementation of the Canadian Fire Weather Index System using as input seasonal forecast data and other climatic datasets. *** -`fireDanger` is part of the [**loadeR**](https://github.com/SantanderMetGroup/loadeR) **bundle**. +`fireDanger` is part of the **climate4R bundle**. *** From 1d80e793dd6145c533d75bf87b29de5bed2b6407 Mon Sep 17 00:00:00 2001 From: jbedia Date: Tue, 21 Aug 2018 10:43:26 +0200 Subject: [PATCH 2/7] Remove PET routine (moved to drought4R) --- R/hsPET.R | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 R/hsPET.R diff --git a/R/hsPET.R b/R/hsPET.R deleted file mode 100644 index b5a664b..0000000 --- a/R/hsPET.R +++ /dev/null @@ -1,37 +0,0 @@ -hsPET <- -function(date, lat=42, t.min, t.max, ret.rad = FALSE) { - d <- as.POSIXlt(date) - lat <- lat * (pi / 180) - tn <- t.min - tx <- t.max - rr <- ret.rad - varnames <- c("d", "tn", "tx") - ind <- c() - for (i in 1:length(varnames)) { - vec <- get(varnames[i]) - if (any(is.na(vec))) { - a <- which(is.na(vec)) - ind <- c(ind, a) - } - } - if (length(ind) > 0) { - warning("Some missing values were removed from the time series before computation") - ind <- unique(ind) - for (i in 1:length(varnames)) { - assign(varnames[i], get(varnames[i])[-ind]) - } - } - J <- as.numeric(format(d, format = "%j")) - Gsc <- 0.082 - ds <- 0.409 * sin(2 * pi * J / 365 - 1.39) - ws <- acos(-tan(lat) * tan(ds)) - dr <- 1 + 0.033 * cos(2 * pi * J / 365) - Ra <- (24 * 60 * .082 * dr * (ws * sin(lat) * sin(ds) + cos(lat) * cos(ds) * sin(ws))) / pi - hs <- .0023 * (Ra / 2.45) * ((tx + tn) / 2 + 17.8) * sqrt(tx - tn) - if (isTRUE(rr)) { - return(list("date" = d, "Rad" = Ra, "HSevap" = hs)) - } - else { - return(list("date" = d, "HSevap" = hs)) - } -} From 234946cff83ade0605898bb47d279b3bb41231da Mon Sep 17 00:00:00 2001 From: jbedia Date: Fri, 28 Sep 2018 14:39:02 +0200 Subject: [PATCH 3/7] Add FFFDI implementation --- R/fffdiGrid.R | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 R/fffdiGrid.R diff --git a/R/fffdiGrid.R b/R/fffdiGrid.R new file mode 100644 index 0000000..3d732ff --- /dev/null +++ b/R/fffdiGrid.R @@ -0,0 +1,80 @@ +# fffdiGrid.R Finnish Forest Fire Danger Index +# +# Copyright (C) 2018 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 . + +#' @title Finnish Forest Fire Danger Index (FFFDI) +#' @description Implementation of the FFFDI for climate4R grids +#' @param pr A climate4R object containing daily precipitation (in mm) +#' @param pet A climate4R object containing daily (potential) evapotranspiration data (in mm). +#' @param Wwol.init Initialization value for volumetric moisture, in the range 0.1-0.5. +#' Default to 0.5 (very wet soil), but see Details. +#' @param z reference surface layer thickness (mm). Default to 60. +#' @references Vajda, A., Venalainen, A., Suomi, I., Junila, P. and Makela, H., 2014. Assessment of forest +#' fire danger in a boreal forest environment: description and evaluation of the operational +#' system applied in Finland. Meteorol. Appl., 21: 879-887, DOI: 10.1002/met.1425 +#' @importFrom transformeR gridArithmetics getDim getShape +#' @importFrom abind asub abind +#' @importFrom transformeR checkDim checkTemporalConsistency redim getShape subsetGrid array3Dto2Dmat getCoordinates +#' @importFrom magrittr %>% %<>% extract2 +#' @return A climate4R object containing FFFDI data +#' @details +#' \strong{Volumetric moisture} +#' The default is 0.5, indicating that the soil is very wet and near field capacity. This is so, assuming that the +#' index is started in early spring. This value is applied to all locations as a spatially constant initialization value. +#' However, Vajda \emph{et al.} (2014, Table 1) provide reference values for different soil moisture conditions. This value ranges +#' from 0.1 (very dry) to 0.5 (very wet). +#' @author J. Bedia (based on the original FORTRAN code from Vajda et al. 2014). +#' @seealso \code{petGrid} function, from package \pkg{drought4R} +#' is recommended for PET estimation . +#' @export + + +fffiGrid <- function(pr, pet, Wvol.init = 0.5, z = 60) { + pr %<>% redim() + pet %<>% redim() + suppressMessages(checkDim(pr, pet)) + checkTemporalConsistency(pr, pet) + if ("var" %in% getDim(pet)) stop("Input multigrids are not allowed") + ntimes <- getShape(pr, "time") + nmem <- getShape(pr, "member") + npoints <- getCoordinates(pet) %>% expand.grid() %>% nrow() + aux.grid <- pet + fffdi.list <- lapply(1:nmem, function(x) { + Wvol <- rep(Wvol.init, npoints) + Wt <- Wvol * z + pr.aux <- subsetGrid(pr, members = x) %>% redim(member = FALSE) %>% extract2("Data") %>% array3Dto2Dmat() + pet.aux <- subsetGrid(pet, members = x) %>% redim(member = FALSE) %>% extract2("Data") %>% array3Dto2Dmat() + ref <- pet.aux + for (i in 1:ntimes) { + dw <- (-pet.aux[i,] * 0.757) / (1 + exp(2.74 - 16.67 * (Wvol - 0.1))) + 5.612 * (1 - exp(-pr.aux[i,] / 5.612)) + Wt <- Wt + dw + Wvol <- Wt/z + Wvol[which(Wvol > 0.5)] <- 0.5 + Wvol[which(Wvol < 0.1)] <- 0.1 + ref[i,] <- 8.76 - 30.879 * Wvol + 30.712 * Wvol^2 + } + grd <- mat2Dto3Darray(ref, x = getCoordinates(pet)[["x"]], y = getCoordinates(pet)[["y"]]) + aux.grid$Data <- grd + redim(aux.grid) %>% return() + }) + out <- do.call("bindGrid", c(fffdi.list, dimension = "member")) + out$Variable$varName <- "fffdi" + descr <- "finnish_forest_fire_danger_index" + attr(out$Variable, "description") <- descr + attr(out$Variable, "longname") <- descr + attr(out$Variable, "daily_agg_cellfun") <- "index" + return(out) +} From fb1d7288b54f6adf77478267c0ddabc17ccb62ec Mon Sep 17 00:00:00 2001 From: jbedia Date: Fri, 28 Sep 2018 14:39:15 +0200 Subject: [PATCH 4/7] Doc update --- .gitignore | 1 + DESCRIPTION | 14 ++++++++------ NAMESPACE | 8 ++++++++ NEWS | 11 +++++++---- man/fffiGrid.Rd | 43 +++++++++++++++++++++++++++++++++++++++++++ man/fwi1D.Rd | 4 ++-- 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 man/fffiGrid.Rd diff --git a/.gitignore b/.gitignore index 1dff876..c086388 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ fireDanger.Rproj *~ vignettes/cache vignettes/figure +ignore diff --git a/DESCRIPTION b/DESCRIPTION index 922f95f..e46c216 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,8 @@ Depends: R(>= 3.1.0) Imports: abind, - transformeR(>= 0.0.7), + transformeR(>= 1.4.7), + magrittr, parallel Suggests: visualizeR, @@ -17,15 +18,16 @@ Suggests: VignetteBuilder: knitr Type: Package Title: Fire weather index calculation from station and model data -Version: 1.0.3 -Date: 2017-07-10 +Version: 1.1.0 +Date: 2018-09-28 Authors@R: as.person(c( "Santander Meteorology Group [aut]", "Joaquin Bedia [ctb, cre]", "Maialen Iturbide [ctb]")) BugReports: https://github.com/SantanderMetGroup/fireDanger/issues -URL: https://github.com/SantanderMetGroup/fireDanger -Description: Tools for computing the Fire Weather Index from weather station and numerical climate model data. +URL: http://www.meteo.unican.es/climate4r +Description: A climate4R package for computing several popular fire danger indices. License: GPL (>= 3) +Encoding: UTF-8 LazyData: true -RoxygenNote: 6.0.1 +RoxygenNote: 6.1.0 diff --git a/NAMESPACE b/NAMESPACE index 9d1e56d..9710f30 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,16 +1,24 @@ # Generated by roxygen2: do not edit by hand +export(fffiGrid) export(fwi1D) export(fwiGrid) importFrom(abind,abind) importFrom(abind,asub) +importFrom(magrittr,"%<>%") +importFrom(magrittr,"%>%") +importFrom(magrittr,extract2) importFrom(parallel,parLapply) importFrom(parallel,splitIndices) importFrom(stats,complete.cases) importFrom(transformeR,array3Dto2Dmat) +importFrom(transformeR,checkDim) +importFrom(transformeR,checkTemporalConsistency) +importFrom(transformeR,getCoordinates) importFrom(transformeR,getDim) importFrom(transformeR,getShape) importFrom(transformeR,getYearsAsINDEX) +importFrom(transformeR,gridArithmetics) importFrom(transformeR,mat2Dto3Darray) importFrom(transformeR,parallelCheck) importFrom(transformeR,redim) diff --git a/NEWS b/NEWS index 39dce87..101416f 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ -New in fireDanger -================= +fireDanger changelog +==================== -* Added CITATION file -* Documentation updates \ No newline at end of file +For earlier version descriptions, got to the [Releases Tab](https://github.com/SantanderMetGroup/fireDanger/releases) + +## v1.1.0 (in devel) +* Included an implementation of the Finish Forest Fire Danger Index System +* Other minor changes and documentation updates diff --git a/man/fffiGrid.Rd b/man/fffiGrid.Rd new file mode 100644 index 0000000..a5c8934 --- /dev/null +++ b/man/fffiGrid.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fffdiGrid.R +\name{fffiGrid} +\alias{fffiGrid} +\title{Finnish Forest Fire Danger Index (FFFDI)} +\usage{ +fffiGrid(pr, pet, Wvol.init = 0.5, z = 60) +} +\arguments{ +\item{pr}{A climate4R object containing daily precipitation (in mm)} + +\item{pet}{A climate4R object containing daily (potential) evapotranspiration data (in mm).} + +\item{z}{reference surface layer thickness (mm). Default to 60.} + +\item{Wwol.init}{Initialization value for volumetric moisture, in the range 0.1-0.5. +Default to 0.5 (very wet soil), but see Details.} +} +\value{ +A climate4R object containing FFFDI data +} +\description{ +Implementation of the FFFDI for climate4R grids +} +\details{ +\strong{Volumetric moisture} +The default is 0.5, indicating that the soil is very wet and near field capacity. This is so, assuming that the + index is started in early spring. This value is applied to all locations as a spatially constant initialization value. + However, Vajda \emph{et al.} (2014, Table 1) provide reference values for different soil moisture conditions. This value ranges + from 0.1 (very dry) to 0.5 (very wet). +} +\references{ +Vajda, A., Venalainen, A., Suomi, I., Junila, P. and Makela, H., 2014. Assessment of forest +fire danger in a boreal forest environment: description and evaluation of the operational +system applied in Finland. Meteorol. Appl., 21: 879-887, DOI: 10.1002/met.1425 +} +\seealso{ +\code{petGrid} function, from package \pkg{drought4R} +is recommended for PET estimation . +} +\author{ +J. Bedia (based on the original FORTRAN code from Vajda et al. 2014). +} diff --git a/man/fwi1D.Rd b/man/fwi1D.Rd index 38d9b61..280a047 100644 --- a/man/fwi1D.Rd +++ b/man/fwi1D.Rd @@ -4,8 +4,8 @@ \alias{fwi1D} \title{Fire Weather Index applied to 1D data} \usage{ -fwi1D(months, Tm, H, r, W, lat = 46, what = "FWI", init.pars = c(85, 6, - 15), spin.up = 0) +fwi1D(months, Tm, H, r, W, lat = 46, what = "FWI", init.pars = c(85, + 6, 15), spin.up = 0) } \arguments{ \item{months}{Vector of integers corresponding to the months in the data} From 4f5381f7d7bebfb3cabf65bcc0a9f8e977e3207e Mon Sep 17 00:00:00 2001 From: jbedia Date: Fri, 28 Sep 2018 15:03:52 +0200 Subject: [PATCH 5/7] suppress messages --- R/fffdiGrid.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fffdiGrid.R b/R/fffdiGrid.R index 3d732ff..87b1abd 100644 --- a/R/fffdiGrid.R +++ b/R/fffdiGrid.R @@ -70,7 +70,7 @@ fffiGrid <- function(pr, pet, Wvol.init = 0.5, z = 60) { aux.grid$Data <- grd redim(aux.grid) %>% return() }) - out <- do.call("bindGrid", c(fffdi.list, dimension = "member")) + out <- suppressMessages(do.call("bindGrid", c(fffdi.list, dimension = "member"))) out$Variable$varName <- "fffdi" descr <- "finnish_forest_fire_danger_index" attr(out$Variable, "description") <- descr From 3111f2d7b8764e20b243de0f0b4cf3a904810e07 Mon Sep 17 00:00:00 2001 From: jbedia Date: Thu, 4 Oct 2018 15:59:48 +0200 Subject: [PATCH 6/7] Doc update and rename function --- DESCRIPTION | 1 + NAMESPACE | 2 +- R/fffdiGrid.R | 2 +- man/{fffiGrid.Rd => fffdiGrid.Rd} | 6 +++--- 4 files changed, 6 insertions(+), 5 deletions(-) rename man/{fffiGrid.Rd => fffdiGrid.Rd} (95%) diff --git a/DESCRIPTION b/DESCRIPTION index e46c216..81b32ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,6 +14,7 @@ Suggests: easyVerification, knitr, rmarkdown, + drought4R, RColorBrewer VignetteBuilder: knitr Type: Package diff --git a/NAMESPACE b/NAMESPACE index 9710f30..5d8c311 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(fffiGrid) +export(fffdiGrid) export(fwi1D) export(fwiGrid) importFrom(abind,abind) diff --git a/R/fffdiGrid.R b/R/fffdiGrid.R index 87b1abd..f7318e1 100644 --- a/R/fffdiGrid.R +++ b/R/fffdiGrid.R @@ -42,7 +42,7 @@ #' @export -fffiGrid <- function(pr, pet, Wvol.init = 0.5, z = 60) { +fffdiGrid <- function(pr, pet, Wvol.init = 0.5, z = 60) { pr %<>% redim() pet %<>% redim() suppressMessages(checkDim(pr, pet)) diff --git a/man/fffiGrid.Rd b/man/fffdiGrid.Rd similarity index 95% rename from man/fffiGrid.Rd rename to man/fffdiGrid.Rd index a5c8934..4a6e36a 100644 --- a/man/fffiGrid.Rd +++ b/man/fffdiGrid.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/fffdiGrid.R -\name{fffiGrid} -\alias{fffiGrid} +\name{fffdiGrid} +\alias{fffdiGrid} \title{Finnish Forest Fire Danger Index (FFFDI)} \usage{ -fffiGrid(pr, pet, Wvol.init = 0.5, z = 60) +fffdiGrid(pr, pet, Wvol.init = 0.5, z = 60) } \arguments{ \item{pr}{A climate4R object containing daily precipitation (in mm)} From 25e5c3109294b30383929091642d2bf3c4701b45 Mon Sep 17 00:00:00 2001 From: jbedia Date: Thu, 4 Oct 2018 17:03:18 +0200 Subject: [PATCH 7/7] Doc update --- DESCRIPTION | 2 +- NEWS | 2 +- R/fffdiGrid.R | 2 +- man/fffdiGrid.Rd | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 81b32ab..662bc6a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ VignetteBuilder: knitr Type: Package Title: Fire weather index calculation from station and model data Version: 1.1.0 -Date: 2018-09-28 +Date: 2018-10-04 Authors@R: as.person(c( "Santander Meteorology Group [aut]", "Joaquin Bedia [ctb, cre]", diff --git a/NEWS b/NEWS index 101416f..d3036b8 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,6 @@ fireDanger changelog For earlier version descriptions, got to the [Releases Tab](https://github.com/SantanderMetGroup/fireDanger/releases) -## v1.1.0 (in devel) +## v1.1.0 (4 Oct 2018) * Included an implementation of the Finish Forest Fire Danger Index System * Other minor changes and documentation updates diff --git a/R/fffdiGrid.R b/R/fffdiGrid.R index f7318e1..07a54cb 100644 --- a/R/fffdiGrid.R +++ b/R/fffdiGrid.R @@ -19,7 +19,7 @@ #' @description Implementation of the FFFDI for climate4R grids #' @param pr A climate4R object containing daily precipitation (in mm) #' @param pet A climate4R object containing daily (potential) evapotranspiration data (in mm). -#' @param Wwol.init Initialization value for volumetric moisture, in the range 0.1-0.5. +#' @param Wvol.init Initialization value for volumetric moisture, in the range 0.1-0.5. #' Default to 0.5 (very wet soil), but see Details. #' @param z reference surface layer thickness (mm). Default to 60. #' @references Vajda, A., Venalainen, A., Suomi, I., Junila, P. and Makela, H., 2014. Assessment of forest diff --git a/man/fffdiGrid.Rd b/man/fffdiGrid.Rd index 4a6e36a..38d9bde 100644 --- a/man/fffdiGrid.Rd +++ b/man/fffdiGrid.Rd @@ -11,10 +11,10 @@ fffdiGrid(pr, pet, Wvol.init = 0.5, z = 60) \item{pet}{A climate4R object containing daily (potential) evapotranspiration data (in mm).} -\item{z}{reference surface layer thickness (mm). Default to 60.} - -\item{Wwol.init}{Initialization value for volumetric moisture, in the range 0.1-0.5. +\item{Wvol.init}{Initialization value for volumetric moisture, in the range 0.1-0.5. Default to 0.5 (very wet soil), but see Details.} + +\item{z}{reference surface layer thickness (mm). Default to 60.} } \value{ A climate4R object containing FFFDI data