-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
161 changed files
with
5,774 additions
and
6,159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cabd_id,reviewer_name,review_date,source,notes | ||
30b88f1b-dc21-4b42-8daa-d4cebae24142,SN,2023-01-01,not noted, | ||
3ca692b8-37cf-44e8-a783-2a315ec83102,SN,2023-01-01,not noted, | ||
ba5fe3eb-7bbe-45c1-b301-555872387c16,SN,2023-01-01,not noted, | ||
8a6b10fa-0d4f-4c45-857c-764d7e8028f8,SN,2023-01-01,not noted, | ||
48478e95-e063-4df6-a047-6aaf6087011b,SN,2023-01-01,not noted, | ||
e8e4bd88-c3c9-407c-a7a0-15c6c51704fd,SN,2023-01-01,not noted,dam may or may not be a barrier but location was incorrect at time of review | ||
6a792d8f-b9c5-44a4-a260-0f06c3b20821,SN,2023-01-01,not noted,dam may or may not be a barrier but location gets matched to Salmon River |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
-- function to query the view (so it is visible in pgfs) | ||
DROP FUNCTION IF EXISTS postgisftw.wcrp_barrier_count; | ||
CREATE FUNCTION postgisftw.wcrp_barrier_count( | ||
watershed_group_code TEXT, | ||
model_status TEXT default 'ALL' | ||
) | ||
-- watershed_group_code: BULK, LNIC, HORS, BOWR, QUES, CARR, ELKR | ||
-- model_status : HABITAT, ACCESSIBLE, ALL (default) | ||
|
||
RETURNS TABLE ( | ||
crossing_feature_type TEXT, | ||
n_passable bigint, | ||
n_barrier bigint, | ||
n_potential bigint, | ||
n_unknown bigint, | ||
total bigint | ||
) | ||
LANGUAGE 'plpgsql' | ||
IMMUTABLE PARALLEL SAFE | ||
|
||
AS $$ | ||
|
||
DECLARE | ||
v_wsg text := watershed_group_code; | ||
v_model_status text := model_status; | ||
|
||
BEGIN | ||
|
||
IF (v_model_status = 'ALL') | ||
then return query | ||
|
||
SELECT | ||
v.crossing_feature_type, | ||
sum(v.n_passable)::bigint as n_passable, | ||
sum(v.n_barrier)::bigint as n_barrier, | ||
sum(v.n_potential)::bigint as n_potential, | ||
sum(v.n_unknown)::bigint as n_unknown, | ||
(sum(v.n_passable) + sum(v.n_barrier) + sum(v.n_potential) + sum(v.n_unknown))::bigint as total | ||
FROM bcfishpass.wcrp_barrier_count_vw v | ||
WHERE v.watershed_group_code = v_wsg | ||
GROUP BY v.crossing_feature_type; | ||
|
||
ELSIF (v_model_status = 'ACCESSIBLE') | ||
then return query | ||
SELECT | ||
v.crossing_feature_type, | ||
sum(v.n_passable)::bigint as n_passable, | ||
sum(v.n_barrier)::bigint as n_barrier, | ||
sum(v.n_potential)::bigint as n_potential, | ||
sum(v.n_unknown)::bigint as n_unknown, | ||
(sum(v.n_passable) + sum(v.n_barrier) + sum(v.n_potential) + sum(v.n_unknown))::bigint as total | ||
FROM bcfishpass.wcrp_barrier_count_vw v | ||
WHERE | ||
v.watershed_group_code = v_wsg and | ||
v.model_status in ('ACCESSIBLE', 'HABITAT') | ||
group by v.crossing_feature_type; | ||
|
||
ELSIF (v_model_status = 'HABITAT') | ||
then return query | ||
SELECT | ||
v.crossing_feature_type, | ||
v.n_passable::bigint as n_passable, | ||
v.n_barrier::bigint as n_barrier, | ||
v.n_potential::bigint as n_potential, | ||
v.n_unknown::bigint as n_unknown, | ||
(v.n_passable + v.n_barrier + v.n_potential + v.n_unknown)::bigint as total | ||
FROM bcfishpass.wcrp_barrier_count_vw v | ||
WHERE | ||
v.watershed_group_code = v_wsg and | ||
v.model_status = 'HABITAT'; | ||
|
||
END IF; | ||
|
||
END | ||
|
||
|
||
$$; | ||
|
||
COMMENT ON FUNCTION postgisftw.wcrp_barrier_count IS | ||
'Return count of crossings per crossing_feature_type within specified watershed group. | ||
Returns count of crossings accessible to target species if model_status=ACCESSIBLE is specified, | ||
Returns count of crossings below modelled habitat if model_status=HABITAT is specified | ||
Returns count of all crossings if model_status=ALL is specified (default)'; | ||
|
||
REVOKE EXECUTE ON FUNCTION postgisftw.wcrp_barrier_count FROM public; | ||
|
||
-- test | ||
--select * from postgisftw.wcrp_barrier_count('QUES'); | ||
--select * from postgisftw.wcrp_barrier_count('QUES','ALL'); | ||
--select * from postgisftw.wcrp_barrier_count('QUES','ACCESSIBLE'); | ||
--select * from postgisftw.wcrp_barrier_count('QUES','HABITAT'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
DROP FUNCTION IF EXISTS postgisftw.wcrp_barrier_extent(TEXT); | ||
|
||
CREATE FUNCTION postgisftw.wcrp_barrier_extent(watershed_group_code TEXT) | ||
|
||
-- watershed_group_code: BULK, LNIC, HORS, BOWR, QUES, CARR, ELKR | ||
|
||
RETURNS TABLE( | ||
crossing_feature_type TEXT, | ||
all_habitat_blocked_km numeric, | ||
total_habitat_km numeric, | ||
extent_pct numeric | ||
) | ||
|
||
LANGUAGE 'plpgsql' | ||
IMMUTABLE PARALLEL SAFE | ||
|
||
AS $$ | ||
|
||
DECLARE | ||
v_wsg text := watershed_group_code; | ||
|
||
BEGIN | ||
|
||
RETURN query | ||
|
||
with barriers as ( | ||
select | ||
c.watershed_group_code, | ||
ft.crossing_feature_type, | ||
ROUND(SUM(h_wcrp.all_spawningrearing_belowupstrbarriers_km)::numeric, 2) as all_spawningrearing_blocked_km | ||
FROM bcfishpass.crossings c | ||
inner join bcfishpass.crossings_upstream_habitat uh using (aggregated_crossings_id) | ||
inner join bcfishpass.crossings_feature_type_vw ft using (aggregated_crossings_id) | ||
inner join bcfishpass.crossings_upstream_habitat_wcrp h_wcrp using (aggregated_crossings_id) | ||
WHERE c.barrier_status IN ('POTENTIAL', 'BARRIER') | ||
AND c.aggregated_crossings_id != '1100002536' -- don't count the Elko Dam in ELKR | ||
AND c.watershed_group_code = v_wsg | ||
GROUP BY c.watershed_group_code, ft.crossing_feature_type | ||
ORDER BY c.watershed_group_code, ft.crossing_feature_type | ||
), | ||
|
||
total AS ( | ||
SELECT | ||
b.crossing_feature_type, | ||
b.all_spawningrearing_blocked_km, | ||
(SELECT all_habitat FROM postgisftw.wcrp_habitat_connectivity_status(v_wsg)) as total_habitat_km | ||
FROM barriers b | ||
) | ||
|
||
SELECT | ||
t.crossing_feature_type, | ||
t.all_spawningrearing_blocked_km, | ||
t.total_habitat_km, | ||
round((t.all_spawningrearing_blocked_km / t.total_habitat_km) * 100, 2) as extent_pct | ||
FROM total t; | ||
|
||
END | ||
|
||
|
||
$$; | ||
|
||
COMMENT ON FUNCTION postgisftw.wcrp_barrier_extent IS | ||
'Return km of all blocked spawning and rearing by barrier type, and the percentage of | ||
total spawning and rearing within given watershed group that this blocked habitat represents.'; | ||
|
||
|
||
REVOKE EXECUTE ON FUNCTION postgisftw.wcrp_barrier_extent FROM public; | ||
|
||
-- select * from postgisftw.wcrp_barrier_extent('QUES'); |
Oops, something went wrong.