Skip to content

Commit

Permalink
Flexibly define market prices to vary with iterations (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
anamileva authored Nov 22, 2024
1 parent 33654ea commit c90a3c3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 32 deletions.
1 change: 1 addition & 0 deletions db/csvs_test_examples/csv_structure.csv
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ reliability/local_capacity/system_local_capacity_requirement,local_capacity,loca
markets/geography_markets,markets,market_scenario_id,geography_markets,simple,,0,,,,,
markets/load_zone_markets,markets,load_zone_market_scenario_id,load_zone_markets,simple,,0,,,,,
markets/prices,markets,market_price_scenario_id,market_prices,simple,,0,,,,,
markets/prices/price_profiles,markets,market_price_profile_scenario_id,market_price_profiles,simple,,0,,,,,
markets/volume,markets,market_volume_scenario_id,market_volume,simple,,0,,,,,
water/water_system_params,water,water_system_params_scenario_id,system_water_system_params,simple,,0,,,,,
water/water_network,water,water_network_scenario_id,geography_water_network,simple,,0,,,,,
Expand Down
21 changes: 2 additions & 19 deletions db/csvs_test_examples/markets/prices/1_base_prices.csv
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
hydro_iteration,stage_id,timepoint,market,market_price
0,1,20200101,Market_Hub,10
0,1,20200102,Market_Hub,-10
0,1,20200201,Market_Hub,10
0,1,20200202,Market_Hub,-10
0,1,20200301,Market_Hub,10
0,1,20200302,Market_Hub,-10
0,1,20200101,Market_Hub2,1
0,1,20200102,Market_Hub2,2
0,1,20200201,Market_Hub2,3
0,1,20200202,Market_Hub2,2
0,1,20200301,Market_Hub2,1
0,1,20200302,Market_Hub2,2
0,2,20200101,Market_Hub2,3
0,2,20200102,Market_Hub2,2
0,2,20200201,Market_Hub2,1
0,2,20200202,Market_Hub2,2
0,2,20200301,Market_Hub2,3
0,2,20200302,Market_Hub2,2
market_price_profile_scenario_id,varies_by_weather_iteration,varies_by_hydro_iteration
1,0,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
weather_iteration,hydro_iteration,stage_id,timepoint,market,market_price
0,0,1,20200101,Market_Hub,10
0,0,1,20200102,Market_Hub,-10
0,0,1,20200201,Market_Hub,10
0,0,1,20200202,Market_Hub,-10
0,0,1,20200301,Market_Hub,10
0,0,1,20200302,Market_Hub,-10
0,0,1,20200101,Market_Hub2,1
0,0,1,20200102,Market_Hub2,2
0,0,1,20200201,Market_Hub2,3
0,0,1,20200202,Market_Hub2,2
0,0,1,20200301,Market_Hub2,1
0,0,1,20200302,Market_Hub2,2
0,0,2,20200101,Market_Hub2,3
0,0,2,20200102,Market_Hub2,2
0,0,2,20200201,Market_Hub2,1
0,0,2,20200202,Market_Hub2,2
0,0,2,20200301,Market_Hub2,3
0,0,2,20200302,Market_Hub2,2
47 changes: 36 additions & 11 deletions db/db_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -932,17 +932,38 @@ CREATE TABLE subscenarios_market_prices
DROP TABLE IF EXISTS inputs_market_prices;
CREATE TABLE inputs_market_prices
(
market_price_scenario_id INTEGER,
hydro_iteration INTEGER NOT NULL,
stage_id INTEGER,
timepoint INTEGER,
market VARCHAR(32),
market_price FLOAT,
PRIMARY KEY (market_price_scenario_id, hydro_iteration, stage_id, timepoint, market),
market_price_scenario_id INTEGER,
market_price_profile_scenario_id INTEGER,
varies_by_weather_iteration INTEGER,
varies_by_hydro_iteration INTEGER,
PRIMARY KEY (market_price_scenario_id, market_price_profile_scenario_id),
FOREIGN KEY (market_price_scenario_id) REFERENCES
subscenarios_market_prices (market_price_scenario_id)
);

DROP TABLE IF EXISTS subscenarios_market_price_profiles;
CREATE TABLE subscenarios_market_price_profiles
(
market_price_profile_scenario_id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(32),
description VARCHAR(128)
);

DROP TABLE IF EXISTS inputs_market_price_profiles;
CREATE TABLE inputs_market_price_profiles
(
market_price_profile_scenario_id INTEGER,
weather_iteration INTEGER NOT NULL,
hydro_iteration INTEGER NOT NULL,
stage_id INTEGER,
timepoint INTEGER,
market VARCHAR(32),
market_price FLOAT,
PRIMARY KEY (market_price_profile_scenario_id, weather_iteration,
hydro_iteration, stage_id, timepoint,
market)
);

DROP TABLE IF EXISTS subscenarios_market_volume;
CREATE TABLE subscenarios_market_volume
(
Expand Down Expand Up @@ -1093,7 +1114,8 @@ CREATE TABLE inputs_system_water_node_reservoir_exogenous_elevations
hydro_iteration INTEGER DEFAULT 0 NOT NULL,
timepoint INTEGER,
reservoir_exogenous_elevation INTEGER,
PRIMARY KEY (water_node, exogenous_elevation_id, timepoint, hydro_iteration),
PRIMARY KEY (water_node, exogenous_elevation_id, timepoint,
hydro_iteration),
FOREIGN KEY (water_node, exogenous_elevation_id) REFERENCES
subscenarios_system_water_node_reservoir_exogenous_elevations
(water_node, exogenous_elevation_id)
Expand Down Expand Up @@ -1143,7 +1165,8 @@ CREATE TABLE inputs_system_water_node_reservoirs_target_volumes
hydro_iteration INTEGER DEFAULT 0 NOT NULL,
timepoint FLOAT,
reservoir_target_volume DECIMAL,
PRIMARY KEY (water_node, target_volume_scenario_id, timepoint, hydro_iteration),
PRIMARY KEY (water_node, target_volume_scenario_id, timepoint,
hydro_iteration),
FOREIGN KEY (water_node, target_volume_scenario_id) REFERENCES
subscenarios_system_water_node_reservoirs_target_volumes
(water_node, target_volume_scenario_id)
Expand Down Expand Up @@ -1235,7 +1258,8 @@ CREATE TABLE inputs_system_water_flows
timepoint FLOAT,
min_flow_vol_per_second TEXT,
max_flow_vol_per_second INTEGER,
PRIMARY KEY (water_flow_scenario_id, water_link, timepoint, hydro_iteration),
PRIMARY KEY (water_flow_scenario_id, water_link, timepoint,
hydro_iteration),
FOREIGN KEY (water_flow_scenario_id) REFERENCES
subscenarios_system_water_flows (water_flow_scenario_id)
);
Expand All @@ -1257,7 +1281,8 @@ CREATE TABLE inputs_system_water_inflows
hydro_iteration INTEGER DEFAULT 0 NOT NULL,
timepoint FLOAT,
exogenous_water_inflow_rate_vol_per_sec TEXT,
PRIMARY KEY (water_inflow_scenario_id, water_node, timepoint, hydro_iteration),
PRIMARY KEY (water_inflow_scenario_id, water_node, timepoint,
hydro_iteration),
FOREIGN KEY (water_inflow_scenario_id) REFERENCES
subscenarios_system_water_inflows (water_inflow_scenario_id)
);
Expand Down
21 changes: 19 additions & 2 deletions gridpath/system/markets/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,19 @@ def get_inputs_from_database(

c = conn.cursor()

prices = c.execute(
(varies_by_weather_iteration, varies_by_hydro_iteration) = c.execute(
f"""
SELECT varies_by_weather_iteration, varies_by_hydro_iteration
FROM inputs_market_prices
WHERE market_price_scenario_id = {subscenarios.MARKET_PRICE_SCENARIO_ID}
"""
).fetchone()

weather_iteration_to_use = weather_iteration if varies_by_weather_iteration else 0
hydro_iteration_to_use = hydro_iteration if varies_by_hydro_iteration else 0

c1 = conn.cursor()
prices = c1.execute(
f"""
SELECT market, timepoint, market_price
-- Get prices for included markets only
Expand All @@ -103,9 +115,14 @@ def get_inputs_from_database(
) as tmp_tbl
LEFT OUTER JOIN (
SELECT market, stage_id, timepoint, market_price
FROM inputs_market_price_profiles
WHERE market_price_profile_scenario_id = (
SELECT market_price_profile_scenario_id
FROM inputs_market_prices
WHERE market_price_scenario_id = {subscenarios.MARKET_PRICE_SCENARIO_ID}
AND hydro_iteration = {hydro_iteration}
AND hydro_iteration = {hydro_iteration_to_use}
AND weather_iteration = {weather_iteration_to_use}
)
) as price_tbl
USING (market, stage_id, timepoint)
;
Expand Down

0 comments on commit c90a3c3

Please sign in to comment.