Ingest SDMs: NOAA SEFSC GoMex Cetacean & Sea-Turtle Densities

Monthly hexagon abundance (#/40 km²) → density → population-percentile suitability [1,100] on the global 0.05° grid

Published

2026-10-30

NOAA SEFSC Gulf-of-Mexico cetacean & sea-turtle spatial density models (NCEI 0256800 v2.2) — 19 hexagon shapefiles, one per species/population, each carrying monthly abundance {Mon}_n (individuals per 40 km² hexagon, -9999 = no data). Like the nc seabird ingest (ingest_sdm-nc.qmd), v11 rasterizes each (species × month) onto the global 0.05° cell grid and maps the heavy-tailed density onto the merge’s [1,100] scale by the population-percentile transform (msens::density_to_suit(method = "ud")), plus an annual surface for scoring. Two dolphins are modelled as split Oceanic + Shelf populations; each population is rasterized on its own geometry (the Oceanic hexagons are clipped, the Shelf ones “Unclipped”) and the densities are summed per cell.

Not yet folded into merge/scoring unless FOLD_DENSITY is set (merge_models_prep.qmd).

1 Setup

Code
librarian::shelf(arrow, DBI, dplyr, duckdb, fs, glue, here, jsonlite, logger, purrr, readr, sf, stringr,
                 terra, tibble, tidyr, xml2, quiet = T)
library(msens)                      # the installed msens (density_to_suit / density_annual); never via shelf(), which can reinstall a stale main
source(here("libs/paths.R"))
source(here("libs/vars.R"))
source(here("libs/duckdb_budget.R"))
sf_use_s2(FALSE)
options(readr.show_col_types = FALSE)

ds_key    <- "gm"
dir_atlas <- glue("{dir_big_v}/marine-atlas")
dir_dist  <- glue("{dir_atlas}/dist/dataset={ds_key}"); dir_create(dir_dist)
mdl_csv   <- glue("{dir_atlas}/dist/model_{ds_key}.csv")
manifest  <- here("data/manifests/ingest_sdm_gm.json"); dir_create(path_dir(manifest))
cmp_csv   <- here("data/gm_transform_compare.csv")
cog_base  <- "https://file.marinesensitivity.org/cog/sdm/raw"
p_cap     <- 0.995                     # the density percentile the OLD recipe used as the 100 point
NA_VAL    <- -9999                     # the shapefiles' no-data
shp_dir   <- path.expand(gm_shp_dir)
taxa_xls  <- path.expand(glue("{shp_dir}/../spp_gmx.xlsx"))
stopifnot("gm inputs not found: hydrate raw/sdm/gm (scripts/pull_from_laptop.sh --drive) or set GM_SHP_DIR" =
            dir_exists(shp_dir) && file_exists(taxa_xls), file_exists(cellid_tif))

# flags (this notebook's own; default = the v11 recipe) ----
gm_transform <- tolower(Sys.getenv("GM_TRANSFORM", "ud"))         # ud (v11) | cap (the v8 recipe, for comparison)
stopifnot("GM_TRANSFORM must be 'ud' or 'cap'" = gm_transform %in% c("ud", "cap"))
log_info("gm: transform = {gm_transform}; inputs = {shp_dir}; redo = {redo_ingest}")

if (redo_ingest && dir_exists(dir_dist)) { dir_delete(dir_dist); dir_create(dir_dist) }

r_grid <- rast(cellid_tif)             # global 0.05° template (values = cell_id)

# write one model surface as (mdl_key, cell_id, val) parquet. mm = NA -> annual key/file.
pq_path <- function(safe, mm) if (is.na(mm)) glue("{dir_dist}/{ds_key}_{safe}.parquet") else
                                             glue("{dir_dist}/{ds_key}_{safe}_{mm}.parquet")
write_surface <- function(d, sid, mm, safe) {
  mk <- if (is.na(mm)) glue("{ds_key}|{sid}") else glue("{ds_key}|{sid}|{mm}")
  msens::write_atlas_parquet(                              # V2/zstd/80MB row groups (Phase A)
    tibble(mdl_key = as.character(mk), cell_id = as.integer(d$cell_id), val = d$val),
    pq_path(safe, mm))
}

2 Cell areas

The ud transform weights each cell by its area (the population in a cell is density × area). The cell table is a property of the grid, not of the release: this version’s sdm.duckdb is used when build_cell_grid has written it, else ver_prev’s (which build_cell_grid copies unchanged).

Code
cell_dbs    <- c(sdm_db, glue("{dir_big}/{ver_prev}/sdm.duckdb")) |> path_expand() |> keep(file_exists)
stopifnot("no sdm.duckdb with a cell table (this version's or ver_prev's)" = length(cell_dbs) > 0)
# the `cell` table is the grid's, identical in every release on it: when this version's database is locked by another process
# (a pipeline stage writing to it) the next candidate (ver_prev's) is read instead
con_sdm <- NULL
for (sdm_cell_db in cell_dbs) {
  con_sdm <- tryCatch(dbConnect(duckdb(sdm_cell_db, read_only = TRUE)),
                      error = \(e) { log_warn("cell areas: {sdm_cell_db} is not readable ({conditionMessage(e)}); trying the next"); NULL })
  if (!is.null(con_sdm)) break
}
stopifnot("no readable sdm.duckdb with a cell table" = !is.null(con_sdm))
log_info("cell areas from {sdm_cell_db}")
duckdb_tune(con_sdm, glue("{dir_big_v}/_tmp/gm"))
ca <- dbGetQuery(con_sdm, "SELECT cell_id, area_km2 FROM cell")
dbDisconnect(con_sdm, shutdown = TRUE)
area_by_id <- rep(NA_real_, 7200 * 3600); area_by_id[ca$cell_id] <- ca$area_km2
# the cell table holds the OCEAN cells only, while the regridded surfaces fade into land cells along the
# coast (whole range, no land mask): those take the area of their latitude row (a cell's area depends on
# its row alone; the table's rows are constant to 1e-9 relative)
row_of <- \(id) (id - 1L) %/% 7200L + 1L
a_row  <- ca |> mutate(row = row_of(cell_id)) |> group_by(row) |>
  summarise(a = first(area_km2), spread = max(area_km2) / min(area_km2) - 1, .groups = "drop")
stopifnot("cell area is not constant within a row" = max(a_row$spread) < 1e-6)
area_by_row <- rep(NA_real_, 3600); area_by_row[a_row$row] <- a_row$a
cell_area <- function(id) {
  a <- area_by_id[id]; miss <- is.na(a)
  if (any(miss)) a[miss] <- area_by_row[row_of(id[miss])]
  stopifnot("a cell id has no area (no ocean cell in its row)" = !anyNA(a), all(a > 0))
  a }
log_info("cell table: {nrow(ca)} ocean cells, area {round(min(ca$area_km2), 3)}-{round(max(ca$area_km2), 1)} km2; ",
         "land cells take their row's area")
rm(ca)

3 Models + species crosswalk

Code
# spp_gmx.xlsx (one sheet, header row 1: taxa_doc, taxa_sci, repeats, taxa_common, taxa_code_auto, taxa_shp).
# A minimal reader (zip + xml2) so the notebook needs no spreadsheet package.
read_xlsx_sheet1 <- function(path) {
  td <- tempfile(); dir_create(td); on.exit(dir_delete(td))
  utils::unzip(path, exdir = td)
  ns <- c(d = "http://schemas.openxmlformats.org/spreadsheetml/2006/main")
  ss <- read_xml(file.path(td, "xl/sharedStrings.xml")) |> xml_find_all("//d:si", ns) |>
    map_chr(\(x) paste(xml_text(xml_find_all(x, ".//d:t", ns)), collapse = ""))
  cells <- read_xml(file.path(td, "xl/worksheets/sheet1.xml")) |> xml_find_all("//d:sheetData/d:row/d:c", ns)
  typ <- xml_attr(cells, "t")
  v   <- map_chr(cells, \(x) { n <- xml_find_first(x, "d:v", ns); if (inherits(n, "xml_missing")) NA_character_ else xml_text(n) })
  is_s <- !is.na(typ) & typ == "s" & !is.na(v)
  v[is_s] <- ss[as.integer(v[is_s]) + 1L]
  ref <- xml_attr(cells, "r")
  d <- tibble(col = sub("[0-9]+$", "", ref), row = as.integer(sub("^[A-Z]+", "", ref)), v = v)
  hdr <- d |> filter(row == 1) |> select(col, name = v)
  d |> filter(row > 1) |> left_join(hdr, by = "col") |> select(row, name, v) |>
    pivot_wider(names_from = name, values_from = v) |> select(-row)
}
d_taxa <- read_xlsx_sheet1(taxa_xls)
stopifnot("spp_gmx.xlsx columns changed" = all(c("taxa_doc", "taxa_sci", "taxa_common", "taxa_shp") %in% names(d_taxa)),
          nrow(d_taxa) == 19)

# one row per shapefile; the two split-population dolphins are Oceanic_* / Shelf_*
m <- tibble(path_shp = as.character(dir_ls(shp_dir, glob = "*.shp"))) |>
  mutate(base_shp   = path_ext_remove(path_file(path_shp)),
         taxa_shp   = str_replace(base_shp, "(.*)_Monthly_.*", "\\1"),
         population = if_else(str_detect(base_shp, "^(Oceanic|Shelf)_"),
                              str_replace(base_shp, "^(Oceanic|Shelf)_.*", "\\1"), NA_character_)) |>
  left_join(d_taxa |> select(taxa_shp, taxa_sci, taxa_common, taxa_doc), by = "taxa_shp")
stopifnot("19 shapefiles expected" = nrow(m) == 19, "a shapefile has no spp_gmx row" = !anyNA(m$taxa_sci))

sp_id = WORMS:{AphiaID} of taxa_sci, resolved from the worms table (accepted, animal, exactly one hit per name). A WoRMS rank other than Species, or a spp_gmx description naming several species (inside the parentheses: a comma, “and”, or “sp.”/“spp.”), makes the sp_id a guild.

Code
con_spp <- dbConnect(duckdb(path.expand(spp_db), read_only = TRUE))
nm <- unique(m$taxa_sci)
wm <- dbGetQuery(con_spp, glue("
  SELECT scientificName AS taxa_sci, CAST(taxonID AS VARCHAR) AS worms_id, taxonRank AS rank
  FROM worms WHERE taxonomicStatus = 'accepted' AND kingdom = 'Animalia'
    AND scientificName IN ({paste(dbQuoteString(con_spp, nm), collapse = ',')})"))
dbDisconnect(con_spp, shutdown = TRUE)
stopifnot("a taxa_sci has no / several accepted WoRMS animal records" = setequal(wm$taxa_sci, nm), !anyDuplicated(wm$taxa_sci))

# a spp_gmx description that names several species ("Ziphius and Mesoplodon spp.", "Orcinus orca, ... combined", "Globicephala sp.")
names_several <- \(doc) { inner <- str_extract(doc, "\\(([^)]*)\\)", group = 1)
                          !is.na(inner) & str_detect(inner, ",| and |spp?\\.") }
m <- m |> left_join(wm, by = "taxa_sci") |>
  mutate(sp_id           = glue("WORMS:{worms_id}") |> as.character(),
         names_several   = names_several(taxa_doc),
         is_guild        = rank != "Species" | names_several,
         # a split-population model is ONE taxon: drop the Oceanic / Shelf prefix from the common name
         common_name     = str_remove(taxa_common, "^(Oceanic|Shelf) "))

# regression: the ids the v8-v10 ingests produced (via the WoRMS API) are the ones resolved here, and the
# guilds are exactly the four genus / family models
ids_v10 <- c(136980, 137017, 137035, 137098, 137105, 137106, 137107, 137108, 137109, 137111, 137119,
             137205, 137206, 137208, 137209, 1576133, 159024)
ids_v10 <- paste0("WORMS:", ids_v10)
stopifnot("sp_id set differs from v8-v10's 17" = setequal(unique(m$sp_id), ids_v10),
          "guild set changed (expected Delphinidae, Globicephala, Ziphius, Kogia)" =
            setequal(unique(m$sp_id[m$is_guild]), paste0("WORMS:", c(136980, 137017, 137035, 159024))))
stopifnot("one sp_id has several is_guild values" = all(tapply(m$is_guild, m$sp_id, \(x) length(unique(x))) == 1),
          "one sp_id has several common names" = all(tapply(m$common_name, m$sp_id, \(x) length(unique(x))) == 1))
log_info("gm shapefiles: {nrow(m)}; sp_id: {n_distinct(m$sp_id)}; split-population shapefiles: {sum(!is.na(m$population))}; guild sp_id: {n_distinct(m$sp_id[m$is_guild])}")
knitr::kable(m |> distinct(sp_id, taxa_sci, rank, names_several, is_guild) |> arrange(desc(is_guild), sp_id),
             caption = "sp_id by WoRMS rank; a guild is a non-Species rank or a description naming several species")
sp_id by WoRMS rank; a guild is a non-Species rank or a description naming several species
sp_id taxa_sci rank names_several is_guild
WORMS:136980 Delphinidae Family TRUE TRUE
WORMS:137017 Globicephala Genus TRUE TRUE
WORMS:137035 Ziphius Genus TRUE TRUE
WORMS:159024 Kogia Genus TRUE TRUE
WORMS:137098 Grampus griseus Species FALSE FALSE
WORMS:137105 Stenella attenuata Species FALSE FALSE
WORMS:137106 Stenella clymene Species FALSE FALSE
WORMS:137107 Stenella coeruleoalba Species FALSE FALSE
WORMS:137108 Stenella frontalis Species FALSE FALSE
WORMS:137109 Stenella longirostris Species FALSE FALSE
WORMS:137111 Tursiops truncatus Species FALSE FALSE
WORMS:137119 Physeter macrocephalus Species FALSE FALSE
WORMS:137205 Caretta caretta Species FALSE FALSE
WORMS:137206 Chelonia mydas Species FALSE FALSE
WORMS:137208 Lepidochelys kempii Species FALSE FALSE
WORMS:137209 Dermochelys coriacea Species FALSE FALSE
WORMS:1576133 Balaenoptera ricei Species FALSE FALSE
Code
knitr::kable(m |> count(sp_id, taxa_sci, name = "n_shp") |> filter(n_shp > 1), caption = "sp_id with several shapefiles (populations summed)")
sp_id with several shapefiles (populations summed)
sp_id taxa_sci n_shp
WORMS:137108 Stenella frontalis 2
WORMS:137111 Tursiops truncatus 2

4 Regrid + transform

Code
# one shapefile (one population) -> long (cell_id, interval, dens) on the 0.05° cells: density = {Mon}_n / 40
# individuals km-2, each month rasterized on a template cropped from the cell-id COG, then cells_from_raster()
# (zero-filled; digits = NULL because the raster holds NATIVE density, which rounds to 0 at 2 decimals; min_value is
# a positive epsilon, i.e. "any positive density"). A month with no modelled hexagon (-9999 everywhere) is absent.
dens_cells_shp <- function(path) {
  x   <- read_sf(path) |> st_transform(4326)
  mos <- intersect(glue("{month.abb}_n"), names(x))
  v   <- terra::vect(x |> select(all_of(mos)))
  tmpl <- terra::crop(r_grid, terra::ext(v), snap = "out")
  map_dfr(mos, \(mo) {
    f  <- as.numeric(v[[mo]][, 1])
    ok <- which(f != NA_VAL & !is.na(f))
    if (!length(ok)) return(NULL)
    vv <- v[ok]; vv$dens <- f[ok] / 40
    r  <- terra::rasterize(vv, tmpl, field = "dens")
    msens::cells_from_raster(r, cellid_tif, min_value = 1e-12, digits = NULL) |> rename(dens = val) |>
      mutate(interval = sprintf("%02d", match(str_remove(mo, "_n$"), month.abb)))
  })
}

# a sp_id's models as (cell_id, interval, dens): populations summed per cell and month
sp_dens <- function(sid) {
  paths <- m$path_shp[m$sp_id == sid]
  map_dfr(paths, dens_cells_shp) |>
    group_by(cell_id, interval) |> summarise(dens = sum(dens), .groups = "drop")
}

# density -> [0,100]: the v11 population percentile (ud, area-weighted by the cell table), or the v8
# recipe (cap: linear to the species' pooled p99.5 of positive density, clamped)
to_val <- function(dens, cell_id, how, cap = NA_real_) {
  if (how == "ud") msens::density_to_suit(dens, "ud", area = cell_area(cell_id), digits = 2)
  else             round(100 * pmin(dens / cap, 1), 2)
}

4.1 The annual surface is the day-weighted mean over ALL twelve months

A month the model does not cover counts as zero over its weight. Checked on the densities, before any transform, on hand-picked species: with twelve months the annual equals the day-weighted mean of the months; the Kogia model covers April–November only (244 of 365 days), so its annual is exactly 244/365 of the day-weighted mean over its modelled months, and lower than the present-only mean the v8 ingest used.

Code
stopifnot("this notebook needs msens >= 0.65.1 (density_annual weights / month_day_weights)" = utils::packageVersion("msens") >= "0.65.1")
w_day   <- msens::month_day_weights()                                       # days per month, names "01".."12"
annual_dw <- \(d) msens::density_annual(d, n_intervals = 12, interval = "interval", weights = w_day)
wide_of <- \(d) d |> pivot_wider(names_from = interval, values_from = dens, values_fill = 0)
dw_mean <- \(w, months) as.vector(as.matrix(w[, months]) %*% w_day[months]) / sum(w_day[months])   # day-weighted mean over `months`

# twelve months: annual == day-weighted mean of the twelve (checked on three species, one of them Rice's whale)
chk12 <- c(`Sperm whale` = "WORMS:137119", `Rice's whale` = "WORMS:1576133", `Loggerhead` = "WORMS:137205")
for (nm_ in names(chk12)) {
  d   <- sp_dens(chk12[[nm_]]); stopifnot(n_distinct(d$interval) == 12)
  ann <- annual_dw(d)
  wd  <- wide_of(d)
  dw  <- tibble(cell_id = wd$cell_id, mean12 = dw_mean(wd, names(w_day)))
  j <- inner_join(ann, dw, by = "cell_id")
  stopifnot("annual != day-weighted 12-month mean" = nrow(j) == nrow(ann), nrow(j) == nrow(dw),
            max(abs(j$dens - j$mean12)) < 1e-12 * max(j$mean12))
}

# Kogia, April-November only
kg <- sp_dens("WORMS:159024")
stopifnot("Kogia months changed (expected Apr-Nov)" = setequal(unique(kg$interval), sprintf("%02d", 4:11)))
ann_kg <- annual_dw(kg)
w_kg   <- wide_of(kg)
mo_kg  <- sprintf("%02d", 4:11)
frac_kg <- sum(w_day[mo_kg]) / sum(w_day)                                                  # the modelled share of the year in days: 244/365
stopifnot("Kogia's modelled days changed (expected 244 of 365)" = sum(w_day[mo_kg]) == 244, sum(w_day) == 365)
mean_modelled <- w_kg |> transmute(cell_id, m8 = dw_mean(w_kg, mo_kg))                     # DAY-WEIGHTED mean over the 8 modelled months (zeros counted)
present_only  <- kg |> group_by(cell_id) |> summarise(po = mean(dens), n_ssn = n(), .groups = "drop")   # the v8 recipe's statistic
j <- ann_kg |> inner_join(mean_modelled, by = "cell_id") |> inner_join(present_only, by = "cell_id")
stopifnot("Kogia annual != sum(days Apr..Nov)/365 x the day-weighted mean over its modelled months" =
            nrow(j) == nrow(ann_kg), all(abs(j$dens - j$m8 * frac_kg) < 1e-12 * max(j$m8)),
          "Kogia annual is not below the present-only mean" = all(j$dens < j$po))
chk_tbl <- tibble(model = "Kogia (Apr-Nov)", months = 8L, cells = nrow(j),
                  mean_annual = mean(j$dens), mean_modelled_months = mean(j$m8), mean_present_only = mean(j$po))
log_info("annual checks passed: {length(chk12)} twelve-month species (annual == day-weighted mean); Kogia (8 months): annual == 244/365 x day-weighted modelled-month mean")
knitr::kable(chk_tbl |> mutate(across(starts_with("mean"), \(v) signif(v, 3))),
             caption = "Kogia: annual vs the mean over its modelled months and the present-only mean the v8 ingest used (cell means)")
Kogia: annual vs the mean over its modelled months and the present-only mean the v8 ingest used (cell means)
model months cells mean_annual mean_modelled_months mean_present_only
Kogia (Apr-Nov) 8 35876 0.00196 0.00293 0.00293
Code
rm(kg, ann_kg, w_kg, mean_modelled, present_only, j, mo_kg, frac_kg)
Code
# per sp_id: regrid every month (populations summed), add the annual (density_annual on the DENSITIES), transform
# each model on its own cells (both recipes, for the comparison), write the selected one.
# resumable (skip existing parquet) unless REDO_INGEST.
sp_ids   <- sort(unique(m$sp_id))
cmp_rows <- list(); cap_rows <- list()
for (sid in sp_ids) {
  safe <- gsub("[^A-Za-z0-9._-]", "_", sid)
  if (file_exists(pq_path(safe, NA)) && !redo_ingest) next

  dd <- sp_dens(sid)
  if (!nrow(dd)) { log_warn("no positive density for {sid}"); next }
  # the v8 recipe's 100 point: pooled p99.5 of the species' positive (regridded) densities, all months
  cap <- as.numeric(quantile(dd$dens, p_cap, names = FALSE))
  if (!is.finite(cap) || cap <= 0) cap <- max(dd$dens)
  ann <- annual_dw(dd) |> mutate(interval = "annual")
  res <- bind_rows(dd, ann) |> group_by(interval) |>
    group_modify(\(x, k) tibble(cell_id = x$cell_id, dens = x$dens,
                                v_ud = to_val(x$dens, x$cell_id, "ud"), v_cap = to_val(x$dens, x$cell_id, "cap", cap))) |>
    ungroup() |> mutate(val = if (gm_transform == "ud") v_ud else v_cap)

  # per-model comparison of the two recipes (cells written = val >= 1)
  q <- \(v) if (length(v)) quantile(v, c(.1, .5, .9), names = FALSE) else rep(NA_real_, 3)
  cmp_rows[[sid]] <- res |> group_by(interval) |>
    summarise(n_cells = n(), n_ud = sum(v_ud >= 1), n_cap = sum(v_cap >= 1),
              ud_q10 = q(v_ud[v_ud >= 1])[1], ud_q50 = q(v_ud[v_ud >= 1])[2], ud_q90 = q(v_ud[v_ud >= 1])[3],
              cap_q10 = q(v_cap[v_cap >= 1])[1], cap_q50 = q(v_cap[v_cap >= 1])[2], cap_q90 = q(v_cap[v_cap >= 1])[3],
              .groups = "drop") |>
    mutate(sp_id = sid, common_name = m$common_name[m$sp_id == sid][1], .before = 1)
  cap_rows[[sid]] <- tibble(sp_id = sid, dens_cap = cap)

  for (iv in unique(res$interval)) {
    d <- res |> filter(interval == iv, val >= 1)
    if (!nrow(d)) next
    write_surface(d, sid, if (iv == "annual") NA_character_ else iv, safe)
  }
}
log_info("rasterized {length(cmp_rows)} sp_id ({gm_transform})")

5 Model registry (model_gm.csv) + transform comparison

Code
# stats of every written surface, read back from the parquet (so a resumed run is complete too)
con <- dbConnect(duckdb())
duckdb_tune(con, glue("{dir_big_v}/_tmp/gm"))
surf <- dbGetQuery(con, glue("
  SELECT mdl_key, count(*) AS n_cells, round(min(val), 2) AS val_min, round(max(val), 2) AS val_max
  FROM read_parquet('{dir_dist}/*.parquet') GROUP BY mdl_key"))
dbDisconnect(con, shutdown = TRUE)

# dens_cap per sp_id: this run's, else the previous registry's (resume)
caps <- bind_rows(cap_rows)
prev_gm <- if (file_exists(mdl_csv)) read_csv(mdl_csv) else tibble()
if ("dens_cap" %in% names(prev_gm))
  caps <- bind_rows(caps, prev_gm |> distinct(sp_id, dens_cap) |> filter(!sp_id %in% caps$sp_id))

meta <- m |> group_by(sp_id) |>
  summarise(common_name = first(common_name), scientific_name = first(taxa_sci), rank = first(rank),
            is_guild = first(is_guild), worms_id = first(worms_id),
            populations = paste(sort(unique(na.omit(population))), collapse = "|"),
            taxa_shp = paste(sort(unique(taxa_shp)), collapse = "|"), .groups = "drop")
# one model row per surface written: the months + the annual
model_gm <- surf |>
  mutate(sp_id = str_extract(mdl_key, "^gm\\|([^|]+)", group = 1),
         interval = coalesce(str_extract(mdl_key, "\\|(\\d\\d)$", group = 1), "annual")) |>
  left_join(meta, by = "sp_id") |>
  left_join(caps, by = "sp_id") |>
  mutate(response_type = "density", transform = gm_transform) |>
  select(mdl_key, interval, sp_id, common_name, scientific_name, rank, is_guild, worms_id, populations,
         response_type, transform, dens_cap, val_min, val_max, n_cells, taxa_shp) |>
  arrange(sp_id, interval)
stopifnot("val outside [1,100]" = all(model_gm$val_min >= 1 & model_gm$val_max <= 100),
          "a model has no dens_cap" = !anyNA(model_gm$dens_cap),
          "a surface has no species row" = !anyNA(model_gm$worms_id),
          "every guild must be ingested" = setequal(model_gm$sp_id[model_gm$is_guild], unique(m$sp_id[m$is_guild])),
          "17 annual surfaces expected" = sum(model_gm$interval == "annual") == 17,
          "every species has exactly one annual surface" = all(table(model_gm$sp_id, model_gm$interval == "annual")[, "TRUE"] == 1))
if (gm_transform == "ud")
  stopifnot("a ud model's densest cell is not 100" = all(model_gm$val_max == 100))
write_csv(model_gm, mdl_csv)
log_info("model_gm.csv: {nrow(model_gm)} mdl_keys ({sum(model_gm$interval=='annual')} annual, {n_distinct(model_gm$sp_id)} sp_id, {n_distinct(model_gm$sp_id[model_gm$is_guild])} guilds)")
knitr::kable(model_gm |> count(interval, name = "n"))
interval n
01 16
02 16
03 16
04 17
05 17
06 17
07 17
08 17
09 17
10 17
11 17
12 16
annual 17
Code
knitr::kable(model_gm |> distinct(sp_id, .keep_all = TRUE) |> count(response_type, rank, is_guild, name = "n_sp_id"),
             caption = "sp_id by response type, WoRMS rank and guild")
sp_id by response type, WoRMS rank and guild
response_type rank is_guild n_sp_id
density Family TRUE 1
density Genus TRUE 3
density Species FALSE 13
Code
knitr::kable(model_gm |> filter(is_guild, interval == "annual") |> select(mdl_key, common_name, scientific_name, rank, n_cells),
             caption = "guilds: ingested as gm|WORMS:{id}, excluded from the merge (is_guild)")
guilds: ingested as gm|WORMS:{id}, excluded from the merge (is_guild)
mdl_key common_name scientific_name rank n_cells
gm|WORMS:136980 Blackfish Delphinidae Family 35119
gm|WORMS:137017 Pilot whales Globicephala Genus 33549
gm|WORMS:137035 Beaked whales Ziphius Genus 31244
gm|WORMS:159024 Pygmy or Dwarf sperm whales Kogia Genus 34141
Code
# the two recipes side by side, per model (species × month|annual); persisted so a resumed run keeps
# the rows of the species it skipped
cmp <- bind_rows(cmp_rows)
if (file_exists(cmp_csv)) cmp <- bind_rows(cmp, read_csv(cmp_csv) |> filter(!sp_id %in% cmp$sp_id))
cmp <- cmp |> arrange(sp_id, interval)
write_csv(cmp |> mutate(across(where(is.double), \(v) signif(v, 5))), cmp_csv)
Code
cat(glue("**{nrow(cmp)} models** (species × month, plus the annual). `n_cells` = cells with a positive ",
         "density; `n_ud` / `n_cap` = cells kept (`val >= 1`) under each recipe; the quantiles are over the kept cells. ",
         "The written surface is `{gm_transform}`.\n\n"))

217 models (species × month, plus the annual). n_cells = cells with a positive density; n_ud / n_cap = cells kept (val >= 1) under each recipe; the quantiles are over the kept cells. The written surface is ud.

Code
print(knitr::kable(
  cmp |> mutate(kind = if_else(interval == "annual", "annual", "monthly")) |> group_by(kind) |>
    summarise(models = n(), across(c(n_cells, n_ud, n_cap, ud_q10, ud_q50, ud_q90, cap_q10, cap_q50, cap_q90), \(v) round(median(v, na.rm = TRUE), 1)),
              .groups = "drop"),
  caption = "median over models, by kind"))
median over models, by kind
kind models n_cells n_ud n_cap ud_q10 ud_q50 ud_q90 cap_q10 cap_q50 cap_q90
annual 17 35876 31244.0 33721.0 2.7 20.1 69.6 2.5 10.7 36.0
monthly 200 35876 29577.5 28548.5 2.5 18.9 67.7 2.2 11.2 41.4
Code
cat("\n\n<details><summary>every model, both recipes</summary>\n\n")
every model, both recipes
Code
print(knitr::kable(cmp |> mutate(across(where(is.double), \(v) round(v, 1)))))
sp_id common_name interval n_cells n_ud n_cap ud_q10 ud_q50 ud_q90 cap_q10 cap_q50 cap_q90
WORMS:136980 Blackfish 01 35876 35003 35876 6.7 36.8 78.6 19.2 27.9 44.4
WORMS:136980 Blackfish 02 35876 35057 35876 6.5 36.5 76.9 16.3 24.4 34.8
WORMS:136980 Blackfish 03 35876 34936 35876 5.4 32.8 75.0 9.9 17.8 30.7
WORMS:136980 Blackfish 04 35876 34744 35876 4.8 29.7 74.7 6.4 13.0 24.4
WORMS:136980 Blackfish 05 35876 34758 35876 4.8 27.5 71.7 5.1 9.5 22.6
WORMS:136980 Blackfish 06 35876 34794 35876 4.9 28.1 69.6 5.2 9.4 20.9
WORMS:136980 Blackfish 07 35876 34543 35876 4.3 26.3 70.7 5.3 11.1 26.8
WORMS:136980 Blackfish 08 35876 34508 35876 4.4 25.6 71.5 5.5 11.0 28.9
WORMS:136980 Blackfish 09 35876 34565 35876 4.8 26.9 72.3 5.9 10.3 25.5
WORMS:136980 Blackfish 10 35876 34707 35876 4.8 27.5 73.3 6.0 11.6 27.1
WORMS:136980 Blackfish 11 35876 34864 35876 5.6 34.2 80.5 10.8 19.6 33.6
WORMS:136980 Blackfish 12 35876 35053 35876 6.6 36.8 80.9 15.9 24.0 39.0
WORMS:136980 Blackfish annual 35876 35119 35876 6.5 36.8 80.1 11.1 17.3 26.3
WORMS:137017 Pilot whales 01 35876 33215 35228 3.1 20.0 65.7 2.1 5.9 20.2
WORMS:137017 Pilot whales 02 35876 33258 35185 3.0 20.4 68.1 1.9 5.9 18.0
WORMS:137017 Pilot whales 03 35876 33134 35169 3.1 20.5 68.0 2.1 6.5 19.4
WORMS:137017 Pilot whales 04 35876 33236 35469 3.3 21.7 69.5 2.6 7.5 22.6
WORMS:137017 Pilot whales 05 35876 33273 35732 3.4 22.9 69.7 3.1 9.7 27.3
WORMS:137017 Pilot whales 06 35876 33544 35870 3.5 23.6 69.5 4.4 12.7 33.0
WORMS:137017 Pilot whales 07 35876 33365 35859 3.4 23.9 69.3 4.7 14.9 36.8
WORMS:137017 Pilot whales 08 35876 33490 35876 3.5 24.1 67.8 5.3 16.2 40.2
WORMS:137017 Pilot whales 09 35876 33415 35876 3.4 22.8 67.9 4.9 14.9 41.6
WORMS:137017 Pilot whales 10 35876 33139 35797 3.2 20.9 65.4 3.9 11.9 37.1
WORMS:137017 Pilot whales 11 35876 33373 35823 3.2 20.0 64.7 2.9 8.2 28.2
WORMS:137017 Pilot whales 12 35876 33328 35644 3.1 20.0 65.8 2.2 6.9 21.7
WORMS:137017 Pilot whales annual 35876 33549 35876 3.4 23.1 68.6 3.5 10.6 28.3
WORMS:137035 Beaked whales 01 35876 31198 32998 5.7 34.5 80.5 8.8 13.7 24.7
WORMS:137035 Beaked whales 02 35876 31254 33032 5.7 34.2 79.5 8.6 13.2 24.2
WORMS:137035 Beaked whales 03 35876 31284 33151 5.7 34.4 79.0 8.8 14.2 26.7
WORMS:137035 Beaked whales 04 35876 31285 33327 5.8 35.1 79.2 9.6 16.5 30.8
WORMS:137035 Beaked whales 05 35876 31279 33674 5.6 33.6 78.2 10.2 19.4 40.1
WORMS:137035 Beaked whales 06 35876 31366 34234 5.8 34.8 80.4 10.0 26.0 48.3
WORMS:137035 Beaked whales 07 35876 31343 34528 5.5 33.1 78.6 9.3 27.8 54.5
WORMS:137035 Beaked whales 08 35876 31235 34599 5.4 32.0 79.0 9.4 31.0 61.6
WORMS:137035 Beaked whales 09 35876 31149 34236 5.5 32.4 78.2 10.4 28.6 57.9
WORMS:137035 Beaked whales 10 35876 31127 33750 5.9 36.5 81.7 10.7 25.5 43.2
WORMS:137035 Beaked whales 11 35876 31101 33298 5.7 35.1 81.2 9.9 18.9 33.9
WORMS:137035 Beaked whales 12 35876 31162 33132 5.7 34.0 80.0 9.2 15.1 28.6
WORMS:137035 Beaked whales annual 35876 31244 33721 5.8 35.0 80.7 10.2 21.7 38.9
WORMS:137098 Risso’s dolphin 01 35941 32482 32442 2.8 21.3 74.0 1.7 5.9 15.9
WORMS:137098 Risso’s dolphin 02 35941 32689 32891 2.7 19.0 71.2 1.6 5.5 16.7
WORMS:137098 Risso’s dolphin 03 35941 32705 33516 2.7 18.9 70.9 1.5 5.8 17.0
WORMS:137098 Risso’s dolphin 04 35941 32857 34943 2.8 19.7 70.4 1.9 7.3 23.1
WORMS:137098 Risso’s dolphin 05 35941 32394 35724 2.5 17.0 66.9 2.0 8.9 36.7
WORMS:137098 Risso’s dolphin 06 35941 32559 35941 2.5 18.9 69.3 3.1 14.9 49.7
WORMS:137098 Risso’s dolphin 07 35941 32415 35941 2.5 16.7 63.1 2.9 12.8 52.6
WORMS:137098 Risso’s dolphin 08 35941 32299 35940 2.5 17.6 65.2 2.8 13.3 53.0
WORMS:137098 Risso’s dolphin 09 35941 32457 35899 2.6 19.0 67.3 2.6 12.6 42.2
WORMS:137098 Risso’s dolphin 10 35941 32915 35407 3.0 22.0 72.0 2.6 10.4 28.0
WORMS:137098 Risso’s dolphin 11 35941 32744 33987 2.9 22.2 72.6 1.8 6.8 17.1
WORMS:137098 Risso’s dolphin 12 35941 32721 33180 2.7 20.4 71.6 1.6 6.0 15.8
WORMS:137098 Risso’s dolphin annual 35941 32967 35706 2.8 20.1 69.6 2.4 9.5 29.9
WORMS:137105 Pantropical spotted dolphin 01 35943 34502 35941 5.0 32.9 78.7 17.2 36.1 61.3
WORMS:137105 Pantropical spotted dolphin 02 35943 34594 35941 5.2 33.8 80.2 19.6 39.7 68.1
WORMS:137105 Pantropical spotted dolphin 03 35943 34748 35941 5.8 35.7 81.3 15.9 27.2 45.1
WORMS:137105 Pantropical spotted dolphin 04 35941 34767 35941 5.8 36.8 82.6 15.1 27.3 42.2
WORMS:137105 Pantropical spotted dolphin 05 35941 34923 35941 6.1 34.9 81.0 17.4 27.8 51.5
WORMS:137105 Pantropical spotted dolphin 06 35941 34977 35941 6.4 33.6 72.9 28.7 40.6 64.1
WORMS:137105 Pantropical spotted dolphin 07 35941 35062 35941 6.7 37.4 83.1 28.5 41.1 68.6
WORMS:137105 Pantropical spotted dolphin 08 35941 34951 35941 6.0 34.2 78.6 27.7 43.5 72.8
WORMS:137105 Pantropical spotted dolphin 09 35942 35141 35941 6.6 36.3 81.4 27.9 41.5 69.7
WORMS:137105 Pantropical spotted dolphin 10 35943 35074 35941 6.8 37.6 81.0 29.9 42.4 67.3
WORMS:137105 Pantropical spotted dolphin 11 35943 34802 35941 5.9 36.4 80.0 23.7 41.2 61.2
WORMS:137105 Pantropical spotted dolphin 12 35941 34618 35941 5.3 34.7 81.3 21.1 43.3 72.2
WORMS:137105 Pantropical spotted dolphin annual 35943 34994 35941 6.7 38.3 81.4 26.1 38.3 56.0
WORMS:137106 Clymene dolphin 01 35876 31132 35378 3.0 22.5 75.9 4.9 28.5 80.4
WORMS:137106 Clymene dolphin 02 35876 31609 35559 2.8 21.9 76.4 4.2 23.2 68.3
WORMS:137106 Clymene dolphin 03 35876 31602 35099 2.4 17.1 74.6 2.5 12.3 45.1
WORMS:137106 Clymene dolphin 04 35876 28896 30317 1.9 12.6 72.4 1.4 8.2 33.1
WORMS:137106 Clymene dolphin 05 35876 26557 22997 1.7 10.7 64.2 1.4 7.1 30.3
WORMS:137106 Clymene dolphin 06 35876 28344 23053 1.8 9.8 62.4 1.2 5.9 21.7
WORMS:137106 Clymene dolphin 07 35876 28914 27038 2.2 13.1 57.4 1.4 4.1 19.7
WORMS:137106 Clymene dolphin 08 35876 30241 28546 2.2 12.9 54.6 1.4 3.7 18.6
WORMS:137106 Clymene dolphin 09 35876 31057 28551 2.4 14.6 55.9 1.3 3.5 17.3
WORMS:137106 Clymene dolphin 10 35876 31057 31624 3.0 19.8 66.1 1.9 5.1 18.2
WORMS:137106 Clymene dolphin 11 35876 32125 35674 2.6 18.8 73.2 2.7 12.1 43.2
WORMS:137106 Clymene dolphin 12 35876 31598 35548 2.9 20.5 74.3 4.4 20.4 67.8
WORMS:137106 Clymene dolphin annual 35876 32476 35686 2.7 20.1 76.6 2.5 10.7 34.9
WORMS:137107 Striped dolphin 01 35941 34014 35941 3.5 22.4 73.0 9.2 25.0 73.8
WORMS:137107 Striped dolphin 02 35941 34049 35941 3.6 22.1 72.9 7.5 19.1 59.1
WORMS:137107 Striped dolphin 03 35941 34322 35941 3.7 22.8 72.4 4.6 11.1 37.4
WORMS:137107 Striped dolphin 04 35941 34469 35941 4.2 27.1 72.6 3.1 6.9 17.6
WORMS:137107 Striped dolphin 05 35941 34313 35851 4.1 27.9 72.2 2.2 5.2 11.2
WORMS:137107 Striped dolphin 06 35941 33733 35892 3.2 21.4 64.8 1.8 5.8 15.8
WORMS:137107 Striped dolphin 07 35941 33314 35283 2.9 20.2 65.2 1.8 5.9 19.9
WORMS:137107 Striped dolphin 08 35941 31852 34112 2.2 14.5 65.5 1.5 6.8 32.6
WORMS:137107 Striped dolphin 09 35941 32153 34588 2.3 14.0 65.6 1.5 5.8 34.1
WORMS:137107 Striped dolphin 10 35941 32483 35184 2.6 17.0 68.4 1.9 6.8 33.9
WORMS:137107 Striped dolphin 11 35941 34055 35941 3.5 22.2 72.5 4.8 12.2 38.9
WORMS:137107 Striped dolphin 12 35941 34259 35941 3.7 22.7 74.3 7.4 18.5 53.8
WORMS:137107 Striped dolphin annual 35941 34262 35941 3.6 22.7 73.9 4.2 10.8 36.0
WORMS:137108 Atlantic spotted dolphin 01 55844 19535 20915 2.0 15.1 58.1 1.7 9.7 33.5
WORMS:137108 Atlantic spotted dolphin 02 55843 19261 21015 2.1 16.0 61.1 1.9 11.7 39.9
WORMS:137108 Atlantic spotted dolphin 03 55843 18840 20896 2.0 15.8 62.4 2.0 13.4 49.0
WORMS:137108 Atlantic spotted dolphin 04 55835 18607 20847 2.0 15.5 63.3 2.1 14.7 58.3
WORMS:137108 Atlantic spotted dolphin 05 55835 18604 21105 2.0 15.3 63.8 2.1 15.8 63.4
WORMS:137108 Atlantic spotted dolphin 06 55838 18741 21273 2.0 15.4 63.8 2.1 16.4 64.6
WORMS:137108 Atlantic spotted dolphin 07 55843 18692 21138 2.0 14.8 62.9 2.1 15.4 63.9
WORMS:137108 Atlantic spotted dolphin 08 55844 18664 21195 2.0 15.3 64.3 2.2 16.2 66.8
WORMS:137108 Atlantic spotted dolphin 09 55850 18610 21102 2.0 15.5 64.5 2.1 16.1 62.9
WORMS:137108 Atlantic spotted dolphin 10 55847 18788 21045 1.9 14.4 62.4 1.9 13.4 56.2
WORMS:137108 Atlantic spotted dolphin 11 55851 19067 20888 2.0 14.4 59.8 1.8 11.3 45.7
WORMS:137108 Atlantic spotted dolphin 12 55850 19264 20852 2.0 14.9 58.6 1.8 10.6 39.1
WORMS:137108 Atlantic spotted dolphin annual 55851 18926 21106 2.0 15.4 62.6 2.0 13.8 51.7
WORMS:137109 Spinner dolphin 01 35941 13503 9483 1.3 4.9 47.3 1.4 5.6 57.6
WORMS:137109 Spinner dolphin 02 35941 13461 9540 1.3 5.0 47.5 1.3 5.6 57.9
WORMS:137109 Spinner dolphin 03 35941 13552 9678 1.3 5.0 47.4 1.3 5.7 58.8
WORMS:137109 Spinner dolphin 04 35941 13595 9878 1.3 4.9 46.9 1.4 5.7 61.6
WORMS:137109 Spinner dolphin 05 35941 13520 10303 1.3 4.9 46.3 1.4 5.8 69.7
WORMS:137109 Spinner dolphin 06 35941 13446 11099 1.3 5.0 48.0 1.4 6.4 79.8
WORMS:137109 Spinner dolphin 07 35941 14282 10537 1.3 4.8 46.6 1.4 6.2 70.8
WORMS:137109 Spinner dolphin 08 35941 11919 10386 1.3 4.3 36.0 1.4 5.9 72.9
WORMS:137109 Spinner dolphin 09 35941 14193 10302 1.3 4.7 45.8 1.4 6.1 67.3
WORMS:137109 Spinner dolphin 10 35941 14032 10324 1.3 4.9 46.4 1.4 5.9 66.1
WORMS:137109 Spinner dolphin 11 35941 13444 9679 1.3 4.9 46.7 1.4 5.7 60.9
WORMS:137109 Spinner dolphin 12 35941 13345 9463 1.3 5.0 47.5 1.4 5.7 57.8
WORMS:137109 Spinner dolphin annual 35941 13617 10175 1.3 4.8 46.2 1.4 5.8 66.2
WORMS:137111 Common bottlenose dolphin 01 55774 21707 24072 2.1 16.1 67.3 2.3 15.2 68.8
WORMS:137111 Common bottlenose dolphin 02 55774 21543 24057 2.1 16.5 67.7 2.3 16.4 72.4
WORMS:137111 Common bottlenose dolphin 03 55774 22060 24285 2.1 16.9 68.2 2.2 14.7 60.6
WORMS:137111 Common bottlenose dolphin 04 55774 23043 24651 2.3 19.5 72.9 2.2 13.6 38.6
WORMS:137111 Common bottlenose dolphin 05 55774 23049 24968 2.3 19.4 72.0 2.4 15.1 43.8
WORMS:137111 Common bottlenose dolphin 06 55774 23072 25892 2.3 19.6 73.2 2.6 20.0 62.5
WORMS:137111 Common bottlenose dolphin 07 55774 22822 25568 2.4 20.9 74.2 2.8 21.8 62.7
WORMS:137111 Common bottlenose dolphin 08 55774 22692 25460 2.3 20.5 74.1 2.7 21.9 64.3
WORMS:137111 Common bottlenose dolphin 09 55774 22483 25239 2.3 19.7 74.1 2.8 21.5 65.9
WORMS:137111 Common bottlenose dolphin 10 55774 22469 24724 2.3 20.2 74.8 2.6 18.4 51.7
WORMS:137111 Common bottlenose dolphin 11 55774 22325 23853 2.4 20.6 75.3 2.5 14.7 40.2
WORMS:137111 Common bottlenose dolphin 12 55774 21934 23876 2.2 17.1 68.2 2.3 14.2 54.8
WORMS:137111 Common bottlenose dolphin annual 55774 22592 24914 2.3 19.3 73.1 2.5 17.6 55.3
WORMS:137119 Sperm whale 01 35876 33888 35876 3.0 27.1 78.9 5.1 23.7 41.4
WORMS:137119 Sperm whale 02 35876 33898 35876 3.0 26.7 78.3 4.9 23.1 41.2
WORMS:137119 Sperm whale 03 35876 33838 35876 3.0 26.4 78.3 5.1 25.1 44.0
WORMS:137119 Sperm whale 04 35876 33835 35876 2.9 26.6 79.3 5.2 27.2 47.0
WORMS:137119 Sperm whale 05 35876 33912 35876 3.0 27.0 80.2 6.5 32.7 55.0
WORMS:137119 Sperm whale 06 35876 33873 35876 3.1 27.4 80.6 8.2 39.8 69.6
WORMS:137119 Sperm whale 07 35876 33870 35876 3.1 27.7 80.3 9.2 42.2 78.8
WORMS:137119 Sperm whale 08 35876 33957 35876 3.1 27.8 80.3 9.6 44.4 80.9
WORMS:137119 Sperm whale 09 35876 33952 35876 3.2 28.1 80.8 9.6 43.3 73.0
WORMS:137119 Sperm whale 10 35876 33956 35876 3.1 27.6 80.7 8.9 41.7 68.5
WORMS:137119 Sperm whale 11 35876 33949 35876 3.1 27.4 79.8 7.2 34.1 57.0
WORMS:137119 Sperm whale 12 35876 33927 35876 3.1 26.7 79.1 6.0 27.4 48.6
WORMS:137119 Sperm whale annual 35876 33949 35876 3.1 27.8 81.0 7.2 34.6 57.6
WORMS:137205 Loggerhead sea turtle 01 19474 17288 19014 2.3 13.4 63.3 2.0 6.6 41.5
WORMS:137205 Loggerhead sea turtle 02 19473 17455 19298 2.5 14.4 66.9 3.0 9.6 53.2
WORMS:137205 Loggerhead sea turtle 03 19473 17673 19349 2.7 16.6 67.4 3.4 11.6 51.5
WORMS:137205 Loggerhead sea turtle 04 19466 17676 19299 2.6 17.9 65.2 3.0 11.6 46.7
WORMS:137205 Loggerhead sea turtle 05 19466 17513 19265 2.6 19.2 67.7 2.2 10.1 33.2
WORMS:137205 Loggerhead sea turtle 06 19468 17328 19155 2.6 19.5 69.0 2.0 10.0 34.0
WORMS:137205 Loggerhead sea turtle 07 19473 17465 19320 2.5 18.2 69.2 2.4 11.6 42.3
WORMS:137205 Loggerhead sea turtle 08 19474 17661 19382 2.7 19.1 68.3 2.9 12.6 42.9
WORMS:137205 Loggerhead sea turtle 09 19480 17267 19198 2.5 18.6 66.5 2.1 11.1 38.8
WORMS:137205 Loggerhead sea turtle 10 19477 17366 18231 2.5 19.1 64.3 1.7 6.6 21.8
WORMS:137205 Loggerhead sea turtle 11 19481 17425 18218 2.5 16.1 65.4 1.6 5.2 24.9
WORMS:137205 Loggerhead sea turtle 12 19480 17381 18887 2.4 14.4 65.3 1.9 6.1 36.1
WORMS:137205 Loggerhead sea turtle annual 19481 17674 19285 2.6 18.2 68.8 2.6 10.2 37.4
WORMS:137206 Green sea turtle 01 19474 9987 5924 1.5 6.6 40.7 1.3 3.7 26.7
WORMS:137206 Green sea turtle 02 19473 12442 7955 1.7 7.5 39.7 1.2 3.3 25.1
WORMS:137206 Green sea turtle 03 19473 13054 9240 1.7 7.5 38.4 1.2 3.2 25.6
WORMS:137206 Green sea turtle 04 19466 13717 11874 1.9 8.9 41.1 1.2 3.0 26.2
WORMS:137206 Green sea turtle 05 19466 13960 13409 2.0 11.6 46.3 1.5 4.3 25.2
WORMS:137206 Green sea turtle 06 19468 14414 14489 2.1 13.2 50.0 1.8 5.5 28.9
WORMS:137206 Green sea turtle 07 19473 14410 14676 2.1 14.3 53.1 1.8 6.8 28.1
WORMS:137206 Green sea turtle 08 19474 14369 14591 2.1 14.8 54.4 1.8 7.1 27.4
WORMS:137206 Green sea turtle 09 19480 14333 14235 2.0 13.0 51.9 1.6 5.6 25.8
WORMS:137206 Green sea turtle 10 19477 13134 10992 1.7 9.6 46.3 1.4 4.0 23.8
WORMS:137206 Green sea turtle 11 19481 11402 8094 1.6 8.6 43.3 1.2 3.2 20.6
WORMS:137206 Green sea turtle 12 19480 10596 6600 1.5 6.6 40.7 1.2 3.9 24.6
WORMS:137206 Green sea turtle annual 19481 14001 12998 2.0 12.1 47.3 1.4 3.8 22.2
WORMS:137208 Kemp’s Ridley sea turtle 01 19474 12413 13310 1.8 12.3 63.8 1.6 9.3 56.4
WORMS:137208 Kemp’s Ridley sea turtle 02 19473 12999 14162 1.9 12.7 64.9 1.8 10.4 60.4
WORMS:137208 Kemp’s Ridley sea turtle 03 19473 13407 13822 1.9 13.8 65.2 1.6 8.7 41.6
WORMS:137208 Kemp’s Ridley sea turtle 04 19466 13623 12945 2.0 15.2 61.8 1.6 6.2 21.0
WORMS:137208 Kemp’s Ridley sea turtle 05 19466 13907 12720 2.1 14.8 56.7 1.5 4.7 15.0
WORMS:137208 Kemp’s Ridley sea turtle 06 19468 14087 13672 2.1 15.9 59.8 1.7 6.1 20.0
WORMS:137208 Kemp’s Ridley sea turtle 07 19473 14015 13846 2.1 16.3 59.7 1.7 6.8 21.9
WORMS:137208 Kemp’s Ridley sea turtle 08 19474 14022 13854 2.1 15.8 59.2 1.6 6.7 22.3
WORMS:137208 Kemp’s Ridley sea turtle 09 19480 14164 14033 2.2 15.8 59.0 1.6 6.2 20.4
WORMS:137208 Kemp’s Ridley sea turtle 10 19477 14263 13495 2.1 15.2 57.5 1.5 5.3 16.8
WORMS:137208 Kemp’s Ridley sea turtle 11 19481 13704 12421 2.0 14.8 58.7 1.5 5.6 18.1
WORMS:137208 Kemp’s Ridley sea turtle 12 19480 12681 12589 1.8 13.2 62.3 1.6 8.1 37.1
WORMS:137208 Kemp’s Ridley sea turtle annual 19481 13738 13683 2.0 15.5 63.7 1.7 7.7 28.3
WORMS:137209 Leatherback sea turtle 01 19474 16303 11838 2.1 14.1 58.0 1.3 3.2 11.5
WORMS:137209 Leatherback sea turtle 02 19473 16247 13649 2.1 15.4 62.0 1.4 4.1 14.1
WORMS:137209 Leatherback sea turtle 03 19473 15668 13149 2.2 16.4 63.7 1.4 3.9 13.1
WORMS:137209 Leatherback sea turtle 04 19466 15645 13217 2.4 16.6 59.1 1.3 3.4 10.2
WORMS:137209 Leatherback sea turtle 05 19466 15917 13316 2.5 17.4 60.1 1.3 3.0 10.0
WORMS:137209 Leatherback sea turtle 06 19468 15908 16337 2.2 16.7 61.5 1.7 7.4 25.0
WORMS:137209 Leatherback sea turtle 07 19473 15370 16944 2.0 13.0 54.8 1.7 9.1 44.2
WORMS:137209 Leatherback sea turtle 08 19474 15366 16921 2.0 13.5 56.5 1.7 9.4 44.9
WORMS:137209 Leatherback sea turtle 09 19480 15718 16871 2.1 14.4 62.7 1.8 8.3 35.9
WORMS:137209 Leatherback sea turtle 10 19477 16027 14660 2.3 15.9 60.2 1.4 4.1 15.3
WORMS:137209 Leatherback sea turtle 11 19481 16381 10428 2.1 13.7 59.0 1.2 2.9 8.5
WORMS:137209 Leatherback sea turtle 12 19480 16368 11094 2.2 15.8 65.8 1.3 3.1 7.8
WORMS:137209 Leatherback sea turtle annual 19481 16347 15899 2.3 16.9 64.2 1.6 5.8 18.0
WORMS:1576133 Rice’s whale 01 45496 4232 4363 1.4 9.2 61.9 1.8 15.4 100.0
WORMS:1576133 Rice’s whale 02 45496 4287 4214 1.4 8.4 59.3 1.7 14.4 97.2
WORMS:1576133 Rice’s whale 03 45496 4234 4016 1.4 8.5 60.3 1.7 12.9 80.7
WORMS:1576133 Rice’s whale 04 45496 4309 3950 1.4 8.3 58.5 1.6 9.8 64.0
WORMS:1576133 Rice’s whale 05 45496 4329 3863 1.4 8.5 57.8 1.6 9.7 59.3
WORMS:1576133 Rice’s whale 06 45496 4185 3830 1.4 8.4 56.5 1.7 9.6 64.2
WORMS:1576133 Rice’s whale 07 45496 4169 3922 1.4 8.0 56.0 1.6 10.6 75.4
WORMS:1576133 Rice’s whale 08 45496 4185 3978 1.4 9.0 55.9 1.6 10.2 69.6
WORMS:1576133 Rice’s whale 09 45496 4324 3959 1.4 8.6 53.8 1.7 10.0 67.4
WORMS:1576133 Rice’s whale 10 45496 4328 4042 1.4 9.1 60.1 1.7 10.7 69.1
WORMS:1576133 Rice’s whale 11 45496 4204 4156 1.4 9.6 61.9 1.7 12.4 80.2
WORMS:1576133 Rice’s whale 12 45496 4139 4312 1.5 9.8 63.0 1.8 15.3 100.0
WORMS:1576133 Rice’s whale annual 45496 4360 4192 1.4 9.3 60.6 1.8 11.5 77.1
WORMS:159024 Pygmy or Dwarf sperm whales 04 35876 33758 35876 3.6 22.6 71.3 6.2 16.1 50.3
WORMS:159024 Pygmy or Dwarf sperm whales 05 35876 33801 35876 3.6 23.1 71.3 5.2 13.7 42.6
WORMS:159024 Pygmy or Dwarf sperm whales 06 35876 33880 35876 3.7 23.4 71.6 5.2 13.2 39.2
WORMS:159024 Pygmy or Dwarf sperm whales 07 35876 33825 35876 3.7 23.6 72.2 5.6 14.0 40.4
WORMS:159024 Pygmy or Dwarf sperm whales 08 35876 33917 35876 3.8 23.5 74.2 5.7 13.9 40.9
WORMS:159024 Pygmy or Dwarf sperm whales 09 35876 34268 35876 4.0 24.6 73.9 6.3 14.4 41.5
WORMS:159024 Pygmy or Dwarf sperm whales 10 35876 34400 35876 4.1 24.7 74.2 7.4 16.2 47.5
WORMS:159024 Pygmy or Dwarf sperm whales 11 35876 34287 35876 3.9 23.0 71.4 9.3 21.3 66.2
WORMS:159024 Pygmy or Dwarf sperm whales annual 35876 34141 35876 3.9 23.8 72.9 4.4 10.4 30.5
Code
cat("\n\n</details>\n\n")

5.1 The rounding fault: Rice’s whale and the beaked whales, ver_prev vs this run

The annual surfaces of the two models the v8 ingest left flat at 100, read from ver_prev’s dist/dataset=gm and from this run. Rice’s whale (WORMS:1576133) is the species; WORMS:137035 (Ziphius) is the beaked-whale model, which includes Cuvier’s beaked whale.

Code
dir_prev <- path.expand(glue("{dir_big}/{ver_prev}/marine-atlas/dist/dataset={ds_key}"))
con <- dbConnect(duckdb())
qs  <- \(dir, tag) dbGetQuery(con, glue("
  SELECT '{tag}' AS run, mdl_key, count(*) AS n_cells, round(min(val), 2) AS min, round(quantile_cont(val, 0.1), 2) AS q10,
         round(quantile_cont(val, 0.5), 2) AS q50, round(quantile_cont(val, 0.9), 2) AS q90, round(max(val), 2) AS max,
         round(avg(CASE WHEN val >= 99.999 THEN 1.0 ELSE 0.0 END), 3) AS frac_100
  FROM read_parquet(['{dir}/gm_WORMS_1576133.parquet', '{dir}/gm_WORMS_137035.parquet']) GROUP BY mdl_key"))
fault <- bind_rows(if (dir_exists(dir_prev)) qs(dir_prev, ver_prev), qs(dir_dist, ver)) |> arrange(mdl_key, desc(run))
dbDisconnect(con, shutdown = TRUE)
knitr::kable(fault, caption = glue("annual surfaces: {ver_prev} (cap recipe on rounded densities) vs {ver} ({gm_transform})"))
annual surfaces: v10 (cap recipe on rounded densities) vs v11 (ud)
run mdl_key n_cells min q10 q50 q90 max frac_100
v11 gm|WORMS:137035 31244 1 5.83 35.03 80.75 100 0
v10 gm|WORMS:137035 3189 100 100.00 100.00 100.00 100 1
v11 gm|WORMS:1576133 4360 1 1.43 9.28 60.56 100 0
v10 gm|WORMS:1576133 620 100 100.00 100.00 100.00 100 1

6 Manifest

Code
# content-addressed, deterministic manifest (Phase A) — no wall-clock, so an identical re-ingest
# produces byte-identical bytes and does NOT invalidate downstream targets.
h    <- msens::hash_parquet(glue("{dir_dist}/*.parquet"))
smry <- arrow::open_dataset(dir_dist) |>
  summarise(n_rows = n(), n_mdl = n_distinct(mdl_key),
            val_min = round(min(val), 2), val_max = round(max(val), 2)) |> collect()
msens::report_table(smry, caption = glue("gm density model_cell surface (density → population percentile [1,100], {gm_transform})"))
gm density model_cell surface (density → population percentile [1,100], ud)
n_rows n_mdl val_min val_max
5299184 217 1 100
Code
msens::write_manifest(
  manifest, target = "ingest_sdm_gm", content_hash = h,
  stats = list(
    ds_key = ds_key, n_sp_id = n_distinct(model_gm$sp_id), n_mdl = nrow(model_gm),
    n_guild = n_distinct(model_gm$sp_id[model_gm$is_guild]), transform = gm_transform, p_cap = p_cap,
    note = "monthly + annual density -> population percentile [1,100]; annual = day-weighted mean over 12 months (uncovered = 0 over its weight) then transformed; Oceanic+Shelf summed per cell; guilds ingested, excluded from the merge; NOT yet folded into merge/scoring unless FOLD_DENSITY"),
  force = msens::force_target("ingest_sdm_gm"))

7 Compare with AquaMaps

Most of these cetaceans + sea turtles also have an AquaMaps model, so the two SDMs can be contrasted directly. Drag the swipe divider left/right: AquaMaps (native 0.5° suitability) on the left vs this GoMex surface (0.05°, months averaged to one annual surface) on the right — both rescaled to 0–100 (spectral). AquaMaps paints broad, coarse suitability across (and beyond) the Gulf; the SEFSC survey model resolves fine density structure within it. Pick any species that has both models and drag the round handle on the divider:

Full-screen on the compare page.