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

AgroForestry: treecover on cropland and betr #644

Merged
merged 147 commits into from
Jun 18, 2024
Merged

Conversation

flohump
Copy link
Contributor

@flohump flohump commented Mar 11, 2024

🐦 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:

  • new module 29_cropland, accouting for crop area, fallow cropland and tree cover on cropland
  • module 30_crop renamed to 30_croparea, which now only accounts for crop area.
  • module 29_ageclass has been renamed to 28_ageclass
  • SNV has been moved from 30_crop to 29_cropland
  • 30_crop/penalty and 30_crop/rotation realizations have been merged into a singe 30_croparea/detail_apr24 realization
  • the previous 30_crop/endo_apr21 crop realization has been renamed to 30_croparea/simple_apr24
  • The new module 29_cropland has two realizations: detail_apr24 and simple_apr24 (default)
  • 29_cropland/detail_apr24 includes all tree cover (includign age-classes) and fallow land calculations
  • 29_cropland/simple_apr24 assumes zero tree cover and fallow land.

todo: include input files for 30_croparea in additional_data.tgz.

todo: emisCO2 in magpie4 reporting

Changelog

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/detail_apr24
  • 30_crop the two realizations penalty_apr22 and rotation_apr22 have been merged into a single 30_croparea/detail_apr24 realization
  • 30_crop the previous 30_crop/endo_apr21 realization has been moved to 30_croparea/simple_apr24

added

  • 29_cropland new module 29_cropland accounting for crop area, fallow cropland and tree cover on cropland with two realizations: detail_apr24 and simple_apr24 (default) .
  • 10_land added interface pm_land_hist with historic land use patterns
  • 32_forestry added technical balance term v32_land_missing_ndc

fixed

  • 80_optimization bugfix in nlp_par. Double solve statement was not working

🔧 Checklist for PR creator 🔧

  • Label pull request from the label list.

    • Low risk: Simple bugfixes (missing files, updated documentation, typos) or changes in start or output scripts
    • Medium risk: Uncritical changes in the model core (e.g. moderate modifications in non-default realizations)
    • High risk: Critical changes in model core or default settings (e.g. changing a model default or adjusting a core mechanic in the model)
  • Self-review own code

    • No hard coded numbers and cluster/country/region names.
    • The new code doesn't contain declared but unused parameters or variables.
    • magpie4 R library has been updated accordingly and backwards compatible where necessary.
    • scenario_config.csv has been updated accordingly (important if default.cfg has been updated)
  • Document changes

    • Add changes to CHANGELOG.md
    • Where relevant, put In-code documentation comments
    • Properly address updates in interfaces in the module documentations
    • run goxygen::goxygen() and verify the modified code is properly documented
  • Perform test runs

    • Low risk:
      • Run a compilation check via Rscript start.R --> "compilation check"
    • Medium risk:
      • Run test runs via Rscript start.R --> "test runs"
      • Check logs for errors/warnings
    • High risk:
      • Run test runs via Rscript start.R --> "test runs"
      • Check logs for errors/warnings
      • Default run from the PR target branch for comparison
      • Provide relevant comparison plots (land-use, emissions, food prices, land-use intensity,...)

Resources_Land_Cover_Cropland-100
Resources_Land_Cover_Cropland_Tree_Cover
Productivity_Landuse_Intensity_Indicator_Tau-87
Emissions_CO2_Land_Land_use_Change-86
Prices_Index2020_Agriculture_Food_products-2

📉 Performance changes 📈

  • Current develop branch default : 27 mins
  • This PR's default : 27 mins

🚨 Checklist for reviewer 🚨

  • PR is labeled correctly
  • Code changes look reasonable
    • No hard coded numbers and cluster/country/region names.
    • No unnecessary increase in module interfaces
    • model behavior/performance is satisfactory.
  • Changes are properly documented
    • CHANGELOG is updated correctly
    • Updates in interfaces have been properly addressed in the module documentations
    • In-code documentation looks appropriate
  • content review done (at least 1)
  • RSE review done (at least 1)

@flohump flohump changed the title treecover on cropland AgroForestry: treecover on cropland and betr Mar 11, 2024
Copy link
Member

@bodirsky bodirsky left a 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!

core/macros.gms Outdated Show resolved Hide resolved
modules/30_crop/endo_apr21/declarations.gms Outdated Show resolved Hide resolved
modules/30_crop/endo_apr21/input.gms Outdated Show resolved Hide resolved
@@ -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");
Copy link
Member

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...

Copy link
Contributor Author

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.

modules/30_crop/endo_apr21/equations.gms Outdated Show resolved Hide resolved

** set bii coefficients
p30_treecover_bii_coeff(bii_class_secd,potnatveg) = 0;
if(s30_treecover_bii_coeff = 0,
Copy link
Member

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!

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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.

modules/30_crop/endo_apr21/declarations.gms Outdated Show resolved Hide resolved
@flohump
Copy link
Contributor Author

flohump commented Mar 12, 2024

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!

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);
Copy link
Contributor

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?

Copy link
Member

@tscheypidi tscheypidi left a 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

core/macros.gms Outdated Show resolved Hide resolved

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) =
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the historic numbers for 2015. pcm_land is the model outcome. Alternatively, we could add a time dimension to pm_land_start (currently on 1995)

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));
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from 32_forestry module.
This fits better into the ageclass 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");
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vm_fallow is fixed to zero in this realization. Therefore, it will not change the default. I added it only for consistency with the other realizations.

*' @equations

*' Total agroforestry cost.
*' Cost for bioenergy trees are accounted for in the [30_crop] module.
Copy link
Member

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

@k4rst3ns k4rst3ns self-requested a review March 26, 2024 15:05
flohump added 6 commits May 30, 2024 09:48
# Conflicts:
#	CHANGELOG.md
#	config/default.cfg
#	config/scenario_fsec.csv
#	modules/30_crop/endo_apr21/input.gms
#	modules/30_crop/penalty_apr22/input.gms
#	modules/30_crop/rotation_apr22/input.gms
Copy link
Member

@k4rst3ns k4rst3ns left a comment

Choose a reason for hiding this comment

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

Looks good.
More comments not always full sentences 😅 but I guess this might be a matter of preference.
The only thing I again thought of was the alignment of fallow in bii and som regards. The difference might be not big, but it might be still good to align these? But this could be also done when I do the changes to the dynamic realization to align them to the new carbon stocks in a couple of weeks.

vm_fallow(j2) =l=
vm_land(j2,"crop") * s29_fallow_max;

*' Fallow land biodiversity value is based on perennial crops.
Copy link
Member

Choose a reason for hiding this comment

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

Ok, but still than we shoudl adress this similarly in the SOM realization:
https://github.com/flohump/magpie/blob/1774fcfba8467d6695b50af1c395efc77672beb1/modules/59_som/cellpool_jan23/preloop.gms#L71

Here we use maize as reference. Maybe we can switch it to "oilpalm" (which is the only perenial we have in som module.

if we change it, for both dynamic realizations it has to be changed ^^'

@flohump flohump merged commit 3122e89 into magpiemodel:develop Jun 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request High risk Higher risk Major Substantial modifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants