Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
8276e71
Bug fixes for the missing ensemble.size error.
Oct 3, 2025
05f82da
Implement joint input sampling in the SDA workflows.
Oct 3, 2025
884a69d
Update the joint inputs sampling function.
Oct 3, 2025
f7f7736
Merge branch 'PecanProject:develop' into SDA_data
DongchenZ Oct 5, 2025
447b08d
Update the ensemble configs function.
Oct 5, 2025
92cd3f1
Clean the multisite sda function.
Oct 5, 2025
f2a96d1
Revert the changes.
Oct 5, 2025
40701fe
Revert changes.
Oct 5, 2025
4893c11
revert changes.
Oct 5, 2025
f6d473a
Revert changes.
Oct 5, 2025
f787a17
Add documentation and bug fixes.
Oct 5, 2025
c82acac
Update document.
Oct 5, 2025
f6f2232
Update the function to work with the newest functions.
Oct 5, 2025
a30c9e8
Remove the samples argument from the function.
Oct 5, 2025
74d5a1e
Add changes to the sda workflow.
Oct 6, 2025
70cfcb1
Add namespace.
Oct 7, 2025
1f87740
Bug fix.
Oct 7, 2025
8b0a640
Apply Mike's comments.
Oct 8, 2025
fe6bdca
Add the merge nc feature.
Oct 8, 2025
660186b
Improve scripts.
Oct 8, 2025
dd0ee2e
Bug fix.
Oct 8, 2025
5ddcaa7
Update the parallel registration.
Oct 15, 2025
ea8332a
Fix the dimension error when YN equals one.
Oct 15, 2025
5cb5a38
Update the parallel registration. And add the else control when it's …
Oct 15, 2025
fdacd5f
Convert from SoilMoist to SoilMoistFrac.
Oct 15, 2025
abecd42
Add the recursive file deletion.
Oct 15, 2025
fa18299
Revert changes to resolve conflicts.
Oct 15, 2025
81f035b
revert change.
Oct 15, 2025
3fc6907
Pull from pecan develop.
Oct 15, 2025
6fba821
change by make.
Oct 15, 2025
02ca610
Combine previous changes with the debias implementation.
Oct 15, 2025
3575463
Merge the debiasing feature into the parallel SDA workflow.
Oct 15, 2025
bebf893
Update document.
Oct 15, 2025
1409564
Update document.
Oct 15, 2025
870593f
Add the debiasing feature to the parallel job submission.
Oct 15, 2025
10310bc
map forecast results to the variable boundary.
Oct 15, 2025
300a900
Update comments.
Oct 15, 2025
408a390
update observation paths.
Oct 15, 2025
5b3cc63
Update computation configuration.
Oct 15, 2025
393c16e
Bug fix.
Oct 15, 2025
4ac6250
Bug fix.
Oct 16, 2025
50c2324
Revert change.
Oct 16, 2025
993e98b
Revert change.
Oct 16, 2025
78e4702
Add debias code.
Oct 16, 2025
d6d06f3
Move the previous debias script to the inst folder.
Oct 18, 2025
460e0ee
remove previous debias functions.
Oct 18, 2025
6025d83
Add the main SDA debias workflow.
Oct 18, 2025
85c59fe
Add the new debias workflow to the multi-site version.
Oct 18, 2025
ec38802
Add the new bias correction workflow to the sda_local script.
Oct 18, 2025
f1d10a1
Add the new SDA debiasing workflow to the SDA job submission function.
Oct 18, 2025
77bda48
Move out of the if control.
Oct 19, 2025
9c3fd8e
Bug fix.
Oct 19, 2025
e6ef100
Bug fix
Oct 19, 2025
087f18a
Remove the condition for the wrapping where we have more than 20 char…
Oct 19, 2025
5a04563
Update the runner script.
Oct 19, 2025
7ba598e
remove arg.
Oct 20, 2025
19db026
Update script.
Oct 20, 2025
2f14acc
Revert "Move out of the if control."
Oct 20, 2025
caefddf
Resolve conflicts.
Oct 20, 2025
6da0cd6
Revert back.
Oct 20, 2025
cb2379a
Revert to using the new debias workflow.
Oct 21, 2025
668c4b1
Update document.
Oct 21, 2025
e543c23
Update document.
Oct 21, 2025
a44399d
Update the runner script.
Oct 21, 2025
4701b41
Update the bias correction function.
Oct 21, 2025
2754b91
Update the usage of the bias correction workflow.
Oct 21, 2025
459c945
Merge branch 'PecanProject:develop' into SDA_data
DongchenZ Oct 21, 2025
0e08b79
Update observation paths.
Oct 21, 2025
af5c081
Update namespace.
Oct 21, 2025
300dfae
Merge branch 'SDA_data' of https://github.com/DongchenZ/pecan into SD…
Oct 21, 2025
c8a8206
Modify the test to match the change in the logger.message function.
Oct 21, 2025
441f732
Change the default value of wrap in the logger message function.
Oct 21, 2025
9099aa0
Revert back.
Oct 21, 2025
4c31603
Update runner script.
Oct 21, 2025
5bac520
Modify configuration.
Oct 21, 2025
55e9706
Add the prefix argument to customize the desired output folder.
Oct 28, 2025
c06ce29
Update configurations.
Oct 28, 2025
6bdca4e
Update the SDA runner script.
Oct 28, 2025
986930b
Merge branch 'PecanProject:develop' into SDA_data
DongchenZ Oct 28, 2025
6dc8e65
Merge branch 'SDA_data' of https://github.com/DongchenZ/pecan into SD…
Oct 28, 2025
e27fb68
Bug fixes for the indexing error.
Nov 20, 2025
e4d293e
Fix the issue when X is a data frame.
Nov 20, 2025
c834c4b
Add the adjustment to the analysis block function.
Nov 20, 2025
e1ae739
Add the adjustment to the function.
Nov 20, 2025
cd98a38
Add the residual lag to the SDA ML debiasing workflow.
Nov 20, 2025
7f8aa58
Use pre-defined soil depth for the soil physics calculation.
Nov 20, 2025
e4bbbf2
Resolve conflicts.
Nov 20, 2025
0d368a9
Add comments for the reason of returning the list object.
Nov 20, 2025
1695ffd
Fix the logic where we already generated analysis from the analysis b…
Nov 20, 2025
e975c90
Remove the ensemble.samples argument.
Nov 20, 2025
993661a
Update documentation.
Nov 20, 2025
7a9d929
Revert the previous comments and add the parameter generation if we d…
Nov 21, 2025
16ddd04
Merge branch 'PecanProject:develop' into SDA_data
DongchenZ Nov 21, 2025
53fdc63
Merge branch 'develop' of https://github.com/PecanProject/pecan into …
Nov 21, 2025
9d947dd
Merge branch 'SDA_data' of https://github.com/DongchenZ/pecan into SD…
Nov 21, 2025
aff087f
Merge branch 'develop' into SDA_data
mdietze Nov 21, 2025
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
2 changes: 1 addition & 1 deletion base/utils/R/combine_model_netcdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ extract_nc_sda <- function (site.id, start.date, end.date, var.name, nc.path) {
return(0)
}
# grab outputs.
res <- ncdf4::ncvar_get(nc, var.name, start = c(time.inds[1], site.ind, 1), count = c(length(time.inds), 1, ensemble.size))
res <- ncdf4::ncvar_get(nc, var.name, start = c(site.ind, 1, time.inds[1]), count = c(1, ensemble.size, length(time.inds)))
# close NC connection.
ncdf4::nc_close(nc)
# prepare outputs.
Expand Down
8 changes: 8 additions & 0 deletions models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
if ("volume_fraction_of_water_in_soil_at_saturation" %in% names(soil_IC_list$vals)) {
#if depth is provided in the file
if ("depth" %in% names(soil_IC_list$dims)) {
# reduce estimates to the pre-defined soil depth.
if (!is.null(settings$run$inputs$soil_physics$soil_depth)) {
inds.depth <- which(soil_IC_list$dims$depth <= as.numeric(settings$run$inputs$soil_physics$soil_depth))
soil_IC_list$dims$depth <- soil_IC_list$dims$depth[inds.depth]
for (soil.val in names(soil_IC_list$vals)) {
soil_IC_list$vals[[soil.val]] <- soil_IC_list$vals[[soil.val]][inds.depth]
}
}
# Calculate the thickness of soil layers based on the assumption that the depth values are at bottoms and the first layer top is at 0
thickness<-c(soil_IC_list$dims$depth[1],diff(soil_IC_list$dims$depth))
thickness<-PEcAn.utils::ud_convert(thickness, "m", "cm")
Expand Down
4 changes: 2 additions & 2 deletions modules/assim.sequential/R/Adjustment.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
##' @export

adj.ens<-function(Pf, X, mu.f, mu.a, Pa){

X <- as.matrix(X)
S_f <- svd(Pf)
L_f <- S_f$d
V_f <- S_f$v
Expand All @@ -25,7 +25,7 @@ adj.ens<-function(Pf, X, mu.f, mu.a, Pa){

for(i in seq_len(nrow(X))){

Z[i,] <- 1/sqrt(L_f) * t(V_f)%*%(X[i,]-mu.f)
Z[i,] <- 1/sqrt(L_f) * t(V_f)%*%matrix(X[i,]-mu.f) %>% t

}
Z[is.na(Z)]<-0
Expand Down
50 changes: 31 additions & 19 deletions modules/assim.sequential/R/Analysis_sda_block.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ analysis_sda_block <- function (settings, block.list.all, X, obs.mean, obs.cov,
# grab cores from settings.
cores <- as.numeric(settings$state.data.assimilation$batch.settings$general.job$cores)
# if we didn't assign number of CPUs in the settings.
if (is.null(cores)) {
cores <- parallel::detectCores() - 1
# if we only have one CPU.
if (cores < 1) cores <- 1
if (length(cores) == 0 | is.null(cores)) {
cores <- parallel::detectCores()
}
cores <- cores - 1
# if we only have one CPU.
if (cores < 1) cores <- 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update the parallel registration.

#convert from vector values to block lists.
if ("try-error" %in% class(try(block.results <- build.block.xy(settings = settings,
block.list.all = block.list.all,
Expand Down Expand Up @@ -84,7 +85,7 @@ analysis_sda_block <- function (settings, block.list.all, X, obs.mean, obs.cov,
PEcAn.logger::logger.info("Completed!")

#convert from block lists to vector values.
if ("try-error" %in% class(try(V <- block.2.vector(block.list.all[[t]], X, H)))) {
if ("try-error" %in% class(try(V <- block.2.vector(block.list.all[[t]], X, H, settings$state.data.assimilation$adjustment)))) {
PEcAn.logger::logger.severe("Something wrong within the block.2.vector function.")
return(0)
}
Expand Down Expand Up @@ -571,6 +572,14 @@ update_q <- function (block.list.all, t, nt, aqq.Init = NULL, bqq.Init = NULL, M
if (is.null(MCMC_dat)) {
#loop over blocks
if (t == 1) {
fresh.run <- TRUE
} else if (t > 1 & is.null(block.list.all[[t-1]])) {
fresh.run <- TRUE
} else {
fresh.run <- FALSE
}
#if t=1 or if it's a fresh run.
if (fresh.run) {
for (i in seq_along(block.list)) {
nvar <- length(block.list[[i]]$data$muf)
nobs <- length(block.list[[i]]$data$y.censored)
Expand All @@ -596,7 +605,7 @@ update_q <- function (block.list.all, t, nt, aqq.Init = NULL, bqq.Init = NULL, M
block.list[[i]]$data$bq <- block.list[[i]]$bqq[t]
}
}
} else if (t > 1) {
} else {
if (!is.null(block.list.all.pre)) {
block.list.pre <- block.list.all.pre[[t - 1]]
} else {
Expand Down Expand Up @@ -643,31 +652,34 @@ update_q <- function (block.list.all, t, nt, aqq.Init = NULL, bqq.Init = NULL, M
##' @param block.list lists of blocks generated by the `build.block.xy` function.
##' @param X A matrix contains ensemble forecasts.
##' @param H H index created by the `construct_nimble_H` function.
##' @param adjustment logical variable determine if we want to adjust the analysis ensembles based on likelihood.
##'
##' @return It returns a list of analysis results by MCMC sampling.
block.2.vector <- function (block.list, X, H) {
block.2.vector <- function (block.list, X, H, adjustment) {
# initialize site.ids, mu.a, mu.f, pa, and pf.
site.ids <- attributes(X)$Site
mu.f <- mu.a <- c()
Pf <- Pa <- matrix(0, length(site.ids), length(site.ids))
analysis <- X
# loop over blocks.
for (L in block.list) {
# grab index for the locations within the current block.
ind <- c()
for (id in L$site.ids) {
ind <- c(ind, which(site.ids == id))
}
#convert mu.f and pf
mu.a[ind] <- mu.f[ind] <- L$update$mufa
Pa[ind, ind] <- Pf[ind, ind] <- L$update$pfa
# MVN sample based on block.
sample <- as.data.frame(mvtnorm::rmvnorm(nrow(X),
L$update$mufa,
L$update$pfa,
method = "svd"))
# grab mu.a, mu.f, pa, and pf from the MCMC updates.
mu.a[ind] <- L$update$mufa
Pa[ind, ind] <- L$update$pfa
mu.f[ind] <- L$data$muf
Pf[ind, ind] <- L$data$pf
# adjustment.
if (as.logical(adjustment)) {
sample <- as.data.frame(adj.ens(Pf[ind, ind], X[,ind], mu.f[ind], mu.a[ind], Pa[ind, ind]))
} else {
sample <- as.data.frame(mvtnorm::rmvnorm(nrow(X), L$update$mufa, L$update$pfa, method = "svd"))
}
analysis[,ind] <- sample
#convert mu.a and pa
ind <- intersect(ind, H$H.ind)
mu.a[ind] <- L$update$mua
Pa[ind, ind] <- L$update$pa
}
return(list(mu.f = mu.f,
Pf = Pf,
Expand Down
Loading
Loading