Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SDA restart capability #3036

Merged
merged 113 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9c7db83
edits to christina's PR
Aug 13, 2021
d401acb
Removed @export from Roxygen
Aug 13, 2021
17433e8
Added namespace call before GEFS functions
Aug 13, 2021
2a7a5ff
"Added csv with args for metprocess"
Aug 18, 2021
2868bab
".Rd and DESCRIPTION updated by make document"
Aug 30, 2021
bd53273
"added @export to download noaa and process noaa functions, also adde…
Aug 30, 2021
74646c6
".Rd and DESCRIPTION updated by make document"
Aug 30, 2021
6dc8566
"added @export back to write noaa function"
Sep 7, 2021
931dd10
"added call for herbaceous dataset"
Sep 14, 2021
28742c9
"ran make document"
Sep 15, 2021
325722a
"added species info for herb data"
Sep 21, 2021
f6aa7a2
"changed imports line 12 from 31 to 33"
Sep 21, 2021
9a2a998
"added a check if plot species data is available or not"
Sep 23, 2021
cdfe30b
"changes to param for extract_NEON_veg"
Oct 4, 2021
0540f27
"changes made to how dates are passed to fcns, added plot area info"
Oct 7, 2021
4b5a019
"make updated .Rd files un-do commit"
Oct 27, 2021
3d5d3d8
"fixed evaportranspiration to Qle conversion"
Oct 30, 2021
b762667
"fixed units for rh calculation in downscaliing fncs"
Nov 3, 2021
9680b15
"GEFS_export merge commits"
Nov 3, 2021
d928e17
"ran make"
Nov 4, 2021
d612960
"fixed unit conversion timing so correct units are passed to met2model"
Nov 16, 2021
07c4ed0
"fixed downscale Na's issue"
Nov 17, 2021
bd14330
"deleted hard coded start and end dates"
Nov 17, 2021
81a899b
"changes made to better integrate herbeceous data"
Nov 19, 2021
62db058
"generalized functions and removed litter C calculation"
Feb 2, 2022
179168a
"added function input for herb dryMass"
Feb 2, 2022
73ca5e6
"removed namespace calls to data.atmosphere"
Feb 4, 2022
d0acd56
"generalize downscale fcns & fixed leap year issue with solar zenith …
Feb 7, 2022
a601959
"debugging SW flux downscaling"
Feb 9, 2022
3f5c7c0
"fixed SW flux calculation so both half hourly ts are estimated from …
Feb 10, 2022
1fcc406
"SW flux debugging"
Feb 18, 2022
4df6d96
"skip match pft for now"
Feb 21, 2022
915e43c
"edited write.configs to loop over IC ens"
Mar 11, 2022
a940e08
"changes to ic funcs"
Mar 26, 2022
d34fd33
"re-ran make"
Apr 29, 2022
38d69df
"re-ran make"
Apr 29, 2022
57f2926
merge commits from sipnet_debug
May 16, 2022
b90600c
"updates to SDA fcns"
May 26, 2022
4f7bef2
"HF LAI SDA"
Jun 1, 2022
bbaa6cb
"merge with develop"
Jun 1, 2022
06c92f4
"new multisite xml for HF and corrected make conflicts in data.land"
Jun 3, 2022
81e52a2
Merge branch 'develop' of https://github.com/helge22a/pecan into ICsd…
Jun 3, 2022
4f7de96
"getting t=1 restart SDA working"
Jun 10, 2022
f6c0e54
Merge https://github.com/helge22a/pecan into ICsdaSIPNET
Jun 10, 2022
dda1190
"added for loop for IC filepath check in check.inputs"
Jun 24, 2022
4523748
"added build_X and sda_matchparam fcns, changed restart to list objec…
Jun 24, 2022
c678262
"match_param working build_X not"
Jun 24, 2022
0bc1a48
Merge https://github.com/helge22a/pecan into ICsdaSIPNET
Jun 27, 2022
3f8475f
"cleaner version of SDA_workflow only for LAI"
Jul 1, 2022
dea45e3
"working on build_X fcn, minor edits to workflow"
Jul 6, 2022
2028379
"unexpected else flagged by make"
Jul 6, 2022
8bc23ff
"missing }"
Jul 6, 2022
ed9669e
"updated .Rd files for new fcns"
Jul 6, 2022
4d56d57
Merge branch 'develop' of https://github.com/helge22a/pecan into ICsd…
Jul 6, 2022
2bd574d
"restart changes working up to call for analysis"
Jul 7, 2022
eb7fe53
"soilmoist xml for Cam"
Jul 7, 2022
df761c1
"changed build X fcn to return reads for params.list and X"
Jul 11, 2022
b1d50eb
"set Q to NULL to match default"
Jul 11, 2022
83c358c
"added new single ob nimble model to Analysis code"
Jul 13, 2022
a9d7cdb
"added args to build_X, added soil pft to xml, changed dates in workf…
Jul 14, 2022
617f99e
"changed outdir for X_build within loop to point to outdir"
Jul 14, 2022
422563f
"revert commit #2927, periods in package name causes nimble to fail c…
Jul 14, 2022
b2db44a
"removed previous edits skipping toggle"
Jul 14, 2022
ec7a3f8
"library call change, removal of soil pft from SDA xml"
Jul 14, 2022
b5a9cbf
"runids stored in different objects depending on what t is"
Jul 16, 2022
ac75f44
"fixed filepath error"
Jul 16, 2022
b1959c6
"forecast met needs to be split by met.start, met.end"
Jul 16, 2022
1cad40e
"changes to workflow to work for multiple sda.start and include NAs"
Jul 16, 2022
66cb1d4
"getting iterarive SDA working, now skipping days with NA"
Jul 20, 2022
cc3f9c5
"fixed restart so correct params are written"
Aug 27, 2022
7fe3cc5
"added check for ensemble member folder to write.ensemble"
Aug 29, 2022
63fb0d0
"updating next.olddir with runs"
Aug 30, 2022
7963cb6
"updated run dates"
Aug 31, 2022
3240dc5
"merge with main"
Sep 13, 2022
9caa7e9
"PR clean up, added new fcn for metSplit, created new folder"
Sep 14, 2022
db315be
Merge branch 'develop' of https://github.com/PecanProject/pecan into …
Sep 14, 2022
8675182
"fix no global binding variable error"
Sep 15, 2022
1a197ac
"fixed global vairable binding in downscale_ShortWave_to_half_hrly"
Sep 15, 2022
7df08ad
"fix PAR, update IC fcns with main"
Oct 3, 2022
bfae23f
"no idea how this ended up in the scripts folder but it was never sup…
Oct 6, 2022
e5f21be
"remove lazydata T"
Oct 6, 2022
cccc1a0
Update base/settings/R/check.all.settings.R
Oct 6, 2022
f6c6c6d
Update base/settings/R/check.all.settings.R
Oct 6, 2022
e4e55ca
"added changelog entry for SIPNET LE fix"
Oct 6, 2022
558d7c0
"delete commented out line"
Oct 6, 2022
58d73a0
"removed extra indent"
Oct 6, 2022
9e7c57e
"remove Rcurl library call"
Oct 6, 2022
9de0320
Update modules/assim.sequential/inst/restart_SDAworkflow_scripts/SDA_…
Oct 6, 2022
cbe93a3
"added back .data rlang import"
Oct 6, 2022
e9e1bb3
"changed startdate back to start_date"
Oct 6, 2022
ab5458c
"add .data import to extract_NEON"
Oct 6, 2022
fde1a2f
"merge with main"
Oct 6, 2022
554d9de
Merge branch 'ICsdaSIPNET' of https://github.com/helge22a/pecan into …
Oct 6, 2022
6b6c132
"added global binding variable for day and hour for Shortwave fcn"
Oct 7, 2022
add2fe5
Update modules/assim.sequential/R/sda.enkf_MultiSite.R
Oct 7, 2022
1e82e43
"add global binding variable"
Oct 7, 2022
8e950d6
"add comment to keep depreciated code for future PR"
Oct 7, 2022
4298ae3
Merge branch 'ICsdaSIPNET' of https://github.com/helge22a/pecan into …
Oct 7, 2022
9b65041
"remove commented out source call"
Oct 7, 2022
0126fdd
"resolved unresolved merge conflicts"
Oct 7, 2022
f0dc679
remove library call and use namespace instead
Oct 18, 2022
7228f86
"fixed examples"
Oct 18, 2022
ffadf72
"fixed character limit"
Oct 18, 2022
80b326e
"fixed examples spacing"
Oct 20, 2022
09fe064
"remove readr dependency for data.land"
Oct 20, 2022
8e98fbd
"remove depricated arg call"
Oct 20, 2022
4249c92
"moving vswc fcn to inst for future PR"
Oct 20, 2022
371b2a4
"delete Rd vswc file"
Oct 20, 2022
e10fe87
"changed veg_info to dat"
Oct 20, 2022
fb06068
Merge branch 'develop' into ICsdaSIPNET
Oct 21, 2022
7565000
Merge branch 'develop' into ICsdaSIPNET
Oct 25, 2022
4350de4
"removed comment from debugging PAR"
Oct 25, 2022
33ad819
Merge branch 'ICsdaSIPNET' of https://github.com/helge22a/pecan into …
Oct 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ convert data for a single PFT fixed (#1329, #2974, #2981)
(#2989; @nanu1605)
- Fixed a bug with ED2 where ED2IN tags supplied in `settings` that were not in the ED2IN template file were not getting added to ED2IN config files (#3034, #3033)
- Fixed a bug where warnings were printed for file paths on remote servers even when they did exist (#3020)
- Fixed bug in model2netcdf.SIPNET that caused LE to be overestimaed 10^3 (#3036)
- Added an updated ED2IN template file, `models/ed/inst/ED2IN.r2.2.0.github`, to reflect new variables in the development version of ED2
- `PEcAn.data.land::gSSURGO.Query` has been updated to work again after changes to the gSSURGO API.
- `PEcAn.settings::read.settings()` now prints a warning when falling back on default `"pecan.xml"` if the named `inputfile` doesn't exist.
Expand Down
17 changes: 11 additions & 6 deletions base/settings/R/check.all.settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ check.inputs <- function(settings) {
}
} else if ("path" %in% names(settings$run$inputs[[tag]])) {
# can we find the file so we can set the tag.id
id <- PEcAn.DB::dbfile.id(
"Input",
settings$run$inputs[[tag]][["path"]],
dbcon,
hostname)
if (!is.na(id)) {
#adding for to loop over ensemble member filepaths
id <- list()
path <- settings$run$inputs[[tag]][["path"]]
for (j in 1:length(path)){
id[j] <- PEcAn.DB::dbfile.id(
"Input",
path[[j]],
dbcon,
hostname)
}
if (any(!is.na(id))) {
settings$run$inputs[[tag]][["id"]] <- id
}
}
Expand Down
10 changes: 7 additions & 3 deletions models/sipnet/R/met2model.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ met2model.SIPNET <- function(in.path, in.prefix, outfolder, start_date, end_date
}

Rain <- ncdf4::ncvar_get(nc, "precipitation_flux")
pres <- ncdf4::ncvar_get(nc,'air_pressure') ## in pascal

press <- ncdf4::ncvar_get(nc,'air_pressure') ## in pascal
helge22a marked this conversation as resolved.
Show resolved Hide resolved

SW <- ncdf4::ncvar_get(nc, "surface_downwelling_shortwave_flux_in_air") ## in W/m2

PAR <- try(ncdf4::ncvar_get(nc, "surface_downwelling_photosynthetic_photon_flux_in_air")) ## in umol/m2/s
Expand All @@ -172,12 +174,14 @@ met2model.SIPNET <- function(in.path, in.prefix, outfolder, start_date, end_date
SVP <- PEcAn.utils::ud_convert(PEcAn.data.atmosphere::get.es(Tair_C), "millibar", "Pa") ## Saturation vapor pressure
VPD <- try(ncdf4::ncvar_get(nc, "water_vapor_saturation_deficit")) ## in Pa
if (!is.numeric(VPD)) {
VPD <- SVP * (1 - PEcAn.data.atmosphere::qair2rh(Qair, Tair_C, pres/100))

VPD <- SVP * (1 - PEcAn.data.atmosphere::qair2rh(Qair, Tair_C, press = press/100))

PEcAn.logger::logger.info("water_vapor_saturation_deficit absent; VPD calculated from Qair, Tair, and SVP (saturation vapor pressure) ")
}
e_a <- SVP - VPD
VPDsoil <- PEcAn.utils::ud_convert(PEcAn.data.atmosphere::get.es(soilT), "millibar", "Pa") *
(1 - PEcAn.data.atmosphere::qair2rh(Qair, soilT, pres/100))
(1 - PEcAn.data.atmosphere::qair2rh(Qair, soilT, press/100))

ncdf4::nc_close(nc)
} else {
Expand Down
6 changes: 3 additions & 3 deletions models/sipnet/R/model2netcdf.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ model2netcdf.SIPNET <- function(outdir, sitelat, sitelon, start_date, end_date,
output[[10]] <- (sub.sipnet.output$plantWoodC * 0.001) + (sub.sipnet.output$plantLeafC * 0.001) +
(sub.sipnet.output$coarseRootC + sub.sipnet.output$fineRootC) * 0.001 # Total living C kgC/m2
output[[11]] <- (sub.sipnet.output$soil * 0.001) + (sub.sipnet.output$litter * 0.001) # Total soil C kgC/m2
if (revision == "r136") {
output[[12]] <- (sub.sipnet.output$evapotranspiration * 10 * PEcAn.data.atmosphere::get.lv()) / timestep.s # Qle W/m2
} else {
if (revision == "unk") {
helge22a marked this conversation as resolved.
Show resolved Hide resolved
## *** NOTE : npp in the sipnet output file is actually evapotranspiration, this is due to a bug in sipnet.c : ***
## *** it says "npp" in the header (written by L774) but the values being written are trackers.evapotranspiration (L806) ***
## evapotranspiration in SIPNET is cm^3 water per cm^2 of area, to convert it to latent heat units W/m2 multiply with :
## 0.01 (cm2m) * 1000 (water density, kg m-3) * latent heat of vaporization (J kg-1)
## latent heat of vaporization is not constant and it varies slightly with temperature, get.lv() returns 2.5e6 J kg-1 by default
output[[12]] <- (sub.sipnet.output$npp * 10 * PEcAn.data.atmosphere::get.lv()) / timestep.s # Qle W/m2
} else {
output[[12]] <- (sub.sipnet.output$evapotranspiration * 10 * PEcAn.data.atmosphere::get.lv()) / timestep.s # Qle W/m2
}
output[[13]] <- (sub.sipnet.output$fluxestranspiration * 10) / timestep.s # Transpiration kgW/m2/s
output[[14]] <- (sub.sipnet.output$soilWater * 10) # Soil moisture kgW/m2
Expand Down
4 changes: 3 additions & 1 deletion models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,11 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
param[which(param[, 1] == "microbeInit"), 2] <- IC$microbe
}
}

else if (length(settings$run$inputs$poolinitcond$path)>0) {
ICs_num <- length(settings$run$inputs$poolinitcond$path)
IC.path <- settings$run$inputs$poolinitcond$path[[sample(1:ICs_num, 1)]]

IC.pools <- PEcAn.data.land::prepare_pools(IC.path, constants = list(sla = SLA))

if(!is.null(IC.pools)){
Expand All @@ -503,7 +505,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
param[which(param[, 1] == "plantWoodInit"), 2] <- PEcAn.utils::ud_convert(IC.pools$wood, "g m-2", "g m-2")
}
## laiInit m2/m2
lai <- try(ncdf4::ncvar_get(IC.nc,"LAI"),silent = TRUE)
lai <- IC.pools$LAI
helge22a marked this conversation as resolved.
Show resolved Hide resolved
if (!is.na(lai) && is.numeric(lai)) {
param[which(param[, 1] == "laiInit"), 2] <- lai
}
Expand Down
2 changes: 1 addition & 1 deletion models/sipnet/R/write_restart.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ write_restart.SIPNET <- function(outdir, runid, start.time, stop.time, settings,
file.path(outdir, runid, paste0("sipnet.", as.Date(start.time), ".out")))
system(paste("rm", file.path(rundir, runid, "sipnet.clim")))
} else {
print(paste("Files not renamed -- Need to rerun year", start.time, "before next time step"))
print(paste("Files not renamed -- Need to rerun timestep", start.time, "before next time step"))
}

settings$run$start.date <- start.time
Expand Down
1 change: 1 addition & 0 deletions modules/assim.sequential/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ License: BSD_3_clause + file LICENSE
Copyright: Authors
Encoding: UTF-8
RoxygenNote: 7.1.2

2 changes: 2 additions & 0 deletions modules/assim.sequential/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(alltocs)
export(alr)
export(assessParams)
export(block_matrix)
export(build_X)
export(conj_wt_wishart_sampler)
export(dwtmnorm)
export(generate_colors_sda)
Expand All @@ -45,6 +46,7 @@ export(sampler_toggle)
export(sda.enkf)
export(sda.enkf.multisite)
export(sda.enkf.original)
export(sda_matchparam)
export(simple.local)
export(tobit.model)
export(tobit2space.model)
Expand Down
57 changes: 41 additions & 16 deletions modules/assim.sequential/R/Analysis_sda_multiSite.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ GEF.MultiSite<-function(setting, Forecast, Observed, H, extraArg,...){
dimensions.tobit = list(X = length(elements.W.Data),
X.mod = ncol(X),
Q = c(nrow(aqq), ncol(aqq))
)
)

# Contants defined in the model
constants.tobit <-
Expand All @@ -402,13 +402,35 @@ GEF.MultiSite<-function(setting, Forecast, Observed, H, extraArg,...){
r = solve(R)
)

# This is the first step in making the nimble model - Nimble does some preliminary checks on the code
model_pred <- nimbleModel(GEF.MultiSite.Nimble,
data = data.tobit,
dimensions = dimensions.tobit,
constants = constants.tobit,
inits = inits.pred,
name = 'base')
# This is the first step in making the nimble model - Nimble does some preliminary checks on the code
#special case for YN == 1 to run nimble model without for loops around nH
if(constants.tobit$YN == 1){
#add error message if trying to run SDA with 1 obs and 1 state variable no model currently exists to handle this case, need to remove for loop from GEF_singleobs_nimble for this case and save new model
if(constants.tobit$N == 1){
PEcAn.logger::logger.error("No model exists for assimilating 1 observation and 1 state variable, add more state variables or edit GEF_singleobs_nimble to work with 1 state variable")
}
#slight adjustment to inputs for nimble function when running with 1 obs
inits.pred$qq <- 0.368
dimensions.tobit$y.censored <- 1
dimensions.tobit$y.ind <- 1
constants.tobit$q.type <- NULL

model_pred <- nimbleModel(GEF_singleobs_nimble,
data = data.tobit,
dimensions = dimensions.tobit,
constants = constants.tobit,
inits = inits.pred,
name = 'base')
}else{
model_pred <- nimbleModel(GEF.MultiSite.Nimble,
data = data.tobit,
dimensions = dimensions.tobit,
constants = constants.tobit,
inits = inits.pred,
name = 'base')
}




model_pred$initializeInfo()
Expand All @@ -418,20 +440,23 @@ GEF.MultiSite<-function(setting, Forecast, Observed, H, extraArg,...){
conf$addMonitors(c("X","Xall","q","Xs"))
samplerNumberOffset <<- length(conf$getSamplers())

for(i in 1:length(y.ind)) {
node <- paste0('y.censored[',i,']')
conf$addSampler(node, 'toggle', control=list(type='RW'))
}

for(i in 1:length(y.ind)) {
helge22a marked this conversation as resolved.
Show resolved Hide resolved
node <- paste0('y.censored[',i,']')
conf$addSampler(node, 'toggle', control=list(type='RW'))
}


conf$printSamplers()

Rmcmc <<- buildMCMC(conf)
Cmodel <<- compileNimble(model_pred)
Cmcmc <<- compileNimble(Rmcmc, project = model_pred)
Cmcmc <<- compileNimble(Rmcmc, project = model_pred, showCompilerOutput = TRUE)

for(i in 1:length(y.ind)) {
valueInCompiledNimbleFunction(Cmcmc$samplerFunctions[[samplerNumberOffset+i]], 'toggle', 1-y.ind[i])
}
valueInCompiledNimbleFunction(Cmcmc$samplerFunctions[[samplerNumberOffset+i]], 'toggle', 1-y.ind[i])
}



save(
inits.pred,
Expand Down
34 changes: 34 additions & 0 deletions modules/assim.sequential/R/Nimble_codes.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,37 @@ conj_wt_wishart_sampler <- nimbleFunction(
}
)
)

GEF_singleobs_nimble <- nimbleCode({

# Sorting out qs
qq ~ dgamma(aq, bq) ## aq and bq are estimated over time
q[1, 1] <- qq * diag(YN)

# # X model
X.mod[1:N] ~ dmnorm(mean = muf[1:N], cov = pf[1:N, 1:N])
# # got rid of for loop no need when nH = 1
Xs[1] <- X.mod[H]

## add process error to x model but just for the state variables that we have data and H knows who
#changed model from dmnorm to dnorm to accomodate when only assimilating 1 obs
X[1] ~ dnorm(Xs[1], q[1, 1])

## Likelihood
#changed model from dmnorm to dnorm to accomodate when only assimilating 1 obs
y.censored[1] ~ dnorm(X[1], r[1, 1])

#puting the ones that they don't have q in Xall - They come from X.model
# If I don't have data on then then their q is not identifiable, so we use the same Xs as Xmodel
for (j in 1:nNotH) {
tmpXmod[j] <- X.mod[NotH[j]]
Xall[NotH[j]] <- tmpXmod[j]
}
# # # #These are the one that they have data and their q can be estimated
#got rid of for loop no need when nH = 1
Xall[H] <- X[1]

y.ind[1] ~ dinterval(y.censored[1], 0)


})
95 changes: 95 additions & 0 deletions modules/assim.sequential/R/build_X.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#' build_X
#'
#' @name build_X
#' @author Alexis Helgeson
#'
#' @description builds X matrix for SDA
#'
#' @param new.params object created from sda_matchparam, passed from sda.enkf_MultiSite
#' @param nens number of ensemble members i.e. runs
#' @param read_restart_times passed from sda.enkf_MultiSite
#' @param settings settings object, passed from sda.enkf_MultiSite
#' @param outdir location of previous run output folder containing .nc files
#' @param out.configs object created for build_X passed from sda.enkf_MultiSite
#' @param t Default t=1, for function to work within time loop
#' @param var.names list of state variables taken from settings object
#' @param my.read_restart object that points to the model restart function i.e. read_restart.SIPNET
#'
#' @return X ready to be passed to SDA Analysis code
#' @export
#'
#' @examples
build_X <- function(out.configs, settings, new.params, nens, read_restart_times, outdir, t = 1, var.names, my.read_restart){

if(t == 1){
reads <-
furrr::future_pmap(list(out.configs %>% `class<-`(c("list")), settings, new.params),function(configs,settings,siteparams) {
# Loading the model package - this is required bc of the furrr
#library(paste0("PEcAn.",settings$model$type), character.only = TRUE)
#source("~/pecan/models/sipnet/R/read_restart.SIPNET.R")

X_tmp <- vector("list", 2)

for (i in seq_len(nens)) {
X_tmp[[i]] <- do.call( my.read_restart,
args = list(
outdir = outdir,
runid = settings$runs$id[i] %>% as.character(),
stop.time = read_restart_times[t+1],
settings = settings,
var.names = var.names,
params = siteparams[[i]]
)
)

}
return(X_tmp)
})

}else{
reads <-
furrr::future_pmap(list(out.configs %>% `class<-`(c("list")), settings, new.params),function(configs,settings,siteparams) {
# Loading the model package - this is required bc of the furrr
#library(paste0("PEcAn.",settings$model$type), character.only = TRUE)
#source("~/pecan/models/sipnet/R/read_restart.SIPNET.R")

X_tmp <- vector("list", 2)

for (i in seq_len(nens)) {
X_tmp[[i]] <- do.call( my.read_restart,
args = list(
outdir = outdir,
runid = configs$runs$id[i] %>% as.character(),
stop.time = read_restart_times[t+1],
settings = settings,
var.names = var.names,
params = siteparams[[i]]
)
)

}
return(X_tmp)
})
}

#commented out text below describes future work - Alexis
# #let's read the parameters of each site/ens
# params.list <- reads %>% map(~.x %>% map("params"))
# # Now let's read the state variables of site/ens
# X <- reads %>% map(~.x %>% map_df(~.x[["X"]] %>% t %>% as.data.frame))
#
# # Now we have a matrix that columns are state variables and rows are ensembles.
# # this matrix looks like this
# # GWBI AbvGrndWood GWBI AbvGrndWood
# #[1,] 3.872521 37.2581 3.872521 37.2581
# # But therer is an attribute called `Site` which tells yout what column is for what site id - check out attr (X,"Site")
# if (multi.site.flag){
# X <- X %>%
# map_dfc(~.x) %>%
# as.matrix() %>%
# `colnames<-`(c(rep(var.names, length(X)))) %>%
# `attr<-`('Site',c(rep(site.ids, each=length(var.names))))
# }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment block looks like it may be good documentation -- material should it move to the @examples section or maybe to a vignette?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wasn't sure where to put this. While I created this function I did not write this code, the code used to exist within the main sda.enkf_MultiSite.R function. So when I created the function I did not want to get rid of the previous documentation. This function is very much a work in progress.


return(reads)
}
Loading