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

co2 emission PR is edited #748

Merged
merged 21 commits into from Sep 29, 2023

Conversation

Emre-Yorat89
Copy link
Contributor

@Emre-Yorat89 Emre-Yorat89 commented May 31, 2023

Closes #488.

Changes proposed in this Pull Request

Currently, the CO2 emissions for the 1990 base year are hard-coded in the config for Europe only. When the user wants to optimize only one country or a set of countries, they have to manually check and adjust the emissions for a base year according to the region of interest.

This pull request adds functionality to returns co2 emissions for given countries in an automated way. The used dataset is database Emissions Database for Global Atmospheric Research (EDGAR) provided by the Joint Research Center (JRC)

Note: this PR is re-implementation of #618 in a cleaner way

Checklist

  • I consent to the release of this PR's code under the AGPLv3 license and non-code contributions under CC0-1.0 and CC-BY-4.0.
  • I tested my contribution locally and it seems to work fine.
  • Code and workflow changes are sufficiently documented.
  • Newly introduced dependencies are added to envs/environment.yaml and doc/requirements.txt.
  • Changes in configuration options are added in all of config.default.yaml and config.tutorial.yaml.
  • Add a test config or line additions to test/ (note tests are changing the config.tutorial.yaml)
  • Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

scripts/prepare_network.py Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
@ekatef
Copy link
Collaborator

ekatef commented May 31, 2023

Hello @Emre-Yorat89! A very nice work. I really like the structure and logic of your code.

Have added a few small comments and questions. Generally, my feeling is that we are close to ready-for-merge :)

@ekatef
Copy link
Collaborator

ekatef commented Jun 1, 2023

@Emre-Yorat89 thanks for addressing all the points! Almost there :)

The remained tasks:

  • add loggers (your suggestion on that sounds great);
  • fix output type of emission_extractor();
  • add automatic_emission_base_year into config tables and a release note.

After that, from my perspective this PR is ready to be merged.

@pz-max or @davide-f would mind to review a final version? That is a very important PR which significantly changes control of decarbonisation modeling. It would be perfect to have your double-check for it.

@ekatef
Copy link
Collaborator

ekatef commented Jun 6, 2023

@Emre-Yorat89 great job!

My feeling is that the PR is ready. I'll give merge it tomorrow unless @davide-f or @pz-max have any comments on that :)

Thank you so much for the contribution!

@davide-f
Copy link
Member

davide-f commented Jun 8, 2023

Hello :) I think that it may be interesting to add a description to this PR and the PR 618
What are the differences?

@ekatef
Copy link
Collaborator

ekatef commented Jun 28, 2023

My feeling is that the latest PR adjustments look really nice :)

@Emre-Yorat89 great work!

@davide-f this PR is re-implementation of #618. Have added a couple of lines into PR description to make clear it's purpose

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

Hello @Emre-Yorat89 Great job!
The code has significantly improved, I've left some suggestions including code to finalize :) great revision!

scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

@Emre-Yorat89 I've added some final (mainly documentation and CI-related comments).
Let me know if you can handle them of if you prefer us to jump in :)

The contribution is really great and you are crafting an amazing feature :)
It would be nice to see some testing and sensitivity on its usage, very nice! (not in this PR...)

scripts/prepare_network.py Show resolved Hide resolved
scripts/prepare_network.py Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
scripts/prepare_network.py Outdated Show resolved Hide resolved
config.tutorial.yaml Outdated Show resolved Hide resolved
Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

Hello @Emre-Yorat89 :D

So, I've been closing past comments and this PR is almost ready :)
As last steps, there is the need to solve a merge conflicts.

The main conflict is related to this PR #823 that introduced the "parameters" into the snakemake.
In the following, we first fix the conflicts and then revise the code to account for the new feature

The easiest way for you to fix it would be:

  • online on github, you see a button "Resolve conflicts", click on it
  • you'll see the conflicts between the existing and your code in prepare_network. You can keep your code only and delete "<<<>>", select "mark as solved" and click on the button commit from github
  • from your computer in your local repository, digit:
    git fetch
    git pull
  • after that, in the file prepare_network, you shall replace
    snakemake.config["electricity"]["automatic_emission"] into snakemake.params["automatic_emission"]
    note: config has been replaced into params
  • in the file "Snakemake", rule "prepare_network", you shall add automatic_emission=snakemake.config["electricity"]["automatic_emission"], under the params section
  • commit and push the changes of the last two steps

Great @Emre-Yorat89, the last round is here :D
If you encounter issues or need a help, I can jump in :)

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

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

As CI works, this PR is ready to merge :)
History is a bit messy because of merges and pre-commits, but rewriting history is more messy than expected.
@Emre-Yorat89 , for next PRs, please make sure to enable the pre-commit:

  • in vscode, view-Command palette->Python: Select Intepreter-> pypsa-earth environment
  • once that is done, in the prompt of commands, digit "pre-commit install"
  • before commiting, may be good to execute "pre-commit run --all" to make sure the code is compliant to pre-commit

@davide-f davide-f merged commit 8bf0701 into pypsa-meets-earth:main Sep 29, 2023
4 checks passed
@davide-f
Copy link
Member

davide-f commented Sep 29, 2023

@Emre-Yorat89 great contribution :D
The PR is merged and you are officially a contributor! :)

@ekatef
Copy link
Collaborator

ekatef commented Sep 29, 2023

@Emre-Yorat89 great contribution :D

The PR is merged and you are officially a contributor! :)

Amazing news 🤩
Congratulations, @Emre-Yorat89 and @davide-f! Great work and a much needed contribution :)

@pz-max
Copy link
Member

pz-max commented Oct 1, 2023

Congrats! Just thinking for the use in the sector coupled model. How would it work then? I can imagine that one could extract data for other sectors as well changing a few lines e.g.
https://github.com/Emre-Yorat89/pypsa-earth/blob/f5994d7dcd3c8dc2f36943038243b23e9643f3d0/scripts/prepare_network.py#L128-L130

@Emre-Yorat89 Emre-Yorat89 deleted the co2-emission_v2 branch October 2, 2023 07:34
@Emre-Yorat89 Emre-Yorat89 restored the co2-emission_v2 branch October 2, 2023 07:35
@Emre-Yorat89
Copy link
Contributor Author

I really thank you to @ekatef and @davide-f for their supports and helps while reviewing and merging the PR.
@pz-max thank you!
I think changing the sector name is enough to extract other sector data if the country has the mentioned sector indeed.
For much more automatic process of sector coupling, the current electricity-related emission can be left as default and an entry to 'electricity' can be added to acquire other sector input from user in the config file. There are many sectors in the excel file. Therefore, the sectors can be added to https://pypsa-earth.readthedocs.io/en/latest/ for users to determine the sectors and write correctly. Also, a fix may be needed since a country may not have the sector given by the user. There should be also a solution if one wants to add more than one sector to the entry too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculate co2base depending on selected countries
4 participants