2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-02-16 10:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2023 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
|
|
|
"""
|
2022-09-16 13:04:04 +00:00
|
|
|
Solves linear optimal dispatch in hourly resolution using the capacities of
|
|
|
|
previous capacity expansion in rule :mod:`solve_network`.
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
import logging
|
|
|
|
|
2018-03-13 09:47:47 +00:00
|
|
|
import numpy as np
|
2022-09-16 13:04:04 +00:00
|
|
|
import pypsa
|
2023-08-15 13:02:41 +00:00
|
|
|
from _helpers import (
|
|
|
|
configure_logging,
|
|
|
|
set_scenario_config,
|
|
|
|
update_config_with_sector_opts,
|
|
|
|
)
|
2022-09-16 13:04:04 +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__":
|
2022-09-16 13:04:04 +00:00
|
|
|
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
|
|
|
|
|
|
|
snakemake = mock_snakemake(
|
|
|
|
"solve_operations_network",
|
2023-03-15 16:00:06 +00:00
|
|
|
configfiles="test/config.electricity.yaml",
|
2022-09-16 13:04:04 +00:00
|
|
|
simpl="",
|
2023-03-09 21:51:56 +00:00
|
|
|
opts="",
|
2022-09-16 13:04:04 +00:00
|
|
|
clusters="5",
|
2023-03-09 21:51:56 +00:00
|
|
|
ll="v1.5",
|
|
|
|
sector_opts="",
|
|
|
|
planning_horizons="",
|
2022-09-16 13:04:04 +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)
|
2023-03-09 21:51:56 +00:00
|
|
|
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-03-09 21:51:56 +00:00
|
|
|
opts = (snakemake.wildcards.opts + "-" + snakemake.wildcards.sector_opts).split("-")
|
|
|
|
opts = [o for o in opts if o != ""]
|
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)
|
|
|
|
n = solve_network(
|
|
|
|
n, config=snakemake.config, opts=opts, 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])
|