Skip to content

Commit

Permalink
Merge branch 'f_pForest' of https://github.com/pvjeetze/magpie into f…
Browse files Browse the repository at this point in the history
…_pForest
  • Loading branch information
pvjeetze committed Jun 5, 2024
2 parents 05e3dc3 + 7c99ab6 commit a3cda4f
Show file tree
Hide file tree
Showing 19 changed files with 493 additions and 223 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]

### changed
- **41_area_equipped_for_irrigation** updated (non-default) AEI data (from Mehta2022 to Mehta2024)
- **22_land_conservation and default.cfg** Added options for baseline protection
- **15_food, default.cfg and scenario_config.csv** changed fader setup and introduced new switches for specifying food substitution scenarios and exogeneous food intake scenarios
- **70_livestock** default.cfg and scenario_config.csv** changed fader setup and introduced new switches for specifying feed substitution with SCP scenarios
Expand Down Expand Up @@ -52,13 +53,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- **35_natveg** removed growing stock calculation and calibration, which is no longer needed.

### fixed
- **14_yields** fix division by zero in preloop of managementcalib_aug19
- **extra/disaggregation** fixed bug in disaggregation of land conservation related to switch from 59k to 67k that produced erroneous outputs
- **44_biodiversity** avoid division by zero
- **scenario_config.csv** same revision for input files as in default.cfg
- **scenario_fsec.csv** scenario settings
- **start/projects/fsec.R** scenario settings
- **80_optimization** fixed a bug in nlp_apr17; cycling through CONOPT4, CONOPT4 without preprocessing and CONOPT3 was not working
- **58_peatland** Added balance variable to avoid random infeasibilites
- **scripts/start/test_runs.R** include all default output script, in particular disaggregation.R, which is needed for BII

## [4.7.3] - 2024-04-12

Expand Down
3 changes: 2 additions & 1 deletion config/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,8 @@ cfg$gms$area_equipped_for_irrigation <- "endo_apr13" # def = endo_apr13

# * switch for initialization area
# * (LUH2v2): area equipped for irrigation based on LUH2v2 irrigated areas
# * (Mehta2022): area equipped for irrigation from Mehta et al. (2022)
# * (Mehta2024_Siebert2013): area equipped for irrigation from Mehta et al. (2024) using GMIA (Siebert et al, 2013) base map
# * (Mehta2024_Meier2018): are equipped for irrigation from Mehta et al. (2024) using Meier et al. (2018) base map
cfg$gms$c41_initial_irrigation_area <- "LUH2v2" # def = LUH2v2

# * Sets the rate of depreciation of irrigation infrastructure in every timestep.
Expand Down
114 changes: 57 additions & 57 deletions config/scenario_config.csv
100644 → 100755

Large diffs are not rendered by default.

35 changes: 34 additions & 1 deletion literature.bib
Original file line number Diff line number Diff line change
Expand Up @@ -1023,14 +1023,47 @@ @article{siebert_FAO_2007
year = {2007},
}

@article{siebert_FAO_2007,
author = {Stefan Siebert and Petra Döll and Sebastian Feick and Jippe Hoogeveen and Karen Frenken},
year = {2007},
title = {Global Map of Irrigation Areas version 4.0.1.},
journal = {Johann Wolfgang Goethe University, Frankfurt am Main, Germany / Food and Agriculture Organization of the United Nations, Rome, Italy.},
url = {http://www.fao.org/nr/water/aquastat/irrigationmap/index10.stm},
}

@article{siebert_FAO_2013,
author = {Stefan Siebert, Verena Henrich, Karen Frenken and Jacob Burk},
year = {2013},
title = {Global Map of Irrigation Areas version 5},
journal = {Rheinische Friedrich-Wilhelms-University, Bonn, Germany / Food and Agriculture Organization of the United Nations, Rome, Italy},
url = {https://data.apps.fao.org/catalog/iso/f79213a0-88fd-11da-a88f-000d939bc5d8},
}

@article{meier_global_2018,
author = {Meier, Jonas; Zabel, Florian; Mauser, Wolfram},
year = {2018},
title = {Global Irrigated Areas dataset},
journal = {PANGAEA},
doi = {https://doi.org/10.1594/PANGAEA.884744},
url = {https://doi.pangaea.de/10.1594/PANGAEA.884744},
}

@article{mehta_half_2024,
author = {Mehta, P., Siebert, S., Kummu, M. et al.},
year = {2024},
title = {Half of twenty-first century global irrigation expansion has been in water-stressed regions},
journal = {Nature Water},
doi = {https://doi.org/10.1038/s44221-024-00206-9},
}

@book{fao_aquastat_2016,
address = {Rome},
title = {{AQUASTAT} core database},
publisher = {Food and Agriculture Organization of the United Nations (FAO)},
author = {{FAO}},
url = {{https://data.harvestportal.org/de/dataset/fao-aquastat/resource/c4668555-eb76-4882-83b1-230038e24f02?inner_span=True}},
year = {2016},
note = {Database accessed on 2023/02/06}
note = {Database accessed on 2023/02/06},
}

@techreport{worldbank_irrigation_1995,
Expand Down
2 changes: 1 addition & 1 deletion modules/10_land/landmatrix_dec18/presolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ vm_lu_transitions.up(j,"primforest","primforest") = Inf;

*' @stop

m_boundfix(vm_land,(j,land),up,10e-5);
m_boundfix(vm_land,(j,land),up,1e-6);
8 changes: 4 additions & 4 deletions modules/14_yields/managementcalib_aug19/preloop.gms
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ i14_croparea_total(t_all,w,j) = sum(kcr, fm_croparea(t_all,j,w,kcr));

i14_modeled_yields_hist(t_past,i,knbe14)
= (sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14) * f14_yields(t_past,j,knbe14,w)) /
sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14)))$(sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14))>0)
sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14)))$(sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14))>0.00001)
+ (sum((cell(i,j),w), i14_croparea_total(t_past,w,j) * f14_yields(t_past,j,knbe14,w)) /
sum((cell(i,j),w), i14_croparea_total(t_past,w,j)))$(sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14))=0);
sum((cell(i,j),w), i14_croparea_total(t_past,w,j)))$(sum((cell(i,j),w), fm_croparea(t_past,j,w,knbe14))<0.00001);


*' The factor `i14_lambda_yields` is calculated for the initial time step depending
Expand Down Expand Up @@ -127,9 +127,9 @@ if ((s14_calib_ir2rf = 1),
* Calibrate newly calibrated yields to FAO yields
i14_modeled_yields_hist2(i,knbe14)
= (sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14) * i14_yields_calib("y1995",j,knbe14,w)) /
sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14)))$(sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14))>0)
sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14)))$(sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14))>0.00001)
+ (sum((cell(i,j),w), i14_croparea_total("y1995",w,j) * f14_yields("y1995",j,knbe14,w)) /
sum((cell(i,j),w), i14_croparea_total("y1995",w,j)))$(sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14))=0);
sum((cell(i,j),w), i14_croparea_total("y1995",w,j)))$(sum((cell(i,j),w), fm_croparea("y1995",j,w,knbe14))<0.00001);

i14_yields_calib(t,j,knbe14,w) = sum((cell(i,j)), i14_fao_yields_hist("y1995",i,knbe14) /
i14_modeled_yields_hist2(i,knbe14)) *
Expand Down
3 changes: 2 additions & 1 deletion modules/35_natveg/pot_forest_may24/equations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ q35_secdforest_regeneration(j2)..

q35_other_regeneration(j2)..
sum(ac_est, vm_land_other(j2,"othernat",ac_est))
=g=
=e=
sum((othertype35,ac_sub),v35_hvarea_other(j2,othertype35,ac_sub))
+ vm_landexpansion(j2,"other")
;

*' The following two constraints distribute additions to secdforest and other land
Expand Down
25 changes: 18 additions & 7 deletions modules/35_natveg/pot_forest_may24/presolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ p35_forest_recovery_area(t,j,ac_est)$(sum(ac_est2, p35_forest_recovery_area(t,j,

* The proportion of secondary forest recovery in total natveg
* recovery is derived from the remaining forest recovery area
pc35_forest_recovery_shr(j) = (pc35_max_forest_recovery(j) - sum(ac_est, p35_forest_recovery_area(t,j,ac_est)))
/ (sum(land_ag, pcm_land(j,land_ag))+pcm_land(j,"urban")+1e-10);
pc35_forest_recovery_shr(j) = 0;
pc35_forest_recovery_shr(j)$((sum(land_ag, pcm_land(j,land_ag))+pcm_land(j,"urban")) > 0) =
(pc35_max_forest_recovery(j) - sum(ac_est, p35_forest_recovery_area(t,j,ac_est)))
/ (sum(land_ag, pcm_land(j,land_ag))+pcm_land(j,"urban"));
pc35_forest_recovery_shr(j)$(pc35_forest_recovery_shr(j) < 0) = 0;
pc35_forest_recovery_shr(j)$(pc35_forest_recovery_shr(j) > 1) = 1;
* Abandoned land pc35_land_other(j,"othernat",ac_est) that has not yet been allocated to
* p35_forest_recovery_area(t,j,ac_est) is then distributed proportionally using the forest recovery share.
p35_forest_recovery_area(t,j,ac_est) = p35_forest_recovery_area(t,j,ac_est)
+ (pc35_land_other(j,"othernat",ac_est) - p35_forest_recovery_area(t,j,ac_est))
* pc35_forest_recovery_shr(j);
p35_forest_recovery_area(t,j,ac_est)$(sum(ac_est2, p35_forest_recovery_area(t,j,ac_est2)) > pc35_max_forest_recovery(j)) = pc35_max_forest_recovery(j)/card(ac_est2);
p35_forest_recovery_area(t,j,ac_est)$(p35_forest_recovery_area(t,j,ac_est) > pc35_land_other(j,"othernat",ac_est)) = pc35_land_other(j,"othernat",ac_est);
p35_forest_recovery_area(t,j,ac_est)$(p35_forest_recovery_area(t,j,ac_est) < 0) = 0;
pc35_land_other(j,"othernat",ac_est) = pc35_land_other(j,"othernat",ac_est) - p35_forest_recovery_area(t,j,ac_est);
pc35_land_other(j,"youngsecdf",ac_est) = pc35_land_other(j,"youngsecdf",ac_est) + p35_forest_recovery_area(t,j,ac_est);

Expand Down Expand Up @@ -144,7 +149,10 @@ vm_land.up(j,"primforest") = pcm_land(j,"primforest");
v35_secdforest.lo(j,ac) = 0;
v35_secdforest.up(j,ac) = Inf;

p35_protection_dist(j,ac_sub) = (pc35_secdforest(j,ac_sub)/sum(ac_sub2,pc35_secdforest(j,ac_sub2)))$(sum(ac_sub2,pc35_secdforest(j,ac_sub2))>0);
* Secondary forest conservation
p35_protection_dist(j,ac_sub) = 0;
p35_protection_dist(j,ac_sub)$(sum(ac_sub2,pc35_secdforest(j,ac_sub2)) > 0) = pc35_secdforest(j,ac_sub) / sum(ac_sub2,pc35_secdforest(j,ac_sub2));
pm_land_conservation(t,j,"secdforest","protect")$(pm_land_conservation(t,j,"secdforest","protect") > sum(ac_sub, pc35_secdforest(j,ac_sub))) = sum(ac_sub, pc35_secdforest(j,ac_sub));
if (sum(sameas(t_past,t),1) = 1,
v35_secdforest.lo(j,ac_sub) = pm_land_conservation(t,j,"secdforest","protect") * p35_protection_dist(j,ac_sub);
else
Expand All @@ -154,9 +162,6 @@ v35_secdforest.lo(j,ac_sub) = max((1-s35_natveg_harvest_shr) * pc35_secdforest(j
v35_secdforest.up(j,ac_sub) = pc35_secdforest(j,ac_sub);
m_boundfix(v35_secdforest,(j,ac_sub),l,1e-6);

* Secondary forest conservation
* protection bound fix
pm_land_conservation(t,j,"secdforest","protect")$(abs(pm_land_conservation(t,j,"secdforest","protect") - sum(ac_sub, pc35_secdforest(j,ac_sub))) < 1e-6) = sum(ac_sub, pc35_secdforest(j,ac_sub));
* set restoration target
p35_land_restoration(j,"secdforest") = pm_land_conservation(t,j,"secdforest","restore");
* Do not restore secdforest in areas where total natural
Expand All @@ -167,6 +172,7 @@ p35_land_restoration(j,"secdforest")$(sum(land_natveg, pcm_land(j,land_natveg))
* any remaining restoration area is substracted and shifted to other land restoration.
p35_restoration_shift(j) = p35_land_restoration(j,"secdforest") - pc35_max_forest_recovery(j);
p35_restoration_shift(j)$(p35_restoration_shift(j) < 0) = 0;
p35_restoration_shift(j)$(p35_restoration_shift(j) > p35_land_restoration(j,"secdforest")) = p35_land_restoration(j,"secdforest");
p35_land_restoration(j,"secdforest") = p35_land_restoration(j,"secdforest") - p35_restoration_shift(j);
pm_land_conservation(t,j,"other","restore") = pm_land_conservation(t,j,"other","restore") + p35_restoration_shift(j);

Expand All @@ -188,7 +194,9 @@ m_boundfix(vm_land_other,(j,othertype35,ac_sub),l,1e-6);

* Other land conservation
* protection bound fix
pm_land_conservation(t,j,"other","protect")$(abs(pm_land_conservation(t,j,"other","protect") - sum(ac_sub, pc35_land_other(j,"othernat",ac_sub))) < 1e-6) = sum(ac_sub, pc35_land_other(j,"othernat",ac_sub));
pm_land_conservation(t,j,"other","protect")$(pm_land_conservation(t,j,"other","protect") >
sum((othertype35,ac_sub), pc35_land_other(j,othertype35,ac_sub))) =
sum((othertype35,ac_sub), pc35_land_other(j,othertype35,ac_sub));
* set restoration target
p35_land_restoration(j,"other") = pm_land_conservation(t,j,"other","restore");
* Do not restore other land in areas where total natural
Expand All @@ -197,6 +205,9 @@ p35_land_restoration(j,"other")$(sum(land_natveg, pcm_land(j,land_natveg)) >= su
* set conservation bound
vm_land.lo(j,"other") = pm_land_conservation(t,j,"other","protect") + p35_land_restoration(j,"other");

* boundfix for land_natveg
m_boundfix(vm_land,(j,land_natveg),up,1e-6);

* ----------------------------
* Calculate carbon density
* ------------------------------
Expand Down
2 changes: 1 addition & 1 deletion modules/37_labor_prod/exo/sets.gms
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*** | Contact: [email protected]

sets
rcp37 climate change impact sceanrios
rcp37 climate change impact scenarios
/ rcp119, rcp585 /

metric37 labor productivity impact metric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@


*' @description This realization allows the model to endogenously decide on investments to deploy additional
*' irrigation infrastructure, i.e. to increase the area equipped for irrigation (AEI). Initial values for AEI
*' in 1995 are taken from @siebert_FAO_2007. Contraction of AEI is not possible.
*' irrigation infrastructure, i.e. to increase the area equipped for irrigation (AEI).
*' Initial values for AEI are areas that are irrigated in the initial time step in LUH2v2.
*' Depreciation of AEI can be set via `s41_AEI_depreciation`.
*' Irrigated crop production can only take place where irrigation infrastructure is present.
*'
*' Unit costs per hectare for AEI expansion are derived from a World Bank study (@worldbank_irrigation_1995)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ sets
/ y1995, y2000, y2005, y2010, y2015 /

aei41 Data source for area equipped for irrigation
/ LUH2v2, Mehta2022 /
/ LUH2v2, Mehta2024_Siebert2013, Mehta2024_Meier2018 /
;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


*' In this realization, area equipped for irrigation is fixed to input data (around the year 2000)
*' for all time steps. The source of the input data is @siebert_FAO_2007.
*' for all time steps. The sources of the input data are @siebert_FAO_2013 and @mehta_half_2024.
*'
*' @limitations No irrigation is possible on areas that have not been equipped for irrigation in the past.
*'
Expand Down
2 changes: 1 addition & 1 deletion modules/41_area_equipped_for_irrigation/static/sets.gms
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ sets
/ y1995, y2000, y2005, y2010, y2015 /

aei41 Data source for area equipped for irrigation
/ LUH2v2, Mehta2022 /
/ LUH2v2, Mehta2024_Siebert2013, Mehta2024_Meier2018 /
;
1 change: 1 addition & 0 deletions modules/42_water_demand/agr_sector_aug13/realization.gms
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*' efficiency times management factor") from @PIK_report104_2007.
*' Here, irrigated area from @siebert_FAO_2007 has been used as aggregation
*' weight.
*' Contraction of AEI happens if a depreciation rate is set in the switch `s41_AEI_depreciation`.
*'
*' * A regression of country values of the "conveyance efficiency times
*' management factor" from @PIK_report104_2007 on GDP.
Expand Down
4 changes: 4 additions & 0 deletions scripts/output/projects/FSEC_water.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ watStressViolations <- watStress
# mark violations in different color
watStressViolations[efvViolation == 1] <- 100
write.magpie(watStressViolations, file_name = file.path(outputdir, "watStressViolations.mz"))

# Water EFV ratio (EFV to EFR)
watEFVratio <- waterEFVratio(gdx, level = "grid", dir = outputdir)
write.magpie(watEFVratio, file_name = file.path(outputdir, "watEFVratio.mz"))
30 changes: 16 additions & 14 deletions scripts/output/projects/inms_reporting_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ print("Start inms reporting reg runscript")

if(!exists("source_include")) {

title <- "inms_SSP2_RCP4p5_PolicyLow_v4"
outputdir <- "output/inms_SSP2_RCP4p5_PolicyLow_v4_2020-07-13_15.37.07"
title <- "inms_SSP2_RCP4p5_PolicyLow_v4"
outputdir <- "output/inms_SSP2_RCP4p5_PolicyLow_v4_2020-07-13_15.37.07"

###Define arguments that can be read from command line
readArgs("outputdir","title")
readArgs("outputdir", "title")
}
#########################################################################################

print(paste0("script started for output directory",outputdir))
print(paste0("script started for output directory", outputdir))

withr::local_dir(outputdir)

Expand All @@ -41,24 +41,26 @@ title <- cfg$title
print("generating INMS output for the run: ")
print(title)

filename=paste0("report_",title,".mif")
gdx=paste0("fulldata.gdx")
a=getReportINMS(gdx,file=filename,scenario = title,dir=".")
filename <- paste0("report_", title, ".mif")
gdx <- paste0("fulldata.gdx")
a <- getReportINMS(gdx, file = filename, scenario = title, dir = ".")

print(filename)
mif=read.report(filename)
mif <- read.report(filename)


missingyears=function(x){
history=paste0("y",1965+((0:5)*5))
x[[1]][[1]] <- time_interpolate(x[[1]][[1]],interpolated_year = c(history,paste0("y",2005+((0:9)*10))),integrate_interpolated_years = TRUE)
x[[1]][[1]][,history,] = 0
missingyears <- function(x) {
history <- paste0("y", 1965 + ((0:5) * 5))
x[[1]][[1]] <- time_interpolate(x[[1]][[1]],
interpolated_year = c(history,paste0("y",2005+((0:9)*10))),
integrate_interpolated_years = TRUE)
x[[1]][[1]][, history, ] <- 0
return(x)
}

#a=c(missingyears(ssp1),missingyears(ssp2))
a=missingyears(mif)
a <- missingyears(mif)

write.reportProject(a,mapping=paste0(wdbefore,"/mapping_inms.csv"),file="report_inms.mif")
write.reportProject(a, mapping = paste0(wdbefore, "/mapping_inms.csv"), file = "report_inms.mif")
#write.report(a,file="magpie_results_nov2019.mif")
warnings()
Loading

0 comments on commit a3cda4f

Please sign in to comment.