Build the measurements catalog record (measurements.json)
Source: R/catalog_measurements.R
build_measurements_catalog.RdOne entry per measurement key the release's obs_env carries — the registry's
variable where set, else the measurement_type — with its series (one per
measurement_type × dataset), each series' counts by year, calendar month,
depth band and quality code, its observed quantiles, the registry's declared
bounds, the source and flag columns, the NERC ids, and the other keys sharing
its P01 concept that are deliberately kept apart.
Usage
build_measurements_catalog(
con,
record,
measurement_type,
variable = NULL,
category,
release_version = NULL,
release_date = NULL,
underway_datasets = "calcofi_mets",
supplemental_tables = c(ctd_raw = "obs_ctd_full", mets_measurement = "obs_mets_full"),
supplemental_rows = NULL,
registries = NULL,
anomaly = TRUE,
anomaly_trend = CC_MEASUREMENT_ANOMALY_TREND,
anomaly_min_cruises = CC_MEASUREMENT_ANOMALY_MIN_CRUISES
)Arguments
- con
a DBI connection holding the release table
obs_env(and, optionally,climatologyand theobs_*_fullsupplementals)- record
the
datasets.jsonrecord — a path or the list frombuild_dataset_catalog()— read fordatasets[].dataset_name_short,colorandcategory, and for the catalog order ofdatasets[]- measurement_type
the measurement vocabulary, from
read_measurement_type()(metadata/measurement_type.csv)- variable
the label registry (
metadata/variable.csv): a data frame with at leastvariableandlabel.NULL(the default) means no registry is available and every measurement falls back to its canonical series' description with theno_labelflag.- category
the category registry (
metadata/category.csv):category,order,realm,icon(and optionallykey)- release_version
the release version (default: the record's)
- release_date
the release date,
YYYY-MM-DD(default: the record's)- underway_datasets
dataset keys whose series are underway intakes rather than casts, which is what makes a shared P01
underway_vs_cast. Named here rather than inferred, because nothing in the release states it.- supplemental_tables
named character vector mapping a registry
_source_tableto the full-resolution release table its non-released series live in. Only a registry row from one of these source tables can be afull_resolution_only[]row: a row from anywhere else that never reachesobs_envis simply not released, not "full resolution only".- supplemental_rows
named numeric vector, release table -> row count, used for any
supplemental_tablesentry the connection does not carry (a promoted release read throughcc_get_db()does not attach them). Read it from that release's owncatalog.json; never type it.full_rowsiscounts$obs_env_rowsplus these, and isNAwhen a supplemental is neither on the connection nor supplied.- registries
the five face registries of
measurements.json1.1 (plan 2026-09-11 "Measurement faces", Appendix A) —NULL(the default), ametadata/directory holdingmeasurement_{chem,method,scale,why,face}.csv, or a named list of any subset ofchem,method,scale,why,faceas data frames, which is how a caller passesread_measurement_chem()and its four siblings. Every field they add is additive: a key with no row in a registry carries no such field, and a build withregistries = NULLwrites exactly the 1.0 record.kind = "computed"rows of the scale registry are recomputed here from their ownhow(gsw.<function>(<numbers>), resolved against TEOS-10's gsw) and never read as typed numbers; a mark whosehowthis package cannot evaluate — carbonate chemistry, which has no R equivalent installed — passes through withcomputed_at_build: false.- anomaly
compute the per-band
anomaly{}block (defaultTRUE) — the yearly departure from the release's ownclimatology, per depth band, for every key the climatology covers.FALSE, or a connection carrying no usableclimatology, leaves the field out.- anomaly_trend
the two years the least-squares trend is fitted between, inclusive (default 1984-2021).
- anomaly_min_cruises
the cruises a year needs before it may set the trend, the extremes or the shared
ymax(default 2). Thinner years stay in the series — the page draws them faded — but never steer a fitted line.
Value
A list ready for write_measurements_catalog() /
jsonlite::write_json(auto_unbox = TRUE), validating against
inst/schema/measurements.schema.json.
Details
Everything is read: obs_env (and, when present, climatology and the
obs_*_full supplementals) on con, the dataset names, colours, categories
and order from record (the datasets.json the release has just written, so
a dataset dot cannot disagree between /datasets/ and /measurements/), and
the vocabulary from the registries. Nothing is authored and nothing is
fetched.
Six grouped queries do the counting — never one per key — and every per-series
lookup is a split index, so the builder is linear in the number of obs_env
groups.
The label. label comes from metadata/variable.csv when that registry
carries a row for the key. Absent a row it falls back to the canonical series'
registry description and the measurement carries the no_label flag: a
column note is not a title, and the builder does not invent one.