Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 27 additions & 8 deletions modules/data.atmosphere/R/met.process.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,34 @@ met.process <- function(site, input_met, start_date, end_date, model,
if(is.null(model)){
stage$model <- FALSE
}


# setup site database number, lat, lon and name and copy for format.vars if new input
latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")]
new.site <- data.frame(id = as.numeric(site$id),
lat = latlon$lat,
lon = latlon$lon)
str_ns <- paste0(new.site$id %/% 1e+09, "-", new.site$id %% 1e+09)

# TODO why are this and the original site object passed around together?
# Could we mutate `site` instead of assigning `new.site`?
new.site <- list(
id = site$id,
lat = site$lat,
lon = site$lon
)
if (is.null(new.site$id)) {
PEcAn.logger::logger.info(
"no site ID provided. Generating one from lat and lon"
)
new.site$id <- paste0("lat", new.site$lat, "_lon", new.site$lon)
}
if (is.null(site$lat) || is.null(new.site$lon)) {
latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")]
new.site$lat <- latlon$lat
new.site$lon <- latlon$lon
}
if (is.numeric(new.site$id) && new.site$id > 1e9) {
# Assume this is a BETY id, format as [server id]-[record number]
str_ns <- paste0(new.site$id %/% 1e+09, "-", new.site$id %% 1e+09)
} else {
str_ns <- as.character(new.site$id)
}

if (is.null(format.vars$lat)) {
format.vars$lat <- new.site$lat
}
Expand Down
36 changes: 19 additions & 17 deletions modules/data.land/R/ic_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ ic_process <- function(settings, input, dir, overwrite = FALSE){

#--------------------------------------------------------------------------------------------------#
# Extract info from settings and setup
site <- settings$run$site
model <- list()
model$type <- settings$model$type
model$id <- settings$model$id
host <- settings$host
dbparms <- settings$database
site <- settings$run$site
model <- list(
type = settings$model$type,
id = settings$model$id
)
host <- settings$host
dbparms <- settings$database

# Handle IC Workflow locally
if(host$name != "localhost"){
if (host$name != "localhost") {
host$name <- "localhost"
dir <- settings$database$dbfiles
}
Expand All @@ -48,26 +49,27 @@ ic_process <- function(settings, input, dir, overwrite = FALSE){
# set up bety connection
con <- PEcAn.DB::db.open(dbparms$bety)
on.exit(PEcAn.DB::db.close(con), add = TRUE)

#grab site lat and lon info

# check if site metadata is available in the settings$run$site
if (isTRUE(nzchar(settings$run$site$lat)) && isTRUE(nzchar(settings$run$site$lon))) {
if (isTRUE(nzchar(site$lat)) && isTRUE(nzchar(site$lon))) {
# if lat and lon are available, use them directly
latlon <- data.frame(lat = settings$run$site$lat, lon = settings$run$site$lon)
latlon <- data.frame(lat = site$lat, lon = site$lon)
} else {
# otherwise, query the site information from the database
latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")]
}

# setup site database number, lat, lon and name and copy for format.vars if new input
new.site <- data.frame(id = as.numeric(site$id),
lat = latlon$lat,
lon = latlon$lon)

new.site$name <- settings$run$site$name

if (isTRUE(new.site$id > 1e9)) {
new.site <- list(
id = site$id,
lat = latlon$lat,
lon = latlon$lon,
name = site$name
)

if (is.numeric(new.site$id) && isTRUE(new.site$id > 1e9)) {
# Assume this is a BETYdb id, condense for readability
str_ns <- paste0(new.site$id %/% 1e+09, "-", new.site$id %% 1e+09)
} else {
Expand Down
8 changes: 6 additions & 2 deletions modules/data.land/R/soil_params_ensemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ soil_params_ensemble_soilgrids <- function(settings,sand,clay,silt,outdir,write_
PATH <- foreach::foreach(i = seq_along(dat), .packages = c("Kendall", "purrr", "PEcAn.data.land"), .options.snow=opts) %dopar% {
samples_ens <- list()
paths <- c()
siteid <- as.numeric(unique(dat[[i]]$siteid))
siteid <- unique(dat[[i]]$siteid)
soil_depth <- unique(dat[[i]]$soil_depth)
str_ns <- paste0(siteid %/% 1e+09, "-", siteid %% 1e+09)
if (is.numeric(siteid) && siteid > 1e9) {
str_ns <- paste0(siteid %/% 1e+09, "-", siteid %% 1e+09)
} else {
str_ns <- as.character(siteid)
}
temp_outdir <- file.path(outdir, siteid)
dir.create(temp_outdir)
# Estimate Dirichlet parameters for each depth at each site
Expand Down
14 changes: 8 additions & 6 deletions modules/data.land/R/soil_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ soil_process <- function(settings, input, dbfiles, overwrite = FALSE,run.local=T
con <- PEcAn.DB::db.open(dbparms$bety)
on.exit(PEcAn.DB::db.close(con), add = TRUE)
# get site info
latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")]
new.site <- data.frame(id = as.numeric(site$id),
lat = latlon$lat,
lon = latlon$lon)
if (isTRUE(nzchar(site$lat)) && isTRUE(nzchar(site$lon))) {
latlon <- data.frame(lat = site$lat, lon = site$lon)
} else {
latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")]
}
new.site <- list(id = site$id, lat = latlon$lat, lon = latlon$lon)

if (isTRUE(new.site$id > 1e9)) {
if (is.numeric(new.site$id) && isTRUE(new.site$id > 1e9)) {
# Assume this is a BETYdb id, condense for readability
str_ns <- paste0(new.site$id %/% 1e+09, "-", new.site$id %% 1e+09)
} else {
Expand All @@ -45,7 +47,7 @@ soil_process <- function(settings, input, dbfiles, overwrite = FALSE,run.local=T

outfolder <- file.path(dbfiles, paste0(input$source, "_site_", str_ns))

if(!dir.exists(outfolder)) dir.create(outfolder)
if (!dir.exists(outfolder)) dir.create(outfolder)
#--------------------------------------------------------------------------------------------------#
# if we are reading from gSSURGO
if (input$source=="gSSURGO"){
Expand Down
Loading