Hello everyone,
I have a quick question about a result I am getting in my code. The results are pasting "=========" in the console pane between my simulation count. I don't really know how to code and so I'm not sure what in my script is causing this. I'm 99% sure the script is still running correctly, but I want to make sure. I've also added a picture of what I'm talking about and included my script below.
Thank you!
library(stringr)
library(data.table)
library(dplyr)
#Rename to folder where TxtInOut is stored
watershed = "RobertsBrookNoLake"
# ***DO NOT FORGET TO CHANGE OUTFLOW CHANNEL (line 124)***
#Pathway to SWAT_Watershed_Tool on your computer
setwd(paste0("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/", watershed, "/TxtInOut"))
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_SOILSAWC_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_AQUIFER_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_CHANHYD_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_CHANNUTR_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_CN_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_HYDROLOGY_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_SNOW_Mod.R")
source("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/SWAT_BASIN_Mod.R")
# Set paths for SWAT+ Input/Output Files = paste0("D:/SWAT+/Calibration/SWAT_Watershed_Tool_NoLake/", watershed, "/SWAT_par_temps/", watershed, "_")
template = paste0("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/", watershed, "/SWAT_par_temps/", watershed, "_")
txtinoutpath = paste0("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/", watershed, "/TxtInOut")
outpath = paste0("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/", watershed, "/ModelOutput")
# Read in best simulations
best_sims <- read.csv(paste0("D:/SWAT+/ResearchTestRuns/SWAT_Watershed_Tool_NoLake/", watershed, "/CalibratedSims/",watershed,"_CDF_Simulations.csv",sep=""))
iterations <- 29
Output = data.frame(matrix(nrow = iterations,ncol = 30))
colnames(Output)<- c("awc","no3_n","bf_max","hl_no3n","flo_min","bed_K","plt_n","ben_nh3n","ptln_stl","nh3n_no2n","no2n_no3n",
"ptln_nh3n","cn2_mult","lat_time","esco","epco","orgn_enrich","fall_tmp","melt_tmp","melt_max",
"melt_min","melt_lag","surlag","orgn_min","n_uptake","n_perc","rsd_decomp","denit_exp","denit_frac", "sim")
#Run for loop to run calibration
for (j in 1:iterations) {
#1a. Resample AWC
Output$awc[j] <- best_sims$awc[j]
SWAT_SOILSAWC_Mod(txtinoutpath, template, Output$awc[j])
#2. Resample bf_max, flo_min, NO3_N, and HL_NO3N
Output$no3_n[j] <- best_sims$no3_n[j]
Output$bf_max[j] <- best_sims$bf_max[j]
Output$hl_no3n[j] <- best_sims$hl_no3n[j]
Output$flo_min[j] <- best_sims$flo_min[j]
SWAT_AQUIFER_Mod(txtinoutpath,template,Output$no3_n[j],Output$bf_max[j],Output$hl_no3n[j],Output$flo_min[j])
#3a. Resample bed_K
Output$bed_K[j] <- best_sims$bed_K[j]
SWAT_CHANHYD_Mod(txtinoutpath,template,Output$bed_K[j])
#3b. Resample channel nutrient parameters
Output$plt_n[j] <- best_sims$plt_n[j]
Output$ben_nh3n[j] <- best_sims$ben_nh3[j]
Output$ptln_stl[j] <- best_sims$ptln_stl[j]
Output$nh3n_no2n[j] <- best_sims$nh3n_no2n[j]
Output$no2n_no3n[j] <- best_sims$no2n_no3n[j]
Output$ptln_nh3n[j] <- best_sims$ptln_nh3n[j]
SWAT_CHANNUTR_Mod(txtinoutpath,template,Output$plt_n[j],Output$ben_nh3[j],Output$ptln_stl[j],Output$nh3n_no2n[j],Output$no2n_no3n[j],Output$ptln_nh3n[j])
#4. Resample SWAT Curve Number
Output$cn2_mult[j] <- best_sims$cn2_mult[j]
SWAT_CN_Mod(txtinoutpath, template, Output$cn2_mult[j])
#5. Resample SWAT Hydrology
Output$lat_time[j] <- best_sims$lat_time[j]
Output$esco[j] <- best_sims$esco[j]
Output$epco[j] <- best_sims$epco[j]
Output$orgn_enrich[j] <- best_sims$orgn_enrich[j]
SWAT_HYDROLOGY_Mod(txtinoutpath,template,Output$lat_time[j],Output$esco[j],Output$epco[j],Output$orgn_enrich[j])
#6. Resample snowmelt parameters
Output$fall_tmp[j] <- best_sims$fall_tmp[j]
Output$melt_tmp[j] <- best_sims$melt_tmp[j]
Output$melt_max[j] <- best_sims$melt_max[j]
Output$melt_min[j] <- best_sims$melt_min[j]
Output$melt_lag[j] <- best_sims$melt_lag[j]
SWAT_SNOW_Mod(txtinoutpath,template,Output$fall_tmp[j],Output$melt_tmp[j],Output$melt_max[j],Output$melt_min[j],Output$melt_lag[j])
#7. Resample surface lag and nutrient parameters
Output$surlag[j] <- best_sims$surlag[j]
Output$orgn_min[j] <- best_sims$orgn_min[j]
Output$n_uptake[j] <- best_sims$n_uptake[j]
Output$n_perc[j] <- best_sims$n_perc[j]
Output$rsd_decomp[j] <- best_sims$rsd_decomp[j]
Output$denit_exp[j] <- best_sims$denit_exp[j]
Output$denit_frac[j] <- best_sims$denit_frac[j]
SWAT_BASIN_Mod(txtinoutpath,template,Output$surlag[j],Output$orgn_min[j],Output$n_uptake[j],Output$n_perc[j],Output$rsd_decomp[j],Output$denit_exp[j],Output$denit_frac[j])
#7. Run SWAT Model
system(paste(txtinoutpath,"/swatplus-61.0.2-ifx-win_amd64-Rel.exe",sep=""), intern = TRUE)
Sys.sleep(0.5)
#8a. Read in and save Daily Model Output Upstream
# --- Read daily nutrient balance at routing unit level ---
data_HRU662 <- fread(
paste(txtinoutpath, "/hru_nb_day.csv", sep = ""), skip = 1)[name == "hru662"]
data_HRU663 <- fread(
paste(txtinoutpath, "/hru_nb_day.csv", sep = ""), skip = 1)[name == "hru663"]
data_HRU672 <- fread(
paste(txtinoutpath, "/hru_nb_day.csv", sep = ""), skip = 1)[name == "hru672"]
# --- Build simulation time series ---
sim_series_denit <- data.frame(
date = as.Date(paste(data_HRU662$yr, data_HRU662$mon, data_HRU662$day, sep = "-")),
denit_HRU662 = as.numeric(data_HRU662$denit),
denit_HRU663 = as.numeric(data_HRU663$denit),
denit_HRU672 = as.numeric(data_HRU672$denit),
denit_total = as.numeric(data_HRU662$denit) + as.numeric(data_HRU663$denit) + as.numeric(data_HRU672$denit)
)
write.csv(sim_series_denit, paste(outpath,"/Simulation_",j,"_DENIT_2D.csv", sep = ''), row.names = FALSE)
#10. Add simulation number for easier id
Output$sim[j] <- j
#Write Output File w/ parameters and objective function values
write.table(Output, paste(outpath,"/Parameter_Combs.csv",sep=""), sep = ",",row.names = FALSE, col.names= TRUE)
print(paste("Simulation:",j,"of",iterations))
#Cleanup big variables to save on computational power
rm(data_HRU662)
rm(data_HRU663)
rm(data_HRU672)
rm(sim_series_denit)
gc()
}
