# OIP-0006: Universal observation (ISO 19156 profile)

| Field | Value |
|---|---|
| Status | DRAFT |
| Functions | `describe` (§5.3), `observe` (§5.5), `qualify` (§5.6); no new function (the register keeps exactly twelve) |
| Affects | header, §4.2, §5.5, §5.6, §10; `schemas/json/observation-record.schema.json` (new major `schemaVersion` `4.0.0`); new schemas `observer`, `deployment`, `feature-of-interest`; `quality-flag` (named flag scheme, additive); `registers/functions.yaml`; `registers/relations.yaml` (`EXT-SOSA` revised, new `EXT-OMS`, `EXT-UCUM`, `EXT-GUM`, `EXT-QCFLAGS`, `EXT-OGCCRS`); new crosswalks `crosswalks/oms.yaml` and `crosswalks/sosa-ssn.yaml`; new cases CT-NODE-010 to CT-NODE-016 |
| Protocol version | obsp/0.1 |
| Work packages | WP-IM-01 (observation model), WP-IM-03 (uncertainty and origin), WP-IM-04 (quality flag schemes) |
| Relates to | the observed-property register (`registers/observed-properties.yaml`), delivered in this folder as `patches/register-properties.patch` by a separate author; OIP-0005 (its OBSP-GRID example observation and alert evidence digests follow this revision once both are accepted) |
| Last call | 30 days (revision of existing functions) unless the editors rule otherwise; see Open questions |

## Problem

The ObservationRecord at `3.1.0` cannot carry the same meaning across instruments, satellites, networks, models and
people:

1. `observedProperty` and `unit` are free strings. Two records of air temperature can say `temperature`/`Cel` and
   `airTemp`/`degC`, and a numeric result without a unit validates (`result` may be a bare number).
2. There is no observer class, no procedure, no feature of interest and no geometry with a coordinate reference
   system. `geometry` accepts any object with a `type`.
3. Nothing states whether a value was measured, derived by a network, produced by a model, simulated or declared. A
   gap-filled or modelled value can travel as if measured, which breaks P5 and P8.
4. Nothing states whether a value can single out a person, although §8 makes person-level data a declared data class
   with its own policy.
5. Store-and-forward links (§5.5) lose the acquisition, storage and receipt times, so latency and replay order cannot
   be checked.
6. `uncertainty` is a free map; nothing says whether a number is a standard uncertainty, an expanded one or a bound.
7. Quality flags exist only in the protocol's vocabulary. Ocean, meteorological and float data arrive with QARTOD,
   WMO or Argo codes, and today each operator converts them its own way.

The established model is ISO 19156:2023 (Observations, measurements and samples), with W3C SOSA/SSN (2017) as its web
ontology. The protocol must profile them, not replace them, and map its fields to theirs.

## Change

### Normative text

§5.5 Observe gains the sub-list "Observation records" (OBS-1 to OBS-7); §5.6 Qualify gains "Uncertainty and flag
schemes" (QUAL-1, QUAL-2) with the mapping table. The full text is in `patches/spec.patch`; in short:

1. **OBS-1.** A record names its observer (UNI and class), procedure (`<UNI>@<version>`), observed property (register
   id `obsp:prop:<id>`), feature of interest (UNI or inline geometry), phenomenon time (RFC 3339 instant or interval)
   and result time.
2. **OBS-2.** A result is exactly one of: quantity (value and UCUM unit, `1` for dimensionless), coverage reference,
   event reference, category from a named vocabulary. A numeric value without a unit is rejected.
3. **OBS-3.** Origin is REQUIRED: `MEASURED`, `NETWORK_DERIVED`, `MODEL_DERIVED`, `SIMULATED`, `DECLARED`. Model and
   simulation results reference their ModelManifest (UNI, version, digest); network-derived results name the issuing
   network function. A value that provenance shows a model activity generated, or that a `MODEL` observer issued, is
   never `MEASURED`.
4. **OBS-4.** Subject class is REQUIRED: `NONE`, `OBJECTS`, `PERSONS`. `PERSONS` requires a consent or policy URI, else
   the record is rejected; a record never exceeds the class its observer declares.
5. **OBS-5.** A store-and-forward observer's records carry `acquiredAt` ≤ `storedAt` ≤ `receivedAt`; no interval ends
   before it starts.
6. **OBS-6.** A geometry names its CRS by OGC or EPSG definition URI; coordinates follow its axis order; vertical datum
   and position uncertainty SHOULD be stated.
7. **OBS-7.** Observers are described by Observer records, installations by Deployment records (period ordered);
   FeatureOfInterest records MAY be published; an `INSTRUMENT` record cites its sensor passport version (§5.3).
8. **QUAL-1.** Uncertainty names its kind after JCGM 100:2008 (GUM): `STANDARD`, `EXPANDED` (coverage factor),
   `INTERVAL` (ordered bounds, coverage probability), `ENSEMBLE` (spread, members), `CATEGORICAL` (probability), in the
   unit of the value it qualifies.
9. **QUAL-2.** A quality flag MAY be set under a named scheme (`OBSP`, `QARTOD`, `WMO`, `ARGO`) with its code; the flag
   is then the OBSP value of the mapping table; an unlisted code is rejected.

§4.2 gains the row "Observer, Deployment, FeatureOfInterest | `observer`, `deployment`, `feature-of-interest` |
Describe, Observe". The header and §10 state that `observation-record` carries `4.0.0`.

Names follow the repository's conventions: enumerations in upper case (`MEASURED`, `PERSONS`, `INSTRUMENT`), the
uncertainty type under `kind` as in `calibration-record`, the observer UNI under `observerUni`. The design text's
`NOT_ASSESSED` is the existing vocabulary value `NOT_CHECKED`; no flag value is added.

### Contract: `observation-record` (schemaVersion `4.0.0`, `$id` `urn:obsp:schema:v4.0:observationrecord`)

| Property | Required | Shape |
|---|---|---|
| `schemaVersion`, `apiVersion`, `kind`, `protocolVersion` | yes | `4.0.0`, `obsp/observation-record/v4.0`, `ObservationRecord`, `obsp/0.1` |
| `observationUni` | yes | UNI |
| `observer` | yes | `{observerUni, class, storeAndForward?}`; class `INSTRUMENT`, `SPACE_SEGMENT`, `NETWORK`, `MODEL`, `PLATFORM`, `PERSON` |
| `deploymentRef` | no | RecordRef to a Deployment |
| `procedure` | yes | `<UNI>@<version>` |
| `observedProperty` | yes | `^obsp:prop:[a-z0-9_]+$` (pattern only; the register is a separate patch) |
| `featureOfInterest` | yes | `{uni, version?}` or `{geometry, sampledFeature?}` |
| `phenomenonTime` | yes | RFC 3339 instant or `{start, end}` |
| `resultTime` | yes | RFC 3339 |
| `validTime` | no | `{start, end}` |
| `times` | when `observer.storeAndForward` is true | `{acquiredAt, storedAt, receivedAt}` |
| `geometry` | no | `{crs, type, coordinates, verticalDatum?, positionUncertainty?}`; `type` Point, MultiPoint, LineString, Polygon |
| `result` | yes | one of `{value, unit}` (UCUM pattern of `sensor-passport`), `{coverageRef}`, `{eventRef}`, `{category, vocabulary}`; `null` only with `resultState` other than `PRESENT` |
| `resultState` | no | unchanged |
| `uncertainty` | no | `{kind, value, coverageFactor?, coverageProbability?, members?}` |
| `origin` | yes | as OBS-3; `modelRef` required for `MODEL_DERIVED` and `SIMULATED`, forbidden for `MEASURED` and `DECLARED`; `networkFunctionUni` required for `NETWORK_DERIVED` |
| `subjectClass` | yes | `NONE`, `OBJECTS`, `PERSONS` (annotation default `NONE`); `subjectPolicyRef` `{uri, digest?}` required for `PERSONS` |
| `evidenceRefs` | yes | unchanged |
| `sensorPassportRef` | when `observer.class` is `INSTRUMENT` | unchanged shape |
| `timeQualityRef`, `quality`, `provenanceRef`, `extensions` | no | unchanged; inline quality entries gain `scheme` and `schemeCode` |

Removed: `systemUni` (now `observer.observerUni`), top-level `unit` (now in the quantity result), `qualityFlags`
(free strings, superseded by `quality` at `3.1.0`).

### New contracts (schemaVersion `3.1.0`, as other new objects of obsp/0.1)

- `observer`: `observerUni`, `version`, `class`, `observedProperties` (register ids), `procedures`,
  `storeAndForward`, `subjectClass` (highest it may produce, with `subjectPolicyRef` for `PERSONS`),
  `sensorPassportRef` (required for `INSTRUMENT`), `modelRef` (required for `MODEL`), `networkFunctionUni` (required
  for `NETWORK`), `hostUni`, `operatorUni` (by role, never a name), `recordedAt`.
- `deployment`: `deploymentUni`, `observerRef` (versioned), `platformRef` (optional), `site` (`siteUni`, optional
  geometry), `period` (`start`, optional `end`), `mounting` (exposure vocabulary of `sensor-passport` plus `IN_ORBIT`,
  typed heights and angles), `recordedAt`.
- `feature-of-interest`: `featureUni`, `version`, `featureType` (token or vocabulary URI), `geometry`,
  `sampledFeature` (for a sampling feature), optional `title`, `recordedAt`.

Uncertainty and Geometry are shared `$defs`, copied into each schema that uses them, since schemas are
self-contained (no external `$ref`).

### `quality-flag` (additive, stays `3.1.0`)

Optional `scheme` (`OBSP`, `QARTOD`, `WMO`, `ARGO`; absent means `OBSP`) and `schemeCode` (required when the scheme is
not `OBSP`). Mapping table (codes only; meanings stay with each scheme):

| Scheme | Code → OBSP flag |
|---|---|
| QARTOD | 1 GOOD, 2 NOT_CHECKED, 3 SUSPECT, 4 BAD, 9 MISSING |
| WMO (BUFR code table 0 33 020) | 0 GOOD, 1 SUSPECT, 2 SUSPECT, 3 BAD, 4 NOT_CHECKED, 5 ESTIMATED, 6 ESTIMATED, 7 MISSING |
| ARGO | 0 NOT_CHECKED, 1 GOOD, 2 SUSPECT, 3 BAD, 4 BAD, 5 ESTIMATED, 8 ESTIMATED, 9 MISSING |

The mapping is conservative: a code that is not certainly good never maps to `GOOD` (Argo "probably good" maps to
`SUSPECT`). The table sits in §5.6 and in the SDK (`FLAG_SCHEMES`); a unit test fails when the two differ.

### Invariants (suite, with unit tests in `sdk/python/tests/test_obsp.py`)

| Invariant | Rule |
|---|---|
| `observation-numeric-has-unit` | a numeric result is `{value, unit}` with a UCUM-shaped unit; a bare number fails (OBS-2) |
| `observation-origin-consistent` | `MODEL_DERIVED`/`SIMULATED` name a `model-manifest` present in the set; `NETWORK_DERIVED` names its network function; `MEASURED` fails when the observer class is `MODEL` or when the referenced provenance shows the record generated by an activity that used a `model-manifest` entity (OBS-3) |
| `observation-subject-policy` | `PERSONS` has an absolute policy URI; a record's class does not exceed its observer's (OBS-4) |
| `observation-times-ordered` | store-and-forward times present and `acquiredAt` ≤ `storedAt` ≤ `receivedAt`, compared as instants; intervals ordered (OBS-5) |
| `deployment-period-ordered` | a deployment does not end before it starts (OBS-7) |
| `observation-uncertainty-consistent` | interval bounds ordered, non-negative standard, expanded and ensemble values, expanded with coverage factor; also position uncertainties (QUAL-1) |
| `quality-flag-scheme-mapped` | scheme code listed and flag equal to the table's value, for `quality-flag` documents and inline flags (QUAL-2) |

### Crosswalks

`crosswalks/oms.yaml` (ISO 19156:2023) and `crosswalks/sosa-ssn.yaml` (W3C Recommendation 2017-10-19) cover the four
contracts; every required property has a row. ISO 19156 was not opened: every OMS row says `checked: not checked` and
cites the clause by schema name only. SOSA/SSN rows with a term cite the Recommendation's section and say `opened`.
Fields with no counterpart (origin, subject class, store-and-forward times, protocol envelope) are `match: none` with
the reason. Examples: `crosswalks/examples/oms/` and `crosswalks/examples/sosa-ssn/` (source fixture plus the mapped
document). As the first crosswalks, they fix the round-trip method in `crosswalks/README.md`: every `exact`/`both`
field survives a mapping to the standard and back. Relation rows: `EXT-OMS` (new) and `EXT-SOSA` (artefact added).

## Compatibility

Breaking for `observation-record`, hence the new major `schemaVersion` `4.0.0` (§10). Other objects are unchanged
(`quality-flag` gains optional fields only). Migration of a `3.1.0` record, applied by the receiver or the producer:

| `3.1.0` | `4.0.0` |
|---|---|
| `systemUni` | `observer.observerUni`; `observer.class` from the system's description (`INSTRUMENT` when a sensor passport is referenced) |
| `observedProperty` (free text) | the register id; a term with no register id cannot migrate and is rejected, not guessed |
| `result` number + `unit` | `result: {value, unit}`; `result: {value}` objects take the top-level `unit` |
| `result` without a unit | not migrated (OBS-2); the producer re-issues it |
| `phenomenonTime` string | instant, or `{start, end}` for a `start/end` interval string |
| `geometry` | `crs` added (`http://www.opengis.net/def/crs/OGC/1.3/CRS84` only when the producer confirms GeoJSON longitude, latitude order) |
| `uncertainty` map | `{kind, value}` when the map states the kind; otherwise dropped and recorded in the migration evidence |
| `qualityFlags` | dropped; `quality` entries kept |
| (absent) | `origin`: no default; the producer states it. `subjectClass`: `NONE` unless the data class says otherwise. `procedure`, `featureOfInterest`: from the sensor passport sampling plan and site, else the record is not migrated |

The digest of a migrated record changes; references that pin a `3.1.0` digest (for example alert evidence in
OIP-0005) are re-pointed to the migrated record and its new version (§5.9, a new version, never an edit in place).

Draft interplay: these patches apply to the current tree on their own. With them applied, the other drafts' patches
still apply except one line: OIP-0005 `registers.patch` changes `"count"` in `registers/implements-edges.json` from the
same base value this proposal also changes (both add external relations). `implements-edges.json` is generated
(`python3 tools/build_edges.py`), so whichever proposal is accepted second regenerates it.

## Tests

| Requirement | Case | Kind | Evidence and invariants |
|---|---|---|---|
| OBS-1, OBS-2, OBS-6 | CT-NODE-010 | invariant | `observation-record`; `observation-numeric-has-unit` |
| OBS-3 | CT-NODE-011 | invariant | `observation-record`; `observation-origin-consistent` |
| OBS-4 | CT-NODE-012 | invariant | `observation-record`, `observer`; `observation-subject-policy` |
| OBS-5 | CT-NODE-013 | invariant | `observation-record`; `observation-times-ordered` |
| OBS-7 | CT-NODE-014 | invariant | `observer`, `deployment`, `feature-of-interest`, `observation-record`; `deployment-period-ordered` |
| QUAL-1 | CT-NODE-015 | invariant | `observation-record`; `observation-uncertainty-consistent` |
| QUAL-2 | CT-NODE-016 | invariant | `quality-flag`, `observation-record`; `quality-flag-scheme-mapped` |

All cases apply to OBSP-NODE, OBSP-SITE and OBSP-GRID; the example sets of all three (and the negative OBSP-NODE set,
which still fails only for its documented reasons) gain an observer, a deployment, a feature of interest and a `4.0.0`
observation; OBSP-GRID also gains a model-derived observation with its model manifest.

Positive fixtures: `observation-record` (`valid`, `obsp-fields`, `missing-typed`, `model-derived`, `network-derived`,
`persons-with-policy`), `observer` (`valid`, `model`), `deployment` (`valid`, `ongoing`), `feature-of-interest`
(`valid`, `sampling`), `quality-flag` (`qartod`, `wmo-not-checked`).

Negative fixtures, one broken rule each: `observation-record.` `v3-schema-version`, `free-text-observed-property`,
`numeric-without-unit`, `bare-number-result`, `non-ucum-unit`, `two-result-shapes`, `missing-origin`,
`unknown-origin`, `model-derived-without-model-ref`, `simulated-without-model-ref`,
`network-derived-without-function`, `measured-with-model-ref`, `missing-subject-class`, `persons-without-policy`,
`persons-policy-not-a-uri`, `store-and-forward-without-times`, `phenomenon-time-not-rfc3339`, `crs-not-a-uri`,
`expanded-uncertainty-without-coverage-factor`, `interval-uncertainty-without-probability`,
`instrument-without-sensor-passport`, `procedure-without-version`, `scheme-without-code` (and the four existing ones,
migrated); `observer.` `instrument-without-passport`, `model-without-model-ref`, `network-without-function`,
`persons-without-policy`, `unknown-class`, `free-text-property`, `missing-store-and-forward`; `deployment.`
`missing-period-start`, `missing-height-as-zero`, `unknown-exposure`, `observer-without-version`;
`feature-of-interest.` `missing-crs`, `point-with-one-coordinate`, `bad-feature-type`, `missing-geometry`;
`quality-flag.` `scheme-without-code`, `unknown-scheme`. Rules JSON Schema cannot express (time order, interval
bounds, scheme mapping, provenance, set membership) are proved by the invariant unit tests.

`tests/test_validate.py`: the crosswalk-layout test counts the shipped crosswalks instead of assuming none.

## Open questions

1. The flag-scheme codes are cited from memory of US IOOS QARTOD (flags 1 to 4 and 9), WMO FM 94 BUFR code table
   0 33 020 and the Argo quality control manual (reference table 2); none was opened for this draft. Editors should
   check each code and the clause references before review. Is Argo 2 ("probably good") → `SUSPECT` the right
   conservative choice, and WMO 1 ("inconsistent") → `SUSPECT` rather than `BAD`?
2. ISO 19156:2023 clause numbers and the exact names of Observer, Host and Deployment were not checked against the
   standard (every OMS row says `not checked`). SOSA/SSN section numbers were read once in the Recommendation.
3. The design text names the flag value `NOT_ASSESSED`; this draft keeps the existing `NOT_CHECKED`. Keep, or rename
   in a later major?
4. Should `calibration-record`'s `confidenceLevel` be renamed `coverageProbability` (the JCGM 100:2008 term this draft
   uses) for one vocabulary?
5. Unit against property: the observed-property register gives each property its dimension. Should a further
   invariant check that a quantity's UCUM unit has that dimension once the register is accepted?
6. CRS axis order: should the protocol require `OGC:CRS84` (longitude, latitude) for interchange, as GeoJSON does,
   instead of allowing any OGC or EPSG CRS in its own axis order?
7. Case numbers CT-NODE-010 to CT-NODE-016 are the next free ones today; parallel drafts may need renumbering.
8. Last call: revision (30 days) or, since a contract takes a new major version, 90 days?

Acceptance needs appointed editors and a last-call window. Until then this proposal stays at DRAFT and the
ObservationRecord stays at `3.1.0`.
