save#

syncopy.save(out, container=None, tag=None, filename=None, overwrite=False)[source]#

Save Syncopy data object to disk

The underlying array data object is stored in a HDF5 file, the metadata in a JSON file. Both can be placed inside a Syncopy container, which is a regular directory with the extension ‘.spy’.

Parameters
  • out (Syncopy data object) – Object to be stored on disk.

  • container (str) – Path to Syncopy container folder (*.spy) to be used for saving. If omitted, the extension ‘.spy’ will be added to the folder name.

  • tag (str) – Tag to be appended to container basename

  • filename (str) – Explicit path to data file. This is only necessary if the data should not be part of a container folder. An extension (*.<dataclass>) is added if omitted. The tag argument is ignored.

  • overwrite (bool) – If True an existing HDF5 file and its accompanying JSON file is overwritten (without prompt).

Returns

Nothing

Return type

None

Notes

Syncopy objects may also be saved using the class method .save that acts as a wrapper for syncopy.save(), e.g.,

>>> save(obj, container="new_spy_container")

is equivalent to

>>> obj.save(container="new_spy_container")

However, once a Syncopy object has been saved, the class method .save can be used as a shortcut to quick-save recent changes, e.g.,

>>> obj.save()

writes the current state of obj to the data/meta-data files on-disk associated with obj (overwriting both in the process). Similarly,

>>> obj.save(tag='newtag')

saves obj in the current container ‘new_spy_container’ under a different tag.

Examples

Save the Syncopy data object obj on disk in the current working directory without creating a spy-container

>>> spy.save(obj, filename="session1")
>>> # --> os.getcwd()/session1.<dataclass>
>>> # --> os.getcwd()/session1.<dataclass>.info

Save obj without creating a spy-container using an absolute path

>>> spy.save(obj, filename="/tmp/session1")
>>> # --> /tmp/session1.<dataclass>
>>> # --> /tmp/session1.<dataclass>.info

Save obj in a new spy-container created in the current working directory

>>> spy.save(obj, container="container.spy")
>>> # --> os.getcwd()/container.spy/container.<dataclass>
>>> # --> os.getcwd()/container.spy/container.<dataclass>.info

Save obj in a new spy-container created by providing an absolute path

>>> spy.save(obj, container="/tmp/container.spy")
>>> # --> /tmp/container.spy/container.<dataclass>
>>> # --> /tmp/container.spy/container.<dataclass>.info

Save obj in a new (or existing) spy-container under a different tag

>>> spy.save(obj, container="session1.spy", tag="someTag")
>>> # --> os.getcwd()/session1.spy/session1_someTag.<dataclass>
>>> # --> os.getcwd()/session1.spy/session1_someTag.<dataclass>.info

See also

syncopy.load

load data created with syncopy.save()