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

SAFER does not work with sector studies #423

Open
2 tasks done
trevorb1 opened this issue Sep 26, 2024 · 0 comments
Open
2 tasks done

SAFER does not work with sector studies #423

trevorb1 opened this issue Sep 26, 2024 · 0 comments
Labels
bug Something isn't working Sector Sector Coupling Issue

Comments

@trevorb1
Copy link
Collaborator

Checklist

  • I am using the current master branch
  • I am running on an up-to-date pypsa-usa environment. Update via conda env update -f envs/environment.yaml

The Issue

In sector studies, gas and coal thermal generators are converted to links to track fuel use between sectors. When adding SAFER constraints, only generators are queried, missing generators that have been converted to links.

Steps To Reproduce

No response

Expected Behavior

No response

Error Message

No response

Anything else?

def add_SAFER_constraints(n, config):
"""
Add a capacity reserve margin of a certain fraction above the peak demand
for regions defined in configuration file. Renewable generators and storage
do not contribute towards PRM.
Parameters
----------
n : pypsa.Network
config : dict
"""
regional_prm = pd.read_csv(
config["electricity"]["SAFE_regional_reservemargins"],
index_col=[0],
)
reeds_prm = pd.read_csv(
snakemake.input.safer_reeds,
index_col=[0],
)
NERC_memberships = (
n.buses.groupby("nerc_reg")["reeds_zone"]
.apply(lambda x: ", ".join(x))
.to_dict()
)
reeds_prm["region"] = reeds_prm.index.map(NERC_memberships)
reeds_prm.dropna(subset="region", inplace=True)
reeds_prm.drop(
columns=["none", "ramp2025_20by50", "ramp2025_25by50", "ramp2025_30by50"],
inplace=True,
)
reeds_prm.rename(columns={"static": "prm", "t": "planning_horizon"}, inplace=True)
regional_prm = pd.concat([regional_prm, reeds_prm])
regional_prm = regional_prm[
regional_prm.planning_horizon.isin(snakemake.params.planning_horizons)
]
for idx, prm in regional_prm.iterrows():
region_list = [region_.strip() for region_ in prm.region.split(",")]
region_buses = n.buses[
(
n.buses.country.isin(region_list)
| n.buses.reeds_state.isin(region_list)
| n.buses.interconnect.str.lower().isin(region_list)
| n.buses.nerc_reg.isin(region_list)
| (1 if "all" in region_list else 0)
)
]
if region_buses.empty:
continue
peakdemand = (
n.loads_t.p_set.loc[
prm.planning_horizon,
n.loads.bus.isin(region_buses.index),
]
.sum(axis=1)
.max()
)
margin = 1.0 + prm.prm
planning_reserve = peakdemand * margin
conventional_carriers = config["electricity"]["conventional_carriers"]
region_gens = n.generators[n.generators.bus.isin(region_buses.index)]
ext_gens_i = region_gens.query(
"carrier in @conventional_carriers & p_nom_extendable",
).index
p_nom = n.model["Generator-p_nom"].loc[ext_gens_i]
lhs = p_nom.sum()
exist_conv_caps = region_gens.query(
"~p_nom_extendable & carrier in @conventional_carriers",
).p_nom.sum()
rhs = planning_reserve - exist_conv_caps
n.model.add_constraints(
lhs >= rhs,
name=f"GlobalConstraint-{prm.name}_{prm.planning_horizon}_PRM",
)

@trevorb1 trevorb1 added bug Something isn't working Sector Sector Coupling Issue labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Sector Sector Coupling Issue
Projects
None yet
Development

No branches or pull requests

1 participant