2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-02-19 15:21:48 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
2019-08-11 20:34:18 +00:00
|
|
|
Solves linear optimal dispatch in hourly resolution using the capacities of
|
2019-08-13 15:52:33 +00:00
|
|
|
previous capacity expansion in rule :mod:`solve_network`.
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
|
|
|
|
2023-10-08 09:20:36 +00:00
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
import logging
|
|
|
|
|
2018-03-13 09:47:47 +00:00
|
|
|
import numpy as np
|
2020-02-10 11:06:43 +00:00
|
|
|
import pypsa
|
2023-08-15 13:02:41 +00:00
|
|
|
from _helpers import (
|
|
|
|
configure_logging,
|
|
|
|
set_scenario_config,
|
2024-02-17 16:16:28 +00:00
|
|
|
update_config_from_wildcards,
|
2023-08-15 13:02:41 +00:00
|
|
|
)
|
2020-02-10 11:06:43 +00:00
|
|
|
from solve_network import prepare_network, solve_network
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2018-02-19 09:17:49 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
2019-12-09 20:29:15 +00:00
|
|
|
from _helpers import mock_snakemake
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2022-06-30 06:39:03 +00:00
|
|
|
snakemake = mock_snakemake(
|
|
|
|
"solve_operations_network",
|
2023-03-15 16:00:06 +00:00
|
|
|
configfiles="test/config.electricity.yaml",
|
2023-03-09 21:51:56 +00:00
|
|
|
opts="",
|
2020-02-10 11:06:43 +00:00
|
|
|
clusters="5",
|
2023-03-09 21:51:56 +00:00
|
|
|
ll="v1.5",
|
|
|
|
sector_opts="",
|
|
|
|
planning_horizons="",
|
2020-02-10 11:06:43 +00:00
|
|
|
)
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-03-09 21:51:56 +00:00
|
|
|
configure_logging(snakemake)
|
2023-08-15 13:02:41 +00:00
|
|
|
set_scenario_config(snakemake)
|
2024-02-17 10:57:16 +00:00
|
|
|
update_config_from_wildcards(snakemake.config, snakemake.wildcards)
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
solve_opts = snakemake.params.options
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-03-09 21:51:56 +00:00
|
|
|
np.random.seed(solve_opts.get("seed", 123))
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2023-07-13 20:31:55 +00:00
|
|
|
n = pypsa.Network(snakemake.input.network)
|
2023-03-09 21:51:56 +00:00
|
|
|
|
2023-05-11 14:58:35 +00:00
|
|
|
n.optimize.fix_optimal_capacities()
|
|
|
|
n = prepare_network(n, solve_opts, config=snakemake.config)
|
2024-08-30 14:15:34 +00:00
|
|
|
n = solve_network(
|
|
|
|
n,
|
|
|
|
config=snakemake.config,
|
|
|
|
params=snakemake.params,
|
|
|
|
solving=snakemake.params.solving,
|
|
|
|
log_fn=snakemake.log.solver,
|
|
|
|
)
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-05-11 14:58:35 +00:00
|
|
|
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
|
|
|
|
n.export_to_netcdf(snakemake.output[0])
|