-
Notifications
You must be signed in to change notification settings - Fork 155
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
AgroForestry: treecover on cropland and betr #644
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few documentation changes.
Seems good to me, but should be done analogous for all 3 realizations.
Please let me know if you need help with understanding the penalty implementation!
|
||
* macro for carbon stocks with age classes | ||
$macro m_carbon_stock_ac(land,carbon_density,sets,sets_sub) \ | ||
sum((&&sets), land(j2,&&sets) * sum(ct, carbon_density(ct,j2,&&sets,ag_pools)))$(sameas(stockType,"actual")) + \ | ||
sum((&&sets_sub), land(j2,&&sets_sub) * sum(ct, carbon_density(ct,j2,&&sets_sub,ag_pools)))$(sameas(stockType,"actualNoAcEst")); | ||
sum((&&sets_sub), land(j2,&&sets_sub) * sum(ct, carbon_density(ct,j2,&&sets_sub,ag_pools)))$(sameas(stockType,"actualNoAcEst")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was ist mit den semicolons? warum werden die nicht mehr benötigt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add the result of two macros. Therefore, the semicolon is put in the equation.
So far, there are acutally two semicolons in many cases where macros are used. One from the macro itself and another one in the code.
I would argue that it makes more sense to define macros without final semicolon.
@tscheypidi What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree
modules/30_crop/endo_apr21/input.gms
Outdated
@@ -29,6 +29,17 @@ s30_snv_relocation_data_x1 First reference value in SNV target cropland dat | |||
s30_snv_relocation_data_x2 Second reference value in SNV target cropland data (1) / 0.5 / | |||
s30_rotation_scenario_start Rotation scenario start year / 2020 / | |||
s30_rotation_scenario_target Rotation scenario target year / 2050 / | |||
s30_treecover_plantation Growth curve switch for tree cover on cropland 0=natveg 1=plantations (1) / 0 / | |||
s30_treecover_bii_coeff BII coefficent to be used for tree cover on cropland 0=natural vegetation 1=plantation (1) / 0 / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value may be a bit high, no? do we have a justification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the value for secondary vegetation until we found something better?
On the other hand, a tree on a field probably has a positive externality on the surrounding crops, that would justify a high BII
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s30_treecover_bii_coeff = 0 is actually secondary vegetation. Will be revised.
@@ -10,7 +10,7 @@ | |||
*' the sum of crop and water supply type specific land requirements: | |||
|
|||
q30_cropland(j2) .. | |||
sum((kcr,w), vm_area(j2,kcr,w)) =e= vm_land(j2,"crop"); | |||
sum((kcr,w), vm_area(j2,kcr,w)) + vm_fallow(j2) + sum(ac, v30_treecover(j2,ac)) =e= vm_land(j2,"crop"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now you introduced fallow into the endo_apr realization. Was that on purpose?
As long as it is fixed to 0, probably doesnt matter...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for consistency because fallow land and treecover will show up in this equation in the other realizations.
|
||
** set bii coefficients | ||
p30_treecover_bii_coeff(bii_class_secd,potnatveg) = 0; | ||
if(s30_treecover_bii_coeff = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, now i see, this is just a switch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be choosen flexibly. In analogy to re-/afforestation.
@@ -79,3 +93,8 @@ | |||
=e= | |||
(vm_land(j2,"crop") - sum((crop_ann30,w), vm_area(j2,crop_ann30,w))) | |||
* fm_bii_coeff("crop_per",potnatveg) * fm_luh2_side_layers(j2,potnatveg); | |||
|
|||
q30_bv_treecover(j2,potnatveg) .. vm_bv(j2,"crop_tree",potnatveg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the set potnatveg doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bii coefficients are defined for two layers: forested and non-forested biomes.
@@ -50,3 +50,43 @@ p30_snv_relocation(t,j)$(p30_snv_relocation(t, j) > p30_max_snv_relocation(t,j)) | |||
*' Area potentially available for cropping | |||
p30_avl_cropland(t,j) = f30_avl_cropland(j,"%c30_marginal_land%") * (1 - p30_snv_shr(t,j)); | |||
*' @stop | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess this is copy paste from a previous implementation, right? only reviewing it shortly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Adapted from 35_natveg.
Sure. This will be included in all 3 realizations once we agreed that the overall approach is fine. |
p30_treecover(t,j,"acx") = p30_treecover(t,j,"acx") | ||
+ sum(ac$(ord(ac) > card(ac)-s30_shift), pc30_treecover(j,ac)); | ||
|
||
pc30_treecover(j,ac) = p30_treecover(t,j,ac); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double checking. Here we go from 3 dimensions (t,j,ac) to 2 dimensions (j,ac). Is this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks overall good to me. Please have a look at the specific comments to see my requests for modifications
|
||
* macro for carbon stocks with age classes | ||
$macro m_carbon_stock_ac(land,carbon_density,sets,sets_sub) \ | ||
sum((&&sets), land(j2,&&sets) * sum(ct, carbon_density(ct,j2,&&sets,ag_pools)))$(sameas(stockType,"actual")) + \ | ||
sum((&&sets_sub), land(j2,&&sets_sub) * sum(ct, carbon_density(ct,j2,&&sets_sub,ag_pools)))$(sameas(stockType,"actualNoAcEst")); | ||
sum((&&sets_sub), land(j2,&&sets_sub) * sum(ct, carbon_density(ct,j2,&&sets_sub,ag_pools)))$(sameas(stockType,"actualNoAcEst")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree
|
||
pcm_land(j,land) = pm_land_start(j,land); | ||
vm_land.l(j,land) = pcm_land(j,land); | ||
|
||
pm_treecover_shr(j) = 0; | ||
pm_treecover_shr(j)$(f10_land("y2015",j,"crop") > 1e-10) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more consistent to compute the treecover share in the agroforestry module. I think the existing interface pcm_land could be used for it (instead of making f10_land a new interface).
ac_est(ac) = yes$(ord(ac) <= (m_yeardiff_forestry(t)/5)); | ||
|
||
ac_sub(ac) = no; | ||
ac_sub(ac) = yes$(ord(ac) > (m_yeardiff_forestry(t)/5)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens here and why? A new set but no other changes in the module?
@@ -10,7 +10,7 @@ | |||
*' the sum of crop and water supply type specific land requirements: | |||
|
|||
q30_cropland(j2) .. | |||
sum((kcr,w), vm_area(j2,kcr,w)) =e= vm_land(j2,"crop"); | |||
sum((kcr,w), vm_area(j2,kcr,w)) + vm_fallow(j2) + vm_treecover_area(j2) =e= vm_land(j2,"crop"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is now fallow coming in here? this will change the default behavior of the realization, right? If so, it should be also labelled differently I think
*' @equations | ||
|
||
*' Total agroforestry cost. | ||
*' Cost for bioenergy trees are accounted for in the [30_crop] module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at the resulting documenation. I would at least use full sentences to describe the methodology. The documentation page should read as a real documentation of the realization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Florian for this major effort.
I added some comments and I also spotted some things that have to be fixed (see comments on the som module). I think in general it looks very good. I guess I normally would comment the code more excessively and added some comments there I would find it really helpful to have more guidance through the code ^^'
@@ -26,7 +26,7 @@ cfg$input <- c(regional = "rev4.104_h12_magpie.tgz", | |||
cellular = "rev4.104_h12_fd712c0b_cellularmagpie_c200_MRI-ESM2-0-ssp370_lpjml-8e6c5eb1.tgz", | |||
validation = "rev4.104_h12_validation.tgz", | |||
additional = "additional_data_rev4.48.tgz", | |||
calibration = "calibration_H12_26Mar24.tgz") | |||
calibration = "calibration_H12_default_30Apr24.tgz") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still produce new calibration files?
We know that the fallow land does not perfectly work together without calibration (due to area mismatches). Did you test the tree cover with and without calibration run?
config/default.cfg
Outdated
# * Tree cover recurring cost (USD05MER per ha) | ||
cfg$gms$s29_cost_treecover_recur <- 500 # def = 500 | ||
# * Penalty for violation of treecover target (USD05MER per ha) | ||
cfg$gms$s29_treecover_penalty <- 2000 # def = 2000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should penalty terms be part of the config?
I guess in development stage this is good for testing, but this might be removed for the final commit?
config/default.cfg
Outdated
# * Target year (year when full implementation is reached): | ||
cfg$gms$s30_betr_scenario_target <- 2050 # def = 2050 | ||
# * Penalty for violation of fallow target (USD05MER per ha) | ||
cfg$gms$s30_betr_penalty <- 500 # def = 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add here, that this setting are used for an agroforestry setup (or at least are interpreted as agroforestry in a way?)
@@ -3,3 +3,5 @@ avl_land_t.cs3 | |||
avl_land_t_0.5.mz | |||
luh2_side_layers.cs3 | |||
avl_land_t_iso.cs3 | |||
CroplandTreecover.cs2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these files be read in in module 29_cropland?
@@ -14,6 +14,11 @@ $ondelim | |||
$include "./modules/10_land/input/avl_land_t.cs3" | |||
$offdelim | |||
; | |||
*due to some rounding errors the input data currently may contain in some cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? - than this should be rather tackled than bugfixes here?
+ v30_betr_missing(j2) * sum(ct, i30_betr_penalty(ct)) | ||
); | ||
|
||
q30_rotation_max(j2,rotamax_red30)$(i30_implementation = 1) .. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here comments are missing?
Could you add these: https://github.com/magpiemodel/magpie/blob/a233ab7cbe6fbfadebca49676f8993e101f3fb9d/modules/30_crop/rotation_apr22/equations.gms#L45C4-L48C17
I know bringing the two realizations together is kind of very messy work. But it also makes it harder to understand the module as well. Maybe there is also a way to structure the code a bit more with some sub-headings? Indicating where the rule-based and the incentive base party starts?
@@ -21,7 +14,7 @@ v32_land_reduction.fx(j,type32,ac_est) = 0; | |||
p32_aff_pol_timestep("y1995",j) = 0; | |||
p32_aff_pol_timestep(t,j)$(ord(t)>1) = p32_aff_pol(t,j) - p32_aff_pol(t-1,j); | |||
* Suitable area (`p32_aff_pot`) for NPI/NDC afforestation | |||
p32_aff_pot(t,j) = (vm_land.l(j,"crop") - vm_land.lo(j,"crop")) + (vm_land.l(j,"past") - vm_land.lo(j,"past")) - pm_land_conservation(t,j,"other","restore"); | |||
p32_aff_pot(t,j) = sum((kcr,w),vm_area.l(j,kcr,w) - vm_area.lo(j,kcr,w)) + (vm_land.l(j,"past") - vm_land.lo(j,"past")) - pm_land_conservation(t,j,"other","restore"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why fallow can't be used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 good point!
+ vm_fallow(j2) * i59_cratio_fallow(j2) | ||
+ vm_treecover(j2) * i59_cratio_treecover) | ||
* sum(ct,f59_topsoilc_density(ct,j2)); | ||
|
||
*' as well as for all non cropland given by | ||
|
||
q59_som_target_noncropland(j2,noncropland59) .. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the new cellpool_jan23 the changes in declarations and preloop are missing.
I know it is a bit messy that we have two almost identical reliaztions in magpie,
At some point the old one should be depreciated.
But since the new one is the one with the missing code, please add it :)
@@ -130,7 +127,7 @@ $batinclude "./modules/include.gms" nl_relax | |||
*' the nonlinear optimization of the model in its full complexity. | |||
|
|||
solve magpie USING nlp MINIMIZING vm_cost_glo; | |||
solve magpie USING nlp MINIMIZING vm_cost_glo; | |||
if(s80_secondsolve = 1, solve magpie USING nlp MINIMIZING vm_cost_glo; ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that has to be reviewed by somebody else.
@tscheypidi
scripts/start/test_runs.R
Outdated
@@ -79,6 +79,16 @@ cfg <- fsecScenario(scenario = "c_BAU") | |||
cfg$results_folder_highres <- "output" | |||
start_run(cfg = cfg, codeCheck = codeCheck) | |||
|
|||
### NatureSparing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the test_run script is intentionally? Please just check ones
# Conflicts: # CHANGELOG.md # config/default.cfg # config/scenario_config.csv # modules/30_crop/endo_apr21/declarations.gms # modules/30_crop/endo_apr21/equations.gms # modules/30_crop/endo_apr21/input.gms # modules/30_crop/endo_apr21/postsolve.gms # modules/30_crop/endo_apr21/presolve.gms # modules/30_crop/penalty_apr22/equations.gms # modules/30_crop/penalty_apr22/input.gms # modules/30_crop/penalty_apr22/presolve.gms # modules/30_crop/rotation_apr22/declarations.gms # modules/30_crop/rotation_apr22/equations.gms # modules/30_crop/rotation_apr22/input.gms # modules/30_crop/rotation_apr22/postsolve.gms # modules/30_crop/rotation_apr22/presolve.gms # modules/30_croparea/detail_apr24/declarations.gms # modules/30_croparea/detail_apr24/postsolve.gms # scripts/start/test_runs.R
# Conflicts: # CHANGELOG.md # config/default.cfg # config/scenario_fsec.csv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some comments, but looks good to me overall
@@ -40,7 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | |||
- **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 | |||
- **80_optimization** bugfix in nlp_par. Double solve statement was not working |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part has been moved to another PR, right?
@@ -7,17 +7,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). | |||
## [Unreleased] | |||
|
|||
### changed | |||
- **29_ageclass** module 29_ageclass has been renamed to 28_ageclass to make space for `29_cropland` just before `30_croparea` | |||
- **30_crop** module `30_crop` renamed to `30_croparea`, which now only accounts for crop area. | |||
- **30_crop** SNV implementation has been moved from `30_crop` to `29_cropland` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would favor to have SNV written out as this abbreviation is from my perspective not established enough to be used without explanation
*' Cropland tree cover establishment rules. | ||
|
||
q29_treecover_est(j2,ac_est) .. | ||
v29_treecover(j2,ac_est) =e= sum(ac_est2, v29_treecover(j2,ac_est2))/card(ac_est2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor questions, looks otherwise good to me!
# * Target year (year when full implementation is reached): | ||
cfg$gms$s30_snv_scenario_target <- 2030 # def = 2030 | ||
cfg$gms$s29_snv_scenario_target <- 2029 # def = 2029 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2029?
|
||
vm_fallow.lo(j) = 0; | ||
vm_fallow.up(j) = p29_avl_cropland(t,j); | ||
m_boundfix(vm_fallow,(j),l,1e-6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
i30_rotation_incentives(t_all,rota30) = | ||
f30_rotation_incentives(rota30,"default") * (1-i30_rotation_scenario_fader(t_all)) + | ||
f30_rotation_incentives(rota30,"%c30_rotation_incentives%") * (i30_rotation_scenario_fader(t_all)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -21,7 +14,7 @@ v32_land_reduction.fx(j,type32,ac_est) = 0; | |||
p32_aff_pol_timestep("y1995",j) = 0; | |||
p32_aff_pol_timestep(t,j)$(ord(t)>1) = p32_aff_pol(t,j) - p32_aff_pol(t-1,j); | |||
* Suitable area (`p32_aff_pot`) for NPI/NDC afforestation | |||
p32_aff_pot(t,j) = (vm_land.l(j,"crop") - vm_land.lo(j,"crop")) + (vm_land.l(j,"past") - vm_land.lo(j,"past")) - pm_land_conservation(t,j,"other","restore"); | |||
p32_aff_pot(t,j) = sum((kcr,w),vm_area.l(j,kcr,w) - vm_area.lo(j,kcr,w)) + (vm_land.l(j,"past") - vm_land.lo(j,"past")) - pm_land_conservation(t,j,"other","restore"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 good point!
@@ -24,6 +24,8 @@ q50_nr_inputs(i2) .. | |||
vm_res_recycling(i2,"nr") | |||
+ sum((cell(i2,j2),kcr,w), vm_area(j2,kcr,w) * f50_nr_fix_area(kcr)) | |||
+ sum(cell(i2,j2),vm_fallow(j2) * f50_nr_fix_area("tece")) | |||
* Commented out for consistency with q50_nr_surplus_nonagland |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code should be removed
🐦 Description of this PR 🐦
This PR adds tree cover on cropland and bioenergy trees as two different AgroForestry systems to MAgPIE
To intergrate cropland tree cover properly into the existing model, the following changes are applied:
29_cropland
, accouting for crop area, fallow cropland and tree cover on cropland30_crop
renamed to30_croparea
, which now only accounts for crop area.29_ageclass
has been renamed to28_ageclass
30_crop
to29_cropland
30_crop/penalty
and30_crop/rotation
realizations have been merged into a singe30_croparea/detail_apr24
realization30_crop/endo_apr21
crop realization has been renamed to30_croparea/simple_apr24
29_cropland
has two realizations:detail_apr24
andsimple_apr24
(default)todo: include input files for 30_croparea in additional_data.tgz.
todo: emisCO2 in magpie4 reporting
Changelog
changed
29_cropland
just before30_croparea
30_crop
renamed to30_croparea
, which now only accounts for crop area.30_crop
to29_cropland/detail_apr24
penalty_apr22
androtation_apr22
have been merged into a single30_croparea/detail_apr24
realization30_crop/endo_apr21
realization has been moved to30_croparea/simple_apr24
added
29_cropland
accounting for crop area, fallow cropland and tree cover on cropland with two realizations:detail_apr24
andsimple_apr24
(default) .pm_land_hist
with historic land use patternsv32_land_missing_ndc
fixed
🔧 Checklist for PR creator 🔧
Label pull request from the label list.
Self-review own code
magpie4
R library has been updated accordingly and backwards compatible where necessary.scenario_config.csv
has been updated accordingly (important ifdefault.cfg
has been updated)Document changes
CHANGELOG.md
goxygen::goxygen()
and verify the modified code is properly documentedPerform test runs
Rscript start.R --> "compilation check"
Rscript start.R --> "test runs"
Rscript start.R --> "test runs"
📉 Performance changes 📈
🚨 Checklist for reviewer 🚨
CHANGELOG
is updated correctly