Skip to content

Commit be01514

Browse files
committed
temp
1 parent 5b99c00 commit be01514

File tree

8 files changed

+64
-15
lines changed

8 files changed

+64
-15
lines changed

guess.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Error: could not open guess.ins for input

modules/assim.sequential/NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export(rwtmnorm)
5151
export(sample_met)
5252
export(sampler_toggle)
5353
export(sda.enkf)
54-
export(sda.enkf.multisite)
54+
export(sda.enkf.multisite_hoptest)
5555
export(sda.enkf.original)
5656
export(sda_weights_site)
5757
export(simple.local)

modules/assim.sequential/R/sda.enkf_MultiSite.R

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@
3737
#' @import nimble furrr
3838
#' @export
3939
#'
40-
sda.enkf.multisite <- function(settings,
40+
sda.enkf.multisite_hoptest <- function(settings,
4141
obs.mean,
4242
obs.cov,
4343
Q = NULL,
4444
restart = NULL,
4545
pre_enkf_params = NULL,
4646
ensemble.samples = NULL,
47-
control=list(trace = TRUE,
47+
control=list(hop_test = TRUE,
48+
trace = TRUE,
4849
TimeseriesPlot = FALSE,
4950
debug = FALSE,
5051
pause = FALSE,
@@ -57,6 +58,7 @@ sda.enkf.multisite <- function(settings,
5758
run_parallel = TRUE,
5859
MCMC.args = NULL),
5960
...) {
61+
6062
#add if/else for when restart points to folder instead if T/F set restart as T
6163
if(is.list(restart)){
6264
old.dir <- restart$filepath
@@ -206,6 +208,7 @@ sda.enkf.multisite <- function(settings,
206208
register.xml <- system.file(paste0("register.", model, ".xml"), package = paste0("PEcAn.", model))
207209
register <- XML::xmlToList(XML::xmlParse(register.xml))
208210
no_split <- !as.logical(register$exact.dates)
211+
# no_split <- TRUE
209212

210213
if (!exists(my.split_inputs) & !no_split) {
211214
PEcAn.logger::logger.warn(my.split_inputs, "does not exist")
@@ -245,6 +248,7 @@ sda.enkf.multisite <- function(settings,
245248

246249
}
247250
} else{
251+
inputs <- settings$run$inputs$met$path
248252
inputs.split <- inputs
249253
}
250254
settings
@@ -280,7 +284,7 @@ sda.enkf.multisite <- function(settings,
280284
#assuming that will only use previous unconstrained forecast runs for first run with SDA which means we are at t=1
281285
#sim.time<-seq_len(nt)
282286
#create params object using previous forecast ensemble members
283-
new.params <- sda_matchparam(settings, ensemble.samples, site.ids, nens)
287+
new.params <- PEcAnAssimSequential:::sda_matchparam(settings, ensemble.samples, site.ids, nens)
284288

285289
#create inputs object for met using previous forecast ensemble members
286290
####add function here, pause on this feature until we add feature to model runs that saves driver ensemble members
@@ -766,5 +770,39 @@ sda.enkf.multisite <- function(settings,
766770
# unlink(list.files(outdir, "*.nc", recursive = TRUE, full.names = TRUE))
767771
# }
768772
## MCD: I commented the above "if" out because if you are restarting from a previous forecast, this might delete the files in that earlier folder
769-
} ### end loop over time
770-
} # sda.enkf
773+
774+
775+
# # Added in the for(t in 1:nt) loop of sda.enkf_MultiSite.R:
776+
# if (t == 2) {
777+
# hop_test_dir <- file.path(settings$outdir, "hop_test_snapshot_t2")
778+
# dir.create(hop_test_dir, showWarnings = FALSE)
779+
#
780+
# # Copy all LPJ-GUESS status files to the snapshot directory
781+
# state_files <- list.files(
782+
# path = file.path(settings$modeloutdir, runid),
783+
# pattern = "guess\\..*\\.bin",
784+
# full.names = TRUE
785+
# )
786+
# file.copy(state_files, hop_test_dir)
787+
#
788+
# PEcAn.logger::logger.info("Hop test: the state file was saved to ", hop_test_dir)
789+
# }
790+
791+
# Suppose that hop test is triggered at t=2
792+
if (t == 2 && control$hop_test) {
793+
# Save the current state to the specified directory
794+
hop_test_dir <- file.path(settings$outdir, "hop_test_snapshot")
795+
dir.create(hop_test_dir, showWarnings = FALSE)
796+
file.copy(
797+
list.files(settings$outdir, full.names = TRUE, recursive = TRUE),
798+
hop_test_dir,
799+
recursive = TRUE
800+
)
801+
PEcAn.logger::logger.info("Hop test: Saved state at t=2. Manually restart from this snapshot.")
802+
break # Exit loop to simulate "stop"
803+
}
804+
805+
806+
} ### end loop over time
807+
} # sda.enkf
808+
#

modules/assim.sequential/R/sda_matchparam.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ sda_matchparam <- function(settings, ensemble.samples, site.ids, nens){
1414
new.params <- list()
1515
all.pft.names <- names(ensemble.samples)
1616

17+
# Determines whether settings are single-site (list contains "run" directly)
18+
# or multi-site (list contains multiple settings)
19+
single_site <- "run" %in% names(settings)
20+
21+
# If it is a single site, convert to a list
22+
if (single_site) {
23+
settings <- list(settings)
24+
site.ids <- list(site.ids)
25+
}
26+
1727
#loop over each site.
1828
for (i in seq_along(site.ids)) {
1929
#match pft name
20-
site.pft.name <- settings[[i]]$run$site$site.pft$pft.name
30+
site.pft.name <- unlist(settings[[i]]$run$site$site.pft)
2131
if(is.null(site.pft.name)){
2232
site_pft = utils::read.csv(settings[[i]]$run$inputs$pft.site$path)
2333
site.pft.name = site_pft$pft[site_pft$site == settings[[i]]$run$site$id]
@@ -35,4 +45,4 @@ sda_matchparam <- function(settings, ensemble.samples, site.ids, nens){
3545
names(new.params) <- site.ids
3646

3747
return(new.params)
38-
}
48+
}

modules/assim.sequential/man/sda.enkf.multisite.Rd renamed to modules/assim.sequential/man/sda.enkf.multisite_hoptest.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/uncertainty/R/ensemble.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ get.ensemble.samples <- function(ensemble.size, pft.samples, env.samples,
212212
##' @author David LeBauer, Carl Davidson, Hamze Dokoohaki
213213
write.ensemble.configs <- function(defaults, ensemble.samples, settings, model,
214214
clean = FALSE, write.to.db = TRUE, restart = NULL, rename = FALSE) {
215-
216215
con <- NULL
217216
my.write.config <- paste("write.config.", model, sep = "")
218217
my.write_restart <- paste0("write_restart.", model)

state.Rdata

236 KB
Binary file not shown.

state/state.rds

69.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)