attach_inventory

method of dascore.core.spool.Spool source

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

Attach a DASDAE inventory to this spool.

The spool carries the reference and nothing else: attaching costs no work per patch and adds nothing to the patches it yields. Call Spool.enrich to copy the inventory’s metadata onto the patches as they are extracted.

Attaching replaces whatever the spool carried before, and clears enrichment set up from it — swapping the inventory silently under a configured enrichment would change every patch’s metadata, so the new one has to be asked for. enrich() resumes with defaults.

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.