Skip to contents

Slims obs to the columns a lens needs, joins the gear and effort of the observation's own sample (sample.tow_type; std_haul_factor, prop_sorted, volume_sampled from sample_measurement), stamps root_id, year, quarter, depth_bin (10 m), hex7, qual_ok (from qual_ok_sql) (year and quarter are the cruise's — since 4.34.0 the year and month of its median cast date (cruise.month_median, read through cruise_tbl) and the season 1 = DJF … 4 = SON (cruise_quarter_sql()), as build_climatology() files the baseline; the cruise_key's YYYY-MM where the cruise table lacks it and the calendar date only where the key does not parse) and, appended after hex7 (4.34.0), cruise_month (that month) and season_year (the year the season belongs to: December counts toward the following winter) and the D8 densities + effort_class (from density_sql). Depth is the observation's, falling back to its sample's and then its root's, so a net tow carries its integrated span. Both realms get the same schema (effort and taxon columns are NULL for env — a NULL column costs nothing in parquet), so one set of SQL templates serves both.

Usage

build_obs_slim(
  con,
  realm = c("bio", "env"),
  qual_ok_sql,
  density_sql,
  tbl = NULL,
  cruise_tbl = "cruise"
)

Arguments

con

DuckDB connection holding obs, sample, sample_measurement, measurement_type and the sample_root built by build_sample_root().

realm

"bio" or "env".

qual_ok_sql

the quality predicate over alias o — calcofi4r::cc_qual_ok_sql("o").

density_sql

the density select-list over the unaliased effort columns — calcofi4r::cc_density_sql().

tbl

output table (default obs_{realm}).

cruise_tbl

the cruise table carrying month_median / date_median (add_cruise_median_date()); NULL, or a table without them, keys the month on the cruise_key.

Value

Invisibly, the row count.

Details

Since 3.31.0 (pre-release plan D-S1) the pair is a strict superset of obs under a name mapping: each row also carries sample_key (the observation's own sampling event — without it a consumer reaches only the root and loses the net / bottle grain), measurement_prec and hex_id (the res-10 H3 cell hex7 is the parent of); realm is implied by the table and measurement_value is value. obs_view_sql() is the UNION ALL that reconstructs obs from the pair under its original 18 column names, and check_obs_pair_parity() asserts the pair holds exactly obs's rows. The one deliberate difference is the depth fallback above: where obs has no depth for a bio row (a net tow whose span lives on sample), the pair — and therefore the view — carries the sample's span; a non-NULL obs depth is never changed.