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

Bugfix SCP "mixed" scenario + "kfo_rd" set added to config file #270

Merged
merged 15 commits into from
Apr 30, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **51_nitrogen** New calculations for emissions from agricultural residues (vm_res_ag_burn)

### added
- **config** The set "kfo_rd" (livst_rum, livst_milk), which is used in the food substitution scenarios c15_rumdairy_scp_scen and c15_rumdairyscen, has been added to the default.cfg file. This allows for sensitivity scenarios (e.g. only livst_milk or only livst_rum).

### removed

### fixed
- **20_processing** The "mixed" scenario for single-cell protein production (c20_scp_type) was not working as expected. The corresponding code in 20_processing has been updated.


## [4.3.3] - 2021-03-30
Expand Down
18 changes: 14 additions & 4 deletions config/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cfg$input <- c("isimip_rcp-IPSL_CM5A_LR-rcp2p6-co2_rev52_c200_690d3718e151be1b45
"rev4.58_h12_magpie.tgz",
"rev4.58_h12_validation.tgz",
"calibration_H12_c200_23Feb21.tgz",
"additional_data_rev3.99.tgz")
"additional_data_rev4.00.tgz")

#a list of repositories (please pay attention to the list format!) in which the
#files should be searched for. Files will be searched in all repositories until
Expand Down Expand Up @@ -281,6 +281,11 @@ cfg$gms$c15_livescen <- "constant" # def = constant
cfg$gms$c15_rumdairy_scp_scen <- "constant" # def = constant
cfg$gms$c15_rumdairyscen <- "constant" # def = constant

# * Set items of kfo_rd. This option allows for sensitivity scenarios (e.g. only livst_milk).
# * kfo_rd is used in the food substitution scenarios c15_rumdairy_scp_scen and c15_rumdairyscen (see above)
# * options: "livst_rum,livst_milk", "livst_rum" or "livst_milk"
cfg$gms$kfo_rd <- "livst_rum,livst_milk" #def = livst_rum,livst_milk

# * Reduction of livestock products towards a kcal/cap/day intake target with or w/o substitution
# * maximum kcal/cap/day intake target used for downwards convergence of livestock products
cfg$gms$s15_kcal_pc_livestock_intake_target <- "430" # def = 430
Expand Down Expand Up @@ -374,9 +379,14 @@ cfg$gms$c18_burn_scen <- "phaseout" # def = phaseout
# * (off): off
cfg$gms$processing <- "substitution_dec18" # def = substitution_dec18

# * SCP type
# * mixed, methane, sugar, cellulose, hydrogen
cfg$gms$c20_scp_type <- "mixed" # def = mixed
# * SCP route
# * single-cell microbial protein production route
# * options: mixed, methane, sugar, cellulose, hydrogen
# * Mapping of scp route to feedstock: methane:foddr, sugar:sugar_cane, cellulose:begr
# * Note that hydrogen does not require land-based inputs
# * Mixed assumes equal shares of methane, sugar, cellulose and hydrogen
#
cfg$gms$c20_scp_type <- "sugar" # def = sugar
flohump marked this conversation as resolved.
Show resolved Hide resolved

# ***--------------------- 21_trade --------------------------------------
# * (free_apr16): free trade without restrictions
Expand Down
52 changes: 24 additions & 28 deletions main.gms
Original file line number Diff line number Diff line change
Expand Up @@ -145,50 +145,46 @@ $title magpie
*' * Always try to access model outputs through the corresponding magpie package instead of accessing them directly with readGDX. It cannot be guaranteed that your script will work in the future if you do otherwise (as only the corresponding magpie package will be continuously adapted to changes in the GAMS code).

*##################### R SECTION START (VERSION INFO) ##########################
*
*
* Used data set: isimip_rcp-IPSL_CM5A_LR-rcp2p6-co2_rev52_c200_690d3718e151be1b450b394c1064b1c5.tgz
* md5sum: NA
* Repository: scp://cluster.pik-potsdam.de/p/projects/landuse/data/input/archive
*
* Repository: https://rse.pik-potsdam.de/data/magpie/public
*
* Used data set: rev4.58_h12_magpie.tgz
* md5sum: NA
* Repository: scp://cluster.pik-potsdam.de/p/projects/rd3mod/inputdata/output
*
* Repository: https://rse.pik-potsdam.de/data/magpie/public
*
* Used data set: rev4.58_h12_validation.tgz
* md5sum: NA
* Repository: scp://cluster.pik-potsdam.de/p/projects/rd3mod/inputdata/output
*
* Repository: https://rse.pik-potsdam.de/data/magpie/public
*
* Used data set: calibration_H12_c200_23Feb21.tgz
* md5sum: NA
* Repository: scp://cluster.pik-potsdam.de/p/projects/landuse/data/input/calibration
*
* Used data set: additional_data_rev3.98.tgz
* md5sum: NA
* Repository: scp://cluster.pik-potsdam.de/p/projects/landuse/data/input/archive
*
* Used data set: patch_f44_bii_coeff.tgz
* md5sum: 82efe7f8e96763a815944b7751a7e47e
* Repository: ../patch_inputdata
*
* Repository: https://rse.pik-potsdam.de/data/magpie/public
*
* Used data set: additional_data_rev4.00.tgz
* md5sum: 0d25d76eb2e080c8d42f92265b05bbfc
* Repository: /Users/flo/OneDrive/Dokumente/PIK/Development/input_data/
*
* Low resolution: c200
* High resolution: 0.5
*
*
* Total number of cells: 200
*
*
* Number of cells per region:
* CAZ CHA EUR IND JPN LAM MEA NEU OAS REF SSA USA
* 28 24 10 7 3 53 17 8 22 7 11 10
*
*
* Regionscode: 690d3718e151be1b450b394c1064b1c5
*
*
* Regions data revision: 4.58
*
*
* lpj2magpie settings:
* * LPJmL data folder: /p/projects/landuse/data/input/lpj_input/isimip_rcp/IPSL_CM5A_LR/rcp2p6/co2
* * Additional input folder: /p/projects/landuse/data/input/other/rev52
* * Revision: 52
* * Call: lpj2magpie(input_folder = path(cfg$lpj_input_folder, gsub("-", "/", cfg$input)), input2_folder = path(cfg$additional_input_folder, paste("rev", floor(cfg$revision), sep = "")), output_file = lpj2magpie_file, rev = cfg$revision)
*
*
* aggregation settings:
* * Input resolution: 0.5
* * Output resolution: c200
Expand All @@ -198,11 +194,11 @@ $title magpie
* * (clustering) n-repeat: 5
* * (clustering) n-redistribute: 0
* * Call: aggregation(input_file = lpj2magpie_file, regionmapping = paste0("../", cfg$regionmapping), output_file = aggregation_file, rev = cfg$revision, res_high = cfg$high_res, res_low = cfg$low_res, hcells = cfg$highres_cells, weight = cfg$cluster_weight, nrepeat = cfg$nrepeat, nredistribute = cfg$nredistribute, sum_spam_file = cfg$spamfile, debug = FALSE, seed = cfg$seed)
*
*
*
* Last modification (input data): Tue Mar 09 18:23:34 2021
*
*
*
*
* Last modification (input data): Sat Apr 24 11:43:21 2021
*
*###################### R SECTION END (VERSION INFO) ###########################

$offupper
Expand Down
3 changes: 3 additions & 0 deletions modules/15_food/anthropometrics_jan18/input.gms
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ sets
VIR,VNM,VUT,WLF,WSM,YEM,ZAF,ZMB,ZWE /
;

$onMultiR
Copy link
Member

Choose a reason for hiding this comment

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

why do you need $onMultiR here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the set kfo_rd needs to be defined in sets.gms (some declarations depend on kfo_rd) and then overwritten in input.gms.

set kfo_rd(kfo) Ruminant meat and dairy food products / livst_rum,livst_milk /;
$offMulti

scalar s15_elastic_demand Elastic demand switch (1=elastic 0=exogenous) (1) / 0 /;

Expand Down
2 changes: 1 addition & 1 deletion modules/20_processing/input/files
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ f20_processing_shares.cs3
f20_processing_conversion_factors.cs3
f20_processing_balanceflow.cs3
f20_processing_unitcosts.cs3
f20_scp_conversionmatrix.csv
f20_scp_processing_shares.csv
f20_scp_type_shr.csv
f20_scp_unitcosts.csv
1 change: 0 additions & 1 deletion modules/20_processing/off/not_used.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
name,type,reason
vm_dem_food,input,questionnaire
fm_attributes,input,questionnaire
sm_fix_SSP2,input, not needed
2 changes: 0 additions & 2 deletions modules/20_processing/substitution_dec18/declarations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ parameters
i20_processing_shares(t_all,i,ksd,kpr) Shares of secondary products coming from a primary product (1)
i20_processing_conversion_factors(t_all,processing20,ksd,kpr) Conversion factors of primary products into secondary products (1)
i20_processing_unitcosts(ksd,kpr) Costs of transforming x units kpr into 1 unit ksd (USD05MER per tDM)
i20_scp_type_shr(t_all,scptype) Share of SCP each type (1)
i20_scp_conversion_factors(t_all,kpr) SCP conversion factors (1)
;


Expand Down
10 changes: 5 additions & 5 deletions modules/20_processing/substitution_dec18/equations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ q20_processing_substitution_brans(i2) ..
*' and extrapolated from the related literature (e.g. @adanacioglu_profitability_2011, @pikaar_decoupling_2018, @valco_thecost_2016)
*' complemented with best educated guess by the module authors.
*' Costs for single-cell protein production (scp) are handled differently because
*' scp production with hydrogen as substrate (scp_hydrogen) has no land requirements, and thus
*' would have no costs (`i20_processing_conversion_factors` is 0 for scp_hydrogen).
*' All other scp production routes (scp_methane,scp_sugar,scp_cellulose) have land requirements
*' mapped to specific crops (`f20_scp_conversionmatrix`).
*' scp production with hydrogen as substrate has no land requirements, and thus
*' would have no cost.
*' All other scp production routes (mixed, methane, sugar and cellulose) have land requirements
*' mapped to specific crops (`f20_scp_processing_shares`).

q20_processing_costs(i2) ..
vm_cost_processing(i2) =e=
sum((ksd,processing20,kpr), v20_dem_processing(i2,processing20,kpr)
flohump marked this conversation as resolved.
Show resolved Hide resolved
*sum(ct,i20_processing_conversion_factors(ct,processing20,ksd,kpr))
* i20_processing_unitcosts(ksd,kpr))
+ (vm_prod_reg(i2,"scp") * sum(scptype, sum(ct, i20_scp_type_shr(ct,scptype)) * f20_scp_unitcosts(scptype)));
+ (vm_prod_reg(i2,"scp") * sum(scptype, sum(ct, f20_scp_type_shr(scptype,"%c20_scp_type%")) * f20_scp_unitcosts(scptype)));
;

*' Finally, we assume that any substitution of one product by another,
Expand Down
8 changes: 4 additions & 4 deletions modules/20_processing/substitution_dec18/input.gms
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*** | MAgPIE License Exception, version 1.0 (see LICENSE file).
*** | Contact: magpie@pik-potsdam.de

$setglobal c20_scp_type mixed
$setglobal c20_scp_type sugar

table f20_processing_balanceflow(t_all,i,ksd) Processing balance flow (mio. tDM)
$ondelim
Expand Down Expand Up @@ -42,10 +42,10 @@ $ondelim
$include "./modules/20_processing/input/f20_scp_type_shr.csv"
$offdelim;

table f20_scp_conversionmatrix(kpr,scptype) Conversion matrix to derive tons of feedstock from tons of production (DM)
table f20_scp_processing_shares(kpr,scen20) Feedstock processing shares for SCP in different scenarios (1)
$ondelim
$include "./modules/20_processing/input/f20_scp_conversionmatrix.csv"
$offdelim ;
$include "./modules/20_processing/input/f20_scp_processing_shares.csv"
$offdelim;

parameter f20_scp_unitcosts(scptype) Costs of production of one unit of SCP exclusive of feedstock costs (USD per tDM)
/
Expand Down
20 changes: 2 additions & 18 deletions modules/20_processing/substitution_dec18/preloop.gms
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
*** | Contact: magpie@pik-potsdam.de


loop(t_all,
if(m_year(t_all) <= sm_fix_SSP2,
i20_scp_type_shr(t_all,scptype) = f20_scp_type_shr(scptype,"mixed");
else
i20_scp_type_shr(t_all,scptype) = f20_scp_type_shr(scptype,"%c20_scp_type%");
);
);

i20_processing_conversion_factors(t_all,processing20,ksd,kpr) = f20_processing_conversion_factors(t_all,processing20,ksd,kpr);
i20_processing_shares(t_all,i,ksd,kpr) = f20_processing_shares(t_all,i,ksd,kpr);
i20_processing_unitcosts(ksd,kpr) = f20_processing_unitcosts(ksd,kpr);
Expand All @@ -23,14 +15,6 @@ i20_processing_unitcosts(ksd,kpr) = f20_processing_unitcosts(ksd,kpr);
*To avoid double accounting the processing costs of scp_methane, scp_sugar and scp_cellulose are set to zero.
i20_processing_unitcosts("scp",kpr) = 0;

*SCP can be produced via different routes. The feedstock conversion_factor for SCP accounts for the mix of SCP routes.
i20_scp_conversion_factors(t_all,kpr) = sum(scptype,i20_scp_type_shr(t_all,scptype)*f20_scp_conversionmatrix(kpr,scptype));
i20_processing_conversion_factors(t,"breeding","scp",kpr) = i20_scp_conversion_factors(t,kpr);
*Processing shares for SCP depend on the type of SCP conversion.
*In case of scp_hydrogen no land-based feedstock is needed. Therefore, the conversion factor is 0, and the processing shares are set to 0.
*In all other cases (scp_methane,scp_sugar,scp_cellulose) exactly one land-based feedstock is needed (foddr,sugr_cane,begr).
*Therefore, the share of the respective feedstock is set to 1.
*SCP can be produced via different routes. The processing shares for SCP are scenario dependent (c20_scp_type).
i20_processing_shares(t_all,i,"scp",kpr) = 0;
i20_processing_shares(t_all,i,"scp",kpr)$(i20_scp_conversion_factors(t_all,kpr) > 0) = 1;


i20_processing_shares(t_all,i,"scp",kpr) = f20_scp_processing_shares(kpr,"%c20_scp_type%");
4 changes: 2 additions & 2 deletions modules/30_crop/endo_jun13/declarations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ parameters
oq30_rotation_min(t,j,crp30,w,type) Local minimum rotational constraints (mio. ha)
oq30_prod(t,j,kcr,type) Production of cropped products (mio. tDM)
oq30_carbon(t,j,ag_pools,type) Cropland above ground carbon content calculation (mio. tC)
oq30_bv_ann(t,j,potnatveg,type) Biodiversity value of annual cropland
oq30_bv_per(t,j,potnatveg,type) Biodiversity value of perennial cropland
oq30_bv_ann(t,j,potnatveg,type) Biodiversity value of annual cropland (Mha)
oq30_bv_per(t,j,potnatveg,type) Biodiversity value of perennial cropland (Mha)
;
*##################### R SECTION END (OUTPUT DECLARATIONS) #####################

Expand Down
2 changes: 1 addition & 1 deletion modules/31_past/endo_jun13/declarations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters
oq31_carbon(t,j,ag_pools,type) Above ground carbon content calculation for pasture (mio tC)
oq31_cost_prod_past(t,i,type) Costs for putting animals on pastures (mio. USD05MER per yr)
oq31_bv_manpast(t,j,potnatveg,type) Biodiversity value for managed pastures (Mha)
oq31_bv_rangeland(t,j,potnatveg,type) Biodiversity value for rangeland (Mha)
oq31_bv_rangeland(t,j,potnatveg,type) Biodiversity value for managed pastures (Mha)
;
*##################### R SECTION END (OUTPUT DECLARATIONS) #####################

Expand Down
5 changes: 3 additions & 2 deletions modules/35_natveg/dynamic_feb21/declarations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ parameters
oq35_prod_primforest(t,j,type) Production of woody biomass from primary forests (mio. tDM per yr)
oq35_prod_other(t,j,type) Production of woody biomass from other land (mio. tDM per yr)
oq35_cost_hvarea(t,i,type) Cost of harvesting natural vegetation (mio. USD)
oq35_bv_primforest(t,j,potnatveg,type) Biodiversity value of primary forest (Mha)
oq35_bv_secdforest(t,j,potnatveg,type) Biodiversity value of secondary vegetation (Mha)
oq35_bv_primforest(t,j,potnatveg,type) Biodiversity value of primary forest (Mha)
oq35_bv_secdforest(t,j,potnatveg,type) Biodiversity value of secondary forest (Mha)
oq35_bv_other(t,j,potnatveg,type) Biodiversity value of other land (Mha)
;
*##################### R SECTION END (OUTPUT DECLARATIONS) #####################
20 changes: 12 additions & 8 deletions modules/35_natveg/dynamic_feb21/postsolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ p35_other(t,j,ac) = v35_other.l(j,ac);
oq35_prod_primforest(t,j,"marginal") = q35_prod_primforest.m(j);
oq35_prod_other(t,j,"marginal") = q35_prod_other.m(j);
oq35_cost_hvarea(t,i,"marginal") = q35_cost_hvarea.m(i);
oq35_bv_primforest(t,j,potnatveg,"marginal") = q35_bv_primforest.m(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"marginal") = q35_bv_secdforest.m(j,potnatveg);
oq35_bv_primforest(t,j,potnatveg,"marginal") = q35_bv_primforest.m(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"marginal") = q35_bv_secdforest.m(j,potnatveg);
oq35_bv_other(t,j,potnatveg,"marginal") = q35_bv_other.m(j,potnatveg);
ov35_secdforest(t,j,ac,"level") = v35_secdforest.l(j,ac);
ov35_other(t,j,ac,"level") = v35_other.l(j,ac);
ov_landdiff_natveg(t,"level") = vm_landdiff_natveg.l;
Expand Down Expand Up @@ -88,8 +89,9 @@ p35_other(t,j,ac) = v35_other.l(j,ac);
oq35_prod_primforest(t,j,"level") = q35_prod_primforest.l(j);
oq35_prod_other(t,j,"level") = q35_prod_other.l(j);
oq35_cost_hvarea(t,i,"level") = q35_cost_hvarea.l(i);
oq35_bv_primforest(t,j,potnatveg,"level") = q35_bv_primforest.l(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"level") = q35_bv_secdforest.l(j,potnatveg);
oq35_bv_primforest(t,j,potnatveg,"level") = q35_bv_primforest.l(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"level") = q35_bv_secdforest.l(j,potnatveg);
oq35_bv_other(t,j,potnatveg,"level") = q35_bv_other.l(j,potnatveg);
ov35_secdforest(t,j,ac,"upper") = v35_secdforest.up(j,ac);
ov35_other(t,j,ac,"upper") = v35_other.up(j,ac);
ov_landdiff_natveg(t,"upper") = vm_landdiff_natveg.up;
Expand Down Expand Up @@ -127,8 +129,9 @@ p35_other(t,j,ac) = v35_other.l(j,ac);
oq35_prod_primforest(t,j,"upper") = q35_prod_primforest.up(j);
oq35_prod_other(t,j,"upper") = q35_prod_other.up(j);
oq35_cost_hvarea(t,i,"upper") = q35_cost_hvarea.up(i);
oq35_bv_primforest(t,j,potnatveg,"upper") = q35_bv_primforest.up(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"upper") = q35_bv_secdforest.up(j,potnatveg);
oq35_bv_primforest(t,j,potnatveg,"upper") = q35_bv_primforest.up(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"upper") = q35_bv_secdforest.up(j,potnatveg);
oq35_bv_other(t,j,potnatveg,"upper") = q35_bv_other.up(j,potnatveg);
ov35_secdforest(t,j,ac,"lower") = v35_secdforest.lo(j,ac);
ov35_other(t,j,ac,"lower") = v35_other.lo(j,ac);
ov_landdiff_natveg(t,"lower") = vm_landdiff_natveg.lo;
Expand Down Expand Up @@ -166,6 +169,7 @@ p35_other(t,j,ac) = v35_other.l(j,ac);
oq35_prod_primforest(t,j,"lower") = q35_prod_primforest.lo(j);
oq35_prod_other(t,j,"lower") = q35_prod_other.lo(j);
oq35_cost_hvarea(t,i,"lower") = q35_cost_hvarea.lo(i);
oq35_bv_primforest(t,j,potnatveg,"lower") = q35_bv_primforest.lo(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"lower") = q35_bv_secdforest.lo(j,potnatveg);
oq35_bv_primforest(t,j,potnatveg,"lower") = q35_bv_primforest.lo(j,potnatveg);
oq35_bv_secdforest(t,j,potnatveg,"lower") = q35_bv_secdforest.lo(j,potnatveg);
oq35_bv_other(t,j,potnatveg,"lower") = q35_bv_other.lo(j,potnatveg);
*##################### R SECTION END (OUTPUT DEFINITIONS) ######################
8 changes: 4 additions & 4 deletions modules/44_biodiversity/bv_btc_mar21/declarations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ parameters
ov_cost_bv_loss(t,j,type) biodiversity value loss cost (mio USD)
ov_bv(t,j,landcover44,potnatveg,type) biodiversity value for all land cover classes (unweighted) (Mha)
ov44_bv_weighted(t,j,landcover44,type) range rarity weighted biodiversity value (Mha)
oq44_bv_loss(t,j,type) total biodiversity value loss constraint
oq44_diff_bv_landcover(t,j,landcover44,type) biodiversity value loss constraint per land class
oq44_bv_weighted(t,j,landcover44,type) biodiversity value stock constraint
oq44_cost_bv_loss(t,j,type) biodiversity value loss cost constraint
oq44_bv_loss(t,j,type) zotal biodiversity value loss constraint (Mha)
oq44_diff_bv_landcover(t,j,landcover44,type) biodiversity value loss constraint per land class (Mha)
oq44_bv_weighted(t,j,landcover44,type) biodiversity value stock constraint (Mha)
oq44_cost_bv_loss(t,j,type) biodiversity value loss cost constraint (mio USD)
;
*##################### R SECTION END (OUTPUT DECLARATIONS) #####################

Loading