conform_to_inventory

method of dascore.core.spool.Spool source

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

Return a spool the inventory describes exactly, patch for patch.

The one eager step of the inventory workflow: every row is resolved now, patches the inventory does not describe are dropped, and a patch whose span crosses a change of optical path is subdivided at each such change — so the spool can grow as well as shrink. A bound the answers survive unchanged is not a change, and does not divide anything. It is metadata work; no patch data is read.

Subdivision is exact. Each piece begins at the first sample at or after the change which opens it, so together they hold every sample the patch held and hold none of them twice, and len and get_contents describe the pieces rather than the original.

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
carrying no acquisition_key, one carrying a key the
inventory does not resolve to exactly one entry, one reaching
outside every matching epoch, or one with no instants to
resolve at because its time axis is not physical. A patch is
judged over its whole span, so one described at its start but
not at its end is undescribed. “raise” (the default)
fails and names them, “warn” drops them and says so, and
“ignore” discards them silently, which is what an inventory
deliberately covering part of an archive wants.

Raises

PatchError If a patch spans a change of acquisition, or must be subdivided but states no time step to find its samples with. An acquisition change means the two halves were recorded under different configurations, so no subdivision makes it one honest patch, and on_unresolved does not cover it: the inventory describes such a patch twice rather than not at all.

Examples

import dascore as dc
from dascore.examples import inventory_patch_pair

patch, inventory = inventory_patch_pair()
spool = dc.spool(patch).attach_inventory(inventory)
assert len(spool.conform_to_inventory()) == 1

# A patch the inventory says nothing about can be dropped.
other = patch.update_attrs(acquisition_key="DAS.R2D1..OTHER")
mixed = dc.spool([patch, other]).attach_inventory(inventory)
assert len(mixed.conform_to_inventory(on_unresolved="ignore")) == 1