R/read_results.R

Defines functions read_results

Documented in read_results

###############################################################################################
##                                         read_results                                      ##
###############################################################################################
# Author : Rodrigo Marinao Rivas                                                             ##
###############################################################################################
# Created: 2021-04-05                                                                        ##
###############################################################################################
#
# Description: Read results saved on disk from an optimization with hydroMOPSO.
#              This feature only applies when fn %in% c("hydromod", "hydromodInR")

read_results <- function(fn = NULL,               # >> 'character/function'. Either a character or a function indicating the function (forgive the 
                                                  # redundancy) to be optimised. When it comes to model optimisation, there are two special
                                                  # specifications: c("hydromod", "hydromodInR"), being "hydromod" proper to the use of a hydrological
                                                  # model controlled from outside R and "hydromodInR" proper to the use of a hydrological model 
                                                  # implemented within R
                        control = list(),         # >> 'list'. A list of control parameters. See 'hydroMOPSO' function in documentation for details 
                        model.FUN = NULL,         # >> 'character' (only used only when fn='hydromod' or fn='hydromodInR'). A valid R function
                                                  # representing the model code to be calibrated/optimised
                        model.FUN.args = list()   # >> 'list' (only used only when fn='hydromod' or fn='hydromodInR'). List with the arguments to pass
                                                  # to model.FUN
                        ){

    if(!is.null(control[["drty.out"]])){
        if(!dir.exists(control[["drty.out"]])){
            stop(paste0("The folder '", control[["drty.out"]],"', specified as the output directory, has not been found... check directories"))
        }else{
            out.drty <- control[["drty.out"]]
        }
    }else{
        if(!dir.exists("MOPSO.out")){
            stop(paste0("You have not specified the name you have assigned to the output directory with the results to read. By default, the name assigned in hydroMOPSO is 'MOPSO.out', but this folder has not been found... check directories"))
        }else{
            out.drty <- "MOPSO.out"
        }
    }


    out <- PostResults(MOPSO.Results = NULL,
                       hydro.Details = NULL,
                       fn = fn,
                       control = control,
                       model.FUN = model.FUN,
                       analysis.period = "calibration",
                       model.FUN.args = model.FUN.args
                       )

    return(out)
} # END

Try the hydroMOPSO package in your browser

Any scripts or data that you put into this service are public.

hydroMOPSO documentation built on June 18, 2025, 9:15 a.m.