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

various improvements for pypsa and amiris loader #509

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions assume/common/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,13 @@ def __init__(
index=self.index, value=price_forecast, name="price_forecast"
)

self.data_dict = {}

for key, value in kwargs.items():
self.data_dict[key] = FastSeries(index=self.index, value=value, name=key)



def __getitem__(self, column: str) -> FastSeries:
"""
Retrieves forecasted values.
Expand Down Expand Up @@ -579,5 +586,7 @@ def __getitem__(self, column: str) -> FastSeries:
return self.demand
elif column == "price_EOM":
return self.price_forecast
elif column in self.data_dict.keys():
return self.data_dict[column]
else:
return FastSeries(value=0.0, index=self.index)
49 changes: 25 additions & 24 deletions assume/common/grid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
if "marginal_cost" not in gen_c.columns:
gen_c["marginal_cost"] = p_set

network.madd(
network.add(

Check warning on line 41 in assume/common/grid_utils.py

View check run for this annotation

Codecov / codecov/patch

assume/common/grid_utils.py#L41

Added line #L41 was not covered by tests
"Generator",
names=generators.index,
name=generators.index,
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators[
"max_power"
Expand All @@ -49,9 +49,10 @@
)
else:
# add generators
network.madd(
generators.drop(["p_min_pu", "p_max_pu", "marginal_cost"], axis=1, inplace=True, errors="ignore")

Check warning on line 52 in assume/common/grid_utils.py

View check run for this annotation

Codecov / codecov/patch

assume/common/grid_utils.py#L52

Added line #L52 was not covered by tests
network.add(
"Generator",
names=generators.index,
name=generators.index,
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators[
"max_power"
Expand Down Expand Up @@ -84,18 +85,18 @@
)

# add generators and their sold capacities as load with reversed sign to have fixed feed in
network.madd(
network.add(
"Load",
names=generators.index,
name=generators.index,
bus=generators["node"], # bus to which the generator is connected to
p_set=p_set,
sign=1,
)

# add upward redispatch generators
network.madd(
network.add(
"Generator",
names=generators.index,
name=generators.index,
suffix="_up",
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators["max_power"], # Nominal capacity of the powerplant/generator
Expand All @@ -105,9 +106,9 @@
)

# add downward redispatch generators
network.madd(
network.add(
"Generator",
names=generators.index,
name=generators.index,
suffix="_down",
bus=generators["node"], # bus to which the generator is connected to
p_nom=generators["max_power"], # Nominal capacity of the powerplant/generator
Expand All @@ -118,18 +119,18 @@
)

# add upward and downward backup generators at each node
network.madd(
network.add(
"Generator",
names=network.buses.index,
name=network.buses.index,
suffix="_backup_up",
bus=network.buses.index, # bus to which the generator is connected to
p_nom=10e4,
marginal_cost=backup_marginal_cost,
)

network.madd(
network.add(
"Generator",
names=network.buses.index,
name=network.buses.index,
suffix="_backup_down",
bus=network.buses.index, # bus to which the generator is connected to
p_nom=10e4,
Expand All @@ -151,9 +152,9 @@
"""

# add backup generators at each node
network.madd(
network.add(
"Generator",
names=network.buses.index,
name=network.buses.index,
suffix="_backup",
bus=network.buses.index, # bus to which the generator is connected to
p_nom=10e4,
Expand All @@ -174,9 +175,9 @@
"""

# add loads
network.madd(
network.add(
"Load",
names=loads.index,
name=loads.index,
bus=loads["node"], # bus to which the generator is connected to
**loads,
)
Expand All @@ -201,9 +202,9 @@
del loads_c["sign"]

# add loads with opposite sign (default for loads is -1). This is needed to properly model the redispatch
network.madd(
network.add(

Check warning on line 205 in assume/common/grid_utils.py

View check run for this annotation

Codecov / codecov/patch

assume/common/grid_utils.py#L205

Added line #L205 was not covered by tests
"Load",
names=loads.index,
name=loads.index,

Check warning on line 207 in assume/common/grid_utils.py

View check run for this annotation

Codecov / codecov/patch

assume/common/grid_utils.py#L207

Added line #L207 was not covered by tests
bus=loads["node"], # bus to which the generator is connected to
sign=1,
**loads_c,
Expand Down Expand Up @@ -237,9 +238,9 @@
del loads_c["sign"]

# add loads as negative generators
network.madd(
network.add(
"Generator",
names=loads.index,
name=loads.index,

Check warning on line 243 in assume/common/grid_utils.py

View check run for this annotation

Codecov / codecov/patch

assume/common/grid_utils.py#L243

Added line #L243 was not covered by tests
bus=loads["node"], # bus to which the generator is connected to
p_nom=loads["max_power"], # Nominal capacity of the powerplant/generator
p_min_pu=p_set,
Expand All @@ -264,10 +265,10 @@
"""

def add_buses(network: pypsa.Network, buses: pd.DataFrame) -> None:
network.import_components_from_dataframe(buses, "Bus")
network.add("Bus", buses.index, **buses)

def add_lines(network: pypsa.Network, lines: pd.DataFrame) -> None:
network.import_components_from_dataframe(lines, "Line")
network.add("Line", lines.index, **lines)

# setup the network
add_buses(network, grid_dict["buses"])
Expand Down
5 changes: 2 additions & 3 deletions assume/common/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@
data, orient="index", columns=["flow"]
).reset_index()
# Split the 'index' column into 'timestamp' and 'line'
df[["timestamp", "line"]] = pd.DataFrame(
df[["datetime", "line"]] = pd.DataFrame(

Check warning on line 418 in assume/common/outputs.py

View check run for this annotation

Codecov / codecov/patch

assume/common/outputs.py#L418

Added line #L418 was not covered by tests
df["index"].tolist(), index=df.index
)
# Rename the columns
df = df.drop(columns=["index"])

# set timestamp to index
df.set_index("timestamp", inplace=True)
df.set_index("datetime", inplace=True)

Check warning on line 425 in assume/common/outputs.py

View check run for this annotation

Codecov / codecov/patch

assume/common/outputs.py#L425

Added line #L425 was not covered by tests

df["simulation"] = self.simulation_id

Expand Down Expand Up @@ -480,7 +480,6 @@
if df is None:
continue

df.reset_index()
if df.empty:
continue

Expand Down
3 changes: 0 additions & 3 deletions assume/markets/clearing_algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@

# try importing pypsa if it is installed
try:
from .nodal_pricing import NodalMarketRole
from .redispatch import RedispatchMarketRole

clearing_mechanisms["redispatch"] = RedispatchMarketRole
clearing_mechanisms["nodal"] = NodalMarketRole

except ImportError:
pass
Loading
Loading