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

Avoid dropping generators with empty time series when clips equal zero #714

Merged
merged 8 commits into from
May 8, 2023

Conversation

davide-f
Copy link
Member

@davide-f davide-f commented May 7, 2023

Closes #704, #706

Changes proposed in this Pull Request

This PR co-authored with @ekatef that identified the issue address the problem of no generators being found and no weight column to be found.
This issue may complement the PR #709.

Checklist

  • I consent to the release of this PR's code under the GPLv3 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 envs/environment.docs.yaml.
  • 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.

@davide-f davide-f linked an issue May 7, 2023 that may be closed by this pull request
2 tasks
@davide-f
Copy link
Member Author

davide-f commented May 7, 2023

@ekatef would you mind reviewing this PR? :)

@ekatef
Copy link
Collaborator

ekatef commented May 7, 2023

@ekatef would you mind reviewing this PR? :)

Looks very elegant! Tomorrow I'll be absolutely happy to review :)

Copy link
Collaborator

@ekatef ekatef left a comment

Choose a reason for hiding this comment

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

@davide-f very nice and well-coded addition.
Have added some comments which relate to code readability/documenting

Comment on lines 431 to 443
inflow_stations = bus_id[inflow_idx]
missing_c = pd.Index(inflow_stations.unique()).difference(
inflow.indexes["plant"]
)
intersection_c = inflow.indexes["plant"].intersection(inflow_stations)

# if missing time series are found, notify the user and exclude missing hydro plants
if not missing_c.empty:
idxs_to_keep = inflow_stations[
inflow_stations.isin(intersection_c)
].index
ror = ror.loc[ror.index.intersection(idxs_to_keep)]
hydro = hydro.loc[hydro.index.intersection(idxs_to_keep)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

A very nice and clean solution by its essence. What has been not easy to understand for me when reading the code are the naming conventions. A couple of suggestions:

  1. Is it possible to clarify in the names what does "_c" imply in missing_c and intersection_c?
  2. Usually we refer generators as power plants, while the"stations" is used in variables names related to a power plants dataset, while stations might have implications with meteorological measurements. Would it be worth to revise naming a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Revised:

  • _c -> _plants
  • stations -> buses

Comment on lines 445 to 447
logger.warning(
f"'{snakemake.input.profile_hydro}' is missing "
f"inflow time-series for at least one bus: {', '.join(missing_c)}. Corresponding hydro plants are dropped."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to output also some data on the missed power plants like coordinates or names along with buses ids?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

Comment on lines 796 to 798
logger.warning(
"Unexpected missing 'weight' column; typical when no generators are detected. Manually added."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd say rather "it could happen" as "typical" can be misleading. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Revised

Comment on lines 503 to 505
# if technology is not hydro, restrict the region of the cutout
# hydrobasins may span beyond the region of the country, so
# it is unsafe to restrict the region for hydro
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could it make sense to re-formulate a bit the comment for better readability? Something like "the region should be restricted for non-hydro technologies, while hydro potential is calculated across hydrobasins which may span beyond the region of the country"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@davide-f
Copy link
Member Author

davide-f commented May 8, 2023

@ekatef Revised :)
Let me know what you think. I think that this PR can be merged with squash and merge, for these reasons:

  1. few line changes with respect to the commits (about 5)
  2. The proposed changes are quite coincise

@ekatef
Copy link
Collaborator

ekatef commented May 8, 2023

@ekatef Revised :) Let me know what you think. I think that this PR can be merged with squash and merge, for these reasons:

  1. few line changes with respect to the commits (about 5)
  2. The proposed changes are quite coincise

Super!! With the revisions implemented, I'm able to recall the coded logic significantly faster ;)

Thanks for the clarification regarding merge. Feels like a bit difficult to formalise, but quite clear when you explain reasoning behind

@davide-f davide-f merged commit 5cc92a7 into main May 8, 2023
cpschau added a commit to cpschau/pypsa-earth that referenced this pull request May 10, 2023
cpschau added a commit to cpschau/pypsa-earth that referenced this pull request May 11, 2023
@cpschau cpschau mentioned this pull request May 11, 2023
8 tasks
davide-f pushed a commit that referenced this pull request May 15, 2023
* adapt #714 to avoid hydro mismatch

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@davide-f davide-f deleted the fix_empty_generators branch July 16, 2023 11:39
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.

Build_hydro issues: missing buses missing column with empty generators dataframe
2 participants