Skip to content

Commit

Permalink
Merge pull request #23 from emolinab/master
Browse files Browse the repository at this point in the history
bugfix dimSums region ValidAgGDP
  • Loading branch information
emolinab authored Nov 29, 2024
2 parents db035ae + 4ba39e1 commit b31c238
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '523636050'
ValidationKey: '523682216'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: '^tests/testthat/_snaps/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: bae853d82da476eee0e0a57960ee6b741a3b3fb7 # frozen: v0.4.3
rev: 3b70240796cdccbe1474b0176560281aaded97e6 # frozen: v0.4.3.9003
hooks:
- id: parsable-R
- id: deps-in-desc
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: 'mrvalidation: madrat data preparation for validation purposes'
version: 2.61.10
date-released: '2024-11-28'
version: 2.61.11
date-released: '2024-11-29'
abstract: Package contains routines to prepare data for validation exercises.
authors:
- family-names: Bodirsky
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: mrvalidation
Title: madrat data preparation for validation purposes
Version: 2.61.10
Date: 2024-11-28
Version: 2.61.11
Date: 2024-11-29
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
33 changes: 17 additions & 16 deletions R/calcValidAgGDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#'
calcValidAgGDP <- function(datasource = "FAO") {

if (datasource == "FAO") {
if (datasource == "FAO") {

prodCrops <- collapseNames(calcOutput("Production", products = "kcr", aggregate = FALSE, attributes = "dm"))
prodLivst <- collapseNames(calcOutput("Production", products = "kli", aggregate = FALSE, attributes = "dm"))

pricesCrops <- setYears(calcOutput("PricesProducer", products = "kcr",
calculation = "VoP", aggregate = FALSE)[, 2005, ], NULL)
calculation = "VoP", aggregate = FALSE)[, 2005, ], NULL)
pricesLivst <- setYears(calcOutput("PricesProducer", products = "kli",
calculation = "FAO", aggregate = FALSE)[, 2005, ], NULL)
calculation = "FAO", aggregate = FALSE)[, 2005, ], NULL)

namesCrops <- intersect(getNames(prodCrops), getNames(pricesCrops))
namesLivst <- intersect(getNames(prodLivst), getNames(pricesLivst))
Expand Down Expand Up @@ -48,7 +48,7 @@ calcValidAgGDP <- function(datasource = "FAO") {
pricesLivstCon <- setYears(calcOutput("IniFoodPrice", products = "kli", aggregate = FALSE), NULL)

years <- intersect(getYears(seedCrops),
intersect(getYears(feedCrops), getYears(vopAll)))
intersect(getYears(feedCrops), getYears(vopAll)))

valueDemand <- dimSums((seedCrops[, years, ] + feedCrops[, years, ]) * pricesCropsCon, dim = 3) +
dimSums((seedLivst[, years, ] + feedLivst[, years, ]) * pricesLivstCon, dim = 3)
Expand All @@ -57,22 +57,23 @@ calcValidAgGDP <- function(datasource = "FAO") {
out[out < 0] <- 0


} else if (datasource == "FAO_consum") {
} else if (datasource == "FAO_consum") {
# Food and material demand
kall <- findset("kall")
foodMat <- collapseNames(dimSums((calcOutput("FAOmassbalance",
aggregate = FALSE)[, , kall][, , c("food", "other_util")])[, , "dm"],
dim = 3.2))

# Food and material demand
kall <- findset("kall")
foodMat <- collapseNames(dimSums((calcOutput("FAOmassbalance",
aggregate = FALSE)[, , kall][, , c("food", "other_util")])[, , "dm"], dim = 3.2))

# Price consumers (World Prices)
pricesKallCon <- setYears(calcOutput("IniFoodPrice", products = "kall", aggregate = FALSE), NULL)
# Price consumers (World Prices)
pricesKallCon <- setYears(calcOutput("IniFoodPrice", products = "kall", aggregate = FALSE), NULL)

# Consumption value and production value should be the same at global level
out <- dimSums(dimSums(foodMat * pricesKallCon, dim = 3), dim = 1)
# Consumption value and production value should be the same at global level. Not a regional level.
out <- dimSums(dimSums(foodMat * pricesKallCon, dim = 3), dim = 1)
out <- setCells(out, "World")

} else {
} else {
stop("unknown datasource")
}
}

getNames(out) <- "Value|Agriculture GDP (million US$2017/yr)"
out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat data preparation for validation purposes

R package **mrvalidation**, version **2.61.10**
R package **mrvalidation**, version **2.61.11**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

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

Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi:10.5281/zenodo.4317826 <https://doi.org/10.5281/zenodo.4317826>, R package version 2.61.10, <https://github.com/pik-piam/mrvalidation>.
Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi:10.5281/zenodo.4317826 <https://doi.org/10.5281/zenodo.4317826>, R package version 2.61.11, <https://github.com/pik-piam/mrvalidation>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrvalidation: madrat data preparation for validation purposes},
author = {Benjamin Leon Bodirsky and Stephen Wirth and Kristine Karstens and Florian Humpenoeder and Mishko Stevanovic and Abhijeet Mishra and Anne Biewald and Isabelle Weindl and Felicitas Beier and David Chen and Michael Crawford and Debbora Leip and Edna {Molina Bacca} and Ulrich Kreidenweis and Amsalu {W. Yalew} and Patrick {von Jeetze} and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves},
year = {2024},
note = {R package version 2.61.10},
note = {R package version 2.61.11},
url = {https://github.com/pik-piam/mrvalidation},
doi = {10.5281/zenodo.4317826},
}
Expand Down

0 comments on commit b31c238

Please sign in to comment.