Skip to content

Commit

Permalink
update to pypsa loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Dec 5, 2024
1 parent 8715949 commit 76b0db8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion assume/common/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def handle_output_message(self, content: dict, meta: MetaDict):
market_id = content.get("market_id")

# content_data is dataframe if flows are from pypsa
if not content_data is not None and len(content_data) <=0:
if content_data is None or len(content_data) <=0:
return

if content_type in [
Expand Down Expand Up @@ -560,6 +560,7 @@ def create_line(row):
continue
df["simulation"] = self.simulation_id
df.reset_index()
df.columns = df.columns.str.lower()

try:
with self.db.begin() as db:
Expand Down
6 changes: 3 additions & 3 deletions assume/markets/clearing_algorithms/nodal_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def clear(
)

# return orderbook_df back to orderbook format as list of dicts
accepted_orders = orderbook_df.to_dict("records")
rejected_orders = []
accepted_orders = orderbook_df[orderbook_df["accepted_volume"] != 0].to_dict("records")
rejected_orders = orderbook_df[orderbook_df["accepted_volume"] == 0].to_dict("records")
meta = []

# calculate meta data such as total upwared and downward redispatch, total backup dispatch
Expand Down Expand Up @@ -262,4 +262,4 @@ def process_dispatch_data(
# rename columns
flows.columns = ["datetime", "line", "flow"]

return flows.to_dict(orient="records")
return flows.to_dict(orient="records")
4 changes: 2 additions & 2 deletions assume/markets/clearing_algorithms/redispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def clear(
logger.debug("No congestion detected")

# return orderbook_df back to orderbook format as list of dicts
accepted_orders = orderbook_df.to_dict("records")
rejected_orders = []
accepted_orders = orderbook_df[orderbook_df["accepted_volume"] != 0].to_dict("records")
rejected_orders = orderbook_df[orderbook_df["accepted_volume"] == 0].to_dict("records")
meta = []

# calculate meta data such as total upwared and downward redispatch, total backup dispatch
Expand Down
17 changes: 9 additions & 8 deletions assume/scenario/loader_oeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def load_oeds(
freq="h",
)
sim_id = f"{scenario}_{study_case}"
logger.info(f"loading scenario {sim_id}")
logger.info(f"loading scenario {sim_id} with {nuts_config}")
infra_interface = InfrastructureInterface("test", infra_uri)

if not nuts_config:
Expand Down Expand Up @@ -111,13 +111,13 @@ def load_oeds(

lat, lon = infra_interface.get_lat_lon_area(area)

sum_demand = demand.sum(axis=1)
sum_demand = demand.sum(axis=1).sum()

world.add_unit_operator(f"demand{area}")
world.add_unit_operator(f"demand_{area}")
world.add_unit(
f"demand{area}1",
f"demand_{area}1",
"demand",
f"demand{area}",
f"demand_{area}",
# the unit_params have no hints
{
"min_power": 0,
Expand Down Expand Up @@ -215,11 +215,12 @@ def load_oeds(
"postgresql://readonly:[email protected]:5432/opendata",
)

nuts_config = os.getenv("NUTS_CONFIG").split(",")
nuts_config = nuts_config or ["DE1", "DEA", "DEB", "DEC", "DED", "DEE", "DEF"]
default_nuts_config = 'DE1, DEA, DEB, DEC, DED, DEE, DEF'
nuts_config = os.getenv("NUTS_CONFIG", default_nuts_config).split(",")
nuts_config = [n.strip() for n in nuts_config]
year = 2019
start = datetime(year, 1, 1)
end = datetime(year + 1, 1, 1) - timedelta(hours=1)
end = datetime(year, 1+1, 1) - timedelta(hours=1)
marketdesign = [
MarketConfig(
"EOM",
Expand Down
2 changes: 1 addition & 1 deletion examples/inputs/example_01d/lines.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name,bus0,bus1,s_nom,x,r
Line,bus0,bus1,s_nom,x,r
Line_N_S_1,north_1,south,5000.0,0.01,0.001
Line_N_S_2,north_2,south,5000.0,0.01,0.001
Line_N_N,north_1,north_2,5000.0,0.01,0.001
Expand Down

0 comments on commit 76b0db8

Please sign in to comment.