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

enh(add_existing_baseyear): Pull out valid_grouping_years algorithm from heat #1570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coroa
Copy link
Member

@coroa coroa commented Mar 11, 2025

Changes proposed in this Pull Request

Minimal refactoring to re-use the grouping_years validation also for power. And fix a wrong indent.

Checklist

  • I tested my contribution locally and it works as intended.
  • Code and workflow changes are sufficiently documented.
  • Changed dependencies are added to envs/environment.yaml.
  • Changes in configuration options are added in config/config.default.yaml.
  • Changes in configuration options are documented in doc/configtables/*.csv.
  • Sources of newly added data are documented in doc/data_sources.rst.
  • A release note doc/release_notes.rst is added.

# Installation is assumed to be linear for the past
ratios = _years / _years.sum()
# get number of years of each interval
_years = pd.Index([grouping_years[0] - baseyear + default_lifetime]).append(
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit confused about this expression here, this can be a negative number or? If grouping_year[0] == 1990 and baseyear == 2020 and lifetime == 20 for example.

Copy link
Member Author

Choose a reason for hiding this comment

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

I must admit, i did not think about this. It is a literal port of Amos':

# Fill NA from .diff() with value for the first interval
_years[0] = valid_grouping_years[0] - baseyear + default_lifetime

Copy link
Member Author

@coroa coroa Mar 11, 2025

Choose a reason for hiding this comment

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

Ok, sorry, Amos, i was wrongly blaming you. The origin story of that expression is complicated.

@lisazeyen came up with:
https://github.com/PyPSA/pypsa-eur/blame/a72388b989d1d667ec7e44d66f6c3b494b46d000/scripts/add_existing_baseyear.py#L466-L467

         _years = (valid_grouping_years.diff().shift(-1)
                  .fillna(baseyear-valid_grouping_years.iloc[-1]))

ie. (baseyear - last of grouping_years) which sounds quite sensible (for an interval, unless the last grouping year is the same as the baseyear).

and then @lindnemi changed it to:

# Fill NA from .diff() with value for the first interval
_years[0] = valid_grouping_years[0] - baseyear + default_lifetime

in #1102 with associated discussion in #1091 .

Copy link
Member Author

Choose a reason for hiding this comment

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

It sounds like there was some back and forth, i'll not try to understand this fully now, maybe its best to have a short discussion.

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.

2 participants