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

Corrected threshold filtering for Alaska SRF and MRF Peak Flow Arrival time services #1015

Merged
merged 2 commits into from
Dec 19, 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
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
DROP TABLE IF EXISTS publish.mrf_gfs_10day_peak_flow_arrival_time_alaska;

WITH arrival_time AS(
SELECT
forecasts.feature_id,
max(forecasts.forecast_hour)+1 AS below_bank_return_hour
FROM ingest.nwm_channel_rt_mrf_gfs_ak_mem1 AS forecasts
GROUP BY forecasts.feature_id
)

SELECT
forecasts.feature_id,
forecasts.feature_id::TEXT AS feature_id_str,
channels.name,
channels.strm_order::integer,
min(forecasts.forecast_hour) AS peak_flow_arrival_hour,
to_char(forecasts.reference_time::timestamp without time zone + INTERVAL '1 hour' * min(forecasts.forecast_hour), 'YYYY-MM-DD HH24:MI:SS UTC') AS peak_flow_arrival_time,
channels.huc6,
'AK' as state,
forecasts.nwm_vers,
forecasts.reference_time,
max_flows.discharge_cfs AS max_flow_cfs,
rf.high_water_threshold,
arrival_time.below_bank_return_hour,
to_char(forecasts.reference_time::timestamp without time zone + INTERVAL '1 hour' * arrival_time.below_bank_return_hour, 'YYYY-MM-DD HH24:MI:SS UTC') AS below_bank_return_time,
arrival_time.below_bank_return_time,
to_char(now()::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC') AS update_time,
channels.strm_order::integer,
channels.name,
channels.huc6,
'AK' as state,
-9999.0 as high_water_threshold,
channels.geom

INTO publish.mrf_gfs_10day_peak_flow_arrival_time_alaska
Expand All @@ -34,9 +26,10 @@ JOIN cache.max_flows_mrf_gfs_10day_ak AS max_flows
ON forecasts.feature_id = max_flows.feature_id AND round((forecasts.streamflow*35.315)::numeric, 2) = max_flows.discharge_cfs

-- Join in channels data to get reach metadata and geometry
JOIN derived.channels_alaska as channels ON forecasts.feature_id = channels.feature_id::bigint
JOIN derived.channels_ak as channels ON forecasts.feature_id = channels.feature_id::bigint

-- Join in arrival_time
JOIN arrival_time ON forecasts.feature_id = arrival_time.feature_id
-- Join in high water arrival time for return time (the yaml config file ensures that arrival time finishes first for this, but we'll join on reference_time as well to ensure)
JOIN publish.mrf_gfs_10day_high_water_arrival_time_ak AS arrival_time ON forecasts.feature_id = arrival_time.feature_id and forecasts.reference_time = arrival_time.reference_time

WHERE round((forecasts.streamflow*35.315)::numeric, 2) >= rf.high_water_threshold
GROUP BY forecasts.feature_id, forecasts.reference_time, forecasts.nwm_vers, forecasts.streamflow, max_flows.discharge_cfs, arrival_time.below_bank_return_hour, channels.geom, channels.strm_order, channels.name, channels.huc6;
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
DROP TABLE IF EXISTS publish.mrf_nbm_10day_peak_flow_arrival_time_alaska;

WITH arrival_time AS(
SELECT
forecasts.feature_id,
max(forecasts.forecast_hour)+1 AS below_bank_return_hour
FROM ingest.nwm_channel_rt_mrf_nbm_ak AS forecasts
GROUP BY forecasts.feature_id
)

SELECT
forecasts.feature_id,
forecasts.feature_id::TEXT AS feature_id_str,
channels.name,
channels.strm_order::integer,
min(forecasts.forecast_hour) AS peak_flow_arrival_hour,
to_char(forecasts.reference_time::timestamp without time zone + INTERVAL '1 hour' * min(forecasts.forecast_hour), 'YYYY-MM-DD HH24:MI:SS UTC') AS peak_flow_arrival_time,
channels.huc6,
'AK' as state,
forecasts.nwm_vers,
forecasts.reference_time,
max_flows.discharge_cfs AS max_flow_cfs,
rf.high_water_threshold,
arrival_time.below_bank_return_hour,
to_char(forecasts.reference_time::timestamp without time zone + INTERVAL '1 hour' * arrival_time.below_bank_return_hour, 'YYYY-MM-DD HH24:MI:SS UTC') AS below_bank_return_time,
arrival_time.below_bank_return_time,
to_char(now()::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC') AS update_time,
channels.strm_order::integer,
channels.name,
channels.huc6,
'AK' as state,
-9999.0 as high_water_threshold,
channels.geom

INTO publish.mrf_nbm_10day_peak_flow_arrival_time_alaska
Expand All @@ -36,7 +28,8 @@ JOIN cache.max_flows_mrf_nbm_10day_ak AS max_flows
-- Join in channels data to get reach metadata and geometry
JOIN derived.channels_alaska as channels ON forecasts.feature_id = channels.feature_id::bigint

-- Join in arrival_time
JOIN arrival_time ON forecasts.feature_id = arrival_time.feature_id
-- Join in high water arrival time for return time (the yaml config file ensures that arrival time finishes first for this, but we'll join on reference_time as well to ensure)
JOIN publish.mrf_nbm_10day_high_water_arrival_time_ak AS arrival_time ON forecasts.feature_id = arrival_time.feature_id and forecasts.reference_time = arrival_time.reference_time

WHERE round((forecasts.streamflow*35.315)::numeric, 2) >= rf.high_water_threshold
GROUP BY forecasts.feature_id, forecasts.reference_time, forecasts.nwm_vers, forecasts.streamflow, max_flows.discharge_cfs, arrival_time.below_bank_return_hour, channels.geom, channels.strm_order, channels.name, channels.huc6;
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ JOIN derived.recurrence_flows_ak AS rf ON forecasts.feature_id = rf.feature_id
-- Join in high water arrival time for return time (the yaml config file ensures that arrival time finishes first for this, but we'll join on reference_time as well to ensure)
JOIN publish.srf_15hr_high_water_arrival_time_alaska AS arrival_time ON forecasts.feature_id = arrival_time.feature_id and forecasts.reference_time = arrival_time.reference_time

WHERE round((forecasts.streamflow*35.315)::numeric, 2) >= rf.high_water_threshold
GROUP BY forecasts.feature_id, forecasts.reference_time, forecasts.nwm_vers, arrival_time.below_bank_return_hour, arrival_time.below_bank_return_time, max_flows.discharge_cfs, channels.geom, channels.strm_order, channels.name, channels.huc6, rf.high_water_threshold;
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ db_max_flows:
max_flows_sql_file: mrf_gfs_10day_max_flows_ak

postprocess_sql:
- sql_file: mrf_gfs_10day_peak_flow_arrival_time_alaska
- sql_file: mrf_gfs_10day_peak_flow_arrival_time_ak
target_table: publish.mrf_gfs_10day_peak_flow_arrival_time_alaska

services:
- mrf_gfs_10day_peak_flow_arrival_time_alaska_noaa
- mrf_gfs_10day_peak_flow_arrival_time_ak_noaa
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ db_max_flows:
max_flows_sql_file: mrf_nbm_10day_max_flows_ak

postprocess_sql:
- sql_file: mrf_nbm_10day_peak_flow_arrival_time_alaska
- sql_file: mrf_nbm_10day_peak_flow_arrival_time_ak
target_table: publish.mrf_nbm_10day_peak_flow_arrival_time_alaska

services:
- mrf_nbm_10day_peak_flow_arrival_time_alaska_noaa
- mrf_nbm_10day_peak_flow_arrival_time_ak_noaa
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ db_max_flows:
max_flows_sql_file: srf_max_flows_ak

postprocess_sql:
- sql_file: srf_15hr_peak_flow_arrival_time_alaska
- sql_file: srf_15hr_peak_flow_arrival_time_ak
target_table: publish.srf_15hr_peak_flow_arrival_time_alaska

services:
- srf_15hr_peak_flow_arrival_time_alaska_noaa
- srf_15hr_peak_flow_arrival_time_ak_noaa
Loading