Skip to content

Commit

Permalink
Merge pull request #19 from caviddhen/master
Browse files Browse the repository at this point in the history
Update to 2017 GDP Base Year
  • Loading branch information
deleip authored Sep 23, 2024
2 parents 0a0d1c2 + 618aaf8 commit 10107d4
Show file tree
Hide file tree
Showing 36 changed files with 122 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '51962778'
ValidationKey: '52171290'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
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.60.1
date-released: '2024-09-12'
version: 2.61.0
date-released: '2024-09-23'
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.60.1
Date: 2024-09-12
Version: 2.61.0
Date: 2024-09-23
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion R/calcValidAgEmployment.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' }
#'

calcValidAgEmployment <- function(datasource = "ILO", dataVersionILO = "Aug23") {
calcValidAgEmployment <- function(datasource = "ILO", dataVersionILO = "Aug24") {

if (datasource == "ILO") {
agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE)[, , c("Livestock", "Crops")]
Expand Down
15 changes: 9 additions & 6 deletions R/calcValidAgFFGDP.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @title calcValidAgFFGDP
#' @description validation for agricultural, fisheries, forestry value added gdp (Million 05USD)
#' @description validation for agricultural, fisheries, forestry value added gdp (Million 17USD)
#' @param datasource datasource for validation (WDI)
#' @return List of magpie object with results on country level, no weight, unit and description.
#' @author David Chen
Expand All @@ -14,16 +14,19 @@ calcValidAgFFGDP <- function(datasource = "WDI") {

# This data is currently in constant 2015 US$MER.
agffVA <- madrat::readSource("WDI", subtype = "NV.AGR.TOTL.KD")
# Convert to constant 2005 US$MER.
agffVA05 <- GDPuc::convertGDP(agffVA, "constant 2015 US$MER", "constant 2005 US$MER", replace_NAs = c("linear", 0))
# Convert to constant 2017 US$MER.
agffVA17 <- GDPuc::convertGDP(agffVA,
"constant 2015 US$MER",
"constant 2017 US$MER",
replace_NAs = c("linear", 0))

out <- agffVA05
magclass::getNames(out) <- "Value|Agriculture, Forestry and Fisheries GDP (million US$05/yr)"
out <- agffVA17
magclass::getNames(out) <- "Value|Agriculture, Forestry and Fisheries GDP (million US$2017/yr)"
out <- magclass::add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- magclass::add_dimension(out, dim = 3.2, add = "model", nm = "WDI")

list(x = out,
weight = NULL,
unit = "million US$05/yr",
unit = "million US$2017/yr",
description = "Agriculture Fisheries Forestry Value added GDP")
}
4 changes: 2 additions & 2 deletions R/calcValidAgGDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ calcValidAgGDP <- function(datasource = "FAO") {
stop("unknown datasource")
}

getNames(out) <- "Value|Agriculture GDP (million US$05/yr)"
getNames(out) <- "Value|Agriculture GDP (million US$2017/yr)"
out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

return(list(x = out,
weight = NULL,
unit = "million US$05/yr",
unit = "million US$2017/yr",
description = "Agriculture Value added GDP"))
}
10 changes: 7 additions & 3 deletions R/calcValidConsumptionValue.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ calcValidConsumptionValue<- function(datasource="FAO") {

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

#Price consumers (World Prices)
prices_kall_con<-setYears(calcOutput("IniFoodPrice",products = "kall",aggregate=FALSE),NULL)
Expand All @@ -29,12 +33,12 @@ calcValidConsumptionValue<- function(datasource="FAO") {
}else{
stop("unknown datasource")}

getNames(out) <- "Value|Consumption Value (million US$05/yr)"
getNames(out) <- "Value|Consumption Value (million US$2017/yr)"
out <- add_dimension(out, dim=3.1, add="scenario", nm="historical")
out <- add_dimension(out, dim=3.2, add="model", nm=datasource)

return(list(x=out,
weight=NULL,
unit="million US$05/yr",
unit="million US$17/yr",
description="Consumption Value"))
}
4 changes: 2 additions & 2 deletions R/calcValidCostsAEI.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ calcValidCostsAEI <- function(datasource = "IMPACT") {
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)
out <- add_dimension(out, dim = 3.3, add = "variable", nm = "Costs|AEI")

getNames(out) <- paste(getNames(out), "(million US$05/yr)", sep = " ")
unit <- "million US$05/yr"
getNames(out) <- paste(getNames(out), "(million US$2017/yr)", sep = " ")
unit <- "million US$2017/yr"

} else {
stop("So far only IMPACT irrigation investment costs available!")
Expand Down
6 changes: 3 additions & 3 deletions R/calcValidCostsCapStocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ calcValidCostsCapStocks <- function(datasource="FAO") {


getNames(CapitalStocks)<-"Costs|Capital Stocks"
getNames(CapitalStocks) <- paste0(getNames(CapitalStocks)," (million US$05)")
getNames(CapitalStocks) <- paste0(getNames(CapitalStocks)," (million US$2017)")

units = "million US$05/yr"
units = "million US$2017/yr"


out<- add_dimension(CapitalStocks, dim=3.1, add="scenario", nm="historical")
Expand All @@ -33,6 +33,6 @@ calcValidCostsCapStocks <- function(datasource="FAO") {

return(list(x=out,weight=weight,
unit=units,
description="Validation for capital stocks (million US$05/yr)"))
description="Validation for capital stocks (million US$2017/yr)"))

}
4 changes: 2 additions & 2 deletions R/calcValidCostsFertilizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ calcValidCostsFertilizer <- function(datasource = "FAO") {
years <- intersect(getItems(totalUseNutrients, dim = 2), getItems(fertPriceNutrient, dim = 2))

fertilizerCosts <- totalUseNutrients[, years, ] * fertPriceNutrient[, years, ] / 1e6
getNames(fertilizerCosts) <- paste0("Costs|Fertilizer (million US$05/yr)")
getNames(fertilizerCosts) <- paste0("Costs|Fertilizer (million US$2017/yr)")
getSets(fertilizerCosts) <- c("region", "year", "variable")

fertilizerCosts <- add_dimension(fertilizerCosts, dim = 3.1, add = "scenario", nm = "historical")
fertilizerCosts <- add_dimension(fertilizerCosts, dim = 3.2, add = "model", nm = datasource)
weight <- NULL
units <- "(million US$MER05/yr)"
units <- "(million US$2017/yr)"
} else {
stop("Datasource not valid")
}
Expand Down
4 changes: 2 additions & 2 deletions R/calcValidCostsLabor.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ calcValidCostsLabor <- function(datasource = "Vittis") {
labor_costs <- summationhelper(labor_costs)
labor_costs <- labor_costs[,, reporting_names, pmatch = "right"]

getNames(labor_costs) <- paste0(getNames(labor_costs), " (million US$05/yr)")
getNames(labor_costs) <- paste0(getNames(labor_costs), " (million US$2017/yr)")
getSets(labor_costs) <- c("region", "year", "variable")
labor_costs <- add_dimension(labor_costs, dim = 3.1, add = "scenario", nm = "historical")
labor_costs <- add_dimension(labor_costs, dim = 3.2, add = "model", nm = datasource)

weight <- NULL
unit <- "million US$05/yr"
unit <- "million US$2017/yr"
} else {
stop("Datasource not valid")
}
Expand Down
10 changes: 5 additions & 5 deletions R/calcValidCostsOverall.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title calcValidCostsOverall
#' @description Returns historical values of the overall value of production for the Agricultural,
#' Forestry sectors, and fisheries (mio.05USD)
#' Forestry sectors, and fisheries (mio.17USD)
#' @param datasource datasource for validation. FAO Value of Production dataset.
#' @return List of magpie object with results on country level, no weight, unit and description.
#' @author Edna J. Molina Bacca
Expand All @@ -15,23 +15,23 @@ calcValidCostsOverall <- function(datasource = "FAO") {

if (datasource == "FAO") {

# Value of Production in mio. 05USDmer units
# Value of Production in mio. 17USDmer units
x <- dimSums(calcOutput("VoPAFF", aggregate = FALSE), dim = 3.1)


getNames(x) <- paste0("Costs|Gross value of production (million US$05/yr)")
getNames(x) <- paste0("Costs|Gross value of production (million US$2017/yr)")
x <- add_dimension(x, dim = 3.1, add = "scenario", nm = "historical")
x <- add_dimension(x, dim = 3.2, add = "model", nm = datasource)

weight <- NULL
units <- "(million US$05/yr)"
units <- "(million US$2017/yr)"

} else {
warning("Only FAO datasource available")
}

return(list(x = x, weight = weight,
unit = units,
description = "Validation for overall costs indicators(million US$05/yr)"))
description = "Validation for overall costs indicators(million US$2017/yr)"))

}
4 changes: 2 additions & 2 deletions R/calcValidCostsTC.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ calcValidCostsTC<-function(datasource="Pardey"){

out <- readSource("PardeyAgRD",convert=TRUE)
getNames(out) <- "Costs|TC"
getNames(out) <- paste(getNames(out), "(million US$05/yr)", sep=" ")
unit <- "(million US$MER05/yr)"
getNames(out) <- paste(getNames(out), "(million US$2017/yr)", sep=" ")
unit <- "(million US$MER2017/yr)"


out <- add_dimension(out, dim=3.1, add="scenario", nm="historical")
Expand Down
8 changes: 4 additions & 4 deletions R/calcValidCostsTransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ calcValidCostsTransport <- function(datasource = "GTAPtransport") {
out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

getNames(out) <- paste(getNames(out), "(million US$05/yr)", sep = " ")
unit <- "million US$05/yr"
getNames(out) <- paste(getNames(out), "(million US$2017/yr)", sep = " ")
unit <- "million US$2017/yr"

} else if (datasource == "MAgPIEcalc") {

Expand Down Expand Up @@ -130,8 +130,8 @@ calcValidCostsTransport <- function(datasource = "GTAPtransport") {
detail = FALSE)
out <- summationhelper(out)

getNames(out) <- paste(getNames(out), "(million US$05/yr)", sep = " ")
unit <- "million US$05/yr"
getNames(out) <- paste(getNames(out), "(million US$2017/yr)", sep = " ")
unit <- "million US$17/yr"

out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)
Expand Down
20 changes: 4 additions & 16 deletions R/calcValidCostsTransport.R.orig
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ calcValidCostsTransport <- function(datasource = "GTAPtransport") {
out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

getNames(out) <- paste(getNames(out), "(million US$05/yr)", sep = " ")
unit <- "million US$05/yr"
getNames(out) <- paste(getNames(out), "(million US$2017/yr)", sep = " ")
unit <- "million US$2017/yr"

} else if (datasource == "MAgPIEcalc") {

Expand All @@ -116,28 +116,16 @@ calcValidCostsTransport <- function(datasource = "GTAPtransport") {
# total costs
out <- costs[, , products] * productionDistance[, , products]

<<<<<<< HEAD
# aggregate to country-level
out <- dimSums(out, dim = c(1.1, 1.2))
out <- toolCountryFill(out, fill = 0)

# add missing product groups, so that report and summation helper work properly.
# Note that forest, secondary, fish, bioenergy and residues set to 0 currently
missingProducts <- setdiff(findset("kall"), products)
out <- add_columns(out, addnm = missingProducts, dim = 3.1)
out[, , missingProducts] <- 0
=======
mapping <- toolGetMapping(name = "CountryToCellMapping.csv", type = "cell", where = "mappingfolder")
out <- toolAggregate(out, rel = mapping, from = "celliso", to = "iso", dim = 1)
out <- toolCountryFill(out, fill = 0)
>>>>>>> master

out <- reporthelper(out, dim = 3.1, level_zero_name = "Costs|Transport", partly = TRUE,
detail = FALSE)
out <- summationhelper(out)

getNames(out) <- paste(getNames(out), "(million US$05/yr)", sep = " ")
unit <- "million US$05/yr"
getNames(out) <- paste(getNames(out), "(million US$2017/yr)", sep = " ")
unit <- "million US$2017/yr"

out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)
Expand Down
2 changes: 1 addition & 1 deletion R/calcValidFoodExpenditure.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ calcValidFoodExpenditure <- function(detail=FALSE) {

return(list(x=out2,
weight=pop,
unit="USD/capita",
unit="US$2017/capita",
description="Per-capita expenditure for food"))
}
2 changes: 1 addition & 1 deletion R/calcValidFoodExpenditureShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ calcValidFoodExpenditureShare <- function(detail=FALSE) {

return(list(x=expenditure_shr,
weight=gdp*pop,
unit="USD/USD",
unit="US$2017/US$2017",
description="Share of expenditure for different food items"))
}
6 changes: 3 additions & 3 deletions R/calcValidHourlyLaborCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' }
#'

calcValidHourlyLaborCosts <- function(datasource = "ILO_completed", dataVersionILO = "Aug23") {
calcValidHourlyLaborCosts <- function(datasource = "ILO_completed", dataVersionILO = "Aug24") {

if (datasource == "ILO_completed") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", dataVersionILO = dataVersionILO,
Expand Down Expand Up @@ -54,7 +54,7 @@ calcValidHourlyLaborCosts <- function(datasource = "ILO_completed", dataVersionI
stop("Datsource not available")
}

hourlyCosts <- setNames(hourlyCosts, "Labor|Wages|Hourly labor costs (USDMER05/h)")
hourlyCosts <- setNames(hourlyCosts, "Labor|Wages|Hourly labor costs (US$2017/h)")

# total hours worked as weight for aggregation to world regions
agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE, subsectors = FALSE)
Expand All @@ -75,7 +75,7 @@ calcValidHourlyLaborCosts <- function(datasource = "ILO_completed", dataVersionI

return(list(x = out,
weight = weight,
unit = "USDMER05/h",
unit = "USD2017$MER/h",
description = description))

}
16 changes: 8 additions & 8 deletions R/calcValidIncome.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") {
add_dimension(collapseNames(x), dim = 3.2, add = "variable", nm = nm)
}

names <- c("Income (million US$05 MER/yr)",
"Income (US$05 MER/cap/yr)",
"Income (million US$05 PPP/yr)",
"Income (US$05 PPP/cap/yr)")
names <- c("Income (million US$2017 MER/yr)",
"Income (US$2017 MER/cap/yr)",
"Income (million US$2017 PPP/yr)",
"Income (US$2017 PPP/cap/yr)")

mer <- .tmp(calcOutput("GDP", unit = "constant 2005 US$MER", naming = "scenario", aggregate = FALSE), names[1])
merpc <- .tmp(calcOutput("GDPpc", unit = "constant 2005 US$MER", naming = "scenario", aggregate = FALSE), names[2])
mer <- .tmp(calcOutput("GDP", unit = "constant 2017 US$MER", naming = "scenario", aggregate = FALSE), names[1])
merpc <- .tmp(calcOutput("GDPpc", unit = "constant 2017 US$MER", naming = "scenario", aggregate = FALSE), names[2])
ppp <- .tmp(calcOutput("GDP", naming = "scenario", aggregate = FALSE), names[3])
ppppc <- .tmp(calcOutput("GDPpc", naming = "scenario", aggregate = FALSE), names[4])

Expand All @@ -41,7 +41,7 @@ calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") {

# Setting weights correctly for intensive and extensive variables
popWeights <- collapseNames(calcOutput(type = "GDPpc",
unit = "constant 2005 US$MER",
unit = "constant 2017 US$MER",
naming = "scenario",
supplementary = TRUE,
aggregate = FALSE)$weight
Expand All @@ -67,7 +67,7 @@ calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") {
return(list(x = out,
weight = weight,
mixed_aggregation = TRUE,
unit = "(million) US Dollar 2005 equivalents in MER/yr, MER/cap/yr, PPP/yr, PPP/cap/yr",
unit = "(million) US Dollar 2017 equivalents in MER/yr, MER/cap/yr, PPP/yr, PPP/cap/yr",
description = "Income")
)
}
8 changes: 4 additions & 4 deletions R/calcValidPriceAgriculture.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title calcValidPriceAgriculture
#'
#' @description provides global prices from the IMPACT model projections, World Bank observations, and FAO
#' obersvations for MAgPIE commodities in $/tDM
#' obersvations for MAgPIE commodities in $2017/tDM
#'
#' @param datasource Options of the source of data: \code{IMPACT3.2.2World_Price}, \code{FAO}, \code{FAOp} and \code{WBGEM}.
#'
Expand Down Expand Up @@ -45,15 +45,15 @@ calcValidPriceAgriculture <- function(datasource="FAO"){

if(!is.null(weight)){
dimnames(weight)[[3]] <- paste0("Prices|Agriculture|",reportingnames(dimnames(weight)[[3]]))
getNames(weight) <- paste0(getNames(weight)," (US$05/tDM)")
getNames(weight) <- paste0(getNames(weight)," (US$2017/tDM)")
}

getNames(x) <- paste0(getNames(x)," (US$05/tDM)")
getNames(x) <- paste0(getNames(x)," (US$2017/tDM)")


return(list(x=x,
weight=weight,
unit="US$05/tDM",
unit="US$2017/tDM",
description=description,
isocountries=isocountries))
}
Loading

0 comments on commit 10107d4

Please sign in to comment.