From 3390aac2e854434c4c4e397374fa6bd4ad2521a5 Mon Sep 17 00:00:00 2001 From: luen Date: Tue, 3 Nov 2026 12:58:56 +1000 Subject: [PATCH 1/3] Charts: link each chart to the Physioshark paper behind it - publications.ts: ids, rummerlab.com PDF file names and 15 more Mo'orea papers (lunar cycle, umbilicus age, home range, nursery criteria, thermal tolerance, escape performance, heatwave stress, aggregation, photo-ID, injuries, genetics, juvenile density, oxygen supply). - ChartCard papers prop: "Paper: Authors (year), Journal (PDF)" under the chart, linking the PDF on rummerlab.com or the DOI. 51 charts on 17 pages cite the study that analysed the same question; mappings were checked against each abstract. - About lists PDF links; AGENTS.md documents the convention. - e2e: exact match for the Biology menu entry (journal names contain it). Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 1 + e2e/pages.spec.ts | 2 +- src/lib/components/ChartCard.svelte | 21 +++ src/lib/publications.ts | 231 +++++++++++++++++++++-- src/routes/+page.svelte | 1 + src/routes/about/+page.svelte | 11 +- src/routes/adults/+page.svelte | 12 +- src/routes/drivers/+page.svelte | 1 + src/routes/effort/+page.svelte | 6 +- src/routes/growth/+page.svelte | 7 +- src/routes/moon/+page.svelte | 5 + src/routes/morphometrics/+page.svelte | 8 +- src/routes/neonates/+page.svelte | 3 + src/routes/notes/+page.svelte | 1 + src/routes/nurseries/+page.svelte | 3 + src/routes/nurseries/[site]/+page.svelte | 8 +- src/routes/ocean/+page.svelte | 9 +- src/routes/physiology/+page.svelte | 10 +- src/routes/pressure/+page.svelte | 11 +- src/routes/recaptures/+page.svelte | 3 + src/routes/tides/+page.svelte | 4 +- src/routes/time-of-day/+page.svelte | 6 +- src/routes/water-quality/+page.svelte | 17 +- 23 files changed, 345 insertions(+), 36 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b2f0f76..9752a18 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -84,6 +84,7 @@ Drop the workbook in `data/` named like `Physioshark_Shark Log 2026-2027.xlsx` ( - Follow the dataviz method: categorical slots in fixed order (`--series-1…8`, validated light and dark), sequential = one hue (`--seq-*`), diverging = blue ↔ red with a neutral midpoint, one y-axis only (never dual axes), legends for ≥ 2 series, text in ink tokens (never the series colour), 4 px rounded bar ends, 2 px lines, hover tooltips, data tables via `ChartCard table`. - Every chart registers its data with the enclosing `ChartCard` (`registerCsv` in `charts/csv.ts`), which shows **Download CSV**. A new chart component must call `registerCsv` too. An explicit `ChartCard table` takes precedence. +- Cite the study behind a chart with `` (ids in `src/lib/publications.ts`). Link only papers that analysed the same question with this dataset; check the abstract first. PDFs are served at `rummerlab.com/papers/` (metadata in the rummerlab-website repo, `data/papers.json`). - Species colours come from `src/lib/species.ts` (blacktip = slot 1, sicklefin lemon = slot 2). - Charts measure their width (`bind:clientWidth`) and carry a `viewBox` so pre-hydration renders scale down instead of overflowing. - Interactive marks (links) inside an SVG → the SVG gets `role="group"`, not `img` (axe `nested-interactive`). Only put `aria-label` on elements that are links. diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index c4e70b4..25e5c88 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -62,7 +62,7 @@ test('nursery links open a profile and the menu works on mobile', async ({ page await page.setViewportSize({ width: 375, height: 800 }); await page.goto('/'); await page.getByRole('button', { name: 'Menu' }).click(); - await page.getByText('Biology').click(); + await page.getByText('Biology', { exact: true }).click(); await page.getByRole('link', { name: /Growth/ }).click(); await expect(page.locator('h1')).toHaveText('Growth'); const overflow = await page.evaluate( diff --git a/src/lib/components/ChartCard.svelte b/src/lib/components/ChartCard.svelte index 8ec64a1..bbf875a 100644 --- a/src/lib/components/ChartCard.svelte +++ b/src/lib/components/ChartCard.svelte @@ -2,6 +2,7 @@ import { onMount, type Snippet } from 'svelte'; import DataTable, { type Column } from './DataTable.svelte'; import { collectCsv, slug, toCsv, type CsvTable } from './charts/csv'; + import { paper, paperHref, type PaperId } from '#lib/publications'; let { title, @@ -10,6 +11,7 @@ source, id, table, + papers = [], children }: { title: string; @@ -18,6 +20,8 @@ source?: string; id?: string; table?: { columns: Column[]; rows: Record[] }; + /** Studies that analysed the same question with this dataset (`#lib/publications`). */ + papers?: PaperId[]; children: Snippet; } = $props(); @@ -65,6 +69,14 @@ Download CSV for {title} {/if} + {#if papers.length} +

+ {papers.length > 1 ? 'Papers' : 'Paper'}: + {#each papers.map(paper) as p, i (p.id)}{#if i > 0};{/if} + {p.authors} ({p.year}), + {p.journal}{#if p.pdf} (PDF){/if}{/each} +

+ {/if} {#if source}

Source: {source}

{/if} @@ -95,6 +107,15 @@ margin: 10px 0 0; line-height: 1.5; } + .papers { + font-size: 0.78rem; + color: var(--ink-2); + margin: 8px 0 0; + line-height: 1.5; + } + .pdf { + color: var(--muted); + } .source { font-size: 0.74rem; color: var(--muted); diff --git a/src/lib/publications.ts b/src/lib/publications.ts index c8e4b31..a6c9e2f 100644 --- a/src/lib/publications.ts +++ b/src/lib/publications.ts @@ -1,27 +1,197 @@ /** - * Publications listed on physioshark.org (#59); metadata from Crossref. `moorea` marks papers built - * on the Mo'orea nursery fieldwork this site visualises, with the most relevant page. + * Physioshark publications (#59); metadata from Crossref and the RummerLab website. `moorea` + * marks papers built on the Mo'orea nursery fieldwork this site visualises, with the most + * relevant page. `pdf` is the file name served at rummerlab.com/papers/. Chart cards cite papers + * by `id` (`ChartCard papers`), so a chart links to the study that analysed the same question. */ export interface Publication { + id: string; doi: string; authors: string; year: number; title: string; journal: string; + pdf?: string; moorea?: { href: string; label: string }; } -export const PUBLICATIONS: Publication[] = [ +const LIST = [ { + id: 'debaere2025injuries', + doi: '10.1111/jfb.16059', + authors: 'Debaere et al.', + year: 2025, + title: 'The costs and healing rates of minor injuries in neonatal reef sharks', + journal: 'Journal of Fish Biology', + pdf: 'Debaere et al., 2025 J Fish Biology.pdf', + moorea: { href: '/neonates', label: 'Newborns' } + }, + { + id: 'lionnet2025photoid', + doi: '10.1111/jfb.70114', + authors: 'Lionnet et al.', + year: 2025, + title: + "A blacktip's black tip: the reliability of using dorsal-fin patterns for photo identification of blacktip reef sharks (Carcharhinus melanopterus)", + journal: 'Journal of Fish Biology', + pdf: 'Lionnet et al., 2025 JFB.pdf', + moorea: { href: '/recaptures', label: 'Recaptures' } + }, + { + id: 'mcinturf2025aggregation', + doi: '10.1002/ece3.71107', + authors: 'McInturf et al.', + year: 2025, + title: 'Catch data can unravel elasmobranch aggregation dynamics and group behaviours', + journal: 'Ecology and Evolution', + pdf: 'McInturf et al., 2025 Ecology and Evolution .pdf', + moorea: { href: '/time-of-day', label: 'Time of day' } + }, + { + id: 'trujillo2025shallows', + doi: '10.1093/conphys/coaf045', + authors: 'Trujillo et al.', + year: 2025, + title: + 'Safety in the shallows: nearshore coastal habitats can provide physical and thermal features that optimize escape performance in newborn blacktip reef sharks (Carcharhinus melanopterus)', + journal: 'Conservation Physiology', + pdf: 'Trujillo et al., 2025 Conservation Physiology.pdf', + moorea: { href: '/water-quality', label: 'Water quality' } + }, + { + id: 'bouyoucos2024abiotic', doi: '10.1071/MF24080', authors: 'Bouyoucos et al.', year: 2024, title: 'No effects of abiotic and anthropogenic factors on reef-associated neonate shark abundance within a shark nursery-area system', journal: 'Marine and Freshwater Research', + pdf: 'Bouyoucos et al., 2024 MFR.pdf', moorea: { href: '/pressure', label: 'Human pressure' } }, { + id: 'debaere2024lunar', + doi: '10.1007/s00338-024-02534-4', + authors: 'Debaere et al.', + year: 2024, + title: + 'The lunar cycle does not influence catch rates or foraging success of neonatal reef sharks in an amphidromic nursery system', + journal: 'Coral Reefs', + pdf: 'Debaere et al., 2024 Coral Reefs.pdf', + moorea: { href: '/moon', label: 'Moon' } + }, + { + id: 'eustache2024density', + doi: '10.1111/jfb.15569', + authors: 'Eustache et al.', + year: 2024, + title: + 'Spatial and temporal analysis of juvenile blacktip reef shark (Carcharhinus melanopterus) demographies identifies critical habitats', + journal: 'Journal of Fish Biology', + pdf: 'Eustache et al., 2024 J Fish Biol.pdf', + moorea: { href: '/nurseries', label: 'Nurseries' } + }, + { + id: 'debaere2023umbilicus', + doi: '10.1093/conphys/coad028', + authors: 'Debaere et al.', + year: 2023, + title: + 'Quantifying changes in umbilicus size to estimate the relative age of neonatal blacktip reef sharks (Carcharhinus melanopterus)', + journal: 'Conservation Physiology', + pdf: 'Debaere et al., 2023 Conservation Physiology.pdf', + moorea: { href: '/neonates', label: 'Newborns' } + }, + { + id: 'eustache2023philopatry', + doi: '10.1038/s41598-023-40140-6', + authors: 'Eustache et al.', + year: 2023, + title: + 'Genetic evidence for plastic reproductive philopatry and matrotrophy in blacktip reef sharks (Carcharhinus melanopterus) of the Moorea Island (French Polynesia)', + journal: 'Scientific Reports', + pdf: 'Eustache et al., 2023 Sci Rep.pdf', + moorea: { href: '/adults', label: 'Adult blacktips' } + }, + { + id: 'bouyoucos2022nursery', + doi: '10.3354/meps13941', + authors: 'Bouyoucos et al.', + year: 2022, + title: + 'Thermally insensitive physiological performance allows neonatal sharks to use coastal habitats as nursery areas', + journal: 'Marine Ecology Progress Series', + pdf: 'Bouyoucos et al., 2022 MEPS.pdf', + moorea: { href: '/growth', label: 'Growth' } + }, + { + id: 'trujillo2022escape', + doi: '10.1242/jeb.243973', + authors: 'Trujillo et al.', + year: 2022, + title: + 'Escape response kinematics in two species of tropical shark: short escape latencies and high turning performance', + journal: 'Journal of Experimental Biology', + pdf: 'Trujillo et al., 2022 JEB.pdf', + moorea: { href: '/physiology', label: 'Physiology & lab' } + }, + { + id: 'bouyoucos2021oxygen', + doi: '10.1016/j.scitotenv.2021.146854', + authors: 'Bouyoucos et al.', + year: 2021, + title: + 'Investigating links between thermal tolerance and oxygen supply capacity in shark neonates from a hyperoxic tropical environment', + journal: 'Science of the Total Environment', + pdf: 'Bouyoucos et al., 2021 STOTEN.pdf', + moorea: { href: '/water-quality', label: 'Water quality' } + }, + { + id: 'schoen2021heatwave', + doi: '10.1093/conphys/coab067', + authors: 'Schoen et al.', + year: 2021, + title: + 'Simulated heatwave and fishing stressors alter corticosteroid and energy balance in neonate blacktip reef sharks, Carcharhinus melanopterus', + journal: 'Conservation Physiology', + pdf: 'Schoen et al., 2021 CP.pdf', + moorea: { href: '/ocean', label: 'Ocean & heat stress' } + }, + { + id: 'bouyoucos2020sharkparks', + doi: '10.1093/oso/9780198843610.003.0011', + authors: 'Bouyoucos & Rummer', + year: 2020, + title: + "Improving 'shark park' protections under threat from climate change using the conservation physiology toolbox", + journal: 'Conservation Physiology (Oxford University Press)', + pdf: 'Bouyoucos and Rummer 2020 Conservation physiology- Integrating physiology into animal conservation and management. .pdf', + moorea: { href: '/ocean', label: 'Ocean & heat stress' } + }, + { + id: 'bouyoucos2020homerange', + doi: '10.1007/s00338-020-01965-z', + authors: 'Bouyoucos et al.', + year: 2020, + title: + 'Home range of newborn blacktip reef sharks (Carcharhinus melanopterus), as estimated using mark-recapture and acoustic telemetry', + journal: 'Coral Reefs', + pdf: 'Bouyoucos et al., 2020 Coral Reefs.pdf', + moorea: { href: '/recaptures', label: 'Recaptures' } + }, + { + id: 'bouyoucos2020thermal', + doi: '10.1242/jeb.221937', + authors: 'Bouyoucos et al.', + year: 2020, + title: + 'Thermal tolerance and hypoxia tolerance are associated in blacktip reef shark (Carcharhinus melanopterus) neonates', + journal: 'Journal of Experimental Biology', + pdf: 'Bouyoucos et al., 2020 JEB.pdf', + moorea: { href: '/water-quality', label: 'Water quality' } + }, + { + id: 'weideli2019condition', doi: '10.1038/s41598-019-49761-2', authors: 'Weideli et al.', year: 2019, @@ -31,6 +201,7 @@ export const PUBLICATIONS: Publication[] = [ moorea: { href: '/morphometrics', label: 'Body size & condition' } }, { + id: 'schwieterman2019blood', doi: '10.1093/conphys/coz081', authors: 'Schwieterman et al.', year: 2019, @@ -40,31 +211,47 @@ export const PUBLICATIONS: Publication[] = [ moorea: { href: '/physiology', label: 'Physiology & lab' } }, { + id: 'bouyoucos2018deadtired', doi: '10.1093/conphys/coy053', authors: 'Bouyoucos et al.', year: 2018, title: 'Dead tired: evaluating the physiological status and survival of neonatal reef sharks under stress', journal: 'Conservation Physiology', + pdf: 'Bouyoucos et al., 2018 ConPhys.pdf', moorea: { href: '/physiology', label: 'Physiology & lab' } }, { + id: 'gervais2016colouration', + doi: '10.1007/s12526-015-0429-2', + authors: 'Gervais et al.', + year: 2016, + title: 'Developing in warm water: irregular colouration and patterns of a neonate elasmobranch', + journal: 'Marine Biodiversity', + pdf: 'Gervais et al. 2016.pdf' + }, + { + id: 'chin2015wounds', doi: '10.1093/conphys/cov062', authors: 'Chin et al.', year: 2015, title: 'Blacktip reef sharks (Carcharhinus melanopterus) show high capacity for wound healing and recovery following injury', journal: 'Conservation Physiology', + pdf: 'Chin et al., 2015 Cons Physiol.pdf', moorea: { href: '/notes', label: 'Field notes' } }, { + id: 'bouyoucos2019oxygen', doi: '10.1007/s11160-019-09553-3', authors: 'Bouyoucos et al.', year: 2019, title: 'Estimating oxygen uptake rates to understand stress in sharks and rays', - journal: 'Reviews in Fish Biology and Fisheries' + journal: 'Reviews in Fish Biology and Fisheries', + pdf: 'Bouyoucos et al., 2019.pdf' }, { + id: 'gervais2018movement', doi: '10.1007/s00227-018-3427-7', authors: 'Gervais et al.', year: 2018, @@ -73,6 +260,7 @@ export const PUBLICATIONS: Publication[] = [ journal: 'Marine Biology' }, { + id: 'lopes2018acidification', doi: '10.1007/s12192-018-0892-3', authors: 'Lopes et al.', year: 2018, @@ -81,6 +269,7 @@ export const PUBLICATIONS: Publication[] = [ journal: 'Cell Stress and Chaperones' }, { + id: 'talwar2017ph', doi: '10.1093/conphys/cox012', authors: 'Talwar et al.', year: 2017, @@ -88,6 +277,7 @@ export const PUBLICATIONS: Publication[] = [ journal: 'Conservation Physiology' }, { + id: 'rosa2017acidification', doi: '10.1098/rsbl.2016.0796', authors: 'Rosa et al.', year: 2017, @@ -95,34 +285,45 @@ export const PUBLICATIONS: Publication[] = [ journal: 'Biology Letters' }, { - doi: '10.1007/s12526-015-0429-2', - authors: 'Gervais et al.', - year: 2016, - title: 'Developing in warm water: irregular colouration and patterns of a neonate elasmobranch', - journal: 'Marine Biodiversity' - }, - { + id: 'johnson2016ontogeny', doi: '10.1093/conphys/cow003', authors: 'Johnson et al.', year: 2016, title: 'Will ocean acidification affect the early ontogeny of a tropical oviparous elasmobranch (Hemiscyllium ocellatum)?', - journal: 'Conservation Physiology' + journal: 'Conservation Physiology', + pdf: 'Johnson et al., 2016 Conserv Physiol.pdf' }, { + id: 'heinrich2016foraging', doi: '10.1093/icesjms/fsv085', authors: 'Heinrich et al.', year: 2016, title: 'Foraging behaviour of the epaulette shark Hemiscyllium ocellatum is not affected by elevated CO2', - journal: 'ICES Journal of Marine Science' + journal: 'ICES Journal of Marine Science', + pdf: 'Heinrich et al., 2015.pdf' }, { + id: 'heinrich2014co2', doi: '10.1093/conphys/cou047', authors: 'Heinrich et al.', year: 2014, title: 'A product of its environment: the epaulette shark (Hemiscyllium ocellatum) exhibits physiological tolerance to elevated environmental CO2', - journal: 'Conservation Physiology' + journal: 'Conservation Physiology', + pdf: 'Heinrich et al., 2014 Cons. Physiol..pdf' } -]; +] as const satisfies readonly Publication[]; + +export const PUBLICATIONS: readonly Publication[] = LIST; + +export type PaperId = (typeof LIST)[number]['id']; + +const byId = new Map(PUBLICATIONS.map((p) => [p.id, p])); + +export const paper = (id: PaperId): Publication => byId.get(id)!; + +/** The PDF on rummerlab.com when the lab hosts one, otherwise the DOI. */ +export const paperHref = (p: Publication) => + p.pdf ? `https://rummerlab.com/papers/${encodeURIComponent(p.pdf)}` : `https://doi.org/${p.doi}`; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index dc0ec34..3414cf1 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -104,6 +104,7 @@
- import { PUBLICATIONS } from '#lib/publications'; + import { PUBLICATIONS, paperHref } from '#lib/publications'; import { date } from '#lib/format'; import type { PageProps } from './$types'; @@ -115,11 +115,15 @@

Publications from the Mo'orea fieldwork

+

+ Charts that answer the same question as one of these papers link to it under the chart. +

    {#each moorea as p (p.doi)}
  • {p.authors} ({p.year}). {p.title}. - {p.journal}. + {p.journal}.{#if p.pdf} + PDF.{/if} See: {p.moorea!.label}
  • {/each} @@ -129,7 +133,8 @@ {#each other as p (p.doi)}
  • {p.authors} ({p.year}). {p.title}. - {p.journal}. + {p.journal}.{#if p.pdf} + PDF.{/if}
  • {/each}
diff --git a/src/routes/adults/+page.svelte b/src/routes/adults/+page.svelte index 64ba5d6..dbaef75 100644 --- a/src/routes/adults/+page.svelte +++ b/src/routes/adults/+page.svelte @@ -58,7 +58,11 @@ xLabel="Total length (mm)" /> - + x.k)} @@ -109,7 +113,11 @@ r={5} /> - + - + z.name)} diff --git a/src/routes/growth/+page.svelte b/src/routes/growth/+page.svelte index 13583ed..4ecda5f 100644 --- a/src/routes/growth/+page.svelte +++ b/src/routes/growth/+page.svelte @@ -57,6 +57,7 @@ num(v, 1)} /> - + num(v, 2)} /> diff --git a/src/routes/morphometrics/+page.svelte b/src/routes/morphometrics/+page.svelte index b6e7826..b054f0e 100644 --- a/src/routes/morphometrics/+page.svelte +++ b/src/routes/morphometrics/+page.svelte @@ -45,6 +45,7 @@ num(v, 2)} /> - + `/seasons/${r.season}`)} /> - + {#if data.moves.length} @@ -172,6 +177,7 @@
= 0 ? 'warmer' : 'cooler'} than the mean of all nurseries logged on the same days.` diff --git a/src/routes/ocean/+page.svelte b/src/routes/ocean/+page.svelte index fd9dd43..ae9bc22 100644 --- a/src/routes/ocean/+page.svelte +++ b/src/routes/ocean/+page.svelte @@ -26,6 +26,7 @@
@@ -38,6 +39,7 @@
- + r.sst != null && r.cpue != null) @@ -156,6 +162,7 @@ diff --git a/src/routes/physiology/+page.svelte b/src/routes/physiology/+page.svelte index 378d94d..f3e93cd 100644 --- a/src/routes/physiology/+page.svelte +++ b/src/routes/physiology/+page.svelte @@ -39,6 +39,7 @@
- + - + ({ name: season(s.season), @@ -155,6 +160,7 @@ {#if data.preyTop.length} num(v, 2)} /> - + - + r.artif, @@ -128,7 +133,7 @@ opacity={0.85} /> - + r.composite, diff --git a/src/routes/recaptures/+page.svelte b/src/routes/recaptures/+page.svelte index ffe60df..af6e8a5 100644 --- a/src/routes/recaptures/+page.svelte +++ b/src/routes/recaptures/+page.svelte @@ -64,6 +64,7 @@ num(v, 2)} /> - + `${t.k} (${t.n})`)} series={[ diff --git a/src/routes/time-of-day/+page.svelte b/src/routes/time-of-day/+page.svelte index c8632bd..ae8b9c7 100644 --- a/src/routes/time-of-day/+page.svelte +++ b/src/routes/time-of-day/+page.svelte @@ -41,7 +41,11 @@ markers={[{ x: 0, label: 'sunset' }]} /> - + = 0 ? 'warmer' : 'cooler'} than the satellite reading offshore.` @@ -85,6 +86,7 @@ - + ({ ...b, color: 'var(--series-7)' }))} yLabel="pH" yFormat={(v) => num(v, 2)} /> - + ({ ...b, color: 'var(--series-1)' }))} yLabel="ppt" @@ -179,7 +186,11 @@ /> {#if data.doMg.length} - + ({ ...b, color: 'var(--series-3)' }))} yLabel="mg/L" From 0617a3f872e239958a5e70a1dbceff5a1b59859a Mon Sep 17 00:00:00 2001 From: luen Date: Tue, 3 Nov 2026 13:04:10 +1000 Subject: [PATCH 2/3] Environment: cloud cover vs catches, moonlight and nursery water (#104) - analytics/cloud.ts: crew cloud score vs ERA5, catch rate on dark nights and bright-moon nights under clear or overcast skies, and cloud vs the in-situ daily high and swing compared within the same month. - Weather: "The crew's cloud score vs the reanalysis". - Moon: "Does cloud hide the moon?" - Water quality: "Clouds and the nursery's afternoon". - Drivers: "Moonlight reaching the water" and the crew's cloud score. - Finding: overcast afternoons are cooler on the nursery sand. Closes #104 Co-Authored-By: Claude Opus 5.5 --- src/lib/server/analytics/cloud.ts | 154 +++++++++++++++++++++++ src/lib/server/analytics/env.ts | 15 +++ src/lib/server/analytics/findings.ts | 13 ++ src/routes/moon/+page.server.ts | 2 + src/routes/moon/+page.svelte | 19 +++ src/routes/water-quality/+page.server.ts | 2 + src/routes/water-quality/+page.svelte | 32 +++++ src/routes/weather/+page.server.ts | 2 + src/routes/weather/+page.svelte | 25 ++++ 9 files changed, 264 insertions(+) create mode 100644 src/lib/server/analytics/cloud.ts diff --git a/src/lib/server/analytics/cloud.ts b/src/lib/server/analytics/cloud.ts new file mode 100644 index 0000000..3ef6ac8 --- /dev/null +++ b/src/lib/server/analytics/cloud.ts @@ -0,0 +1,154 @@ +/** + * Cloud cover (#104): the crew's own cloud score against ERA5, cloud as a filter on moonlight, + * and cloud against the in-situ water temperature. Exploratory: correlations, not causes. + */ +import { finite, mean, pairs, se, spearman, welch } from '#lib/stats'; +import type { Dataset, SetRow } from '../data'; +import { effortSets, round } from './common'; + +/** Bright moon: at least this illuminated and this high (degrees) at mid-set. */ +const BRIGHT_ILLUM = 0.6; +const BRIGHT_ALT = 10; +/** Sky classes from ERA5 cloud cover (%). */ +export const CLEAR_MAX = 40; +export const OVERCAST_MIN = 70; + +/** + * Moonlight reaching the water at mid-set, 0–1: illuminated fraction × sine of the moon's + * altitude (0 below the horizon) × clear-sky fraction from ERA5 cloud cover. + */ +export function moonlight(s: SetRow): number | null { + if (s.moonIllum == null || s.moonAltMid == null || s.cloudEvening == null) return null; + const sinAlt = Math.max(0, Math.sin((s.moonAltMid * Math.PI) / 180)); + return s.moonIllum * sinAlt * (1 - s.cloudEvening / 100); +} + +const ci = (ys: (number | null)[]) => { + const m = mean(ys); + const e = se(ys); + return { + n: finite(ys).length, + mean: round(m), + lo: m != null && e != null ? round(Math.max(0, m - 1.96 * e)) : null, + hi: m != null && e != null ? round(m + 1.96 * e) : null + }; +}; + +/** Mean ERA5 cloud cover during the sets the crew scored 1–4 (2020–22 set logs). */ +export function crewVsEra5(d: Dataset) { + const scored = d.sets.filter((s) => s.cloudCover != null && s.cloudEvening != null); + const rows = [1, 2, 3, 4].map((score) => ({ + score, + ...ci(scored.filter((s) => Math.round(s.cloudCover!) === score).map((s) => s.cloudEvening)) + })); + const r = spearman( + pairs( + scored, + (s) => s.cloudCover, + (s) => s.cloudEvening + ) + ); + const means = rows.map((x) => x.mean).filter((m): m is number => m != null); + return { + rows, + n: scored.length, + rho: r ? round(r.rho) : null, + increasing: means.length === 4 && means.every((m, i) => i === 0 || m > means[i - 1]) + }; +} + +/** Catch rate on dark nights and on bright-moon nights under clear or overcast skies. */ +export function moonCloud(d: Dataset) { + const sets = effortSets(d).filter( + (s) => s.cpue != null && s.moonIllum != null && s.moonAltMid != null && s.cloudEvening != null + ); + const bright = sets.filter((s) => s.moonIllum! >= BRIGHT_ILLUM && s.moonAltMid! > BRIGHT_ALT); + const clear = bright.filter((s) => s.cloudEvening! < CLEAR_MAX); + const overcast = bright.filter((s) => s.cloudEvening! >= OVERCAST_MIN); + const dark = sets.filter((s) => s.moonAltMid! <= 0 || s.moonIllum! < 0.25); + const w = welch( + clear.map((s) => s.cpue), + overcast.map((s) => s.cpue) + ); + const r = spearman(pairs(sets, moonlight, (s) => s.cpue)); + return { + groups: [ + { k: 'Dark: moon down or < 25% lit', ...ci(dark.map((s) => s.cpue)) }, + { k: 'Bright moon, clear sky', ...ci(clear.map((s) => s.cpue)) }, + { k: 'Bright moon, overcast', ...ci(overcast.map((s) => s.cpue)) } + ], + p: w ? w.p : null, + rho: r ? round(r.rho) : null, + n: sets.length + }; +} + +/** + * Nursery water against daily cloud cover. Cloudy wet-season months are also the warmest, so + * each day is compared with its own month: anomalies of the island-wide daily high and swing. + */ +export function cloudWater(d: Dataset) { + const cloud = new Map(d.weather.map((w) => [w.date, w.cloud])); + const byDate = new Map(); + for (const r of d.loggerDaily) { + const e = byDate.get(r.date) ?? { max: [], min: [] }; + e.max.push(r.max); + e.min.push(r.min); + byDate.set(r.date, e); + } + const days = [...byDate] + .map(([date, e]) => ({ + date, + cloud: cloud.get(date) ?? null, + max: mean(e.max)!, + swing: mean(e.max)! - mean(e.min)! + })) + .filter( + (x): x is { date: string; cloud: number; max: number; swing: number } => x.cloud != null + ); + const byMonth = new Map(); + for (const x of days) { + const l = byMonth.get(x.date.slice(0, 7)); + if (l) l.push(x); + else byMonth.set(x.date.slice(0, 7), [x]); + } + const anom: { cloud: number; max: number; swing: number }[] = []; + // Within-month contrast of overcast vs clear days, weighted by the smaller group. + let wSum = 0; + let dMax = 0; + let dSwing = 0; + for (const l of byMonth.values()) { + if (l.length < 10) continue; + const mMax = mean(l.map((x) => x.max))!; + const mSwing = mean(l.map((x) => x.swing))!; + for (const x of l) anom.push({ cloud: x.cloud, max: x.max - mMax, swing: x.swing - mSwing }); + const c = l.filter((x) => x.cloud < CLEAR_MAX); + const o = l.filter((x) => x.cloud >= OVERCAST_MIN); + if (c.length >= 3 && o.length >= 3) { + const w = Math.min(c.length, o.length); + dMax += w * (mean(o.map((x) => x.max))! - mean(c.map((x) => x.max))!); + dSwing += w * (mean(o.map((x) => x.swing))! - mean(c.map((x) => x.swing))!); + wSum += w; + } + } + const bins = [0, 20, 40, 60, 80, 100].slice(0, -1).map((a) => { + const b = a + 20; + const inBin = anom.filter((x) => x.cloud >= a && (b === 100 ? x.cloud <= b : x.cloud < b)); + return { + x: a + 10, + label: `${a}–${b}%`, + n: inBin.length, + max: round(mean(inBin.map((x) => x.max))), + swing: round(mean(inBin.map((x) => x.swing))) + }; + }); + const rMax = spearman(anom.map((x) => [x.cloud, x.max])); + return { + bins: bins.filter((b) => b.n >= 20), + days: anom.length, + rhoMax: rMax ? round(rMax.rho) : null, + overcastVsClear: wSum + ? { max: round(dMax / wSum), swing: round(dSwing / wSum), months: wSum } + : null + }; +} diff --git a/src/lib/server/analytics/env.ts b/src/lib/server/analytics/env.ts index 66d513c..d19c651 100644 --- a/src/lib/server/analytics/env.ts +++ b/src/lib/server/analytics/env.ts @@ -1,6 +1,7 @@ /** Per-set explanatory variables used by the drivers, tides, moon and weather pages (#45). */ import { spearman, pairs } from '#lib/stats'; import type { SetRow } from '../data'; +import { moonlight } from './cloud'; import { seasonDay } from './common'; export interface SetVariable { @@ -31,6 +32,20 @@ export const SET_VARIABLES: SetVariable[] = [ { key: 'rain24h', label: 'Rain in previous 24 h', unit: 'mm', dp: 1, get: (s) => s.rain24h }, { key: 'rainSet', label: 'Rain during the set', unit: 'mm', dp: 1, get: (s) => s.rainEvening }, { key: 'cloud', label: 'Cloud cover', unit: '%', dp: 0, get: (s) => s.cloudEvening }, + { + key: 'cloudCrew', + label: 'Cloud cover noted by the crew (1–4)', + unit: '', + dp: 0, + get: (s) => s.cloudCover + }, + { + key: 'moonlight', + label: 'Moonlight reaching the water', + unit: '', + dp: 2, + get: moonlight + }, { key: 'pressure', label: 'Air pressure', unit: 'hPa', dp: 1, get: (s) => s.pressure }, { key: 'waves', label: 'Wave height (offshore)', unit: 'm', dp: 1, get: (s) => s.waveHeight }, { key: 'swell', label: 'Swell height (offshore)', unit: 'm', dp: 1, get: (s) => s.swellHeight }, diff --git a/src/lib/server/analytics/findings.ts b/src/lib/server/analytics/findings.ts index c7c2a43..495b8d3 100644 --- a/src/lib/server/analytics/findings.ts +++ b/src/lib/server/analytics/findings.ts @@ -18,6 +18,7 @@ import { seasonDayLabel, siteName } from './common'; +import { cloudWater } from './cloud'; import { dailyMaxBySite, versusSst } from './insitu'; export interface Finding { @@ -317,6 +318,18 @@ function compute(d: Dataset): Finding[] { }); } + // Cloud cover and nursery water (#104): within-month contrast, so season doesn't confound it. + const cw = cloudWater(d).overcastVsClear; + if (cw?.max != null && cw.swing != null && cw.months >= 30 && cw.max < 0) + out.push({ + id: 'cloud-cools-nursery', + kind: 'pattern', + title: 'Clouds take the edge off nursery afternoons', + value: `−${num(Math.abs(cw.max), 2)} °C`, + text: `Compared with clear days in the same month, overcast days peak ${num(Math.abs(cw.max), 2)} °C cooler on the nursery sand, and the day–night swing is ${num(Math.abs(cw.swing), 2)} °C ${cw.swing <= 0 ? 'smaller' : 'larger'}. Shallow water heats fast under full sun.`, + href: '/water-quality' + }); + // Earliest newborn const openScar = caps.filter((c) => c.umbilical === 'open' && c.date); if (openScar.length) { diff --git a/src/routes/moon/+page.server.ts b/src/routes/moon/+page.server.ts index d6b647b..4d732aa 100644 --- a/src/routes/moon/+page.server.ts +++ b/src/routes/moon/+page.server.ts @@ -1,6 +1,7 @@ import { memo } from '#lib/server/data'; import { binnedMean, cpueOf, effortSets, fieldCaptures, round } from '#lib/server/analytics/common'; import { MOON_PHASES } from '#lib/server/astro'; +import { moonCloud } from '#lib/server/analytics/cloud'; import { histogram, median, welch } from '#lib/stats'; import type { PageServerLoad } from './$types'; @@ -27,6 +28,7 @@ export const load: PageServerLoad = () => const bright = caps.filter((c) => (c.moonIllum ?? 0.5) > 0.75).map((c) => c.minAfterSunset); const w = welch(bright, dark); return { + moonCloud: moonCloud(d), phases, illum: binnedMean( sets, diff --git a/src/routes/moon/+page.svelte b/src/routes/moon/+page.svelte index a5000cb..89100a3 100644 --- a/src/routes/moon/+page.svelte +++ b/src/routes/moon/+page.svelte @@ -9,6 +9,7 @@ let { data }: PageProps = $props(); const t = $derived(data.timing); + const mc = $derived(data.moonCloud);
@@ -102,6 +103,24 @@ labels /> + 0.05 && mc.rho != null && Math.abs(mc.rho) < 0.1 ? ' Accounting for cloud does not reveal a moonlight effect.' : ''}`} + > + `${g.k} (${g.n})`)} + series={[ + { + name: 'Sharks / net-hour', + color: 'var(--series-7)', + values: mc.groups.map((g) => g.mean) + } + ]} + errors={mc.groups.map((g) => (g.lo != null && g.hi != null ? [g.lo, g.hi] : null))} + valueFormat={(v) => num(v, 2)} + /> + diel, dielAmp: { warm: amp(diel.warm), cool: amp(diel.cool) }, dailyMax: dailyMaxBySite(d), + cloud: cloudWater(d), coverage: coverage(d) } : null; diff --git a/src/routes/water-quality/+page.svelte b/src/routes/water-quality/+page.svelte index 443e1e0..e46aa2d 100644 --- a/src/routes/water-quality/+page.svelte +++ b/src/routes/water-quality/+page.svelte @@ -115,6 +115,38 @@ yFormat={(v) => num(v, 1)} /> + {#if ins.cloud.bins.length >= 3} + {@const oc = ins.cloud.overcastVsClear} + + ins.cloud.bins.find((b) => b.x === v)?.label ?? `${v}%`} + yFormat={(v) => num(v, 2)} + refs={[{ y: 0, label: 'month average' }]} + series={[ + { + name: 'Daily high', + color: 'var(--series-2)', + dots: true, + points: ins.cloud.bins.map((b) => ({ x: b.x, y: b.max })) + }, + { + name: 'Day–night swing', + color: 'var(--series-1)', + dots: true, + points: ins.cloud.bins.map((b) => ({ x: b.x, y: b.swing })) + } + ]} + /> + + {/if} (a: number, b: number) => `${round(a, dp)}–${round(b, dp)}${u}`; return { + crewCloud: crewVsEra5(d), byMonth, rainMonthly: [...monthly.entries()] .sort() diff --git a/src/routes/weather/+page.svelte b/src/routes/weather/+page.svelte index b280727..d89e82f 100644 --- a/src/routes/weather/+page.svelte +++ b/src/routes/weather/+page.svelte @@ -118,6 +118,31 @@ /> {/each} + {#if data.crewCloud.n >= 30} + + `Score ${r.score} (${r.n})`)} + series={[ + { + name: 'ERA5 cloud cover (%)', + color: 'var(--series-6)', + values: data.crewCloud.rows.map((r) => r.mean) + } + ]} + errors={data.crewCloud.rows.map((r) => + r.lo != null && r.hi != null ? [r.lo, r.hi] : null + )} + yLabel="%" + valueFormat={(v) => num(v, 0)} + /> + + {/if} Date: Tue, 3 Nov 2026 13:05:55 +1000 Subject: [PATCH 3/3] Cloud cover: cite papers, document, test Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 +++++ src/lib/server/analytics/cloud.test.ts | 24 ++++++++++++++++++++++++ src/routes/moon/+page.svelte | 1 + src/routes/water-quality/+page.svelte | 1 + 4 files changed, 31 insertions(+) create mode 100644 src/lib/server/analytics/cloud.test.ts diff --git a/AGENTS.md b/AGENTS.md index eab8948..f36a503 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,6 +77,11 @@ samples/fixture/ synthetic workbooks for tests/CI (committed) - Cleaning: trim 2 h at the start of each file and 2 h (EnvLogger) or 24 h (HOBO, read out back at the station) at the end; drop readings outside 15–40 °C; merge repeated downloads of one logger by timestamp. Days need ≥ 18 site-hours. Tables: `logger_files`, `logger_daily`, `logger_diel`, plus `sets.insitu_temp`. - Comparisons between nurseries only use those logged ≥ 1 year with both seasons covered (a summer-only logger looks hottest). +### Cloud cover (#104) + +- ERA5 `cloud_evening` covers every set; the crew's 1–4 `cloud_cover` score exists only in 2020–22 and tracks ERA5 (score 1 ≈ 43%, 4 ≈ 94%). `moonlight()` in `analytics/cloud.ts` = illumination × sin(moon altitude) × clear-sky fraction. +- Cloud vs water temperature must be compared within the same month: the cloudy wet season is also the warmest, so raw correlations are ~0 while within-month ones are strongly negative. + ### Adding a new season Drop the workbook in `data/` named like `Physioshark_Shark Log 2026-2027.xlsx` (the `YYYY-YYYY` in the file name sets the season). Check the Data quality page for unknown sites, unmatched headers ("Sheet not imported") and unit warnings, and extend aliases if needed. Never rename columns in the workbook to make the importer happy. diff --git a/src/lib/server/analytics/cloud.test.ts b/src/lib/server/analytics/cloud.test.ts new file mode 100644 index 0000000..2bc797b --- /dev/null +++ b/src/lib/server/analytics/cloud.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from 'vitest'; +import { dataset, type SetRow } from '../data'; +import { cloudWater, moonCloud, moonlight } from './cloud'; + +describe('cloud cover (#104)', () => { + it('scales moonlight by illumination, moon height and clear sky', () => { + const s = (moonIllum: number, moonAltMid: number, cloudEvening: number) => + ({ moonIllum, moonAltMid, cloudEvening }) as SetRow; + expect(moonlight(s(1, 90, 0))).toBeCloseTo(1, 6); + expect(moonlight(s(1, 30, 50))).toBeCloseTo(0.25, 6); + expect(moonlight(s(1, -5, 0))).toBe(0); + expect(moonlight({ ...s(1, 30, 0), cloudEvening: null })).toBeNull(); + }); + + it('runs on the synthetic fixture', () => { + const d = dataset(); + const mc = moonCloud(d); + expect(mc.groups).toHaveLength(3); + expect(mc.n).toBeGreaterThan(0); + const cw = cloudWater(d); + expect(cw.days).toBeGreaterThan(0); + for (const b of cw.bins) expect(b.n).toBeGreaterThanOrEqual(20); + }); +}); diff --git a/src/routes/moon/+page.svelte b/src/routes/moon/+page.svelte index b98f584..ca0b8e3 100644 --- a/src/routes/moon/+page.svelte +++ b/src/routes/moon/+page.svelte @@ -109,6 +109,7 @@ 0.05 && mc.rho != null && Math.abs(mc.rho) < 0.1 ? ' Accounting for cloud does not reveal a moonlight effect.' : ''}`} > diff --git a/src/routes/water-quality/+page.svelte b/src/routes/water-quality/+page.svelte index 1fdb46d..93a7cc8 100644 --- a/src/routes/water-quality/+page.svelte +++ b/src/routes/water-quality/+page.svelte @@ -122,6 +122,7 @@ {@const oc = ins.cloud.overcastVsClear}