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

add Linopy to PyPSA-Eur #625

Merged
merged 10 commits into from
Mar 10, 2023
10 changes: 1 addition & 9 deletions config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,7 @@ solving:
track_iterations: false
min_iterations: 4
max_iterations: 6
keep_shadowprices:
- Bus
- Line
- Link
- Transformer
- GlobalConstraint
- Generator
- Store
- StorageUnit
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved
seed: 123

solver:
name: gurobi
Expand Down
9 changes: 4 additions & 5 deletions rules/solve_electricity.smk
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

rule solve_network:
input:
RESOURCES + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
network=RESOURCES + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
output:
RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
log:
solver=normpath(
LOGS + "solve_network/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_solver.log"
Expand All @@ -31,10 +31,9 @@ rule solve_network:

rule solve_operations_network:
input:
unprepared=RESOURCES + "networks/elec_s{simpl}_{clusters}_ec.nc",
optimized=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
output:
RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_op.nc",
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_op.nc",
log:
solver=normpath(
LOGS
Expand Down
2 changes: 1 addition & 1 deletion rules/solve_myopic.smk
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ rule solve_sector_network_myopic:
conda:
"../envs/environment.yaml"
script:
"../scripts/solve_sector_network.py"
"../scripts/solve_network.py"
2 changes: 1 addition & 1 deletion rules/solve_overnight.smk
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ rule solve_sector_network:
conda:
"../envs/environment.yaml"
script:
"../scripts/solve_sector_network.py"
"../scripts/solve_network.py"
7 changes: 4 additions & 3 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,12 @@ def mock_snakemake(rulename, configfiles=[], **wildcards):
kwargs = (
dict(rerun_triggers=[]) if parse(sm.__version__) > Version("7.7.0") else {}
)
workflow = sm.Workflow(snakefile, **kwargs)
workflow.include(snakefile)

if isinstance(configfiles, str):
configfiles = [configfiles]

workflow = sm.Workflow(snakefile, overwrite_configfiles=configfiles, **kwargs)
workflow.include(snakefile)

if configfiles:
for f in configfiles:
if not os.path.exists(f):
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_transport_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def build_transport_demand(traffic_fn, airtemp_fn, nodes, nodal_transport_data):
)

transport = (
(transport_shape.multiply(energy_totals_transport) * 1e6 * Nyears)
(transport_shape.multiply(energy_totals_transport) * 1e6 * nyears)
.divide(efficiency_gain * ice_correction)
.multiply(1 + dd_EV)
)
Expand Down Expand Up @@ -181,7 +181,7 @@ def bev_dsm_profile(snapshots, nodes, options):

snapshots = pd.date_range(freq="h", **snakemake.config["snapshots"], tz="UTC")

Nyears = 1
nyears = len(snapshots) / 8760
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved

nodal_transport_data = build_nodal_transport_data(
snakemake.input.transport_data, pop_layout
Expand Down
12 changes: 8 additions & 4 deletions scripts/make_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,13 @@ def calculate_metrics(n, label, metrics):
["line_volume_AC", "line_volume_DC"], label
].sum()

if hasattr(n, "line_volume_limit"):
metrics.at["line_volume_limit", label] = n.line_volume_limit
metrics.at["line_volume_shadow", label] = n.line_volume_limit_dual
if "lv_limit" in n.global_constraints.index:
metrics.at["line_volume_limit", label] = n.global_constraints.at[
"lv_limit", "constant"
]
metrics.at["line_volume_shadow", label] = n.global_constraints.at[
"lv_limit", "mu"
]

if "CO2Limit" in n.global_constraints.index:
metrics.at["co2_shadow", label] = n.global_constraints.at["CO2Limit", "mu"]
Expand Down Expand Up @@ -695,7 +699,7 @@ def to_csv(df):
for planning_horizon in snakemake.config["scenario"]["planning_horizons"]
}

Nyears = 1
Nyears = len(pd.date_range(freq="h", **snakemake.config["snapshots"])) / 8760
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved

costs_db = prepare_costs(
snakemake.input.costs,
Expand Down
14 changes: 8 additions & 6 deletions scripts/plot_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ def plot_h2_map(network, regions):
link_widths=link_widths_retro,
branch_components=["Link"],
ax=ax,
color_geomap=False,
boundaries=map_opts["boundaries"],
**map_opts,
)

regions.plot(
Expand Down Expand Up @@ -922,11 +921,11 @@ def plot_series(network, carrier="AC", name="test"):
snakemake = mock_snakemake(
"plot_network",
simpl="",
clusters="181",
ll="vopt",
opts="",
sector_opts="Co2L0-730H-T-H-B-I-A-solar+p3-linemaxext10",
planning_horizons="2050",
clusters="5",
ll="v1.5",
sector_opts="CO2L0-1H-T-H-B-I-A-solar+p3-dist1",
planning_horizons="2030",
)

logging.basicConfig(level=snakemake.config["logging"]["level"])
Expand All @@ -938,6 +937,9 @@ def plot_series(network, carrier="AC", name="test"):

map_opts = snakemake.config["plotting"]["map"]

if map_opts["boundaries"] is None:
map_opts["boundaries"] = regions.total_bounds[[0, 2, 1, 3]] + [-1, 1, -1, 1]

plot_map(
n,
components=["generators", "links", "stores", "storage_units"],
Expand Down
Loading