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

no carbon storage across years for annual grasses in BioCro #2496

Merged
merged 7 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha

### Fixed

- Use initial biomass pools for Sorghum and Setaria #2495, #2496
- PEcAn.DB::betyConnect() is now smarter, and will try to use either config.php or environment variables to create a connection. It has switched to use db.open helper function (#2632).
- PEcAn.utils::tranformstats() assumed the statistic names column of its input was a factor. It now accepts character too, and returns the same class given as input (#2545).
- fixed and added tests for `get.rh` function in PEcAn.data.atmosphere
Expand Down
91 changes: 49 additions & 42 deletions models/biocro/R/call_biocro.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ call_biocro_0.9 <- function(WetDat, genus, year_in_run,
# Check that all variables are present in the expected order --
# BioGro < 1.0 accesses weather vars by position and DOES NOT check headers.
expected_cols <- c("year", "doy", "hour", "[Ss]olar", "Temp", "RH", "WS|windspeed", "precip")
if(!all(mapply(grepl, expected_cols, colnames(WetDat)))){
if (!all(mapply(grepl, expected_cols, colnames(WetDat)))) {
PEcAn.logger::logger.severe("Format error in weather file: Columns must be (", expected_cols, "), in that order.")
}
day1 <- min(WetDat$doy) # data already subset upstream, but BioCro 0.9 assumes a full year if day1/dayn are unset
Expand All @@ -26,52 +26,60 @@ call_biocro_0.9 <- function(WetDat, genus, year_in_run,
# If not, rescale day1 and dayn to be relative to the start of the input.
# Scaling is derived by inverting Biocro's day->index equations.
biocro_checks_doy <- tryCatch(
{m <- BioCro::BioGro(
WetDat = matrix(c(0,10,0,0,0,0,0,0), nrow = 1),
day1 = 10, dayn = 10, timestep = 24);
inherits(m, "BioGro") },
error = function(e){FALSE})
if (!biocro_checks_doy && min(WetDat[,"doy"])>1) {
if (!is.null(day1)){
{
m <- BioCro::BioGro(
WetDat = matrix(c(0, 10, 0, 0, 0, 0, 0, 0), nrow = 1),
day1 = 10, dayn = 10, timestep = 24
)
inherits(m, "BioGro")
},
error = function(e) {
FALSE
}
)
if (!biocro_checks_doy && min(WetDat[, "doy"]) > 1) {
if (!is.null(day1)) {
# Biocro calculates line number as `indes1 <- (day1 - 1) * 24`
indes1 <- Position(function(x)x==day1, WetDat[,"doy"])
day1 <- indes1/24 + 1
indes1 <- Position(function(x) x == day1, WetDat[, "doy"])
day1 <- indes1 / 24 + 1
}
if (!is.null(dayn)){
if (!is.null(dayn)) {
# Biocro calculates line number as `indesn <- (dayn) * 24`
indesn <- Position(function(x)x==dayn, WetDat[,"doy"], right = TRUE)
dayn <- indesn/24
indesn <- Position(function(x) x == dayn, WetDat[, "doy"], right = TRUE)
dayn <- indesn / 24
}
}

coppice.interval = config$pft$coppice.interval
if(is.null(coppice.interval)) {
coppice.interval = 1 # i.e. harvest every year
coppice.interval <- config$pft$coppice.interval
if (is.null(coppice.interval)) {
coppice.interval <- 1 # i.e. harvest every year
}

if (genus == "Saccharum") {
# probably should be handled like coppice shrubs or perennial grasses
tmp.result <- BioCro::caneGro(
WetDat = WetDat,
lat = lat,
soilControl = l2n(config$pft$soilControl))
# Addin Rhizome an Grain to avoid error in subsequent script processing results
soilControl = l2n(config$pft$soilControl)
)
# Addin Rhizome and Grain to avoid error in subsequent script processing results
tmp.result$Rhizome <- 0
tmp.result$Grain <- 0
} else if (genus %in% c("Salix", "Populus")) {
} else if (genus %in% c("Salix", "Populus")) { # coppice trees / shrubs
if (year_in_run == 1) {
iplant <- config$pft$iPlantControl
} else {
iplant$iRhizome <- data.table::last(tmp.result$Rhizome)
iplant$iRoot <- data.table::last(tmp.result$Root)
iplant$iStem <- data.table::last(tmp.result$Stem)

if ((year_in_run - 1)%%coppice.interval == 0) {
if ((year_in_run - 1) %% coppice.interval == 0) {
# coppice when remainder = 0
HarvestedYield <- round(data.table::last(tmp.result$Stem) * 0.95, 2)
} else if ((year_in_run - 1)%%coppice.interval == 1) {
} else if ((year_in_run - 1) %% coppice.interval == 1) {
# year after coppice
iplant$iStem <- iplant$iStem * 0.05
} # else { # do nothing if neither coppice year nor year following
} # else { # do nothing if neither coppice year nor year following
}
## run willowGro
tmp.result <- BioCro::willowGro(
Expand All @@ -85,9 +93,9 @@ call_biocro_0.9 <- function(WetDat, genus, year_in_run,
canopyControl = l2n(config$pft$canopyControl),
willowphenoControl = l2n(config$pft$phenoParms),
seneControl = l2n(config$pft$seneControl),
photoControl = l2n(config$pft$photoParms))

} else if (genus %in% c("Miscanthus", "Panicum")) {
photoControl = l2n(config$pft$photoParms)
)
} else if (genus %in% c("Miscanthus", "Panicum")) { # perennial grasses
if (year_in_run == 1) {
iRhizome <- config$pft$iPlantControl$iRhizome
} else {
Expand All @@ -104,35 +112,33 @@ call_biocro_0.9 <- function(WetDat, genus, year_in_run,
phenoControl = l2n(config$pft$phenoParms),
seneControl = l2n(config$pft$seneControl),
iRhizome = as.numeric(iRhizome),
photoControl = config$pft$photoParms)

} else if (genus %in% c("Sorghum", "Setaria")) {
if (year_in_run == 1) {
iplant <- config$pft$iPlantControl
} else {
iplant$iRhizome <- data.table::last(tmp.result$Rhizome)
iplant$iRoot <- data.table::last(tmp.result$Root)
iplant$iStem <- data.table::last(tmp.result$Stem)
}
photoControl = config$pft$photoParms
)
} else if (genus %in% c("Sorghum", "Setaria")) { # annual grasses
# Perennial Sorghum exists but is not a major crop
# assume these are replanted from seed each year
# https://landinstitute.org/our-work/perennial-crops/perennial-sorghum/
dlebauer marked this conversation as resolved.
Show resolved Hide resolved
iplant <- config$pft$iPlantControl
## run BioGro
tmp.result <- BioCro::BioGro(
WetDat = WetDat,
iRhizome = as.numeric(iplant$iRhizome),
iRoot = as.numeric(iplant$iRoot),
iStem = as.numeric(iplant$iStem),
iLeaf = as.numeric(iplant$iLeaf),
iLeaf = as.numeric(iplant$iLeaf),
day1 = day1,
dayn = dayn,
soilControl = l2n(config$pft$soilControl),
canopyControl = l2n(config$pft$canopyControl),
phenoControl = l2n(config$pft$phenoParms),
seneControl = l2n(config$pft$seneControl),
photoControl = l2n(config$pft$photoParms))

photoControl = l2n(config$pft$photoParms)
)
} else {
PEcAn.logger::logger.severe(
"Genus '", genus, "' is not supported by PEcAn.BIOCRO when using BioCro 0.9x.",
"Supported genera: Saccharum, Salix, Populus, Sorghum, Miscanthus, Panicum, Setaria")
"Supported genera: Saccharum, Salix, Populus, Sorghum, Miscanthus, Panicum, Setaria"
)
}
names(tmp.result) <- sub("DayofYear", "doy", names(tmp.result))
names(tmp.result) <- sub("Hour", "hour", names(tmp.result))
Expand All @@ -148,7 +154,6 @@ call_biocro_0.9 <- function(WetDat, genus, year_in_run,
call_biocro_1 <- function(WetDat, genus, year_in_run,
config, lat, lon,
tmp.result, HarvestedYield) {

if (year_in_run == 1) {
initial_values <- config$pft$initial_values
} else {
Expand All @@ -162,13 +167,15 @@ call_biocro_1 <- function(WetDat, genus, year_in_run,
initial_values = initial_values,
parameters = config$pft$parameters,
varying_parameters = WetDat,
modules = config$pft$modules)
modules = config$pft$modules
)

tmp.result <- dplyr::rename(tmp.result,
ThermalT = "TTc",
LAI = "lai",
SoilEvaporation = "soil_evaporation",
CanopyTrans = "canopy_transpiration")
CanopyTrans = "canopy_transpiration"
)
tmp.result$AboveLitter <- tmp.result$LeafLitter + tmp.result$StemLitter
tmp.result$BelowLitter <- tmp.result$RootLitter + tmp.result$RhizomeLitter

Expand Down