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 functions and scripts for downloading, extracting, and processing observations, initial conditions, land cover types, ERA5 drivers for anchor sites within NA. #3278

Merged
merged 84 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
eddb3ac
Add shapefiles of level 1 and 2 NA eco-region.
Mar 12, 2024
0370079
Add a script for processing anchor site data preparations.
Mar 12, 2024
0ac8aee
Automatic updated namespace.
Mar 12, 2024
76fa0f2
Update codes for grabbing site info from a multi-settings object.
Mar 12, 2024
f4102be
Add a function for extracting ISCN SOC initial conditions.
Mar 12, 2024
80de614
Add a function for downloading soil moisture from the CDS server.
Mar 12, 2024
2c7d181
Add a function for extracting downloaded soil moisture netcdf files.
Mar 12, 2024
d31f478
Add rdata file for the ISCN SOC records along with the corresponding …
Mar 12, 2024
0fb6a4d
Add a script for processing initial conditions for the anchor site.
Mar 12, 2024
2ecace0
Tweak ecoregion finder function to adjust the NA area.
Mar 12, 2024
fa445ce
Automatic updated namespace.
Mar 12, 2024
f8025bb
Update MODIS_LAI_prep function.
Mar 12, 2024
b2ebe9b
Add a function to download, extract and filter MODIS LC data.
Mar 12, 2024
c9eb19d
Add a function for extracting AGB initial conditions from GeoTIFF files.
Mar 12, 2024
dace7a2
Merge branch 'develop' of https://github.com/PecanProject/pecan into …
Mar 12, 2024
a75ab0b
Updated previous documentation.
Mar 17, 2024
d919d12
Update progress bar for the qsub_parallel function.
Apr 25, 2024
d89d66a
Correct the unit for using the soil moisture initial condition in SDA.
Apr 25, 2024
d27e7dd
Correct the indexing for block based analysis function.
Apr 25, 2024
a854ed9
Correct logic for the analysis run.
Apr 25, 2024
4cfc6be
Add arguments in the plotting function to control plot size.
Apr 25, 2024
a103d7b
Update create a multi-site script to include the NA anchor sites.
Apr 25, 2024
8d0bc46
Fix the bug where we write ERA5 paths into the settings.xml file.
Apr 25, 2024
9c1dbf4
Update the script to download North America ERA5 data.
Apr 25, 2024
ca4fa97
Provide another option for downloading SoilGrids data if the parallel…
Apr 25, 2024
68a1471
Add argument to decide if we want to skip the high sd observations fo…
Apr 25, 2024
43f73bf
Update function for reading geotiff file of AGB initial conditions.
Apr 25, 2024
6b19993
Update the filtering scheme upon the QC band.
Apr 25, 2024
5cdaa47
Remove shapefiles of NA ecoregion maps from the repo.
Apr 25, 2024
a6aa42d
Remove R script and replace it with the RMD file.
Apr 25, 2024
cde0988
Update the usage of ecoregion maps when searching for ecoregion code.
Apr 25, 2024
4b14550
Rename the current ERA5 USA download script to NA.
Apr 25, 2024
8391427
Replace the previous R script with a more informative Rmd file.
Apr 25, 2024
11845e3
Reverted dependency to dplyr
Apr 25, 2024
3c5e4b9
Update documentation.
Apr 25, 2024
d57b7bb
Update ecoregion paths argument.
Apr 25, 2024
586c694
Add introduction on how to build python CDS API.
Apr 25, 2024
d5af569
Update documentation
Apr 25, 2024
5b44da9
Update the documentation.
Apr 25, 2024
2ac0ad6
Merge branch 'PecanProject:develop' into develop
DongchenZ Apr 25, 2024
82b35d7
Merge branch 'develop' of https://github.com/DongchenZ/pecan into dev…
Apr 25, 2024
f0401c4
Bug fix
Apr 25, 2024
2eeffce
Create interface for user to create their own credentials.
Apr 26, 2024
1a0d3b7
Bug fix.
Apr 27, 2024
5645ceb
Update ISCN extract function based on new Rdata file.
Apr 27, 2024
64bb891
update data.
Apr 27, 2024
85cf197
Update documentation.
Apr 27, 2024
536d742
Update the way of automatically create the credential file.
Apr 27, 2024
ccfe190
Update documentation.
Apr 27, 2024
e7fb69b
document iscn_soc rdata.
Apr 27, 2024
308e996
Update dependencies.
Apr 27, 2024
053fe56
Bug fix.
Apr 27, 2024
af45b0d
Fix documentation.
Apr 27, 2024
59bf4b8
Fix typo in roxygen.
Apr 27, 2024
d11887c
Revert back to the magrittr dependency.
Apr 27, 2024
7fe5670
add namespace.
Apr 27, 2024
bb6d6df
Put the instruction in the roxygen structure.
May 16, 2024
6757a92
Updated documentation.
May 16, 2024
ac37744
Update logger info.
May 16, 2024
14df11a
Update the usage for filtering high sd data and documentation.
May 16, 2024
2446661
Update the usage for exporting the csv file.
May 16, 2024
d83f343
Update the qc.filter usage.
May 16, 2024
1a68cee
Rename the function to be more product specific.
May 16, 2024
8f2823c
Update documentation.
May 16, 2024
08a454e
Update documentation.
May 16, 2024
69a3faf
Move file to the correct folder.
May 16, 2024
8a14ec0
Update documentations.
May 16, 2024
9b09744
Update documentation.
May 16, 2024
c91660b
Merge branch 'PecanProject:develop' into develop
DongchenZ May 16, 2024
fda90e3
Merge branch 'develop' of https://github.com/DongchenZ/pecan into dev…
May 16, 2024
569da69
Update documentation.
May 16, 2024
bbb304f
Update change log file.
May 16, 2024
9e121ff
Bug fixes.
May 16, 2024
2eaddc8
Merge branch 'PecanProject:develop' into develop
DongchenZ May 21, 2024
e5bae23
Update book source.
May 21, 2024
87e75fe
Update IC prep script
May 21, 2024
10d6307
Update documentation.
May 21, 2024
9b911cd
Merge branch 'develop' of https://github.com/DongchenZ/pecan into dev…
May 21, 2024
aaf1a93
Update documentation
May 21, 2024
dda87a1
Fix ifelse.
May 21, 2024
5b82269
Remove the level 1 ecoregion map.
May 21, 2024
fce4f1b
Remove ecoregion map from assimsequential package.
May 21, 2024
0c6224d
Change the package name.
May 21, 2024
bffb27e
Update documentation.
May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ see if you need to change any of these:
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.
- Added new SDA workflow for the 342 North America anchor sites.
- Added new feature of preparing initial conditions for MODIS LAI, AGB, ISCN SOC, and soil moisture across NA anchor sites.

### Fixed

Expand Down
3 changes: 0 additions & 3 deletions base/remote/R/qsub_parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ qsub_parallel <- function(settings, files = NULL, prefix = "sipnet.out", sleep =
#compare two progresses and set the maximum progress for the progress bar.
pbi <- L_folder - length(folders)
utils::setTxtProgressBar(pb, pbi)

pbi1 <- L_jobid - length(jobids)
utils::setTxtProgressBar(pb1, pbi1)
}
} else {
#special case that only detect the job ids on the server.
Expand Down
17 changes: 17 additions & 0 deletions book_source/03_topical_pages/04_R_workflow.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Within the PEcAn repository, code pertaining to input conversion is in the MODUL

## Initial Conditions {#workflow-input-initial}

### CONUS (NEON/FIA/BADM) Initial Conditions.

To convert initial condition data into the PEcAn Standard and then into the model formats we follow three main steps:

1. Downloading vegetation info
Expand Down Expand Up @@ -52,6 +54,21 @@ This function will create ensemble member ncdf files by resampling the veg file
put_veg_module()
This function will convert the ensemble member ncdf files into model specific format. Currently the supported models are ED2 and SIPNET.

### North America (NA) Initial Conditions.

To create initial condition files across North America, you will need to strictly follow the script located at `~/pecan/modules/assim.sequential/inst/anchor/IC_prep_anchorSites.Rmd`. Within the script we will be following those main steps:
1. Loading `settings.xml` file and specify paths.
2. Downloading/extracting estimations of four major carbon/water pools (leaf, wood, soil C, soil water) into by-site and by-ensemble tables.
3. Doing unit conversion. For each ensemble of each site, we will be preparing the `poolinfo` object consisting of converted pool estimations.
4. We will finally be writing the NC files through the `PEcAn.SIPNET::veg2model.SIPNET` function.
5. Within the loop, we will store the NC file paths into the settings object and rewrite the settings into the XML file to the destination.

Within the script we proposed the following new datasets for handling the NA initial condition preparations:

1. The leaf carbon is initialized with MODIS LAI observations and the SLA for the corresponding PFT.
2. The above ground biomass (AGB) is initialized with the 2010 global AGB map (DOI: https://doi.org/10.3334/ORNLDAAC/1763).
3. The soil moisture (SM) is initialized with the SM estimations starting from 1978 (DOI: 10.24381/cds.d7782f18).
4. The soil organic carbon (SOC) is initialized with ISCN SOC estimations (data already prepared on PEcAn, use `PEcAn.data.land::iscn_soc` to load) based on the level 2 ecoregion map (pre-downloaded using the following link: https://www.epa.gov/eco-research/ecoregions).

## Meteorological Data {#workflow-met}

Expand Down
3 changes: 3 additions & 0 deletions docker/depends/pecan_package_dependencies.csv
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"future","*","modules/data.remote","Imports",FALSE
"geonames","> 0.998","modules/data.atmosphere","Imports",FALSE
"getPass","*","base/remote","Suggests",FALSE
"getPass","*","modules/data.land","Suggests",FALSE
"ggmcmc","*","modules/meta.analysis","Suggests",FALSE
"ggplot2","*","base/utils","Suggests",FALSE
"ggplot2","*","base/visualization","Imports",FALSE
Expand All @@ -93,6 +94,7 @@
"glue","*","models/ed","Imports",FALSE
"glue","*","modules/assim.sequential","Suggests",FALSE
"glue","*","modules/data.atmosphere","Imports",FALSE
"glue","*","modules/data.land","Suggests",FALSE
"glue","*","modules/data.remote","Imports",FALSE
"graphics","*","base/qaqc","Imports",FALSE
"graphics","*","modules/allometry","Imports",FALSE
Expand Down Expand Up @@ -451,6 +453,7 @@
"reshape2","*","modules/data.atmosphere","Imports",FALSE
"reshape2",">= 1.4.2","modules/assim.sequential","Suggests",FALSE
"reticulate","*","modules/data.atmosphere","Suggests",FALSE
"reticulate","*","modules/data.land","Suggests",FALSE
"reticulate","*","modules/data.remote","Imports",FALSE
"rjags","*","base/utils","Suggests",FALSE
"rjags","*","modules/assim.batch","Imports",FALSE
Expand Down
6 changes: 4 additions & 2 deletions models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,10 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
}
## soilWFracInit fraction
soilWFrac <- try(ncdf4::ncvar_get(IC.nc,"SoilMoistFrac"),silent = TRUE)
if (!is.na(soilWFrac) && is.numeric(soilWFrac)) {
param[which(param[, 1] == "soilWFracInit"), 2] <- sum(soilWFrac)
if (!"try-error" %in% class(soilWFrac)) {
if (!is.na(soilWFrac) && is.numeric(soilWFrac)) {
param[which(param[, 1] == "soilWFracInit"), 2] <- sum(soilWFrac)/100
}
}
## litterWFracInit fraction
litterWFrac <- soilWFrac
Expand Down
8 changes: 4 additions & 4 deletions modules/assim.sequential/R/Analysis_sda_block.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ build.block.xy <- function(settings, block.list.all, X, obs.mean, obs.cov, t) {
block.list[[i]]$data$muf <- mu.f[f.start:f.end]
block.list[[i]]$data$pf <- Pf[f.start:f.end, f.start:f.end]
#find indexs for Y.
y.start <- sum(obs_per_site[1:i])
y.end <- y.start + obs_per_site[i] - 1
y.start <- sum(obs_per_site[1:i]) - obs_per_site[i] + 1
y.end <- sum(obs_per_site[1:i])
#fill in y and r
#if there is no observation for this site.
if (y.end < y.start) {
Expand Down Expand Up @@ -256,8 +256,8 @@ build.block.xy <- function(settings, block.list.all, X, obs.mean, obs.cov, t) {
for (j in seq_along(ids)) {
f.start <- (ids[j] - 1) * length(var.names) + 1
f.end <- ids[j] * length(var.names)
y.start <- sum(obs_per_site[1:ids[j]])
y.end <- y.start + obs_per_site[ids[j]] - 1
y.start <- sum(obs_per_site[1:ids[j]]) - obs_per_site[ids[j]] + 1
y.end <- sum(obs_per_site[1:ids[j]])
f.ind <- c(f.ind, f.start:f.end)
#if the current site has greater or equal than 1 observation.
if (y.end >= y.start) {
Expand Down
2 changes: 1 addition & 1 deletion modules/assim.sequential/R/SDA_OBS_Assembler.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @return list of obs.mean and obs.cov
#' @export
#' @author Dongchen Zhang
#' @importFrom magrittr %>%
#' @importFrom dplyr %>%
#' @importFrom lubridate %m+%
#'
#' @examples
Expand Down
3 changes: 2 additions & 1 deletion modules/assim.sequential/R/sda.enkf_MultiSite.R
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ sda.enkf.multisite <- function(settings,
###-------------------------------------------------------------------###----
#To trigger the analysis function with free run, you need to first specify the control$forceRun as TRUE,
#Then specify the settings$state.data.assimilation$scalef as 0, and settings$state.data.assimilation$free.run as TRUE.
if (!is.null(obs.mean[[t]][[1]]) | as.logical(settings$state.data.assimilation$free.run) & control$forceRun) {
if (!is.null(obs.mean[[t]][[1]]) | (as.logical(settings$state.data.assimilation$free.run) & control$forceRun)) {
# TODO: as currently configured, Analysis runs even if all obs are NA,
# which clearly should be triggering the `else` of this if, but the
# `else` has not been invoked in a while an may need updating
Expand Down Expand Up @@ -756,6 +756,7 @@ sda.enkf.multisite <- function(settings,
system2(sendmail, c("-f", paste0("\"", control$send_email$from, "\""), paste0("\"", control$send_email$to, "\""), "<", mailfile))
unlink(mailfile)
}
gc()
# useful for debugging to keep .nc files for assimilated years. T = 2, because this loops removes the files that were run when starting the next loop
# if (keepNC && t == 1){
# unlink(list.files(outdir, "*.nc", recursive = TRUE, full.names = TRUE))
Expand Down
19 changes: 11 additions & 8 deletions modules/assim.sequential/R/sda_plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ post.analysis.multisite.ggplot <- function(settings, t, obs.times, obs.mean, obs
Name=.data$site.names)

suppressMessages({
aoi_boundary_HARV <- sf::st_read(system.file("extdata", "eco-regionl2.json", package = "PEcAnAssimSequential"))
aoi_boundary_HARV <- sf::st_read(system.file("extdata", "eco-regionl2.json", package = "PEcAn.data.land"))
infotroph marked this conversation as resolved.
Show resolved Hide resolved
})

#transform site locs into new projection - UTM 2163
Expand Down Expand Up @@ -918,20 +918,29 @@ post.analysis.multisite.ggplot <- function(settings, t, obs.times, obs.mean, obs
##' @param CI range of confidence interval.
##' @param unit list of unit used for y axis label.
##' @param style color option.
##' @param PDF_w width of exported PDF file.
Copy link
Member

Choose a reason for hiding this comment

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

What units? I'm guessing probably whatever pdf() defaults to?

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

Copy link
Member

Choose a reason for hiding this comment

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

For cases like this I like to leave a breadcrumb trail:

Suggested change
##' @param PDF_w width of exported PDF file.
##' @param PDF_w width of exported PDF file, passed on to `base::pdf()`.

(and similar for PDF_h)

##' @param PDF_h height of exported PDF file.
##' @param t.inds index of period that will be plotted.
##' @export
##' @author Dongchen Zhang
SDA_timeseries_plot <- function(ANALYSIS, FORECAST, obs.mean = NULL, obs.cov = NULL, outdir, pft.path = NULL, by = "site", types = c("FORECAST", "ANALYSIS", "OBS"), CI = c(0.025, 0.975),
unit = list(AbvGrndWood = "Mg/ha", LAI = "m2/m2", SoilMoistFrac = "", TotSoilCarb = "kg/m2"),
style = list(general_color = c("FORECAST" = "blue", "ANALYSIS" = "red", "OBS" = "black"),
fill_color = c("FORECAST" = "yellow", "ANALYSIS" = "green", "OBS" = "grey"),
title_color = "red")){
title_color = "red"),
PDF_w = 20,
PDF_h = 16,
t.inds = NULL){
#Check package availability.
if("try-error" %in% class(try(find.package("ggpubr"), silent = T))){
PEcAn.logger::logger.info("Package ggpubr is not installed! Please install it and rerun the function!")
return(0)
}
#TODO: make page, font, line, point sizes adjustable.
time_points <- names(FORECAST)
if (!is.null(t.inds)) {
time_points <- time_points[t.inds]
}
site_ids <- attributes(FORECAST[[1]])$Site
var_names <- attributes(FORECAST[[1]])$dimnames[[2]]
#new diag function: fixed the bug when length==1 then it will return 0x0 matrix
Expand Down Expand Up @@ -979,8 +988,6 @@ SDA_timeseries_plot <- function(ANALYSIS, FORECAST, obs.mean = NULL, obs.cov = N
}
#if we plot by each site.
if(by == "site") {
PDF_w <- 10
PDF_h <- 8
p <- list()
for (site.id in sort(unique(site_ids))) {
site_p <- list()
Expand All @@ -1001,8 +1008,6 @@ SDA_timeseries_plot <- function(ANALYSIS, FORECAST, obs.mean = NULL, obs.cov = N
}
#if we plot by each state variable
} else if (by == "var") {
PDF_w <- 20
PDF_h <- 16
p <- list()
for (var.name in sort(unique(var_names))) {
var_p <- list()
Expand All @@ -1028,8 +1033,6 @@ SDA_timeseries_plot <- function(ANALYSIS, FORECAST, obs.mean = NULL, obs.cov = N
PEcAn.logger::logger.info("Please provide the pdf path!")
return(0)
} else {
PDF_w <- 20
PDF_h <- 16
p <- list()
for (PFT in sort(unique(pft$pft))) {
site_id_pft <- pft$site[which(pft$pft == PFT)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ start_date <- "2012/01/01"
end_date <- "2021/12/31"

#setup working space
outdir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/SDA/"
SDA_run_dir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/SDA/run/"
SDA_out_dir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/SDA/out/"
outdir <- "/projectnb/dietzelab/dongchen/anchorSites/SDA/"
SDA_run_dir <- "/projectnb/dietzelab/dongchen/anchorSites/SDA/run/"
SDA_out_dir <- "/projectnb/dietzelab/dongchen/anchorSites/SDA/out/"

ERA5_dir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/ERA5_2012_2021/"
XML_out_dir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/SDA/pecan.xml"
ERA5_dir <- "/projectnb/dietzelab/dongchen/anchorSites/ERA5_2012_2021/"
XML_out_dir <- "/projectnb/dietzelab/dongchen/anchorSites/SDA/pecan.xml"

pft_csv_dir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/site_pft.csv"
pft_csv_dir <- "/projectnb/dietzelab/dongchen/anchorSites/site_pft.csv"

#Obs_prep part
#AGB
Expand Down Expand Up @@ -44,14 +44,14 @@ SoilC_export_csv <- TRUE
#Obs Date
obs_start_date <- "2012-07-15"
obs_end_date <- "2021-07-15"
obs_outdir <- "/projectnb/dietzelab/dongchen/All_NEON_SDA/test_OBS"
obs_outdir <- "/projectnb/dietzelab/dongchen/anchorSites/Obs"
timestep <- list(unit="year", num=1)

#specify model binary
model_binary <- "/usr2/postdoc/istfer/SIPNET/trunk//sipnet_if"

#specify host section
host.flag <- "rabbitmq"
host.flag <- "local"
if (host.flag == "remote") {
#if we submit jobs through tunnel remotely.
host = structure(list(
Expand All @@ -78,11 +78,10 @@ if (host.flag == "remote") {
host = structure(list(
name = "localhost",
rabbitmq = structure(list(
prefix = NULL,
uri = "amqp://guest:guest@pecan-rabbitmq:15672/%2F",
queue = "SIPNET_r136",
cp2cmd = "oc rsync @RUNDIR@ $(oc get pod -l app.kubernetes.io/name=pecan-model-sipnet-136 -o name):@RUNDIR@",
cpfcmd = "/data/bin/oc rsync @OUTFOLDER@ $(/data/bin/oc get pod -l app=dongchen-sda -o name):@OUTDIR@"
cpfcmd = "/data/bin/oc rsync @OUTDIR@ $(/data/bin/oc get pod -l app=dongchen-sda -o name):@OUTDIR@"
)),
folder = SDA_out_dir,
outdir = SDA_out_dir,
Expand All @@ -109,11 +108,11 @@ template <- PEcAn.settings::Settings(list(
FullYearNC = TRUE,
NC.Overwrite = FALSE,
NC.Prefix = "sipnet.out",
q.type = "SINGLE",
q.type = "vector",
by.site = FALSE,
Localization.FUN = "Local.support",
scalef = 1,
chains = 5,
chains = 1,
data = structure(list(format_id = 1000000040, input.id = 1000013298)),
state.variables = structure(list(
#you could add more state variables here
Expand Down Expand Up @@ -291,7 +290,7 @@ template <- PEcAn.settings::Settings(list(
# )),
# soilinitcond = structure(list(path = "/projectnb/dietzelab/ahelgeso/EFI_Forecast_Challenge/"
# )),
pft.site = structure(list(path = "/projectnb/dietzelab/dongchen/All_NEON_SDA/NEON42/site_pft.csv"))
pft.site = structure(list(path = pft_csv_dir))
))
))
))
Expand All @@ -304,8 +303,8 @@ template <- PEcAn.settings::Settings(list(
############################################################################
############################################################################

sitegroupId <- 1000000031
nSite <- 39
sitegroupId <- 1000000033
nSite <- 330

multiRunSettings <- PEcAn.settings::createSitegroupMultiSettings(
template,
Expand All @@ -314,6 +313,9 @@ multiRunSettings <- PEcAn.settings::createSitegroupMultiSettings(
if(file.exists(XML_out_dir)){
unlink(XML_out_dir)
}



PEcAn.settings::write.settings(multiRunSettings, outputfile = "pecan.xml")

#here we re-read the xml file to fix issues of some special character within the Host section.
Expand Down Expand Up @@ -346,6 +348,26 @@ for (i in 1:nSite) {
settings[[i]]$run$site$name <- site_info$sitename[index_site_info]#temp_ID
}

#remove overlapped sites
site.locs <- settings$run %>%
purrr::map('site') %>%
purrr::map_dfr(~c(.x[['lon']],.x[['lat']]) %>% as.numeric)%>%
t %>%
`colnames<-`(c("lon","lat")) %>% data.frame
del.ind <- c()
for (i in 1:nrow(site.locs)) {
for (j in i:nrow(site.locs)) {
if (i == j) {
next
}
if (site.locs$lon[i] == site.locs$lon[j] &&
site.locs$lat[i] == site.locs$lat[j]) {
del.ind <- c(del.ind, j)
}
}
}
settings <- settings[-del.ind]

#####
unlink(paste0(settings$outdir,"/pecan.xml"))
PEcAn.settings::write.settings(settings, outputfile = "pecan.xml")
Expand Down