From 140ccea430b9b2b3f218cf7ad2b5460d2736a9fa Mon Sep 17 00:00:00 2001 From: mmyrte <24587121+mmyrte@users.noreply.github.com> Date: Sun, 2 Nov 2025 10:36:53 +0000 Subject: [PATCH 1/5] move into standard repo structure --- topmodel/DESCRIPTION => DESCRIPTION | 0 topmodel/NAMESPACE => NAMESPACE | 0 {topmodel/R => R}/NSeff.R | 0 {topmodel/R => R}/flowlength.R | 0 {topmodel/R => R}/infiltration.R | 0 {topmodel/R => R}/make.classes.R | 0 {topmodel/R => R}/outlet.R | 0 {topmodel/R => R}/river.R | 0 {topmodel/R => R}/sinkfill.R | 0 {topmodel/R => R}/streamorder.R | 0 {topmodel/R => R}/subcatch.R | 0 {topmodel/R => R}/topidx.R | 0 {topmodel/R => R}/topmodel.R | 0 Readme.md => README.md | 0 {topmodel/data => data}/huagrahuma.RData | Bin {topmodel/data => data}/huagrahuma.dem.RData | Bin {examples => inst/examples}/Full Run.R | 58 +++++++++---------- {topmodel/man => man}/NSeff.Rd | 0 {topmodel/man => man}/flowlength.Rd | 0 {topmodel/man => man}/huagrahuma.Rd | 0 {topmodel/man => man}/huagrahuma.dem.Rd | 0 {topmodel/man => man}/infiltration.Rd | 0 {topmodel/man => man}/make.classes.Rd | 0 {topmodel/man => man}/outlet.Rd | 0 {topmodel/man => man}/river.Rd | 0 {topmodel/man => man}/sinkfill.Rd | 0 {topmodel/man => man}/subcatch.Rd | 0 {topmodel/man => man}/topidx.Rd | 0 {topmodel/man => man}/topmodel.Rd | 0 {topmodel/src => src}/NS.c | 0 {topmodel/src => src}/c_flowlength.c | 0 {topmodel/src => src}/c_infiltration.c | 0 {topmodel/src => src}/c_sinkfill.c | 0 {topmodel/src => src}/c_streamorder.c | 0 {topmodel/src => src}/c_subcatch.c | 0 {topmodel/src => src}/c_topidx.c | 0 {topmodel/src => src}/c_topmodel.c | 0 {topmodel/src => src}/core_topmodel.c | 0 {topmodel/src => src}/get_f.c | 0 {topmodel/src => src}/misc.c | 0 {topmodel/src => src}/output.c | 0 {topmodel/src => src}/param_init.c | 0 {topmodel/src => src}/river.c | 0 {topmodel/src => src}/startroutines.c | 0 {topmodel/src => src}/topmodel.h | 1 - {topmodel/src => src}/topmodel_init.c | 0 46 files changed, 29 insertions(+), 30 deletions(-) rename topmodel/DESCRIPTION => DESCRIPTION (100%) mode change 100755 => 100644 rename topmodel/NAMESPACE => NAMESPACE (100%) mode change 100755 => 100644 rename {topmodel/R => R}/NSeff.R (100%) rename {topmodel/R => R}/flowlength.R (100%) rename {topmodel/R => R}/infiltration.R (100%) rename {topmodel/R => R}/make.classes.R (100%) rename {topmodel/R => R}/outlet.R (100%) rename {topmodel/R => R}/river.R (100%) rename {topmodel/R => R}/sinkfill.R (100%) rename {topmodel/R => R}/streamorder.R (100%) rename {topmodel/R => R}/subcatch.R (100%) rename {topmodel/R => R}/topidx.R (100%) rename {topmodel/R => R}/topmodel.R (100%) rename Readme.md => README.md (100%) rename {topmodel/data => data}/huagrahuma.RData (100%) rename {topmodel/data => data}/huagrahuma.dem.RData (100%) rename {examples => inst/examples}/Full Run.R (78%) rename {topmodel/man => man}/NSeff.Rd (100%) rename {topmodel/man => man}/flowlength.Rd (100%) rename {topmodel/man => man}/huagrahuma.Rd (100%) rename {topmodel/man => man}/huagrahuma.dem.Rd (100%) rename {topmodel/man => man}/infiltration.Rd (100%) rename {topmodel/man => man}/make.classes.Rd (100%) rename {topmodel/man => man}/outlet.Rd (100%) rename {topmodel/man => man}/river.Rd (100%) rename {topmodel/man => man}/sinkfill.Rd (100%) rename {topmodel/man => man}/subcatch.Rd (100%) rename {topmodel/man => man}/topidx.Rd (100%) rename {topmodel/man => man}/topmodel.Rd (100%) rename {topmodel/src => src}/NS.c (100%) rename {topmodel/src => src}/c_flowlength.c (100%) rename {topmodel/src => src}/c_infiltration.c (100%) rename {topmodel/src => src}/c_sinkfill.c (100%) rename {topmodel/src => src}/c_streamorder.c (100%) rename {topmodel/src => src}/c_subcatch.c (100%) rename {topmodel/src => src}/c_topidx.c (100%) rename {topmodel/src => src}/c_topmodel.c (100%) rename {topmodel/src => src}/core_topmodel.c (100%) rename {topmodel/src => src}/get_f.c (100%) rename {topmodel/src => src}/misc.c (100%) rename {topmodel/src => src}/output.c (100%) rename {topmodel/src => src}/param_init.c (100%) rename {topmodel/src => src}/river.c (100%) rename {topmodel/src => src}/startroutines.c (100%) rename {topmodel/src => src}/topmodel.h (98%) rename {topmodel/src => src}/topmodel_init.c (100%) diff --git a/topmodel/DESCRIPTION b/DESCRIPTION old mode 100755 new mode 100644 similarity index 100% rename from topmodel/DESCRIPTION rename to DESCRIPTION diff --git a/topmodel/NAMESPACE b/NAMESPACE old mode 100755 new mode 100644 similarity index 100% rename from topmodel/NAMESPACE rename to NAMESPACE diff --git a/topmodel/R/NSeff.R b/R/NSeff.R similarity index 100% rename from topmodel/R/NSeff.R rename to R/NSeff.R diff --git a/topmodel/R/flowlength.R b/R/flowlength.R similarity index 100% rename from topmodel/R/flowlength.R rename to R/flowlength.R diff --git a/topmodel/R/infiltration.R b/R/infiltration.R similarity index 100% rename from topmodel/R/infiltration.R rename to R/infiltration.R diff --git a/topmodel/R/make.classes.R b/R/make.classes.R similarity index 100% rename from topmodel/R/make.classes.R rename to R/make.classes.R diff --git a/topmodel/R/outlet.R b/R/outlet.R similarity index 100% rename from topmodel/R/outlet.R rename to R/outlet.R diff --git a/topmodel/R/river.R b/R/river.R similarity index 100% rename from topmodel/R/river.R rename to R/river.R diff --git a/topmodel/R/sinkfill.R b/R/sinkfill.R similarity index 100% rename from topmodel/R/sinkfill.R rename to R/sinkfill.R diff --git a/topmodel/R/streamorder.R b/R/streamorder.R similarity index 100% rename from topmodel/R/streamorder.R rename to R/streamorder.R diff --git a/topmodel/R/subcatch.R b/R/subcatch.R similarity index 100% rename from topmodel/R/subcatch.R rename to R/subcatch.R diff --git a/topmodel/R/topidx.R b/R/topidx.R similarity index 100% rename from topmodel/R/topidx.R rename to R/topidx.R diff --git a/topmodel/R/topmodel.R b/R/topmodel.R similarity index 100% rename from topmodel/R/topmodel.R rename to R/topmodel.R diff --git a/Readme.md b/README.md similarity index 100% rename from Readme.md rename to README.md diff --git a/topmodel/data/huagrahuma.RData b/data/huagrahuma.RData similarity index 100% rename from topmodel/data/huagrahuma.RData rename to data/huagrahuma.RData diff --git a/topmodel/data/huagrahuma.dem.RData b/data/huagrahuma.dem.RData similarity index 100% rename from topmodel/data/huagrahuma.dem.RData rename to data/huagrahuma.dem.RData diff --git a/examples/Full Run.R b/inst/examples/Full Run.R similarity index 78% rename from examples/Full Run.R rename to inst/examples/Full Run.R index b214d47..56b77a6 100644 --- a/examples/Full Run.R +++ b/inst/examples/Full Run.R @@ -1,4 +1,3 @@ - ## install and load the required packages: install.packages("topmodel") @@ -17,11 +16,11 @@ library(Hmisc) # Take for instance this minimalistic DEM, saved in a test file called "DEM.txt" # Values outside the catchment are given the value -9999 (this can be any other value that, obviously, does not occur in the DEM values): --9999 -9999 828.9 835.6 -9999 -818.3 826.0 830.7 834.5 836.0 -817.1 824.0 825.2 833.3 836.9 -816.5 820.0 824.1 330.8 -9999 -810.7 815.6 822.2 -9999 -9999 +# -9999 -9999 828.9 835.6 -9999 +# 818.3 826.0 830.7 834.5 836.0 +# 817.1 824.0 825.2 833.3 836.9 +# 816.5 820.0 824.1 330.8 -9999 +# 810.7 815.6 822.2 -9999 -9999 # This file can be imported and processed in R with: @@ -30,7 +29,7 @@ DEM <- as.matrix(DEM) # Remove the values outside the catchment: -DEM[DEM==-9999] <- NA +DEM[DEM == -9999] <- NA # You may want to plot the DEM to see whether everything looks OK: @@ -40,21 +39,21 @@ image(DEM) # Here we use the DEM from Huagrahuma as an example: data(huagrahuma.dem) -DEM <- sinkfill(huagrahuma.dem, cellsize=25, degree=0.1) -topindex <- topidx(DEM, resolution=25) +DEM <- sinkfill(huagrahuma.dem, cellsize = 25, degree = 0.1) +topindex <- topidx(DEM, resolution = 25) # The values need to be split into a set of classes, since topmodel() is a semidistributed model that lumps hydrologically similar areas into the same hydrological response units. # Here we define 16 hydrological response units: -topidx <- make.classes(topindex,16) +topidx <- make.classes(topindex, 16) # the delay function is a bit more tricky because this requires cumulative fractions, but you generate it as follows: n <- 5 # number of classes; a higher number will result in a smoother histogram -delay <- flowlength(huagrahuma.dem)*25 # TODO: add the outlet coordinates; otherwise the flowlength will be calculated to the edge of the map. +delay <- flowlength(huagrahuma.dem) * 25 # TODO: add the outlet coordinates; otherwise the flowlength will be calculated to the edge of the map. delay <- make.classes(delay, n) -delay <- delay[n:1,] -delay[,2] <- c(0, cumsum(delay[1:(n-1),2])) +delay <- delay[n:1, ] +delay[, 2] <- c(0, cumsum(delay[1:(n - 1), 2])) ############ PART 1: running the rainfall-runoff model ############## @@ -71,12 +70,12 @@ topidx parameters rain -plot(rain, type="h") +plot(rain, type = "h") ## run the model and visualise the outcome: Qsim <- topmodel(parameters, topidx, delay, rain, ET0) -plot(Qsim, type="l", col="red") +plot(Qsim, type = "l", col = "red") points(Qobs) ## Evaluate the model with a performance metric @@ -99,7 +98,7 @@ NSeff(Qobs, Qsim) ## What value do you get? Do you think this is a good simulation? ## Verify by plotting: -plot(Qsim, type="l", col="red") +plot(Qsim, type = "l", col = "red") points(Qobs) ## Now sample all parameters at random. We take a sample size of 100 @@ -118,7 +117,7 @@ k0 <- runif(n, min = 0, max = 10) CD <- runif(n, min = 0, max = 5) dt <- 0.25 -parameters <- cbind(qs0,lnTe,m,Sr0,Srmax,td,vch,vr,k0,CD,dt) +parameters <- cbind(qs0, lnTe, m, Sr0, Srmax, td, vch, vr, k0, CD, dt) ## run the model and evaluate with the Nash – Sutcliffe efficiency metric: ## Note: the function accepts a table of parameter sets @@ -129,22 +128,22 @@ max(NS) ## visualisation of the sensitivity using dotty plots: -plot(lnTe, NS, ylim = c(0,1)) +plot(lnTe, NS, ylim = c(0, 1)) ############ PART 3: GLUE uncertainty analysis ############## ## choose a behavioural threshold and remove the “bad” parameter sets: -parameters <- parameters[NS > 0.3,] +parameters <- parameters[NS > 0.3, ] NS <- NS[NS > 0.3] ## generate predictions for the behavioural parameter sets: -Qsim <- topmodel(parameters,topidx,delay,rain,ET0) +Qsim <- topmodel(parameters, topidx, delay, rain, ET0) ## (have a look at the predictions for the first time step:) -hist(Qsim[1,]) +hist(Qsim[1, ]) ## construct weights based on the performance measure @@ -154,19 +153,20 @@ weights <- weights / sum(weights) ## make prediction boundaries by weighted quantile calculation ## (we need the Hmisc package for that) -limits <- apply(Qsim, 1, "wtd.quantile", weights = weights, -probs = c(0.05,0.95), normwt=T) +limits <- apply(Qsim, 1, "wtd.quantile", + weights = weights, + probs = c(0.05, 0.95), normwt = T +) -plot(limits[2,], type="l") -points(limits[1,], type="l") -points(Qobs, col="red") +plot(limits[2, ], type = "l") +points(limits[1, ], type = "l") +points(Qobs, col = "red") ## how many measurements fall outside of the prediction limits? -outside <- (Qobs > limits[2,]) | (Qobs < limits[1,]) +outside <- (Qobs > limits[2, ]) | (Qobs < limits[1, ]) summary(outside) ## width of the prediction boundaries -mean(limits[2,] - limits[1,]) / mean(Qobs, na.rm=T) - +mean(limits[2, ] - limits[1, ]) / mean(Qobs, na.rm = T) diff --git a/topmodel/man/NSeff.Rd b/man/NSeff.Rd similarity index 100% rename from topmodel/man/NSeff.Rd rename to man/NSeff.Rd diff --git a/topmodel/man/flowlength.Rd b/man/flowlength.Rd similarity index 100% rename from topmodel/man/flowlength.Rd rename to man/flowlength.Rd diff --git a/topmodel/man/huagrahuma.Rd b/man/huagrahuma.Rd similarity index 100% rename from topmodel/man/huagrahuma.Rd rename to man/huagrahuma.Rd diff --git a/topmodel/man/huagrahuma.dem.Rd b/man/huagrahuma.dem.Rd similarity index 100% rename from topmodel/man/huagrahuma.dem.Rd rename to man/huagrahuma.dem.Rd diff --git a/topmodel/man/infiltration.Rd b/man/infiltration.Rd similarity index 100% rename from topmodel/man/infiltration.Rd rename to man/infiltration.Rd diff --git a/topmodel/man/make.classes.Rd b/man/make.classes.Rd similarity index 100% rename from topmodel/man/make.classes.Rd rename to man/make.classes.Rd diff --git a/topmodel/man/outlet.Rd b/man/outlet.Rd similarity index 100% rename from topmodel/man/outlet.Rd rename to man/outlet.Rd diff --git a/topmodel/man/river.Rd b/man/river.Rd similarity index 100% rename from topmodel/man/river.Rd rename to man/river.Rd diff --git a/topmodel/man/sinkfill.Rd b/man/sinkfill.Rd similarity index 100% rename from topmodel/man/sinkfill.Rd rename to man/sinkfill.Rd diff --git a/topmodel/man/subcatch.Rd b/man/subcatch.Rd similarity index 100% rename from topmodel/man/subcatch.Rd rename to man/subcatch.Rd diff --git a/topmodel/man/topidx.Rd b/man/topidx.Rd similarity index 100% rename from topmodel/man/topidx.Rd rename to man/topidx.Rd diff --git a/topmodel/man/topmodel.Rd b/man/topmodel.Rd similarity index 100% rename from topmodel/man/topmodel.Rd rename to man/topmodel.Rd diff --git a/topmodel/src/NS.c b/src/NS.c similarity index 100% rename from topmodel/src/NS.c rename to src/NS.c diff --git a/topmodel/src/c_flowlength.c b/src/c_flowlength.c similarity index 100% rename from topmodel/src/c_flowlength.c rename to src/c_flowlength.c diff --git a/topmodel/src/c_infiltration.c b/src/c_infiltration.c similarity index 100% rename from topmodel/src/c_infiltration.c rename to src/c_infiltration.c diff --git a/topmodel/src/c_sinkfill.c b/src/c_sinkfill.c similarity index 100% rename from topmodel/src/c_sinkfill.c rename to src/c_sinkfill.c diff --git a/topmodel/src/c_streamorder.c b/src/c_streamorder.c similarity index 100% rename from topmodel/src/c_streamorder.c rename to src/c_streamorder.c diff --git a/topmodel/src/c_subcatch.c b/src/c_subcatch.c similarity index 100% rename from topmodel/src/c_subcatch.c rename to src/c_subcatch.c diff --git a/topmodel/src/c_topidx.c b/src/c_topidx.c similarity index 100% rename from topmodel/src/c_topidx.c rename to src/c_topidx.c diff --git a/topmodel/src/c_topmodel.c b/src/c_topmodel.c similarity index 100% rename from topmodel/src/c_topmodel.c rename to src/c_topmodel.c diff --git a/topmodel/src/core_topmodel.c b/src/core_topmodel.c similarity index 100% rename from topmodel/src/core_topmodel.c rename to src/core_topmodel.c diff --git a/topmodel/src/get_f.c b/src/get_f.c similarity index 100% rename from topmodel/src/get_f.c rename to src/get_f.c diff --git a/topmodel/src/misc.c b/src/misc.c similarity index 100% rename from topmodel/src/misc.c rename to src/misc.c diff --git a/topmodel/src/output.c b/src/output.c similarity index 100% rename from topmodel/src/output.c rename to src/output.c diff --git a/topmodel/src/param_init.c b/src/param_init.c similarity index 100% rename from topmodel/src/param_init.c rename to src/param_init.c diff --git a/topmodel/src/river.c b/src/river.c similarity index 100% rename from topmodel/src/river.c rename to src/river.c diff --git a/topmodel/src/startroutines.c b/src/startroutines.c similarity index 100% rename from topmodel/src/startroutines.c rename to src/startroutines.c diff --git a/topmodel/src/topmodel.h b/src/topmodel.h similarity index 98% rename from topmodel/src/topmodel.h rename to src/topmodel.h index 58f624c..5acbd7a 100755 --- a/topmodel/src/topmodel.h +++ b/src/topmodel.h @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/topmodel/src/topmodel_init.c b/src/topmodel_init.c similarity index 100% rename from topmodel/src/topmodel_init.c rename to src/topmodel_init.c From e7a646a4ba25a5d242bbf558121070c43bd9df7a Mon Sep 17 00:00:00 2001 From: mmyrte <24587121+mmyrte@users.noreply.github.com> Date: Sun, 2 Nov 2025 10:54:34 +0000 Subject: [PATCH 2/5] replace Calloc / Free with R_Calloc / R_Free These had been deprecated since R 3.4.0 https://cran.r-project.org/doc/manuals/r-release/NEWS.html --- src/startroutines.c | 108 ++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/startroutines.c b/src/startroutines.c index a785b25..c8ef39d 100755 --- a/src/startroutines.c +++ b/src/startroutines.c @@ -5,8 +5,8 @@ void topidx_calc(double *topidx, int nidxclass) int i, j; double x; - idxstats.atb = (double *) Calloc(nidxclass, double); - idxstats.Aatb_r = (double *) Calloc(nidxclass, double); + idxstats.atb = (double *) R_Calloc(nidxclass, double); + idxstats.Aatb_r = (double *) R_Calloc(nidxclass, double); for(i=0; i Date: Sun, 2 Nov 2025 10:55:38 +0000 Subject: [PATCH 3/5] unused-but-set-variable warning (kept as comments for debugging) --- src/c_topidx.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/c_topidx.c b/src/c_topidx.c index e04944e..08225df 100755 --- a/src/c_topidx.c +++ b/src/c_topidx.c @@ -10,7 +10,7 @@ void c_topidx(double *inputdem, int *inputriver, - int *nrow, + int *nrow, int *ncol, double *ew_res, double *ns_res, @@ -21,12 +21,12 @@ void c_topidx(double *inputdem, int nrout,river,not_yet; double **dem, **atb, **area, **slope, **rivermap; double exclude,dnx,routefac,nslp; - int nsink = 0; + // int nsink = 0; double routdem[9], tanb[9]; double c,dx1,dx2,sum,sumtb; /* memory allocation */ - + dem = (double **) R_alloc(*nrow, sizeof(double *)); atb = (double **) R_alloc(*nrow, sizeof(double *)); area = (double **) R_alloc(*nrow, sizeof(double *)); @@ -97,7 +97,7 @@ void c_topidx(double *inputdem, for(j = 0; j < *ncol; j++) { for(i = 0; i < *nrow; i++) { - + /* skip non catchment cells and cells that are done */ if((dem[i][j] == exclude) || (atb[i][j] >= ZERO)) continue; @@ -108,7 +108,7 @@ void c_topidx(double *inputdem, if(rivermap[i][j] == 1) river = 1; else { - /* check the 8 flow directions for upslope elements + /* check the 8 flow directions for upslope elements without a topidx value */ not_yet = 0; @@ -116,7 +116,7 @@ void c_topidx(double *inputdem, for(jj=-1; jj < 2; jj++){ for(ii=-1; ii < 2; ii++){ if(((i+ii >= 0) && (i+ii < *nrow) && (j+jj >= 0) && (j+jj < *ncol)) - && ((ii != 0) || (jj != 0)) + && ((ii != 0) || (jj != 0)) && (dem[i+ii][j+jj] != exclude)) { if((dem[i+ii][j+jj] > dem[i][j]) && (atb[i+ii][j+jj] < ZERO)) not_yet = 1; @@ -129,7 +129,7 @@ void c_topidx(double *inputdem, /* if there are no upslope elements without a topidx value, start calculations */ - /* find the outflow direction and calculate the sum of weights using + /* find the outflow direction and calculate the sum of weights using (tanb*countour length). Contour length = 0.5dx for the cardinal direction and 0.354dx for diagonal */ @@ -145,7 +145,7 @@ void c_topidx(double *inputdem, for(jj=-1; jj < 2; jj++){ for(ii=-1; ii < 2; ii++){ if(((i+ii >= 0) && (i+ii < *nrow) && (j+jj >= 0) && (j+jj < *ncol)) - && ((ii != 0) || (jj != 0)) + && ((ii != 0) || (jj != 0)) && (dem[i+ii][j+jj] != exclude)) { if((ii == 0) || (jj == 0)) { dnx = dx1; @@ -172,7 +172,7 @@ void c_topidx(double *inputdem, /* if a sink or a river cell... */ if((nrout == 0) || (river == 1)) { - nsink++; + // nsink++; river = 0; /* assume that there is a channel of length dx running midway through @@ -184,7 +184,7 @@ void c_topidx(double *inputdem, for(jj=-1; jj < 2; jj++){ for(ii=-1; ii < 2; ii++){ if(((i+ii >= 0) && (i+ii < *nrow) && (j+jj >= 0) && (j+jj < *ncol)) - && ((ii != 0) || (jj != 0)) + && ((ii != 0) || (jj != 0)) && (dem[i+ii][j+jj] != exclude)) { if((ii == 0) || (jj == 0)) dnx = dx1; else dnx = dx2; @@ -237,7 +237,7 @@ void c_topidx(double *inputdem, for(jj=-1; jj < 2; jj++){ for(ii=-1; ii < 2; ii++){ if(((i+ii >= 0) && (i+ii < *nrow) && (j+jj >= 0) && (j+jj < *ncol)) - && ((ii != 0) || (jj != 0)) + && ((ii != 0) || (jj != 0)) && (atb[i+ii][j+jj] != exclude)) { if(routdem[nrout] > 0) area[i+ii][j+jj] += c * routdem[nrout]; } @@ -261,7 +261,3 @@ void c_topidx(double *inputdem, } return; } - - - - From 7c864ab9ab86660af4408f2f976b467477ffc720 Mon Sep 17 00:00:00 2001 From: mmyrte <24587121+mmyrte@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:48:26 +0000 Subject: [PATCH 4/5] readme with installation instructions --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a25fe5..f8daa12 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,56 @@ +# TOPMODEL R Package -# Topmodel R package +An R implementation of the hydrological model TOPMODEL, based on the 1995 FORTRAN version by Keith Beven. This package provides a set of hydrological functions for rainfall-runoff modeling and catchment analysis. -Initial dump of the code of the Topmodel R package, available on CRAN: +## Installation -https://cran.r-project.org/package=topmodel +This package is currently not available on CRAN as it is in maintenance mode. You can install it from GitHub using: -Full documentation to come... +```r +devtools::install_github("ICHydro/topmodel") +``` +## Main Features +- **Rainfall-runoff modeling**: Simulate flow from precipitation and evapotranspiration data +- **Topographical analysis**: Calculate topographic indices and flow delay functions from digital elevation models +- **Sensitivity analysis**: Explore parameter sensitivity using Monte Carlo sampling +- **Uncertainty analysis**: GLUE (Generalized Likelihood Uncertainty Estimation) framework for prediction uncertainty + +## Quick Example + +```r +library(topmodel) + +# Load example data into global environment +data(huagrahuma) +list2env(huagrahuma, envir = .GlobalEnv) + +# Run the model +Qsim <- topmodel( + parameters, + topidx, + delay, + rain, + ETp +) + +# Evaluate performance +NSeff( + Qobs, + Qsim +) +``` + +## Background + +TOPMODEL is a physically-based, variable contributing area model of basin hydrology that uses topographic indices to represent the spatial variability of hydrological processes. The model was originally developed by Beven and Kirkby (1979) and has been widely used in hydrological research and applications. + +## References + +- Beven, K. J., Kirkby, M. J. (1979). A physically based variable contributing area model of basin hydrology. *Hydrological Sciences Bulletin*, 24, 43-69. +- Beven K, Lamb R, Quinn P, Romanowicz R, Freer J (1995). TOPMODEL. In: Singh VP (Ed), *Computer Models of Watershed Hydrology*. Water Resources Publications, Colorado. pp. 627-668. + +## Documentation + +For detailed examples and documentation, see the package help files. A complete example workflow is available in `inst/examples/Full Run.R`. From d03728ecb2bbd8bb10d3724c842832d6ebbc6b41 Mon Sep 17 00:00:00 2001 From: mmyrte <24587121+mmyrte@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:59:56 +0000 Subject: [PATCH 5/5] a word --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8daa12..585d526 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ devtools::install_github("ICHydro/topmodel") ## Main Features -- **Rainfall-runoff modeling**: Simulate flow from precipitation and evapotranspiration data +- **Rainfall-runoff modeling**: Simulate discharge from precipitation and evapotranspiration data - **Topographical analysis**: Calculate topographic indices and flow delay functions from digital elevation models - **Sensitivity analysis**: Explore parameter sensitivity using Monte Carlo sampling - **Uncertainty analysis**: GLUE (Generalized Likelihood Uncertainty Estimation) framework for prediction uncertainty