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

Patch for get.trait.data.pft.R #2761

Merged
merged 6 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -39,6 +39,7 @@ This is a major change:
- ensure Tleaf converted to K for temperature corrections in PEcAn.photosynthesis::fitA (#2726)
- fix bug in summarize.result to output stat, which is needed to turn on RE in the meta-analysis (#2753)
- ensure that control treatments always receives the random effect index of 1; rename madata.Rdata to jagged.data.Rdata and include database ids and names useful for calculating parameter estimates by treatment (#2756)
- ensure that existing meta-analysis results can be used for pfts with cultivars (#2761)

### Changed

Expand Down
14 changes: 10 additions & 4 deletions base/db/R/get.trait.data.pft.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,26 @@ get.trait.data.pft <- function(pft, modeltype, dbfiles, dbcon, trait.names,
} else {
# Check if PFT membership has changed
PEcAn.logger::logger.debug("Checking if PFT membership has changed.")
if (pfttype == "plant") {
Copy link
Member

Choose a reason for hiding this comment

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

There seems to be a lot more duplicate code here than necessary. Could we just have the if be used to define the colClasses variable, and then use that variable in the existing_membership load?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, fixed to be much more compact. Thanks!

# Columns are: id, genus, species, scientificname
colClass = c("double", "character", "character", "character")
} else if (pfttype == "cultivar") {
# Columns are: id, specie_id, genus, species, scientificname, cultivar
colClass = c("double", "double", "character", "character", "character", "character")
}
existing_membership <- utils::read.csv(
need_paths[["pft_membership"]],
# Columns are: id, genus, species, scientificname
# Need this so NA values are formatted consistently
colClasses = c("double", "character", "character", "character"),
colClasses = colClass,
stringsAsFactors = FALSE,
na.strings = c("", "NA")
)
)
diff_membership <- symmetric_setdiff(
existing_membership,
pft_members,
xname = "existing",
yname = "current"
)
)
if (nrow(diff_membership) > 0) {
PEcAn.logger::logger.error(
"\n PFT membership has changed. \n",
Expand Down