-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
130 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
# maybe rename to loss? | ||
#' @title calcLossShare | ||
#' @description Calculates share of domestic supply wasted | ||
#' | ||
#' @return List of magpie object with results and weight on country or cellular level, unit and description. | ||
#' @author Benjamin Leon Bodirsky | ||
#' @examples | ||
#' \dontrun{ | ||
#' calcOutput("LossShare") | ||
#' } | ||
#' @importFrom magpiesets findset | ||
|
||
calcLossShare <- function() { | ||
|
||
massbalance <- calcOutput("FAOmassbalance", aggregate = FALSE) | ||
|
||
# connected to domestic supply, as FAOSTATS flossary states that | ||
# "Waste is often estimated as a fixed percentage of availability, the latter | ||
# being defined as production plus imports plus stock withdrawals." | ||
wasteshr <- dimSums(massbalance[, , "waste"][, , "dm"], | ||
dim = c(3.2, 3.3)) / dimSums(massbalance[, , "domestic_supply"][, , "dm"], | ||
dim = c(3.2, 3.3)) | ||
weight <- dimSums(massbalance[, , "domestic_supply"][, , "dm"], dim = c(3.2, 3.3)) | ||
wasteshr <- | ||
dimSums(massbalance[, , "waste"][, , "dm"], dim = c(3.2, 3.3)) / | ||
dimSums(massbalance[, , "domestic_supply"][, , "dm"], dim = c(3.2, 3.3)) | ||
weight <- | ||
dimSums(massbalance[, , "domestic_supply"][, , "dm"], dim = c(3.2, 3.3)) | ||
newproducts <- c("begr", "betr", "scp") | ||
#assume a waste share of 1 percent for begr, betr and scp | ||
|
||
# assume a waste share of 1 percent for begr, betr and scp | ||
wasteshr[, , newproducts] <- 0.01 | ||
weight[, , newproducts] <- 1 | ||
wasteshr[, , "pasture"] <- 0 | ||
weight[, , newproducts] <- 1 | ||
wasteshr[, , "pasture"] <- 0 | ||
wasteshr[is.na(wasteshr)] <- 0 | ||
weight[wasteshr == Inf] <- 0 | ||
weight[wasteshr == Inf] <- 0 | ||
wasteshr[wasteshr == Inf] <- 0 | ||
|
||
wasteshr <- toolHoldConstantBeyondEnd(wasteshr) | ||
weight <- toolHoldConstantBeyondEnd(weight) | ||
|
||
weight <- toolHoldConstantBeyondEnd(weight) + 10^-10 | ||
|
||
return(list(x = wasteshr, weight = weight, unit = "DM share, weight: domestic supply", | ||
return(list(x = wasteshr, | ||
weight = weight, | ||
unit = "DM share, weight: domestic supply", | ||
description = "Share of domestic supply wasted")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
#' @title calcSeedShare | ||
#' @description Calculates Seed share (seed demand per production) | ||
#' | ||
#' @return List of magpie object with results and weight on country or cellular level, unit and description. | ||
#' @author Benjamin Leon Bodirsky | ||
#' @examples | ||
#' \dontrun{ | ||
#' calcOutput("SeedShare") | ||
#' } | ||
#' @importFrom magpiesets findset | ||
|
||
calcSeedShare<-function(){ | ||
massbalance<-calcOutput("FAOmassbalance",aggregate=F) | ||
kcr<-findset("kcr") | ||
seedshr<-dimSums(massbalance[,,"seed"][,,"dm"][,,kcr],dim=c(3.2,3.3))/dimSums(massbalance[,,"production"][,,"dm"][,,kcr],dim=c(3.2,3.3)) | ||
weight<-dimSums(massbalance[,,"production"][,,"dm"][,,kcr],dim=c(3.2,3.3)) | ||
|
||
#assume a seed share of 1 percent for begr and betr | ||
seedshr[,,c("begr","betr")]<-0.01 | ||
weight[,,c("begr","betr")]<-1 | ||
seedshr[is.nan(seedshr)]<-0 | ||
weight[seedshr==Inf]<-0 | ||
seedshr[seedshr==Inf]<-0 | ||
calcSeedShare <- function() { | ||
|
||
seedshr <- toolHoldConstantBeyondEnd(seedshr) | ||
weight <- toolHoldConstantBeyondEnd(weight) | ||
|
||
return(list(x=seedshr,weight=weight,unit="DM share, weight: production quantity",description="Share of production used as seed")) | ||
massbalance <- calcOutput("FAOmassbalance", aggregate = FALSE) | ||
kcr <- findset("kcr") | ||
seedshr <- | ||
dimSums(massbalance[, , "seed"][, , "dm"][, , kcr], dim = c(3.2, 3.3)) / | ||
dimSums(massbalance[, , "production"][, , "dm"][, , kcr], dim = c(3.2, 3.3)) | ||
weight <- dimSums(massbalance[, , "production"][, , "dm"][, , kcr], dim = c(3.2, 3.3)) | ||
|
||
# assume a seed share of 1 percent for begr and betr | ||
seedshr[, , c("begr", "betr")] <- 0.01 | ||
weight[, , c("begr", "betr")] <- 1 | ||
seedshr[is.nan(seedshr)] <- 0 | ||
weight[seedshr == Inf] <- 0 | ||
seedshr[seedshr == Inf] <- 0 | ||
|
||
seedshr <- mstools::toolHoldConstantBeyondEnd(seedshr) | ||
weight <- mstools::toolHoldConstantBeyondEnd(weight) + 10^-10 | ||
|
||
return(list(x = seedshr, | ||
weight = weight, | ||
unit = "DM share, weight: production quantity", | ||
description = "Share of production used as seed")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.