Skip to content

Commit

Permalink
Changed min to 0 and max to very high value in EATLancet recommendati…
Browse files Browse the repository at this point in the history
…on to simplify GAMS code. And linter fixes.
  • Loading branch information
FelicitasBeier committed Jan 8, 2024
1 parent c92b90c commit 1358efe
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '10308853'
ValidationKey: '10338520'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrland: MadRaT land data package'
version: 0.52.3
date-released: '2023-12-20'
version: 0.52.4
date-released: '2024-01-08'
abstract: The package provides land related data via the madrat framework.
authors:
- family-names: Dietrich
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrland
Title: MadRaT land data package
Version: 0.52.3
Date: 2023-12-20
Version: 0.52.4
Date: 2024-01-08
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre")),
person("Abhijeet", "Mishra", role = "aut"),
Expand Down
8 changes: 4 additions & 4 deletions R/calcNutritionAttributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ calcNutritionAttributes <- function() {
fooduseFlour <- dimSums(massbalance[, , c("food", "flour1")][, , c("ge", "nr")], dim = c(1, 3.2), na.rm = TRUE)

if (any(household > fooduseFlour)) {
message(paste("The following items violate massbalance constraints:",
paste(unique(dimnames(household)[[3]][which(household > fooduseFlour, arr.ind = TRUE)[, 3]]),
collapse = " "),
". Violating items are corrected through household balance flow."))
message(paste("The following items violate massbalance constraints: ",
paste(unique(dimnames(household)[[3]][which(household > fooduseFlour, arr.ind = TRUE)[, 3]]),
collapse = " "),
". Violating items are corrected through household balance flow."))
household[household > fooduseFlour] <- fooduseFlour[household > fooduseFlour]
}

Expand Down
64 changes: 28 additions & 36 deletions R/convertEATLancet.R
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
#' Convert data from the EAT Lancet Comission
#'
#' Convert data from the EAT Lancet Comission to ISO country level.
#'
#'
#' @title convertEATLancet
#' @description Convert data from the EAT Lancet Commission to be used in MAgPIE
#'
#' @param x MAgPIE object containing EAT Lancet data at mixed country-region
#' resolution
#' @param subtype Type of EAT Lancet data that should be read. Available types are:
#' \itemize{
#' \itemize{
#' \item \code{cons_data}: Consumption analysis ("EAT_Lancet_cons_data.csv")
#' \item \code{recommend}: Food recommendations ("EAT_Lancet_recommendations.csv")
#' }
#' @return EAT Lancet data as MAgPIE object at ISO country level
#' @author Isabelle Weindl
#' @author Isabelle Weindl, Felicitas Beier
#' @seealso \code{\link{readSource}}
#' @examples
#'
#' \dontrun{
#' a <- readSource(type="EATLancet",subtype="cons_data")
#' a <- readSource(type = "EATLancet", subtype = "cons_data")
#' }
#' @importFrom madrat getISOlist

convertEATLancet <- function(x,subtype) {

if(subtype == "cons_data"){

y <- toolAggregate(x, "regionmappingEATLancet.csv", weight=NULL )

} else if (subtype == "recommend") {

iso <- getISOlist(type = "all")
mapping <- cbind(rep("GLO",length(iso)),as.character(iso))
y <- toolAggregate(x, rel = mapping, weight=NULL )

} else {

stop("Not a valid subtype!")

}

return(y)
}


convertEATLancet <- function(x, subtype) {

if (subtype == "cons_data") {

y <- toolAggregate(x, "regionmappingEATLancet.csv", weight = NULL)

} else if (subtype == "recommend") {
# replace NA's for min and max values
x[, , "min"] <- ifelse(is.na(x[, , "min"]), 0, x[, , "min"])
x[, , "max"] <- ifelse(is.na(x[, , "max"]), 999999, x[, , "max"])



# expand to all iso countries
iso <- getISOlist(type = "all")
mapping <- cbind(rep("GLO", length(iso)), as.character(iso))
y <- toolAggregate(x, rel = mapping, weight = NULL)




} else {

stop("Not a valid subtype! Please select cons_data or recommend in readEATLancet function.")

}

return(y)
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRaT land data package

R package **mrland**, version **0.52.3**
R package **mrland**, version **0.52.4**

[![CRAN status](https://www.r-pkg.org/badges/version/mrland)](https://cran.r-project.org/package=mrland) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3822083.svg)](https://doi.org/10.5281/zenodo.3822083) [![R build status](https://github.com/pik-piam/mrland/workflows/check/badge.svg)](https://github.com/pik-piam/mrland/actions) [![codecov](https://codecov.io/gh/pik-piam/mrland/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrland) [![r-universe](https://pik-piam.r-universe.dev/badges/mrland)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,16 +39,16 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

To cite package **mrland** in publications use:

Dietrich J, Mishra A, Weindl I, Bodirsky B, Wang X, Baumstark L, Kreidenweis U, Klein D, Steinmetz N, Chen D, Humpenoeder F, von Jeetze P, Wirth S, Beier F, Hoetten D (2023). _mrland: MadRaT land data package_. doi:10.5281/zenodo.3822083 <https://doi.org/10.5281/zenodo.3822083>, R package version 0.52.3, <https://github.com/pik-piam/mrland>.
Dietrich J, Mishra A, Weindl I, Bodirsky B, Wang X, Baumstark L, Kreidenweis U, Klein D, Steinmetz N, Chen D, Humpenoeder F, von Jeetze P, Wirth S, Beier F, Hoetten D (2024). _mrland: MadRaT land data package_. doi:10.5281/zenodo.3822083 <https://doi.org/10.5281/zenodo.3822083>, R package version 0.52.4, <https://github.com/pik-piam/mrland>.

A BibTeX entry for LaTeX users is

```latex
@Manual{,
title = {mrland: MadRaT land data package},
author = {Jan Philipp Dietrich and Abhijeet Mishra and Isabelle Weindl and Benjamin Leon Bodirsky and Xiaoxi Wang and Lavinia Baumstark and Ulrich Kreidenweis and David Klein and Nele Steinmetz and David Chen and Florian Humpenoeder and Patrick {von Jeetze} and Stephen Wirth and Felicitas Beier and David Hoetten},
year = {2023},
note = {R package version 0.52.3},
year = {2024},
note = {R package version 0.52.4},
doi = {10.5281/zenodo.3822083},
url = {https://github.com/pik-piam/mrland},
}
Expand Down
11 changes: 5 additions & 6 deletions man/convertEATLancet.Rd

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

0 comments on commit 1358efe

Please sign in to comment.