Skip to content
Open
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
16 changes: 11 additions & 5 deletions examples/3_rowcrop/01_ERA5_nc_to_clim.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ args <- optparse::OptionParser(option_list = options) |>
future::plan(args$parallel_strategy, workers = args$n_cores)

file_info <- read.csv(args$site_info_file) |>
dplyr::distinct(id) |>
dplyr::distinct(id, lat, lon) |>
dplyr::mutate(
start_date = args$start_date,
end_date = args$end_date
end_date = args$end_date,
# match locations to half-degree ERA5 grid cell centers
# CAUTION: Calculation only correct when all lats are N and all lons are W!
ERA5_grid_cell = paste0(
((lat + 0.25) %/% 0.5) * 0.5, "N_",
((abs(lon) + 0.25) %/% 0.5) * 0.5, "W"
)
) |>
dplyr::cross_join(data.frame(ens_id = 1:10))

Expand All @@ -77,16 +83,16 @@ if (!dir.exists(args$site_sipnet_met_path)) {
}
furrr::future_pwalk(
file_info,
function(id, start_date, end_date, ens_id, ...) {
function(start_date, end_date, ens_id, ERA5_grid_cell, ...) {
PEcAn.SIPNET::met2model.SIPNET(
in.path = file.path(
args$site_era5_path,
paste("ERA5", id, ens_id, sep = "_")
paste("ERA5", ERA5_grid_cell, ens_id, sep = "_")
),
start_date = start_date,
end_date = end_date,
in.prefix = paste0("ERA5.", ens_id),
outfolder = file.path(args$site_sipnet_met_path, id)
outfolder = file.path(args$site_sipnet_met_path, ERA5_grid_cell)
)
}
)
15 changes: 12 additions & 3 deletions examples/3_rowcrop/02a_build_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ args <- optparse::OptionParser(option_list = options) |>

library(tidyverse)

# Locate tools/event_prep/ relative to this script's own file location, so it
# works regardless of the caller's working directory (magic-ensemble invokes
# with cwd = repo root; the README's manual workflow uses cwd = this directory).
this_file <- function() {
cmd_args <- commandArgs(trailingOnly = FALSE)
normalizePath(sub("^--file=", "", grep("^--file=", cmd_args, value = TRUE)))
}
event_prep_dir <- normalizePath(file.path(dirname(this_file()), "..", "..", "tools", "event_prep"))

# TODO these probably deserve to be runtime args,
# but first better fix other version-specific assumptions below
mgmt_subdirs <- list(
Expand All @@ -76,15 +85,15 @@ cargs <- function(...) {
if (args$raw_parquet_dir != "") {
PEcAn.logger::logger.info("Cleaning irrigation files")
callr::rscript(
"../../tools/event_prep/01a-clean-irrigation.R",
file.path(event_prep_dir, "01a-clean-irrigation.R"),
cmdargs = cargs(
irr_path = mgmt_subdirs$irri,
outdir = args$clean_parquet_dir
)
)
PEcAn.logger::logger.info("Cleaning other management files")
callr::rscript(
"../../tools/event_prep/01b-clean-other-events.R",
file.path(event_prep_dir, "01b-clean-other-events.R"),
cmdargs = cargs(
pheno_dir = mgmt_subdirs$pheno,
planting_dir = mgmt_subdirs$plant,
Expand All @@ -98,7 +107,7 @@ if (args$raw_parquet_dir != "") {

PEcAn.logger::logger.info("converting management files to events")
callr::rscript(
"../../tools/event_prep/02-events-to-json-and-sipnet.R",
file.path(event_prep_dir, "02-events-to-json-and-sipnet.R"),
cmdargs = cargs(
site_info_path = args$site_info_path,
parquet_dir = args$clean_parquet_dir,
Expand Down
97 changes: 0 additions & 97 deletions examples/3_rowcrop/04_set_up_runs.R

This file was deleted.

110 changes: 0 additions & 110 deletions examples/3_rowcrop/05_run_model.R

This file was deleted.

Loading