Skip to content

Commit f9660da

Browse files
bbestclaude
andcommitted
counts are records, statistics see the zeros: n = count(obs_id) in every template, n_samples = tows sampled
The zero-filled rows of slice_bio.sql had been counted as observations (sardine larvae: 6,158 → 52,741 "in view", the observations bars showing effort instead of catch, the pills reading 55,301). obs_id is NULL only on a zero-filled row, so n = count(obs_id) restores every count to the records while mean / se / median keep running over all sampled tows; picker.sql reports n_filled beside them and the bundle README says "N observation rows (+ M zero-filled tows)". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XJj3nb6xYaquerksg2vkYz
1 parent 81a1ad6 commit f9660da

13 files changed

Lines changed: 24 additions & 18 deletions

sql/cruise.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SELECT cruise_key, count(*) AS n, count(DISTINCT root_id) AS n_samples, count(DISTINCT grid_key) AS n_sta,
1+
SELECT cruise_key, count(obs_id) AS n, count(DISTINCT root_id) AS n_samples, count(DISTINCT grid_key) AS n_sta,
22
avg({{val}}) AS mean, median({{val}}) AS med, epoch(min(datetime)) AS t0, epoch(max(datetime)) AS t1
33
FROM slice
44
WHERE cruise_key IS NOT NULL AND {{where}}

sql/cruise_samples.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- the chosen cruise's sampled values, one dot per root sample
22
SELECT root_id, any_value(latitude) AS latitude, any_value(longitude) AS longitude, any_value(grid_key) AS grid_key,
3-
count(*) AS n, avg({{val}}) AS mean, median({{val}}) AS med, epoch(min(datetime)) AS t
3+
count(obs_id) AS n, avg({{val}}) AS mean, median({{val}}) AS med, epoch(min(datetime)) AS t
44
FROM slice
55
WHERE cruise_key = {{cruise}} AND latitude IS NOT NULL AND {{where}}
66
GROUP BY root_id

sql/depth_strip.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- the water-column strip: median / IQR per 10 m bin over the current selection (all depths, so the brush has context)
2-
SELECT depth_bin, count(*) AS n, median({{val}}) AS med,
2+
SELECT depth_bin, count(obs_id) AS n, median({{val}}) AS med,
33
quantile_cont({{val}}, 0.25) AS q1, quantile_cont({{val}}, 0.75) AS q3
44
FROM slice
55
WHERE depth_bin IS NOT NULL AND {{where_nodepth}}

sql/depth_strip_ds.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- the maximized water-column profile: the per-dataset median per 10 m bin (one dotted line per dataset,
22
-- beside the all-dataset median + IQR of depth_strip.sql)
3-
SELECT dataset_key, depth_bin, count(*) AS n, median({{val}}) AS med,
3+
SELECT dataset_key, depth_bin, count(obs_id) AS n, median({{val}}) AS med,
44
quantile_cont({{val}}, 0.25) AS q1, quantile_cont({{val}}, 0.75) AS q3
55
FROM slice
66
WHERE depth_bin IS NOT NULL AND {{where_nodepth}}

sql/hex.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- the hex column is printf('%x', parent(hex7, res)): an H3 parent is bit arithmetic on the res-7 cell
22
-- (calcofi4db::h3_parent_sql), rendered as the standard H3 string deck.gl / h3-js take directly
3-
SELECT {{hex}} AS hex, count(*) AS n, count(DISTINCT root_id) AS n_samples,
3+
SELECT {{hex}} AS hex, count(obs_id) AS n, count(DISTINCT root_id) AS n_samples,
44
avg({{val}}) AS mean, median({{val}}) AS med
55
FROM slice
66
WHERE hex7 IS NOT NULL AND {{where}}

sql/picker.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
-- D8 rule 4: dataset x life stage x effort class x gear, with how many rows each denominator can serve
1+
-- D8 rule 4: dataset x life stage x effort class x gear, with how many RECORDS each denominator can serve
2+
-- (n_filled: the zero-filled tows of slice_bio.sql beside them, never counted as observations)
23
SELECT dataset_key, life_stage, effort_class, tow_type, any_value(units) AS units,
3-
count(*) AS n, count(density_per_10m2) AS n_10m2, count(density_per_1000m3) AS n_1000m3,
4+
count(obs_id) AS n, count(density_per_10m2) FILTER (WHERE obs_id IS NOT NULL) AS n_10m2, count(density_per_1000m3) FILTER (WHERE obs_id IS NOT NULL) AS n_1000m3,
5+
count(*) FILTER (WHERE obs_id IS NULL) AS n_filled,
46
count(*) FILTER (WHERE NOT qual_ok) AS n_flagged
57
FROM slice GROUP BY ALL ORDER BY 1, 2, 3, 4

sql/region.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- exact per-root-sample membership (sample_spatial), one layer at a time because layers overlap
2-
SELECT sp.spatial_key, any_value(sp.spatial_name) AS spatial_name, count(*) AS n, count(DISTINCT s.root_id) AS n_samples,
2+
SELECT sp.spatial_key, any_value(sp.spatial_name) AS spatial_name, count(s.obs_id) AS n, count(DISTINCT s.root_id) AS n_samples,
33
avg({{val}}) AS mean, median({{val}}) AS med, min(year) AS y0, max(year) AS y1
44
FROM slice s JOIN {{spatial_src}} sp USING (root_id)
55
WHERE sp.layer = {{layer}} AND {{where}}

sql/section_bio.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- bio has no depth axis in this cut (tows are depth-integrated): the section is line x year
22
SELECT station, year,
3-
avg({{val}}) AS v, count(*) AS n
3+
avg({{val}}) AS v, count(obs_id) AS n
44
FROM slice
55
WHERE line = {{line}} AND {{where}}
66
GROUP BY ALL ORDER BY station, year

sql/section_cruises.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- cruises that sampled this line, newest first (a YYYY-MM-NODC key sorts chronologically by itself);
22
-- n_sta is the picker's bar and App.tsx picks the cruise with the most stations as the default
3-
SELECT cruise_key, count(DISTINCT grid_key) AS n_sta, count(*) AS n, min(year) AS year
3+
SELECT cruise_key, count(DISTINCT grid_key) AS n_sta, count(obs_id) AS n, min(year) AS year
44
FROM slice
55
WHERE cruise_key IS NOT NULL AND line = {{line}} AND {{where}}
66
GROUP BY cruise_key ORDER BY cruise_key DESC

sql/slice_bio.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
-- dataset sampled (a root sample with >= 1 row of any taxon; the effort it can standardize by is what its
66
-- rows carry) gets a zero row per life stage the dataset records this taxon at, unless it has a row already.
77
-- a dataset that ships its own zeros (cufes, zooscan, zoodb, phyllosoma) is left as it is. zero rows have
8-
-- obs_id NULL and qual_ok TRUE.
8+
-- obs_id NULL and qual_ok TRUE; every template counts n = count(obs_id) (records) and n_samples = tows, so the
9+
-- counts shown stay the records and only the statistics (mean, se, median) see the zeros.
910
CREATE OR REPLACE TABLE slice AS
1011
WITH pos AS (
1112
SELECT obs_id, dataset_key, root_id, grid_key,

0 commit comments

Comments
 (0)