-
Notifications
You must be signed in to change notification settings - Fork 241
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
Improved the current SDA workflow to reach the North American runs with 6400 sites. #3340
base: develop
Are you sure you want to change the base?
Changes from 43 commits
81d6c05
39a886b
cead5d5
6ce1b39
dc06316
7dc12d3
a538129
4c172a1
c7d0ca9
f6f1c2a
cc025a4
fecb781
b407404
e9edbd6
9346ed3
08b93dc
3b1a250
0fc424a
b29173f
bb8b142
75f02eb
b7f72b4
70d6a90
12fa426
cd6360e
98d8046
1870d98
abdc1f8
0050826
5f1216e
be9b047
b51cc40
8cc437e
ab56e79
bb71ff8
9ab9b08
4c0131d
296b0d6
daf3558
86a3d16
c43cba4
a683263
e8ac7bc
0224572
76f2b72
345530f
fcc3804
9fa90a8
382e38d
2cdfea8
59c348d
9934011
7962ffd
0a25664
aa67032
6b5543e
54bb331
dd5f44b
b796bcd
51cb8b5
f1536d6
bf38bcb
3e20018
85d0b46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,6 @@ | |
##' @param var.names vector names of state variable names. | ||
##' @param X a matrix of state variables. In this matrix rows represent ensembles, while columns show the variables for different sites. | ||
##' @param localization.FUN This is the function that performs the localization of the Pf matrix and it returns a localized matrix with the same dimensions. | ||
##' @param t not used | ||
##' @param blocked.dis passed to `localization.FUN` | ||
##' @param ... passed to `localization.FUN` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is undoing a fix I made in #3346 (and apparently forgot to update Rcheck_reference.log, sorry! That's why the checks didn't complain about this being undone.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...But if you have better descriptions for the parameters, please do improve my wording! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
##' @description The argument X needs to have an attribute pointing the state variables to their corresponding site. This attribute needs to be called `Site`. | ||
##' At the moment, the cov between state variables at blocks defining the cov between two sites are assumed zero. | ||
##' @return It returns the var-cov matrix of state variables at multiple sites. | ||
|
@@ -27,15 +24,15 @@ Contruct.Pf <- function(site.ids, var.names, X, localization.FUN=NULL, t=1, bloc | |
for (site in site.ids){ | ||
#let's find out where this cov (for the current site needs to go in the main cov matrix) | ||
pos.in.matrix <- which(attr(X,"Site") %in% site) | ||
#foreach site let's get the Xs | ||
#foreach site let's get the Xs | ||
pf.matrix [pos.in.matrix, pos.in.matrix] <- stats::cov( X [, pos.in.matrix] ,use="complete.obs") | ||
} | ||
|
||
# This is where we estimate the cov between state variables of different sites | ||
#I put this into a sperate loop so we can have more control over it | ||
site.cov.orders <- expand.grid(site.ids,site.ids) %>% | ||
dplyr::filter( .data$Var1 != .data$Var2) | ||
|
||
infotroph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (i in seq_len(nrow(site.cov.orders))){ | ||
# first we need to find out where to put it in the big matrix | ||
rows.in.matrix <- which(attr(X,"Site") %in% site.cov.orders[i,1]) | ||
|
@@ -57,13 +54,13 @@ Contruct.Pf <- function(site.ids, var.names, X, localization.FUN=NULL, t=1, bloc | |
|
||
# adding labels to rownames and colnames | ||
labelss <- paste0(rep(var.names, length(site.ids)) %>% as.character(),"(", | ||
rep(site.ids, each=length(var.names)),")") | ||
rep(site.ids, each=length(var.names)),")") | ||
|
||
colnames(pf.matrix.out ) <-labelss | ||
rownames(pf.matrix.out ) <-labelss | ||
|
||
return(pf.matrix.out) | ||
|
||
infotroph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
##' @title Construct.R | ||
|
@@ -82,34 +79,59 @@ Contruct.Pf <- function(site.ids, var.names, X, localization.FUN=NULL, t=1, bloc | |
##' @export | ||
|
||
Construct.R<-function(site.ids, var.names, obs.t.mean, obs.t.cov){ | ||
|
||
# foreach. | ||
cores <- parallel::detectCores() | ||
cl <- parallel::makeCluster(cores) | ||
doSNOW::registerDoSNOW(cl) | ||
#progress bar | ||
pb <- utils::txtProgressBar(min=1, max=length(site.ids), style=3) | ||
progress <- function(n) utils::setTxtProgressBar(pb, n) | ||
opts <- list(progress=progress) | ||
|
||
# keeps Hs of sites | ||
site.specific.Rs <-list() | ||
# | ||
nsite <- length(site.ids) | ||
# | ||
nvariable <- length(var.names) | ||
Y<-c() | ||
|
||
for (site in site.ids){ | ||
choose <- sapply(var.names, agrep, x=names(obs.t.mean[[site]]), max=1, USE.NAMES = FALSE) %>% unlist | ||
# if there is no obs for this site | ||
if(length(choose) == 0){ | ||
next; | ||
}else{ | ||
Y <- c(Y, unlist(obs.t.mean[[site]][choose])) | ||
#collecting them | ||
if (ncol(obs.t.mean[[site]]) > 1) | ||
{ | ||
site.specific.Rs <- c(site.specific.Rs, list(as.matrix(obs.t.cov[[site]][choose,choose]))) | ||
} else { | ||
site.specific.Rs <- c(site.specific.Rs, list(as.matrix(obs.t.cov[[site]][choose]))) | ||
} | ||
# fix GitHub checks. | ||
site <- NULL | ||
res <- foreach::foreach(site = site.ids, | ||
.packages=c("Kendall", "purrr"), | ||
.options.snow=opts) %dopar% { | ||
choose <- sapply(var.names, agrep, x=names(obs.t.mean[[site]]), max=1, USE.NAMES = FALSE) %>% unlist | ||
# if there is no obs for this site | ||
if(length(choose) == 0){ | ||
return(NA); | ||
}else{ | ||
Y <- unlist(obs.t.mean[[site]][choose]) | ||
#collecting them | ||
if (ncol(obs.t.mean[[site]]) > 1) | ||
{ | ||
site.R <- list(as.matrix(obs.t.cov[[site]][choose,choose])) | ||
} else { | ||
site.R <- list(as.matrix(obs.t.cov[[site]][choose])) | ||
} | ||
} | ||
return(list(site.R = site.R, | ||
site.Y = Y, | ||
choose = choose)) | ||
} | ||
for (i in seq_along(site.ids)){ | ||
temp <- res[[i]] | ||
if (is.na(temp)) { | ||
next | ||
} else { | ||
Y <- c(Y, unlist(obs.t.mean[[site.ids[i]]][temp$choose])) | ||
site.specific.Rs <- c(site.specific.Rs, temp$site.R) | ||
} | ||
} | ||
#make block matrix out of our collection | ||
R <- Matrix::bdiag(site.specific.Rs) %>% as.matrix() | ||
} | ||
|
||
# stop parallel. | ||
parallel::stopCluster(cl) | ||
foreach::registerDoSEQ() | ||
return(list(Y=Y, R=R)) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEcAn.logger already has built-in verbosity control via
logger.setLevel()
-- is a function-specific verbose flag needed here or is it enough for the user to set the logger level to something higher than debug so that this message isn't printed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.setLevel()
works inside thePEcAn.logger
package.