Skip to content

Commit c3d0bce

Browse files
committed
Update get_inputs.py to create hydro_timepoints.csv
1 parent 9e4011e commit c3d0bce

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

switch_model/generators/extensions/hydro_simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
expects data in variable_capacity_factors.csv.
3434
3535
hydro_timeseries.csv
36-
hydro_generation_project, timeseries, hydro_min_flow_mw,
36+
hydro_generation_project, hydro_timeseries, hydro_min_flow_mw,
3737
hydro_avg_flow_mw
3838
3939
The file hydro_timepoints.csv is an optional mapping of timepoints
@@ -42,7 +42,7 @@
4242
specified over a different time period.
4343
4444
hydro_timepoints.csv (optional)
45-
timepoint,tp_to_hts
45+
timepoint_id,tp_to_hts
4646
"""
4747
from __future__ import division
4848
# ToDo: Refactor this code to move the core components into a

switch_model/wecc/get_inputs/get_inputs.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,27 +637,52 @@ def query_db(full_config, skip_cf):
637637
# zone + watershed. Eventually, we may rethink this derating, but it is a reasonable
638638
# approximation for a large hydro fleet where plant outages are individual random events.
639639
# Negative flows are replaced by 0.
640+
write_csv_from_query(
641+
db_cursor,
642+
"hydro_timepoints",
643+
["timepoint_id", "tp_to_hts"],
644+
f"""
645+
SELECT
646+
tp.raw_timepoint_id AS timepoint_id,
647+
p.label || '_M' || date_part('month', timestamp_utc) AS tp_to_hts
648+
FROM switch.sampled_timepoint AS tp
649+
JOIN switch.period AS p USING(period_id, study_timeframe_id)
650+
WHERE time_sample_id = {time_sample_id}
651+
AND study_timeframe_id = {study_timeframe_id}
652+
ORDER BY 1;
653+
"""
654+
)
655+
640656
write_csv_from_query(
641657
db_cursor,
642658
"hydro_timeseries",
643659
["hydro_project", "timeseries", "hydro_min_flow_mw", "hydro_avg_flow_mw"],
644660
f"""
645-
select generation_plant_id as hydro_project,
646-
{timeseries_id_select},
661+
SELECT
662+
generation_plant_id AS hydro_project,
663+
hts.hydro_timeseries,
647664
CASE
648665
WHEN hydro_min_flow_mw <= 0 THEN 0
649666
ELSE least(hydro_min_flow_mw, capacity_limit_mw * (1-forced_outage_rate)) END,
650667
CASE
651668
WHEN hydro_avg_flow_mw <= 0 THEN 0
652669
ELSE least(hydro_avg_flow_mw, capacity_limit_mw * (1-forced_outage_rate)) END
653-
as hydro_avg_flow_mw
654-
from hydro_historical_monthly_capacity_factors
655-
join sampled_timeseries on(month = date_part('month', first_timepoint_utc) and year = date_part('year', first_timepoint_utc))
656-
join generation_plant using (generation_plant_id)
670+
AS hydro_avg_flow_mw
671+
FROM (
672+
SELECT DISTINCT
673+
date_part('month', tp.timestamp_utc) as month,
674+
date_part('year', tp.timestamp_utc) as year,
675+
p.label || '_M' || date_part('month', timestamp_utc) AS hydro_timeseries
676+
FROM switch.sampled_timepoint AS tp
677+
JOIN switch.period AS p USING(period_id, study_timeframe_id)
678+
WHERE time_sample_id = {time_sample_id}
679+
AND study_timeframe_id = {study_timeframe_id}
680+
) AS hts
681+
JOIN switch.hydro_historical_monthly_capacity_factors USING(month, year)
682+
JOIN switch.generation_plant USING(generation_plant_id)
657683
JOIN temp_generation_plant_ids USING(generation_plant_id)
658-
where hydro_simple_scenario_id={hydro_simple_scenario_id}
659-
and time_sample_id = {time_sample_id}
660-
order by 1;
684+
WHERE hydro_simple_scenario_id={hydro_simple_scenario_id}
685+
ORDER BY 1;
661686
""",
662687
)
663688

0 commit comments

Comments
 (0)