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

Add the block-based SDA workflow. #3197

Merged
merged 62 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
363b42c
Add the matrix_network and the GrabFillMatrix functions into the util…
Jul 13, 2023
ee5ce67
Update the documentation.
Jul 13, 2023
5282ab7
Add the namespace for the assimSeqential package and the construct_ni…
Jul 13, 2023
57d0b07
Add the script for the block-based SDA workflow.
Jul 13, 2023
dc949e8
Added the nimble code for the block-based MCMC sampling.
Jul 13, 2023
b704d70
Update the script.
Jul 13, 2023
61f28ff
Add the MCMC_Init function.
Jul 13, 2023
5b6019f
Add the MCMC_block_function.
Jul 13, 2023
c78f5b1
Add the analysis_sda_block function.
Jul 13, 2023
8fd4485
Add the block.2.vector function.
Jul 13, 2023
4501326
Add the build.block.xy function.
Jul 13, 2023
7e48b21
Add the update_q function.
Jul 13, 2023
fc5ad95
Reformat the arguments and connected this function to the block analy…
Jul 13, 2023
2b883e5
Format.
Jul 13, 2023
987e86d
Merge branch 'develop' of https://github.com/DongchenZ/pecan into dev…
Jul 13, 2023
4f0959f
Update the changelog file.
Jul 13, 2023
feb47ab
Export the GEF.Block.Nimble code, and use the future_map function ins…
Jul 13, 2023
7a1679e
Move the matrix_operation.R into the AssimSequential package.
Jul 13, 2023
b352a15
Move the script from util to Assimsequential.
Jul 13, 2023
678393f
Remove the namespace for the AssimSequential package.
Jul 13, 2023
9813880
Add namespace.
Jul 13, 2023
463e48a
Tweak the documents.
Jul 14, 2023
cbfe7b6
bug fixes for initializing aqq and bqq.
Jul 17, 2023
1d0b8ce
Add the tolerance for detecting the nc files.
Jul 17, 2023
b886ae4
Bug fixes for unusually high soil carbon values.
Jul 17, 2023
020174b
lower the threshold.
Jul 17, 2023
81dc1dd
Update the function.
Aug 2, 2023
be2ca7b
Merge branch 'PecanProject:develop' into develop
DongchenZ Aug 2, 2023
339581a
1) Allow pre-existed aqq & bqq imported from outside.
Aug 22, 2023
8d71e9f
Add the special case where only one observation existed for one site.
Aug 22, 2023
3625e44
Add the feature of returning NULL values for a free run inside the ob…
Aug 22, 2023
c3b6a2e
Bug fixings.
Aug 22, 2023
7fd1df4
1) Remove the free_run tag from the control list and instead use the …
Aug 22, 2023
8a236d7
Update the rd files.
Aug 22, 2023
25a004e
Update the Rd file.
Aug 22, 2023
92f73ec
Update the roxygen information and the Rd files.
Aug 22, 2023
14c985a
Bug fixes for the "too many nc files opened!" for the prepare_pools f…
Aug 22, 2023
0fa327f
Update the documentation.
Aug 22, 2023
d8729d3
Merge branch 'PecanProject:develop' into develop
DongchenZ Aug 22, 2023
d0896fd
Merge branch 'develop' of https://github.com/DongchenZ/pecan into dev…
Aug 22, 2023
70eabaa
Remove the %>% operator to avoid adding a dependency.
Aug 22, 2023
68cdac1
Add namespace for the var function.
Aug 22, 2023
026f329
update the documentation.
Aug 23, 2023
dc613a3
update the documentation.
Aug 23, 2023
59eeadf
Fix bug for the single site and no observation case.
Aug 25, 2023
892b379
Merge branch 'PecanProject:develop' into develop
DongchenZ Aug 25, 2023
957d72c
Merge branch 'develop' of https://github.com/DongchenZ/pecan into dev…
Aug 25, 2023
289f59a
Merge branch 'PecanProject:develop' into develop
DongchenZ Aug 28, 2023
d08f417
Fix the issue when some sites have no observation.
Sep 8, 2023
c16f88a
Fix the logic for the analysis function.
Sep 8, 2023
d4a3548
Merge branch 'PecanProject:develop' into develop
DongchenZ Nov 9, 2023
f81a414
Merge block GEF into general GEF.
Nov 14, 2023
e551332
Add sleep time.
Nov 14, 2023
2927ac4
Update documentations.
Nov 14, 2023
778f9ca
Update documentations.
Nov 14, 2023
729873e
Upgrade the detection of the boundary case for wood carbon propagation.
Nov 14, 2023
d39fbde
Update the documentation of parameters and functions per Mike's request.
Nov 14, 2023
4a37538
Typo
Nov 14, 2023
50b61ec
Update the documentation of the roxygen structure.
Nov 14, 2023
a3fc931
Fixes on nc_close and on.exit usage.
Nov 14, 2023
0be65ac
Update Rd files.
Nov 14, 2023
6eec29f
Merge branch 'develop' into develop
mdietze Nov 24, 2023
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 @@ -44,6 +44,7 @@ see if you need to change any of these:
- Added new features of the SDA function including: 1) allow user-defined free-run mode;
2) allow user-defined parallel mode for the qsub submission; 3) allow user-defined email option to report the progress.
- The analysis function now supports the parallelization of multi-chain MCMC sampling with the fully randomized inits function.
- Added the new feature of the block-based SDA workflow, which supports the parallel computation.

### Fixed

Expand Down
19 changes: 9 additions & 10 deletions base/remote/R/qsub_parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' @param settings pecan settings object
#' @param files allow submit jobs based on job.sh file paths.
#' @param prefix used for detecting if jobs are completed or not.
#' @param sleep time (in second) that we wait each time for the jobs to be completed.
#' @export
#' @examples
#' \dontrun{
Expand All @@ -11,7 +12,7 @@
#' @author Dongchen Zhang
#'
#' @importFrom foreach %dopar%
qsub_parallel <- function(settings, files = NULL, prefix = "sipnet.out") {
qsub_parallel <- function(settings, files = NULL, prefix = "sipnet.out", sleep = 10) {
if("try-error" %in% class(try(find.package("doSNOW"), silent = T))){
PEcAn.logger::logger.info("Package doSNOW is not installed! Please install it and rerun the function!")
return(0)
Expand Down Expand Up @@ -91,19 +92,17 @@ qsub_parallel <- function(settings, files = NULL, prefix = "sipnet.out") {
pb <- utils::txtProgressBar(min = 0, max = length(unlist(run_list)), style = 3)
pbi <- 0
folders <- file.path(settings$host$outdir, run_list)
while (length(folders) > 0) {
Sys.sleep(10)
mdietze marked this conversation as resolved.
Show resolved Hide resolved
completed_folders <- foreach::foreach(folder = folders, settings = rep(settings, length(run_list))) %dopar% {
completed_folders <- c()
while (length(completed_folders) < length(folders)) {
Sys.sleep(sleep)
completed_folders <- foreach::foreach(folder = folders) %dopar% {
if(file.exists(file.path(folder, prefix))){
return(folder)
}
}
if(length(unlist(completed_folders)) > 0){
Ind <- which(unlist(completed_folders) %in% folders)
folders <- folders[-Ind]
pbi <- pbi + length(completed_folders)
utils::setTxtProgressBar(pb, pbi)
}
completed_folders <- unlist(completed_folders)
pbi <- length(completed_folders)
utils::setTxtProgressBar(pb, pbi)
}
close(pb)
parallel::stopCluster(cl)
Expand Down
4 changes: 3 additions & 1 deletion base/remote/man/qsub_parallel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions book_source/03_topical_pages/03_pecan_xml.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,16 @@ The following tags can be used for state data assimilation. More detailed inform
```xml
<state.data.assimilation>
<process.variance>TRUE</process.variance>
<aqq.Init>1</aqq.Init>
<bqq.Init>1</bqq.Init>
<sample.parameters>FALSE</sample.parameters>
<adjustment>TRUE</adjustment>
<censored.data>FALSE</censored.data>
<FullYearNC>TRUE</FullYearNC>
<NC.Overwrite>FALSE</NC.Overwrite>
<NC.Prefix>sipnet.out</NC.Prefix>
<q.type>SINGLE</q.type>
<free.run>FALSE</free.run>
<Localization.FUN>Local.support</Localization.FUN>
<scalef>1</scalef>
<chains>5</chains>
Expand Down Expand Up @@ -835,13 +838,16 @@ The following tags can be used for state data assimilation. More detailed inform
```

* **process.variance** : [optional] TRUE/FLASE flag for if process variance should be estimated (TRUE) or not (FALSE). If TRUE, a generalized ensemble filter will be used. If FALSE, an ensemble Kalman filter will be used. Default is FALSE.
* **aqq.Init** : [optional] The initial value of `aqq` used for estimate the Q distribution, the default value is 1 (note that, the `aqq.init` and `bqq.init` right now only work on the `VECTOR` q type, and we didn't account for the variabilities of them across sites or variables, meaning we initialize the `aqq` and `bqq` given single value).
* **bqq.Init** : [optional] The initial value of `bqq` used for estimate the Q distribution, the default value is 1.
* **sample.parameters** : [optional] TRUE/FLASE flag for if parameters should be sampled for each ensemble member or not. This allows for more spread in the intial conditions of the forecast.
* **adjustment** : [optional] Bool variable decide if you want to adjust analysis results by the likelihood.
* **censored.data** : [optional] Bool variable decide if you want to do MCMC sampling for the forecast ensemble space, the default is FALSE.
* **FullYearNC** : [optional] Bool variable decide if you want to generate the full-year netcdf file when there is a overlap in time, the default is TRUE.
* **NC.Overwrite** : [optional] Bool variable decide if you want to overwrite the previous netcdf file when there is a overlap in time, the default is FALSE.
* **NC.Prefix** : [optional] The prefix for the generation of the full-year netcdf file, the default is sipnet.out.
* **q.type** : [optional] The type of process variance that will be estimated, the default is SINGLE.
* **free.run** : [optional] If it's a free run without any observations, the default is FALSE.
* **Localization.FUN** : [optional] The localization function name for the localization operation, the default is Local.support.
* **scalef** : [optional] The scale parameter used for the localization operation, the smaller the value is, the sites are more isolated.
* **chains** : [optional] The number of chains needed to be estimated during the MCMC sampling process.
Expand Down
7 changes: 6 additions & 1 deletion models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
plant_wood_vars <- c("AbvGrndWood", "abvGrndWoodFrac", "coarseRootFrac", "fineRootFrac")
if (all(plant_wood_vars %in% ic.names)) {
# reconstruct total wood C
wood_total_C <- IC$AbvGrndWood / IC$abvGrndWoodFrac
if(IC$abvGrndWoodFrac < 0.05){
wood_total_C <- IC$AbvGrndWood
}else{
wood_total_C <- IC$AbvGrndWood / IC$abvGrndWoodFrac
}

#Sanity check
if (is.infinite(wood_total_C) | is.nan(wood_total_C) | wood_total_C < 0) {
wood_total_C <- 0
Expand Down
4 changes: 4 additions & 0 deletions modules/assim.sequential/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(EnKF.MultiSite)
export(GEF)
export(GEF.MultiSite)
export(GEF.MultiSite.Nimble)
export(GrabFillMatrix)
export(Local.support)
export(Obs.data.prepare.MultiSite)
export(Prep_OBS_SDA)
Expand All @@ -25,13 +26,15 @@ export(alr)
export(assessParams)
export(block_matrix)
export(conj_wt_wishart_sampler)
export(construct_nimble_H)
export(dwtmnorm)
export(generate_colors_sda)
export(get_ensemble_weights)
export(hop_test)
export(interactive.plotting.sda)
export(inv.alr)
export(load_data_paleon_sda)
export(matrix_network)
export(metSplit)
export(obs_timestep2timepoint)
export(outlier.detector.boxplot)
Expand All @@ -57,6 +60,7 @@ export(y_star_create)
import(furrr)
import(lubridate)
import(nimble)
importFrom(dplyr,"%>%")
importFrom(lubridate,"%m+%")
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
Loading
Loading