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

PEcAn.ED2 check warnings #3135

Merged
merged 15 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion Makefile.depends
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $(call depends,models/cable): | .install/base/logger .install/base/utils
$(call depends,models/clm45): | .install/base/logger .install/base/utils
$(call depends,models/dalec): | .install/base/logger .install/base/remote .install/base/utils
$(call depends,models/dvmdostem): | .install/base/logger .install/base/utils
$(call depends,models/ed): | .install/modules/data.atmosphere .install/modules/data.land .install/base/logger .install/base/remote .install/base/settings .install/base/utils
$(call depends,models/ed): | .install/modules/data.atmosphere .install/modules/data.land .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils
$(call depends,models/fates): | .install/base/logger .install/base/remote .install/base/utils
$(call depends,models/gday): | .install/base/utils .install/base/logger .install/base/remote
$(call depends,models/jules): | .install/modules/data.atmosphere .install/base/logger .install/base/remote .install/base/utils
Expand Down
1 change: 1 addition & 0 deletions models/ed/.Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^data-raw$
^.*\.Rproj$
^\.Rproj\.user$
vignettes/ed_run_data/
1 change: 1 addition & 0 deletions models/ed/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Imports:
ncdf4 (>= 1.15),
PEcAn.data.atmosphere,
PEcAn.data.land,
PEcAn.DB,
PEcAn.logger,
PEcAn.remote,
PEcAn.settings,
Expand Down
2 changes: 1 addition & 1 deletion models/ed/R/create_veg.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ create_site <- function(input, check = TRUE) {
#' @return Modified `data.frame`
modify_df <- function(input, base) {
col_names <- colnames(base)
out_list <- modifyList(as.list(base), as.list(input))
out_list <- utils::modifyList(as.list(base), as.list(input))
as.data.frame(out_list)[col_names]
}
2 changes: 1 addition & 1 deletion models/ed/R/download_edi.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ download_edi <- function(directory) {
download_link <- "https://files.osf.io/v1/resources/b6umf/providers/osfstorage/5a948ea691b689000fa2a588/?zip="
target_file <- paste0(directory, ".zip")
PEcAn.utils::download_file(download_link, target_file)
unzip(target_file, exdir = directory)
utils::unzip(target_file, exdir = directory)
invisible(TRUE)
}
1 change: 1 addition & 0 deletions models/ed/R/ed_varlookup.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' Lookup function for translating commonly used ED variables
#' returns out list, readvar variables to read from file, expr if any derivation is needed
#' @param varname character; variable name to read from file
#' @export
ed.var <- function(varname) {
if(varname == "AGB") {
Expand Down
3 changes: 3 additions & 0 deletions models/ed/R/met2model.ED2.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
#' @param start_date the start date of the data to be downloaded (will only use the year part of the date)
#' @param end_date the end date of the data to be downloaded (will only use the year part of the date)
#' @param lst timezone offset to GMT in hours
#' @param lat latitude; if not provide the function will attempt to discover it in input files
#' @param lon longitude; if not provide the function will attempt to discover it in input files
#' @param overwrite should existing files be overwritten
#' @param verbose should the function be very verbose
#' @param leap_year Enforce Leap-years? If set to TRUE, will require leap years to have 366 days. If set to false, will require all years to have 365 days. Default = TRUE.
#' @param ... currently unused
met2model.ED2 <- function(in.path, in.prefix, outfolder, start_date, end_date, lst = 0, lat = NA,
lon = NA, overwrite = FALSE, verbose = FALSE, leap_year = TRUE, ...) {

Expand Down
2 changes: 1 addition & 1 deletion models/ed/R/model2netcdf.ED2.R
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ put_T_values <-
model_timestep_s <- length(output_date_vector) / length(out[[1]])
iter_per_day <- round(1 / model_timestep_s) ## e.g. 48
## Create a timesteps vector (e.g. 0.00000000 0.02083333 0.04166667 0.06250000 0.08333333 0.10416667 ...)
timesteps <- head(seq(0, 1, by = 1 / iter_per_day), -1)
timesteps <- utils::head(seq(0, 1, by = 1 / iter_per_day), -1)
## Create a new date vector where each day is repeated by iter_per_day
## (e.g. "2001-07-15" "2001-07-15" "2001-07-15" "2001-07-15" "2001-07-15" ...)
sub_dates <- rep(output_date_vector, each = iter_per_day)
Expand Down
6 changes: 3 additions & 3 deletions models/ed/R/modify_ed2in.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ modify_ed2in <- function(ed2in, ...,
if (is.null(.dots)) {
.dots <- list()
}
dots <- modifyList(.dots, list(...))
dots <- utils::modifyList(.dots, list(...))
is_upper <- names(dots) == toupper(names(dots))
lower_args <- names(dots)[!is_upper]
if (length(lower_args) > 0) {
Expand Down Expand Up @@ -211,7 +211,7 @@ modify_ed2in <- function(ed2in, ...,
# 3 for HDF5 output, 0 for no output
on_types <- (valid_types %in% output_types) * 3
names(on_types) <- names(valid_types)
ed2in <- modifyList(ed2in, as.list(on_types))
ed2in <- utils::modifyList(ed2in, as.list(on_types))
}

if (!is.null(output_dir)) {
Expand Down Expand Up @@ -249,6 +249,6 @@ modify_ed2in <- function(ed2in, ...,
)
}
}
ed2in <- modifyList(ed2in, namelist_args)
ed2in <- utils::modifyList(ed2in, namelist_args)
ed2in
}
5 changes: 4 additions & 1 deletion models/ed/R/other.helpers.ED2.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ list.files.nodir <- function(path, ...) {


#' Function translating pecan vars to ED vars
#' @param varnames character; variable names to translate
#' @export
#' @examples
#' var.names <- c("DBH", "AGB", "AbvGrndWood")
#' @export
#' translate_vars_ed(var.names)
translate_vars_ed <- function(varnames) {

var.list <- add.list <- list()
Expand Down
4 changes: 2 additions & 2 deletions models/ed/R/read_ed_metheader.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ read_ed_metheader <- function(filename, check = TRUE, check_files = TRUE) {
PEcAn.logger::logger.warn(msg)
}
}
metadata <- unlist(read.table(text = sub_file[2]))
metadata <- unlist(utils::read.table(text = sub_file[2]))
names(metadata) <- c("nlon", "nlat", "dx", "dy", "xmin", "ymin")
nvars <- as.numeric(sub_file[3])
variables_raw <- read.table(text = sub_file[4:6], header = TRUE)
variables_raw <- utils::read.table(text = sub_file[4:6], header = TRUE)
variables_raw$value_type <- c("update_frequency", "flag")
variables_table <- variables_raw %>%
tidyr::gather("variable", "value", -.data$value_type) %>%
Expand Down
6 changes: 3 additions & 3 deletions models/ed/R/read_ed_veg.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ get_latlon <- function(filepath, latlon) {
#' @return `data.frame` containing
#' @export
read_css <- function(filepath, check = TRUE, ...) {
css <- read.table(filepath, header = TRUE)
css <- utils::read.table(filepath, header = TRUE)
if (check) {
check_css(css, ...)
}
Expand All @@ -103,7 +103,7 @@ read_css <- function(filepath, check = TRUE, ...) {
#' @rdname read_css
#' @export
read_pss <- function(filepath, check = TRUE) {
pss <- read.table(filepath, header = TRUE)
pss <- utils::read.table(filepath, header = TRUE)
if (check) {
check_pss(pss)
}
Expand All @@ -116,7 +116,7 @@ read_site <- function(filepath, check = TRUE, ...) {
top_line <- readLines(filepath, n = 1)
nsite <- as.numeric(gsub(".*nsite +([[:digit:]]+).*", "\\1", top_line))
file_format <- as.numeric(gsub(".*file_format +([[:digit:]]+).*", "\\1", top_line))
site <- read.table(filepath, header = TRUE, skip = 1)
site <- utils::read.table(filepath, header = TRUE, skip = 1)
attr(site, "nsite") <- nsite
attr(site, "file_format") <- file_format
if (check) {
Expand Down
7 changes: 6 additions & 1 deletion models/ed/R/read_restart.ED2.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#' @title State data assimilation read-restart for ED2
#'
#' @author Alexey Shiklomanov, Istem Fer
#' @inheritParams PEcAn.ModelName::read_restart.ModelName
#' @param outdir Output directory
#' @param runid Run ID
#' @param stop.time Year that is being read
#' @param settings PEcAn settings object
#' @param var.names Variable names to be extracted
#' @param params Any parameters required for state calculations
#' @examples
#' \dontrun{
#' outdir <- "~/sda-hackathon/outputs"
Expand Down
2 changes: 1 addition & 1 deletion models/ed/R/run_ed_singularity.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @param ed2in_path Path to ED2IN file.
#' @param app Singularity "app" to run. Either "ED" or "EDR".
#' @param singularity_args Additional arguments to be passed to `singularity run` (before)
#' @param Additional arguments to [base::system2]
#' @param ... Additional arguments to [base::system2]
#' @export
run_ed_singularity <- function(img_path, ed2in_path,
app = "ED",
Expand Down
6 changes: 3 additions & 3 deletions models/ed/R/veg2model.ED2.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ veg2model.ED2 <- function(outfolder, veg_info, start_date, new_site, source, ens
css$time[is.na(css$time)] <- start_year
css$cohort[is.na(css$cohort)] <- 1:sum(is.na(css$cohort))
css$dbh[is.na(css$dbh)] <- 1 # assign nominal small dbh to missing
density.median <- median(css$n[which(css$n > 0)])
density.median <- stats::median(css$n[which(css$n > 0)])
css$n[is.na(css$n) | css$n == 0] <- density.median
css$hite <- css$bdead <- css$balive <- css$lai <- 0

Expand All @@ -177,10 +177,10 @@ veg2model.ED2 <- function(outfolder, veg_info, start_date, new_site, source, ens
# Write files

# css
write.table(css, filenames_full[1], quote = FALSE, row.names = FALSE)
utils::write.table(css, filenames_full[1], quote = FALSE, row.names = FALSE)

# pss
write.table(pss, filenames_full[2], quote = FALSE, row.names = FALSE)
utils::write.table(pss, filenames_full[2], quote = FALSE, row.names = FALSE)

# site
# hardcoded per fia2ED implemention
Expand Down
12 changes: 6 additions & 6 deletions models/ed/R/write.configs.ed.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ write.config.ED2 <- function(trait.values, settings, run.id, defaults = settings
## Edit ED2IN file for runs
revision <- settings$model$revision
if (is.null(revision)) {
model <- db.query(paste("SELECT * FROM models WHERE id =", settings$model$id), params = settings$database$bety)
model <- PEcAn.DB::db.query(paste("SELECT * FROM models WHERE id =", settings$model$id), params = settings$database$bety)
infotroph marked this conversation as resolved.
Show resolved Hide resolved
revision <- model$revision
}
revision <- gsub("^r", "", revision)
Expand Down Expand Up @@ -255,7 +255,7 @@ write.config.ED2 <- function(trait.values, settings, run.id, defaults = settings

# Overwrite defaults with values from settings$model$ed2in_tags list
if(!is.null(settings$model$ed2in_tags)){
sda_tags <- modifyList(sda_tags, settings$model$ed2in_tags[names(sda_tags)])
sda_tags <- utils::modifyList(sda_tags, settings$model$ed2in_tags[names(sda_tags)])
}
ed2in.text <- modify_ed2in(ed2in.text, .dots = sda_tags, add_if_missing = TRUE, check_paths = check)
}
Expand Down Expand Up @@ -520,12 +520,12 @@ write.config.xml.ED2 <- function(settings, trait.values, defaults = settings$con
}

if (grepl("soil", pft)) {
data(soil, package = "PEcAn.ED2", envir = environment())
utils::data(soil, package = "PEcAn.ED2", envir = environment())
vals <- as.list(soil)
names(vals) <- colnames(soil)

converted.trait.values <- convert.samples.ED(trait.values[[i]])
vals <- modifyList(vals, converted.trait.values)
vals <- utils::modifyList(vals, converted.trait.values)

decompositon.xml <- PEcAn.settings::listToXml(vals, "decomposition")
xml <- XML::append.xmlNode(xml, decompositon.xml)
Expand All @@ -548,14 +548,14 @@ write.config.xml.ED2 <- function(settings, trait.values, defaults = settings$con
converted.trait.values <- convert.samples.ED(trait.values[[i]])

## Selectively replace defaults with trait values
vals <- modifyList(vals, converted.trait.values)
vals <- utils::modifyList(vals, converted.trait.values)

## Convert settings constants to ED units
converted.defaults <- convert.samples.ED(defaults[[pft]]$constants)

## Selectively replace defaults and trait values with constants from settings
if (!is.null(converted.defaults)){
vals <- modifyList(vals, converted.defaults)
vals <- utils::modifyList(vals, converted.defaults)
}

## Make sure that include_pft is set to 1
Expand Down
6 changes: 3 additions & 3 deletions models/ed/R/write_ed_veg.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ write_ed_veg <- function(ed_veg, path_prefix) {
#' @export
write_css <- function(css, path_prefix, latitude = NULL, longitude = NULL) {
css_fname <- prepare_ed_veg_filename(path_prefix, ".css", latitude, longitude)
write.table(css, css_fname, quote = FALSE, row.names = FALSE)
utils::write.table(css, css_fname, quote = FALSE, row.names = FALSE)
invisible(css_fname)
}

#' @rdname write_css
#' @export
write_pss <- function(pss, path_prefix, latitude = NULL, longitude = NULL) {
pss_fname <- prepare_ed_veg_filename(path_prefix, ".pss", latitude, longitude)
write.table(pss, pss_fname, quote = FALSE, row.names = FALSE)
utils::write.table(pss, pss_fname, quote = FALSE, row.names = FALSE)
invisible(pss_fname)
}

Expand All @@ -61,7 +61,7 @@ write_site <- function(site, path_prefix, latitude = NULL, longitude = NULL) {
attr(site, "file_format")
)
writeLines(first_line, site_fname)
write.table(site, site_fname, quote = FALSE, row.names = FALSE, append = TRUE)
utils::write.table(site, site_fname, quote = FALSE, row.names = FALSE, append = TRUE)
invisible(site_fname)
}

Expand Down
13 changes: 12 additions & 1 deletion models/ed/R/write_restart.ED2.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#' @title Write ED2 restart file from SDA results
#'
#' @param outdir output directory
#' @param runid run id
#' @param start.time Time of current assimilation step
#' @param stop.time Time of next assimilation step
#' @param settings pecan settings list
#' @param new.state Analysis state matrix returned by `sda.enkf`
#' @param RENAME flag to either rename output file or not
#' @param new.params optional, additional params to pass `write.configs` that
#' are deterministically related to the parameters updated by the analysis
#' @param inputs new input paths updated by the SDA workflow, will be passed to
#' `write.configs`
#'
#' @author Alexey Shiklomanov, Istem Fer
#' @inheritParams PEcAn.ModelName::write_restart.ModelName
#' @return TRUE if successful
#' @export
write_restart.ED2 <- function(outdir, runid, start.time, stop.time,
Expand Down
3 changes: 3 additions & 0 deletions models/ed/man/ed.var.Rd

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

6 changes: 6 additions & 0 deletions models/ed/man/met2model.ED2.Rd

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

2 changes: 1 addition & 1 deletion models/ed/man/run_ed_singularity.Rd

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

9 changes: 7 additions & 2 deletions models/ed/man/translate_vars_ed.Rd

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

8 changes: 5 additions & 3 deletions models/ed/man/write_restart.ED2.Rd

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

Loading