Skip to content

Commit 131a1de

Browse files
authored
enable observation QA (#743)
* enable exclusion of observations noted by QA as invalid for bcfishpass purposes and identification of observations that are known to be releases or associated with releases * tag fish observations that are found (by QA) to be probable releases * flag releases based on source/source_ref string matching * include steehead in barrier/observation qa tables and exclude releases from counts upstream of natural barriers * fix line endings, fix classification of two observations * fix observation exclusion query
1 parent f8ea817 commit 131a1de

File tree

8 files changed

+436
-43
lines changed

8 files changed

+436
-43
lines changed

.github/workflows/ng-prod.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
jobs/connect
9292
cd model/01_access
9393
./02_model_access_anthropogenic.sh
94-
psql $DATABASE_URL -v ON_ERROR_STOP=1 -f sql/load_qa_observations_naturalbarriers_ch_cm_co_pk_sk.sql
94+
psql $DATABASE_URL -v ON_ERROR_STOP=1 -f sql/load_qa_observations_naturalbarriers.sql
9595
model-habitat-linear:
9696
runs-on: ubuntu-latest
9797
environment: ng-prod
@@ -125,7 +125,7 @@ jobs:
125125
aws s3 cp wsg_crossing_summary_current.csv s3://bchamp/wsg_crossing_summary_current.csv --acl public-read
126126
aws s3 cp wsg_linear_summary_current.csv s3://bchamp/wsg_linear_summary_current.csv --acl public-read
127127
jobs/release_fptwg
128-
psql $DATABASE_URL -c "select * from bcfishpass.qa_observations_ch_cm_co_pk_sk" --csv > qa_observations_ch_cm_co_pk_sk.csv
129-
psql $DATABASE_URL -c "select * from bcfishpass.qa_naturalbarriers_ch_cm_co_pk_sk" --csv > qa_naturalbarriers_ch_cm_co_pk_sk.csv
130-
aws s3 cp qa_observations_ch_cm_co_pk_sk.csv s3://bchamp/qa_observations_ch_cm_co_pk_sk.csv --acl public-read
131-
aws s3 cp qa_naturalbarriers_ch_cm_co_pk_sk.csv s3://bchamp/qa_naturalbarriers_ch_cm_co_pk_sk.csv --acl public-read
128+
psql $DATABASE_URL -c "select * from bcfishpass.qa_observations_ch_cm_co_pk_sk_st" --csv > qa_observations_ch_cm_co_pk_sk_st.csv
129+
psql $DATABASE_URL -c "select * from bcfishpass.qa_naturalbarriers_ch_cm_co_pk_sk_st" --csv > qa_naturalbarriers_ch_cm_co_pk_sk_st.csv
130+
aws s3 cp qa_observations_ch_cm_co_pk_sk.csv s3://bchamp/qa_observations_ch_cm_co_pk_sk_st.csv --acl public-read
131+
aws s3 cp qa_naturalbarriers_ch_cm_co_pk_sk.csv s3://bchamp/qa_naturalbarriers_ch_cm_co_pk_sk_st.csv --acl public-read

data/observation_exclusions.csv

Lines changed: 209 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- update natural barrier/observation QA tables to
2+
-- - include steelhead
3+
-- - flag likely releases
4+
-- - include counts per species
5+
6+
BEGIN;
7+
8+
CREATE TABLE bcfishpass.qa_observations_ch_cm_co_pk_sk_st (
9+
observation_key text primary key ,
10+
species_code character varying(6) ,
11+
observation_date date ,
12+
activity_code character varying(100) ,
13+
activity character varying(300) ,
14+
life_stage_code character varying(100) ,
15+
life_stage character varying(300) ,
16+
acat_report_url character varying(254) ,
17+
agency_name character varying(60) ,
18+
source character varying(1000),
19+
source_ref character varying(4000),
20+
release boolean ,
21+
watershed_group_code character varying(4) ,
22+
gradient_15_dnstr text ,
23+
gradient_20_dnstr text ,
24+
gradient_25_dnstr text ,
25+
gradient_30_dnstr text ,
26+
falls_dnstr text ,
27+
subsurfaceflow_dnstr text ,
28+
gradient_15_dnstr_count integer ,
29+
gradient_20_dnstr_count integer,
30+
gradient_25_dnstr_count integer,
31+
gradient_30_dnstr_count integer,
32+
falls_dnstr_count integer,
33+
subsurfaceflow_dnstr_count integer
34+
);
35+
36+
-- natural barriers to salmon with salmon observations upstream (exluding known/likely releases)
37+
CREATE TABLE bcfishpass.qa_naturalbarriers_ch_cm_co_pk_sk_st (
38+
barrier_id text primary key,
39+
barrier_type text,
40+
watershed_group_code text,
41+
observations_upstr text,
42+
n_observations_upstr integer,
43+
n_ch_upstr integer,
44+
n_cm_upstr integer,
45+
n_co_upstr integer,
46+
n_pk_upstr integer,
47+
n_sk_upstr integer,
48+
n_st_upstr integer
49+
);
50+
51+
DROP TABLE bcfishpass.qa_observations_ch_cm_co_pk_sk;
52+
DROP TABLE bcfishpass.qa_naturalbarriers_ch_cm_co_pk_sk;
53+
54+
COMMIT;

db/v0.7.8/migrate.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ set -euxo pipefail
33

44
PSQL="psql $DATABASE_URL -v ON_ERROR_STOP=1"
55

6-
# document the cabd fix tables
6+
# enable exclusion of individual fish observation records based on QA
7+
$PSQL -f observation_exclusions.sql
8+
9+
# update observation/natural barrier qa tables
10+
$PSQL -f barrier_observation_qa.sql
11+
12+
# document cabd fix tables
713
$PSQL -f cabd_fix_table_comments.sql
814

915
$PSQL -c "update bcfishpass.db_version set tag = '${PWD##*/}'"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- ADD FISH OBSERVATION EXCLUSIONS
2+
BEGIN;
3+
4+
CREATE TABLE bcfishpass.observation_exclusions (
5+
observation_key text ,
6+
exclude boolean,
7+
release boolean,
8+
reviewer_name text,
9+
review_date date,
10+
source_1 text,
11+
source_2 text,
12+
notes text,
13+
primary key (observation_key)
14+
);
15+
16+
ALTER TABLE bcfishpass.observations ADD COLUMN release boolean;
17+
18+
COMMIT;

jobs/release_fptwg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,17 @@ ogr2ogr \
223223
-sql "select
224224
observation_key,
225225
species_code,
226+
species_name,
226227
observation_date,
228+
agency_name,
229+
source,
230+
source_ref,
227231
activity_code,
228232
activity,
229233
life_stage_code,
230234
life_stage,
231235
acat_report_url,
236+
release,
232237
linear_feature_id,
233238
blue_line_key,
234239
downstream_route_measure,

model/01_access/sql/load_observations.sql

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ begin;
4141
-- filter on species code and watershed group
4242
insert into bcfishpass.observations (
4343
observation_key,
44+
release,
4445
fish_observation_point_id,
4546
species_code,
4647
agency_id,
@@ -76,6 +77,7 @@ begin;
7677
)
7778
select
7879
o.observation_key,
80+
x.release, -- note records at locations of ongoing/documented release programs
7981
o.fish_observation_point_id,
8082
r.species_code_remap as species_code,
8183
o.agency_id,
@@ -111,6 +113,24 @@ begin;
111113
from bcfishobs.observations o
112114
inner join wsg_spp on o.watershed_group_code = wsg_spp.watershed_group_code
113115
inner join species_code_remap r on o.species_code = r.species_code
114-
and array[o.species_code]::text[] && wsg_spp.species_codes;
116+
and array[o.species_code]::text[] && wsg_spp.species_codes
117+
-- exclude observations identified by QA as invalid (for fish passage modelling purposes)
118+
left outer join bcfishpass.observation_exclusions x on o.observation_key = x.observation_key
119+
where coalesce(x.exclude, false) is false;
120+
121+
-- use source_ref to find and tag records related to stocking/releases
122+
123+
-- note that this source seems to be obsolete - was present nov 2025 but is absent from table as of jan 05 2026
124+
UPDATE bcfishpass.observations
125+
SET release = true
126+
WHERE substring(source from 1 for position(':' in source)) = 'Releases Database:';
127+
128+
UPDATE bcfishpass.observations
129+
SET release = true
130+
WHERE source_ref ilike '%BC RELEASE RECORDS DATABASE%';
131+
132+
UPDATE bcfishpass.observations
133+
SET release = true
134+
WHERE source_ref ilike '%STOCKING%';
115135

116136
commit;

0 commit comments

Comments
 (0)