attach_inventory

method of dascore.core.spool.Spool source

attach_inventory(
    self ,
    inventory = None,
)-> ‘Self’

Attach a DASDAE inventory to this spool.

Attaching is lazy and does not modify yielded patches. It replaces any previous inventory and clears configured enrichment; call enrich to copy inventory metadata onto extracted patches.

Parameters

Parameter Description
inventory The inventory to carry: an Inventory, or the path of one
(an authoring directory or a serialized file), which is read
at the first question rather than now. None means the one
the spool’s own directory carries, read again.

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 "gauge_length" not in dict(spool[0].attrs)
assert spool.enrich()[0].attrs.gauge_length == 10.0
Note

Attaching promises nothing about the spool matching the inventory; conform_to_inventory is what makes it so. Once attached, the coordinates the inventory defines along the fiber become selectable, and expand_by can expand the spool by the values of one.

A spool opened on a directory which carries an inventory under the name .inventory starts out attached to it, so this is needed there only to attach a different one — or, with no argument, to read that one again after editing it. An inventory is read once and held, since it is an input rather than a cache; re-reading it is a thing the program says, not something which happens behind it.