| Title: | Interface to Auto-Calibration Software UCODE |
|---|---|
| Description: | Functions enabling to write UCODE input files and to run UCODE. |
| Authors: | Hauke Sonnenberg [aut, cre] (ORCID: <https://orcid.org/0000-0001-9134-2871>), Michael Rustler [ctb] (ORCID: <https://orcid.org/0000-0003-0647-7726>), OPTIWELLS-2 [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
| Maintainer: | Hauke Sonnenberg <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-31 08:30:19 UTC |
| Source: | https://github.com/KWB-R/kwb.ucode |
History HTML for calibration progress visualisation
htmlForCalibrationHistory(n, current = "ucCurrent.html")htmlForCalibrationHistory(n, current = "ucCurrent.html")
n |
number of plots |
current |
default: "ucCurrent.html" |
Main HTML for calibration progress visualisation
htmlForCalibrationPage( htmlHist = "ucHistory.html", htmlCurr = "ucCurrent.html" )htmlForCalibrationPage( htmlHist = "ucHistory.html", htmlCurr = "ucCurrent.html" )
htmlHist |
default: "ucHistory.html" |
htmlCurr |
default: "ucCurrent.html" |
Content HTML for calibration progress visualisation
htmlForCalibrationState(refresh = 1)htmlForCalibrationState(refresh = 1)
refresh |
|
Configure UCODE run
ucConf( general = ucConfGeneral(), parameters = ucDefaultConfParameters(), weights = ucDefaultConfWeights() )ucConf( general = ucConfGeneral(), parameters = ucDefaultConfParameters(), weights = ucDefaultConfWeights() )
general |
configuration of control |
parameters |
data.frame with each row representing a parameter
configuration as e.g. retrieved by |
weights |
Matrix of |
lines for input block Model_Command_Lines
ucConf_Model_Command_Lines(bfile)ucConf_Model_Command_Lines(bfile)
bfile |
name of batch file to be invoked by UCODE |
Lines for input block Model_Input_Files
ucConf_Model_Input_Files()ucConf_Model_Input_Files()
Lines for input block Model_Output_Files
ucConf_Model_Output_Files()ucConf_Model_Output_Files()
Lines for input block Observation_Data
ucConf_Observation_Data(weights)ucConf_Observation_Data(weights)
weights |
Matix of |
Lines for input block Parameter_Data
ucConf_Parameter_Data(confParameters)ucConf_Parameter_Data(confParameters)
confParameters |
data frame representing table as required in Parameter_Data block of
UCODE input file. , for example see |
lines for input block UCODE_Control_Data
ucConf_Reg_GN_Controls(maxIter)ucConf_Reg_GN_Controls(maxIter)
maxIter |
Maximum number of parameter-estimation iterations allowed before stopping |
lines for input block UCODE_Control_Data
ucConf_UCODE_Control_Data()ucConf_UCODE_Control_Data()
General settings in UCODE configuration
ucConfGeneral(gof.digits = 5, maxIter = 100)ucConfGeneral(gof.digits = 5, maxIter = 100)
gof.digits |
Number of digits to be used in goodness of fit values. Default: 5 |
maxIter |
Maximum number of parameter-estimation iterations allowed before stopping |
Create parameter for UCODE configuration
ucConfParameter( paramname, startvalue = 1e+38, lowerValue = -1e+38, upperValue = 1e+38, lowerConstraint = 0, upperConstraint = 1, constrain = "yes", adjustable = "yes", maxChange = 2, perturbAmt = 0.5 )ucConfParameter( paramname, startvalue = 1e+38, lowerValue = -1e+38, upperValue = 1e+38, lowerConstraint = 0, upperConstraint = 1, constrain = "yes", adjustable = "yes", maxChange = 2, perturbAmt = 0.5 )
paramname |
Parameter name (up to 12 characters; not case sensitive) - a
character string that is used in a template file or in an equation of a
derived parameter in the Derived_Parameters input block. Each parameter
name needs to be unique and can not be the same as any parameter name
defined in the Derived_Parameter input block. For possible parameter names
see |
startvalue |
Starting parameter value. Default=A huge real number. The huge real number is obtained for the computer being used and commonly is about 1e38. |
lowerValue |
Smallest reasonable value for this parameter. Default= -(Huge real number). In absolute value, commonly about -1e38. |
upperValue |
Largest reasonable value for this parameter. Default= +(Huge real number). Commonly about +1e38. |
lowerConstraint |
Lower limit of considered parameter values. Default (HS): 0 |
upperConstraint |
Upper limit of considered parameter values. Default (HS): 1 |
constrain |
yes: |
adjustable |
yes: change this value as needed depending on the purpose of the UCODE_2005 run defined in the UCODE_Control_Data input file. no: leave the value of this parameter unchanged. Default (HS): "yes". |
maxChange |
Maximum fractional parameter change allowed between parameter iterations. Default=2.0. |
perturbAmt |
Fractional amount of parameter value to perturb to calculate sensitivity. Commonly 0.01 to 0.10. Default (HS): 0.5. See discussion in Chapter 3. |
data.frame containing all argument values with column names equalling function argument names
ucConf, ucDefaultConfParameters
# Use rbind to create a data.frame containing parameter information as # required by ucConf: cpara <- rbind( ucConfParameter(paramname = "HKR", startvalue = 2e-5, lowerConstraint = 1e-5, upperConstraint = 1e-1, maxChange = 1, perturbAmt = 0.5, constrain = "yes", adjustable = "yes"), ucConfParameter(paramname = "HKZ", startvalue = 2e-7, lowerConstraint = 1e-7, upperConstraint = 1e-3, maxChange = 1, perturbAmt = 0.5, constrain = "yes", adjustable = "yes")) # set this parameter setting in default UCODE configuration ucConf(parameters = cpara)# Use rbind to create a data.frame containing parameter information as # required by ucConf: cpara <- rbind( ucConfParameter(paramname = "HKR", startvalue = 2e-5, lowerConstraint = 1e-5, upperConstraint = 1e-1, maxChange = 1, perturbAmt = 0.5, constrain = "yes", adjustable = "yes"), ucConfParameter(paramname = "HKZ", startvalue = 2e-7, lowerConstraint = 1e-7, upperConstraint = 1e-3, maxChange = 1, perturbAmt = 0.5, constrain = "yes", adjustable = "yes")) # set this parameter setting in default UCODE configuration ucConf(parameters = cpara)
Default parameter definition for UCODE configuration
ucDefaultConfParameters()ucDefaultConfParameters()
data.frame with each row representing a model parameter
Weights are given for each pair of well name (pumping well PW or
observation wells) and name of goodness of fit (gof)-function.
ucDefaultConfWeights( wells = wtConfiguredWellnames(wtDefaultConfiguration()), gofs = c("RMSE", "NSE", "mNSE") )ucDefaultConfWeights( wells = wtConfiguredWellnames(wtDefaultConfiguration()), gofs = c("RMSE", "NSE", "mNSE") )
wells |
well names, default:
|
gofs |
default: |
Matrix of weights used when calculating overall fitness.
Row names = names of fitness indicators out of the set of c("ME", "MAE",
"MSE", "RMSE", "NRMSE", "PBIAS", "RSR", "rSD", "NSE", "mNSE", "rNSE",
"d", "md", "rd", "cp", "r", "R2", "bR2", "KGE, "VE"). Column names = well
names ("PW" = pumping well, observation wells named as in parameter
setting).
Lines for UCODE main input file
ucInpFileLines(uconf, command)ucInpFileLines(uconf, command)
uconf |
UCODE configuration as retrieved by |
command |
name of batch file that is invoked by UCODE with each iteration |
Plot WTAQ results to png file
ucPlotPng(fname, wtaqResult, i)ucPlotPng(fname, wtaqResult, i)
fname |
fname |
wtaqResult |
wtaqResult |
i |
i |
????
Plot UCODE summary file
ucPlotSummary(sfile)ucPlotSummary(sfile)
sfile |
path to summary file |
???
All input files needed to run a UCODE calibration of a WTAQ model are created
in the directory tdir. By default (open.tdir = TRUE) this
directory is opened in the Windows explorer. You can use the created batch
file runParallelUCode.bat to start the UCODE calibration.
ucPrepCalib( wtaqConfiguration = wtDefaultConfiguration(), uconf = ucConf(), tdir = tempdir(), open.tdir = TRUE, wtaq = system.file("extdata", "wtaq.2.1.exe", package = "kwb.wtaq"), ucode = system.file("extdata", "ucode_2005.exe", package = "kwb.wtaq") )ucPrepCalib( wtaqConfiguration = wtDefaultConfiguration(), uconf = ucConf(), tdir = tempdir(), open.tdir = TRUE, wtaq = system.file("extdata", "wtaq.2.1.exe", package = "kwb.wtaq"), ucode = system.file("extdata", "ucode_2005.exe", package = "kwb.wtaq") )
wtaqConfiguration |
WTAQ configuration as retrieved by
|
uconf |
UCode configuration as retrieved by |
tdir |
target directory in which all input and control files are to be created. Default: temporary directory of current R Session. Attention! This temporary directory will be emptied after the R session has finished! |
open.tdir |
if TRUE, the target directory will be opened in the Windows Explorer in order to allow inspecting the created files |
wtaq |
full path to WTAQ executable |
ucode |
full path to UCODE executable |
# Define WTAQ configuration... # Here: just load the configuration of WTAQ's Sample problem 2 wtaqConfiguration <- kwb.wtaq::wtConfigurationExample2() # Define parameters p <- rbind( ucConfParameter( "HKR", startvalue = 2e-5, lowerConstraint = 1e-5, upperConstraint = 1e-1, maxChange = 1, perturbAmt = 0.5 ), ucConfParameter( "HKZ", startvalue = 2e-7, lowerConstraint = 1e-7, upperConstraint = 1e-3, maxChange = 1, perturbAmt = 0.5 ) ) # Define weights # # The following weight matrix w gives a weight of 1 to the root mean square # error (RMSE) and the Nash-Sutcliffe-Efficiency (NSE) between simulated # and observed values at the pumping well ("PW") and to the NSE between # simulated and observed values at the observation well "PS1". # # well -> PW PS1 w <- matrix(c( 1, 1, # RMSE <- GOF 1, 1), # NSE nrow = 2, byrow = TRUE, dimnames = list(c("RMSE", "NSE"), c("PW", "PS1"))) # Create UCODE configuration uconf <- ucConf(general = ucConfGeneral(maxIter = 100), parameters = p, weights = w) # Create all input files needed to run the UCODE calibration of WTAQ # sample problem 2 tdir <- ucPrepCalib(wtaqConfiguration = wtaqConfiguration, uconf = uconf) # Run loop waiting for input files provided by UCODE (remove the comment # character in the following line!) #ucRunParallel(tdir, uconf = uconf) # Now, run runParallelUCode.bat in the target directory...# Define WTAQ configuration... # Here: just load the configuration of WTAQ's Sample problem 2 wtaqConfiguration <- kwb.wtaq::wtConfigurationExample2() # Define parameters p <- rbind( ucConfParameter( "HKR", startvalue = 2e-5, lowerConstraint = 1e-5, upperConstraint = 1e-1, maxChange = 1, perturbAmt = 0.5 ), ucConfParameter( "HKZ", startvalue = 2e-7, lowerConstraint = 1e-7, upperConstraint = 1e-3, maxChange = 1, perturbAmt = 0.5 ) ) # Define weights # # The following weight matrix w gives a weight of 1 to the root mean square # error (RMSE) and the Nash-Sutcliffe-Efficiency (NSE) between simulated # and observed values at the pumping well ("PW") and to the NSE between # simulated and observed values at the observation well "PS1". # # well -> PW PS1 w <- matrix(c( 1, 1, # RMSE <- GOF 1, 1), # NSE nrow = 2, byrow = TRUE, dimnames = list(c("RMSE", "NSE"), c("PW", "PS1"))) # Create UCODE configuration uconf <- ucConf(general = ucConfGeneral(maxIter = 100), parameters = p, weights = w) # Create all input files needed to run the UCODE calibration of WTAQ # sample problem 2 tdir <- ucPrepCalib(wtaqConfiguration = wtaqConfiguration, uconf = uconf) # Run loop waiting for input files provided by UCODE (remove the comment # character in the following line!) #ucRunParallel(tdir, uconf = uconf) # Now, run runParallelUCode.bat in the target directory...
Read UCODE summary file
ucReadSummary(sfile)ucReadSummary(sfile)
sfile |
path to summary file |
data frame, ordered by ITER
Run main calibration loop
ucRunParallel( uconf = ucConf(), tdir = tempdir(), wtaq = system.file("extdata", "wtaq.2.1.exe", package = "kwb.wtaq"), FUN = NULL )ucRunParallel( uconf = ucConf(), tdir = tempdir(), wtaq = system.file("extdata", "wtaq.2.1.exe", package = "kwb.wtaq"), FUN = NULL )
uconf |
UCode configuration as retrieved by |
tdir |
tdir |
wtaq |
wtaq |
FUN |
function that is invoked each time before WTAQ is run |
???
Set placeholder for parameter value in WTAQ parameter setting
ucSetPlaceholder(parname, wtaqConfiguration, pchar = "@")ucSetPlaceholder(parname, wtaqConfiguration, pchar = "@")
parname |
Parameter name. Must be one of the aquifer parameters "bb",
"hkr", "hkz", "ss", "sy" (for description see
|
wtaqConfiguration |
WTAQ parameter setting as created by means of
|
pchar |
character to be used as the very first and very last character of the placeholder. Default: “@” |
Parameter setting in which a parameter value is replaced by an appropriate placeholder
Creates lines to be put in TABLE-data block of UCODE input file representing data in given data frame
ucTable(dat)ucTable(dat)
dat |
data frame |
Test run of batch file
ucTestBatchWtaq(bfile, wtaqConfiguration)ucTestBatchWtaq(bfile, wtaqConfiguration)
bfile |
path to batch file |
wtaqConfiguration |
WTAQ configuration |
Write WTAQ arguments file
ucWriteArgs(afile)ucWriteArgs(afile)
afile |
path to file containing arguments |
Write batch file invoking UCODE
ucWriteBatchUcode( bfile, ucode = system.file("extdata", "ucode_2005.exe", package = "kwb.wtaq"), waitForInput = TRUE, inpfile = "ucode.in" )ucWriteBatchUcode( bfile, ucode = system.file("extdata", "ucode_2005.exe", package = "kwb.wtaq"), waitForInput = TRUE, inpfile = "ucode.in" )
bfile |
full path to batch file |
ucode |
full path to UCODE executable file |
waitForInput |
if |
inpfile |
name of |
Write batch file invoked by UCODE, running first WTAQ and second the R script doing the goodness of fit evaluation
ucWriteBatchWtaq(bfile, wtaq, verbose, waitForInput = FALSE)ucWriteBatchWtaq(bfile, wtaq, verbose, waitForInput = FALSE)
bfile |
path to batch file |
wtaq |
path to WTAQ executable |
verbose |
if |
waitForInput |
if |
Write batch file invoked by UCODE, which is just waiting until WTAQ has finished and goodness of fit is available
ucWriteBatchWtaqParallel(bfile, recheckAfterMs = 10)ucWriteBatchWtaqParallel(bfile, recheckAfterMs = 10)
bfile |
path to batchfile |
recheckAfterMs |
time to wait for file, in milliseconds |
Write R script evaluating goodness of fit from WTAQ output file
ucWriteEvalGofR(rfile, uconf)ucWriteEvalGofR(rfile, uconf)
rfile |
path to R script file to be generated |
uconf |
UCODE configuration |
Write UCODE instruction file, describing how to read goodness of fit values from wtaq.gof
ucWriteInstruction(ifile, wtaqConfiguration, uconf)ucWriteInstruction(ifile, wtaqConfiguration, uconf)
ifile |
path to instruction file |
wtaqConfiguration |
WTAW configuration |
uconf |
UCODE configuration |
Write UCODE main input file
ucWriteMainInput(ufile, uconf, command)ucWriteMainInput(ufile, uconf, command)
ufile |
path to UCODE input file |
uconf |
UCODE configuration |
command |
name of batch file that is invoked by UCODE with each iteration |
Write WTAQ input template file
ucWriteTemplate(tfile, wtaqConfiguration, uconf, pchar = "@")ucWriteTemplate(tfile, wtaqConfiguration, uconf, pchar = "@")
tfile |
path to template file |
wtaqConfiguration |
WTAQ configuration |
uconf |
UCODE configuration |
pchar |
character indicating a placeholder |
Evaluate goodness of fit for WTAQ result
uwGofEval(res, logtimes = FALSE, gofs = names(uwGofTargetValue()), ...)uwGofEval(res, logtimes = FALSE, gofs = names(uwGofTargetValue()), ...)
res |
either character string representing full path to WTAQ result plot file or data.frame containing the content of the WTAQ result plot file. |
logtimes |
if TRUE, time steps are supposed to be logarithmic, i.e. it is assumed that the result plot file is in “matrix form”. |
gofs |
vector of names of fitness functions, evaluated by |
... |
arguments passed to gof() function, e.g. digits: decimal places used for rounding the goodness-of-fit indexes. |
Evaluation matrix
Names of available Goodness of fit (GOF) functions
uwGofNames()uwGofNames()
Target values for different GOF functions, i.e. values that GOF functions return if observed and calculated timeseries are identical
uwGofTargetValue(gofs = uwGofNames())uwGofTargetValue(gofs = uwGofNames())
gofs |
names of GOF functions of which target values are to be returned |