Merge branch 'master' into validation

This commit is contained in:
Fabian Hofmann 2023-07-05 11:21:09 +02:00 committed by GitHub
commit 9c3f89160a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -16,6 +16,8 @@ Upcoming Release
* Bugfix: Correct typo in the CPLEX solver configuration in ``config.default.yaml``. * Bugfix: Correct typo in the CPLEX solver configuration in ``config.default.yaml``.
* Bugfix: Error in ``add_electricity`` where carriers were added multiple times to the network, resulting in a non-unique carriers error.
* Renamed script file from PyPSA-EUR ``build_load_data`` to ``build_electricity_demand`` and ``retrieve_load_data`` to ``retrieve_electricity_demand``. * Renamed script file from PyPSA-EUR ``build_load_data`` to ``build_electricity_demand`` and ``retrieve_load_data`` to ``retrieve_electricity_demand``.
* Fix docs readthedocs built * Fix docs readthedocs built

View File

@ -121,6 +121,15 @@ def calculate_annuity(n, r):
return 1 / n return 1 / n
def add_missing_carriers(n, carriers):
"""
Function to add missing carriers to the network without raising errors.
"""
missing_carriers = set(carriers) - set(n.carriers.index)
if len(missing_carriers) > 0:
n.madd("Carrier", missing_carriers)
def sanitize_carriers(n, config): def sanitize_carriers(n, config):
""" """
Sanitize the carrier information in a PyPSA Network object. Sanitize the carrier information in a PyPSA Network object.
@ -150,9 +159,7 @@ def sanitize_carriers(n, config):
for c in n.iterate_components(): for c in n.iterate_components():
if "carrier" in c.df: if "carrier" in c.df:
missing_carrier = set(c.df.carrier.unique()) - set(n.carriers.index) - {""} add_missing_carriers(n, c.df)
if len(missing_carrier):
n.madd("Carrier", missing_carrier)
carrier_i = n.carriers.index carrier_i = n.carriers.index
nice_names = ( nice_names = (
@ -351,6 +358,7 @@ def update_transmission_costs(n, costs, length_factor=1.0):
def attach_wind_and_solar( def attach_wind_and_solar(
n, costs, input_profiles, carriers, extendable_carriers, line_length_factor=1 n, costs, input_profiles, carriers, extendable_carriers, line_length_factor=1
): ):
for car in carriers: for car in carriers:
if car == "hydro": if car == "hydro":
continue continue
@ -415,7 +423,7 @@ def attach_conventional_generators(
fuel_price=None, fuel_price=None,
): ):
carriers = list(set(conventional_carriers) | set(extendable_carriers["Generator"])) carriers = list(set(conventional_carriers) | set(extendable_carriers["Generator"]))
n.madd("Carrier", carriers) add_missing_carriers(n, carriers)
add_co2_emissions(n, costs, carriers) add_co2_emissions(n, costs, carriers)
ppl = ( ppl = (
@ -492,7 +500,7 @@ def attach_conventional_generators(
def attach_hydro(n, costs, ppl, profile_hydro, hydro_capacities, carriers, **params): def attach_hydro(n, costs, ppl, profile_hydro, hydro_capacities, carriers, **params):
n.madd("Carrier", carriers) add_missing_carriers(n, carriers)
add_co2_emissions(n, costs, carriers) add_co2_emissions(n, costs, carriers)
ppl = ( ppl = (
@ -625,7 +633,7 @@ def attach_extendable_generators(n, costs, ppl, carriers):
logger.warning( logger.warning(
"The function `attach_extendable_generators` is deprecated in v0.5.0." "The function `attach_extendable_generators` is deprecated in v0.5.0."
) )
n.madd("Carrier", carriers) add_missing_carriers(n, carriers)
add_co2_emissions(n, costs, carriers) add_co2_emissions(n, costs, carriers)
for tech in carriers: for tech in carriers: