enrich

method of dascore.core.spool.Spool source

enrich(
    self ,
    on_unresolved: Literal[‘warn’, ‘raise’, ‘ignore’] = warn,
    **kwargs ,
)-> ‘Self’

Enrich each patch this spool yields from an inventory.

The work happens as each patch is extracted, not now, so this is cheap on a large spool and costs one Patch.enrich per patch which actually comes out. Enrichment survives select, sort, chunk and friends; Spool.remove_inventory undoes it.

Enriching never removes a patch: one the inventory does not describe comes out unchanged rather than missing, so an inventory covering part of an archive needs no pruning first. Deciding membership is conform_to_inventory’s job, and leaving it there is what keeps this lazy — nothing resolves until a patch is pulled.

The inventory is the one attach_inventory put on the spool, which is the only way a spool gets one.

Parameters

Parameter Description
on_unresolved What to do with a patch the inventory does not describe — one
naming no entry, or naming one the inventory does not resolve
to exactly one of. “warn” (the default) leaves it un-enriched
and says so, “ignore” leaves it silently, and “raise” fails.
A patch which straddles two epochs is described twice rather
than not at all, and raises regardless: it needs subdividing.
**kwargs Held and passed to
Patch.enrich for each
extracted patch. The names accepted are read from its
signature, so the two cannot disagree. The names, the policies
and the shape of an acquisition_key are checked now — the
rest each patch’s own enrichment checks as it is extracted.
Calling enrich again replaces these rather than adding to
them. They are:

Other Parameters

Parameter Description
attrs True (the default) to copy the observing-system facts the inventory
is authoritative for, a tuple of names to copy exactly those, or
False to copy none. The blanket form is every scalar field of the
resolved acquisition (and of its interrogator) except data_type
and data_units, which describe the data as it now stands rather
than the system, and sample_rate and spatial_interval, which the
patch’s own coordinates already state and a decimated patch would
contradict. Naming one of those four asks for the as-acquired value;
whether it lands over one the patch already states is conflict’s
business, as it is for every other name.
coords True (the default) to add the geometry axes and label groups of
the resolved optical path, a tuple of names to add exactly those, or
False to add none. The blanket form adds the geometry axes, the
label groups, and coupling, whose values are the coupling type of
each channel. Names may be distance for optical distance, one of
the axes the inventory’s CRS names, a label group, a typed track
(coupling, geometry, optical_components), or a qualified track
field such as coupling.medium.
acquisition_key The inventory identity to resolve, for patches which do not
carry one. Given both, each patch and this argument must agree.
time The instant to resolve at, for patches whose time axis is not
physical. A patch with a real time coordinate resolves at its
own time and passing this raises.
on_missing What to do when an explicitly requested name is one the inventory does
not define: “raise” (the default), “warn” to say so and leave it off,
“ignore” to leave it off silently, or “null” to fill the
dtype-appropriate missing marker so the name is present either way.
Blanket requests copy what is applicable and never trigger it, and
per-channel coverage gaps are always missing values rather than errors.
conflict Indicates how to handle attributes which hold conflicting values across
the patches being combined (eg data_type, data_units, custom attrs). A
missing value (None, NaN, ““) is a value like any other: it equals
another missing one and nothing else, so a patch which never stated an
attribute conflicts with one which did. History and the ids are never
compared. If”raise” (default) raise an
AttributeMergeError for
conflicting values. If “drop”, omit the conflicting attributes from the
output. If “keep_first”, keep the first patch’s value of each.
Enrichment combines the inventory’s values with the patch’s own
rather than a sequence of patches, so it also accepts keep_last,
which is the inventory correcting the file. The default keep_first
keeps what the patch already stated: an attr a reader read out of the
file header was there first. Either way an attr the patch leaves
unset is filled, which is most of what enrichment does. raise is
the misresolution guard: a header disagreeing with the resolved
acquisition usually means the acquisition_key resolved to the
wrong place.

Examples

import dascore as dc
from dascore.examples import inventory_patch_pair

patch, inventory = inventory_patch_pair()
spool = dc.spool(patch).attach_inventory(inventory).enrich()
assert spool[0].attrs.gauge_length == 10.0

# Or name what is wanted, as with Patch.enrich.
attached = dc.spool(patch).attach_inventory(inventory)
spool = attached.enrich(coords=False)