From af705124371a471c22ccd78da827613b6a95b9f4 Mon Sep 17 00:00:00 2001 From: Mauricio Zambrano-Bigiarini <hzambran@users.noreply.github.com> Date: Mon, 15 Oct 2012 11:59:27 +0000 Subject: [PATCH] +importFrom(zoo, is.zoo) --- DESCRIPTION | 3 +-- NAMESPACE | 1 + R/hydromod.R | 21 +++++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8c51232..5e07faa 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,13 +3,12 @@ Type: Package Title: Model-Independent Particle Swarm Optimisation for Environmental Models Version: 0.1-58-10 Date: 2012-09-28 -Author: Mauricio Zambrano-Bigiarini [aut, cre] and Rodrigo Rojas [ctb] Authors@R: c(person("Mauricio", "Zambrano-Bigiarini", email="mzb.devel@gmail.com", role=c("aut","cre")), person("Rodrigo", "Rojas", email="Rodrigo.RojasMujica@gmail.com", role=c("ctb")) ) Maintainer: Mauricio Zambrano-Bigiarini <mzb.devel@gmail.com> Description: This package implements a state-of-the-art version of the Particle Swarm Optimisation (PSO) algorithm (SPSO-2011 and SPSO-2007 capable), with a special focus on the calibration of environmental models. hydroPSO is model-independent, allowing the user to easily interface any model code with the calibration engine (PSO). It includes a series of controlling options and PSO variants to fine-tune the performance of the calibration engine to different calibration problems. An advanced sensitivity analysis function together with user-friendly plotting summaries facilitate the interpretation and assessment of the calibration results. Bugs reports/comments/questions are very welcomed. License: GPL (>=2) Depends: R (>= 2.10.0) -Imports: Hmisc, sp, lattice, grid +Imports: Hmisc, sp, lattice, zoo, grid Suggests: hydroGOF(>= 0.3-3), hydroTSM(>= 0.3-0), zoo(>= 1.7-2), xts(>= 0.8-2), lhs, scatterplot3d, vioplot, multicore URL: http://www.rforge.net/hydroPSO, http://cran.r-project.org/web/packages/hydroPSO Classification: optimisation, optimization, calibration, environment, environmental sciences, hydrology, PSO diff --git a/NAMESPACE b/NAMESPACE index 25c0eae..fa9a593 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ importFrom("Hmisc", wtd.quantile, wtd.Ecdf) importFrom("sp", coordinates, spplot) importFrom("lattice", xyplot, axis.default) +importFrom("zoo", is.zoo) import(grid) #importFrom("hydroTSM", hydroplot, hydropairs, dip, mip, yip, vector2zoo) #importFrom("hydroGOF", ggof) diff --git a/R/hydromod.R b/R/hydromod.R index 8464207..d4d8ff4 100755 --- a/R/hydromod.R +++ b/R/hydromod.R @@ -20,8 +20,8 @@ # Author : Mauricio Zambrano-Bigiarini # # Started: 14-Dec-2010 at JRC Ispra # # Updates: 20-Dec-2010 # -# 19-Jan-2011 ; 22-Jan-2011 ; 02-Feb-2011 ; 11-May-2011 # -# 13-Jan-2012 ; 16-Jan-2012 ; 23-Jan-2012 ; 02-May-2012 # +# 19-Jan-2011 ; 22-Jan-2011 ; 02-Feb-2011 ; 11-May-2011 # +# 13-Jan-2012 ; 16-Jan-2012 ; 23-Jan-2012 ; 02-May-2012 ; 12-Oct-2012 # ################################################################################ hydromod <- function( param.values, # Numeric vector with the paramter values that will be used in the input files of the hydrological model @@ -137,7 +137,7 @@ hydromod <- function( out.FUN.argsDefaults <- formals(out.FUN) out.FUN.args <- modifyList(out.FUN.argsDefaults, out.FUN.args) - sim <- do.call(out.FUN, as.list(out.FUN.args)) + sim <- do.call(out.FUN, as.list(out.FUN.args)) ############################################################################## # 4) Goodness of fit # @@ -151,10 +151,10 @@ hydromod <- function( # 'sim' and 'obs' are subset to the time period selected for the GoF function if (!missing(gof.Ini) ) { - if (!is.zoo(obs)) { + if (!zoo::is.zoo(obs)) { stop( "Invalid argument: 'obs' must be a zoo or xts object to use 'gof.Ini' !" ) } else obs <- window(obs, start=as.Date(gof.Ini, format=date.fmt) ) - if (!is.zoo(sim)) { + if (!zoo::is.zoo(sim)) { stop( "Invalid argument: 'sim' must be a zoo or xts object to use 'gof.Ini' !" ) } else sim <- window(sim, start=as.Date(gof.Ini, format=date.fmt) ) } # IF end @@ -163,14 +163,14 @@ hydromod <- function( if (gof.Fin < gof.Ini) { stop( "Invalid argument: 'gof.Fin < gof.Ini' (", gof.Fin, " < ", gof.Ini, ")" ) } else { - if (!is.zoo(obs)) { + if (!zoo::is.zoo(obs)) { stop( "Invalid argument: 'obs' must be a zoo or xts object to use 'gof.Fin' !" ) } else obs <- window(obs, end=as.Date(gof.Fin, format=date.fmt) ) - if (!is.zoo(sim)) { + if (!zoo::is.zoo(sim)) { stop( "Invalid argument: 'sim' must be a zoo or xts object to use 'gof.Fin' !" ) } else sim <- window(sim, end=as.Date(gof.Fin, format=date.fmt) ) } # IF end - } # IF end + } # IF end nobs <- length(obs) nsim <- length(sim) @@ -211,13 +211,14 @@ hydromod <- function( png(filename=png.fname, width= width, height= height, res=res) if ( !is.na( match("hydroGOF", installed.packages()[,"Package"] ) ) ) { + library(hydroGOF) ggof(sim, obs, main=main, cex.main=1.5, leg.cex=leg.cex, tick.tstep=tick.tstep, lab.tstep=lab.tstep, lab.fmt=lab.fmt) - } else + } else plot_out(sim=sim, obs=obs, ptype="corr") dev.off() if (verbose) message("===========================================") - if (verbose) message("[ See the file 'Obs_vs_Sim.png' ]") + if (verbose) message("[ See the file '", basename(png.fname), "' ") if (verbose) message("===========================================") } # IF end -- GitLab