Skip to content

Commit

Permalink
Merge pull request #87 from NREL/fix-hc-queries
Browse files Browse the repository at this point in the history
Properly handle secondary voltages in HC scripts
  • Loading branch information
daniel-thom authored Apr 15, 2022
2 parents 920465b + 8a54c2f commit 8075943
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 32 deletions.
12 changes: 6 additions & 6 deletions disco/postprocess/hosting_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def synthesize_voltage(results_df):
"sample",
"penetration_level",
"scenario",
"node_type"]
]

df = results_df.groupby(filter_cols)[["min_voltage"]].min().reset_index()
df2 = results_df.groupby(filter_cols)[["max_voltage"]].max().reset_index()
Expand All @@ -72,8 +72,8 @@ def synthesize_voltage(results_df):
results_df.groupby(filter_cols)[
[
"num_nodes_any_outside_ansi_b",
"num_time_points_with_ansi_b_violations"
]
"num_time_points_with_ansi_b_violations",
]
]
.max()
.reset_index()
Expand Down Expand Up @@ -161,10 +161,10 @@ def compute_hc_per_metric_class(
)
meta_df = meta_df.dropna(axis="index", subset=["sample", "penetration_level"])

metric_df, meta_df = synthesize(metric_df, meta_df, metric_class)

if metric_class == "voltage" and len(node_types) == 1:
metric_df = metric_df[metric_df.node_types == node_types[0]]
metric_df = metric_df[metric_df.node_type == node_types[0]]

metric_df, meta_df = synthesize(metric_df, meta_df, metric_class)

queries = build_queries(metric_df.columns, thresholds, metric_class, on=on)
query_phrase = " & ".join(queries)
Expand Down
79 changes: 53 additions & 26 deletions disco/postprocess/query.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,33 @@ CREATE TEMP VIEW hc_max AS
GROUP BY feeder
;

-- Create a table with worst-case values.
DROP VIEW IF EXISTS worst_case;
CREATE TEMP VIEW worst_case AS
SELECT
feeder
,sample
,penetration_level
,transformer_instantaneous_threshold
{{#thermal}}
,MAX(line_max_instantaneous_loading_pct) as line_max_instantaneous_loading_pct_overall
,MAX(line_max_moving_average_loading_pct) as line_max_moving_average_loading_pct_overall
,MAX(line_num_time_points_with_instantaneous_violations) as line_num_time_points_with_instantaneous_violations_overall
,MAX(line_num_time_points_with_moving_average_violations) as line_num_time_points_with_moving_average_violations_overall
,MAX(transformer_max_instantaneous_loading_pct) as transformer_max_instantaneous_loading_pct_overall
,MAX(transformer_max_moving_average_loading_pct) as transformer_max_moving_average_loading_pct_overall
,MAX(transformer_num_time_points_with_instantaneous_violations) as transformer_num_time_points_with_instantaneous_violations_overall
,MAX(transformer_num_time_points_with_moving_average_violations) as transformer_num_time_points_with_moving_average_violations_overall
{{/thermal}}
{{#voltage}}
,MIN(min_voltage) AS min_voltage_overall
,MAX(max_voltage) AS max_voltage_overall
,MAX(num_nodes_any_outside_ansi_b) as num_nodes_any_outside_ansi_b_overall
,MAX(num_time_points_with_ansi_b_violations) as num_time_points_with_ansi_b_violations_overall
{{/voltage}}
FROM jt
GROUP BY feeder, sample, penetration_level, transformer_instantaneous_threshold;

-- Create a table showing hosting capacity by feeder and sample.
DROP VIEW IF EXISTS hc_by_sample;
CREATE TEMP VIEW hc_by_sample AS
Expand All @@ -222,36 +249,36 @@ CREATE TEMP VIEW hc_by_sample AS
,sample
--,pv_distance
,MAX(penetration_level) AS max_passing_penetration_level
FROM jt
FROM worst_case
WHERE
true
{{#thermal}}
AND
(
line_max_instantaneous_loading_pct <= {{thermal.line_max_instantaneous_loading_pct}}
AND line_max_moving_average_loading_pct <= {{thermal.line_max_moving_average_loading_pct}}
AND line_num_time_points_with_instantaneous_violations <= {{thermal.line_num_time_points_with_instantaneous_violations}}
AND line_num_time_points_with_moving_average_violations <= {{thermal.line_num_time_points_with_moving_average_violations}}
line_max_instantaneous_loading_pct_overall <= {{thermal.line_max_instantaneous_loading_pct}}
AND line_max_moving_average_loading_pct_overall <= {{thermal.line_max_moving_average_loading_pct}}
AND line_num_time_points_with_instantaneous_violations_overall <= {{thermal.line_num_time_points_with_instantaneous_violations}}
AND line_num_time_points_with_moving_average_violations_overall <= {{thermal.line_num_time_points_with_moving_average_violations}}
AND
(
transformer_instantaneous_threshold IS NULL
OR
(
transformer_max_instantaneous_loading_pct <= {{thermal.transformer_max_instantaneous_loading_pct}}
AND transformer_max_moving_average_loading_pct <= {{thermal.transformer_max_moving_average_loading_pct}}
AND transformer_num_time_points_with_instantaneous_violations <= {{thermal.transformer_num_time_points_with_instantaneous_violations}}
AND transformer_num_time_points_with_moving_average_violations <= {{thermal.transformer_num_time_points_with_moving_average_violations}}
transformer_max_instantaneous_loading_pct_overall <= {{thermal.transformer_max_instantaneous_loading_pct}}
AND transformer_max_moving_average_loading_pct_overall <= {{thermal.transformer_max_moving_average_loading_pct}}
AND transformer_num_time_points_with_instantaneous_violations_overall <= {{thermal.transformer_num_time_points_with_instantaneous_violations}}
AND transformer_num_time_points_with_moving_average_violations_overall <= {{thermal.transformer_num_time_points_with_moving_average_violations}}
)
)
)
{{/thermal}}
{{#voltage}}
AND
(
min_voltage >= {{voltage.min_voltage}}
AND max_voltage <= {{voltage.max_voltage}}
AND num_nodes_any_outside_ansi_b <= {{voltage.num_nodes_any_outside_ansi_b}}
AND num_time_points_with_ansi_b_violations <= {{voltage.num_time_points_with_ansi_b_violations}}
min_voltage_overall >= {{voltage.min_voltage}}
AND max_voltage_overall <= {{voltage.max_voltage}}
AND num_nodes_any_outside_ansi_b_overall <= {{voltage.num_nodes_any_outside_ansi_b}}
AND num_time_points_with_ansi_b_violations_overall <= {{voltage.num_time_points_with_ansi_b_violations}}
)
{{/voltage}}
GROUP BY feeder, sample;
Expand Down Expand Up @@ -282,36 +309,36 @@ CREATE TEMP VIEW hc_per_level1 AS
feeder
,sample
,penetration_level
FROM jt
FROM worst_case
WHERE
true
{{#thermal}}
AND
(
line_max_instantaneous_loading_pct <= {{thermal.line_max_instantaneous_loading_pct}}
AND line_max_moving_average_loading_pct <= {{thermal.line_max_moving_average_loading_pct}}
AND line_num_time_points_with_instantaneous_violations <= {{thermal.line_num_time_points_with_instantaneous_violations}}
AND line_num_time_points_with_moving_average_violations <= {{thermal.line_num_time_points_with_moving_average_violations}}
line_max_instantaneous_loading_pct_overall <= {{thermal.line_max_instantaneous_loading_pct}}
AND line_max_moving_average_loading_pct_overall <= {{thermal.line_max_moving_average_loading_pct}}
AND line_num_time_points_with_instantaneous_violations_overall <= {{thermal.line_num_time_points_with_instantaneous_violations}}
AND line_num_time_points_with_moving_average_violations_overall <= {{thermal.line_num_time_points_with_moving_average_violations}}
AND
(
transformer_instantaneous_threshold IS NULL
OR
(
transformer_max_instantaneous_loading_pct <= {{thermal.transformer_max_instantaneous_loading_pct}}
AND transformer_max_moving_average_loading_pct <= {{thermal.transformer_max_moving_average_loading_pct}}
AND transformer_num_time_points_with_instantaneous_violations <= {{thermal.transformer_num_time_points_with_instantaneous_violations}}
AND transformer_num_time_points_with_moving_average_violations <= {{thermal.transformer_num_time_points_with_moving_average_violations}}
transformer_max_instantaneous_loading_pct_overall <= {{thermal.transformer_max_instantaneous_loading_pct}}
AND transformer_max_moving_average_loading_pct_overall <= {{thermal.transformer_max_moving_average_loading_pct}}
AND transformer_num_time_points_with_instantaneous_violations_overall <= {{thermal.transformer_num_time_points_with_instantaneous_violations}}
AND transformer_num_time_points_with_moving_average_violations_overall <= {{thermal.transformer_num_time_points_with_moving_average_violations}}
)
)
)
{{/thermal}}
{{#voltage}}
AND
(
min_voltage >= {{voltage.min_voltage}}
AND max_voltage <= {{voltage.max_voltage}}
AND num_nodes_any_outside_ansi_b <= {{voltage.num_nodes_any_outside_ansi_b}}
AND num_time_points_with_ansi_b_violations <= {{voltage.num_time_points_with_ansi_b_violations}}
min_voltage_overall >= {{voltage.min_voltage}}
AND max_voltage_overall <= {{voltage.max_voltage}}
AND num_nodes_any_outside_ansi_b_overall <= {{voltage.num_nodes_any_outside_ansi_b}}
AND num_time_points_with_ansi_b_violations_overall <= {{voltage.num_time_points_with_ansi_b_violations}}
)
{{/voltage}}
;
Expand Down

0 comments on commit 8075943

Please sign in to comment.