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+ #
0 commit comments