forked from open-energy-transition/pypsa-eur
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Integrate hydro inflows from PEMMDB #77
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d2576ed
feat: introduce pipeline for hydro inflow data
daniel-rdt 5edeafb
feat: infer resolution of input data for each technology and fix unit…
daniel-rdt 277f0e2
feat: add more generalised retrieve for additional tyndp datasets and…
daniel-rdt d37199f
Merge branch 'master' into feat/74-hydro-inflows
daniel-rdt cfcd6f6
feat: introduce safe_pyear helper function
daniel-rdt 9bf086b
feat: add verbose option to safe_pyear helper function
daniel-rdt 4a2a6d0
feat: add config section with switch, techs and available years
daniel-rdt 9299cec
feat: build hydro profile file with dimensions bus, time, year, hydro…
daniel-rdt 0165421
feat: add hydro to tyndp test config
daniel-rdt 2cec738
fix: disable tyndp_hydro_profiles in default config
daniel-rdt bb49919
fix: differentiate hydro profiles in prepare_sector_network.py
daniel-rdt f0427b8
doc: document new config option
daniel-rdt 0ceee6e
doc: add release note
daniel-rdt b9e6e00
Resolve merge conflicts
daniel-rdt 9fbf3b2
ci: add explicit ruleorder for tyndp hydro rules
daniel-rdt 9faaccc
doc: add documentation for retrieve_tyndp_hydro_inflows rule
daniel-rdt 9abc99d
Apply suggestions from code review
daniel-rdt 45d6b3b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c6259e1
refactor: change the order of config parameters for consistency
daniel-rdt 465be65
refactor: rename profile_hydro_tyndp to profile_pemmdb_hydro
daniel-rdt fb30763
apply more suggestions from code review
daniel-rdt 01b079a
doc: add autodoc for missing hydro profile and pecd rules
daniel-rdt a752402
refactor: move static variable outside of function
daniel-rdt d3b0f8b
refactor: remove redundant fill value and clean up GB and UK renaming
daniel-rdt 1baf259
feat: add source parameter for logging of retrieve_additional_tyndp_data
daniel-rdt 0e07ba7
feat: improve input_data_hydro_tyndp formulation
daniel-rdt 79ac928
feat: improve data cleaning
daniel-rdt f2ed432
Merge branch 'master' into feat/74-hydro-inflows
daniel-rdt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # SPDX-FileCopyrightText: Open Energy Transition gGmbH | ||
|
daniel-rdt marked this conversation as resolved.
Outdated
|
||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| """ | ||
| Build hydroelectric inflow time-series for each country based on TYNDP hydro inflow data. | ||
|
daniel-rdt marked this conversation as resolved.
Outdated
|
||
|
|
||
| Outputs | ||
| ------- | ||
|
|
||
| - ``resources/profile_hydro_tyndp.nc``: | ||
|
|
||
| =================== ================ ========================================================= | ||
| Field Dimensions Description | ||
| =================== ================ ========================================================= | ||
| inflow bus, time, Inflow to the state of charge (in MW), | ||
| year, hydro_tech e.g. due to river inflow in hydro reservoir. | ||
| =================== ================ ========================================================= | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| import pandas as pd | ||
| import xarray as xr | ||
| from tqdm.contrib.itertools import product | ||
|
|
||
| from scripts._helpers import ( | ||
| configure_logging, | ||
| get_snapshots, | ||
| safe_pyear, | ||
| set_scenario_config, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| if __name__ == "__main__": | ||
| if "snakemake" not in globals(): | ||
| from scripts._helpers import mock_snakemake | ||
|
|
||
| snakemake = mock_snakemake("build_tyndp_hydro_profile") | ||
| configure_logging(snakemake) | ||
| set_scenario_config(snakemake) | ||
|
|
||
| time = get_snapshots(snakemake.params.snapshots, snakemake.params.drop_leap_day) | ||
|
|
||
| years_in_time = pd.DatetimeIndex(time).year.unique() | ||
|
|
||
| technologies = snakemake.params.technologies | ||
| pyears = snakemake.params.planning_horizons | ||
|
|
||
| inflows = [] | ||
|
|
||
| for year, technology in product(pyears, technologies): | ||
| logger.info( | ||
| f"Extracting hydro inflows for year {year} for technology {technology}..." | ||
|
daniel-rdt marked this conversation as resolved.
Outdated
|
||
| ) | ||
| year_i = year | ||
| # falling back to latest available pyear if not in list of available years | ||
| year = safe_pyear( | ||
| int(year), | ||
| available_years=snakemake.params.available_years, | ||
| source="PEMMDB hydro inflow", | ||
| ) | ||
|
|
||
| inflow = ( | ||
| pd.read_csv( | ||
| snakemake.input[f"hydro_inflow_tyndp_{technology}_{year}"], | ||
| parse_dates=True, | ||
| index_col=0, | ||
| ) | ||
| .rename_axis("time") | ||
| .reset_index() | ||
| .melt(id_vars=["time"], var_name="bus", value_name="profile") | ||
| .assign(year=year_i, hydro_tech=technology) | ||
| .set_index(["bus", "time", "year", "hydro_tech"]) | ||
| .to_xarray() | ||
| ) | ||
|
|
||
| inflows.append(inflow) | ||
|
|
||
| ds = xr.merge(inflows) | ||
| ds = ds.sel(time=time) | ||
|
|
||
| ds.to_netcdf(snakemake.output.profile) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.