skneuromsi.io module
Implementation of I/O for skneuromsi.
This module provides functions for storing and loading NDResult and NDResultCollection objects to and from files or file-like objects using a zip-based format.
The NDResult and NDResultCollection objects are serialized using a combination of JSON (for metadata) and NetCDF (for the underlying nddata). The resulting files are zip archives containing the serialized metadata and data.
- skneuromsi.io.store_ndresults_collection(path_or_stream, ndrcollection, *, metadata=None, tqdm_cls=<class 'tqdm.asyncio.tqdm_asyncio'>, **kwargs)[source]
Store an NDResultCollection to a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to write the NDResultCollection to.
ndrcollection (NDResultCollection) – The NDResultCollection object to store.
metadata (dict, optional) – Additional metadata to include in the output file.
**kwargs – Additional keyword arguments to pass to zipfile.ZipFile.
- Raises:
TypeError – If ndrcollection is not an instance of NDResultCollection.
- skneuromsi.io.store_ndresult(path_or_stream, ndresult, *, metadata=None, **kwargs)[source]
Store a single NDResult object to a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to write the NDResult to.
ndresult (NDResult) – The NDResult object to store.
metadata (dict, optional) – Additional metadata to include in the output file.
**kwargs – Additional keyword arguments to pass to store_ndrcollection.
- Raises:
TypeError – If ndresult is not an instance of NDResult.
- skneuromsi.io.open_ndresults_collection(path_or_stream, *, compression_params=('lz4', 9), expected_size=None, tqdm_cls=<class 'tqdm.asyncio.tqdm_asyncio'>, **kwargs)[source]
Retrieve an NDResultCollection from a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to read the NDResultCollection from.
compression_params (dict, optional) – Compression parameters for the NDResultCollection.
expected_size (int, optional) – The expected number of NDResult objects in the collection.
tqdm_cls (callable, optional) – The tqdm class to use for progress bars.
**kwargs – Additional keyword arguments to pass to zipfile.ZipFile.
- Returns:
The retrieved NDResultCollection object.
- Return type:
- Raises:
ValueError – If the expected size doesn’t match the actual size of the collection.
- skneuromsi.io.open_ndresult(path_or_stream, **kwargs)[source]
Open a single NDResult object from a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to read the NDResult from.
**kwargs – Additional keyword arguments to pass to open_ndrcollection.
- Returns:
The retrieved NDResult object.
- Return type:
- skneuromsi.io.to_ndr(path_or_stream, ndresult, *, metadata=None, **kwargs)
Store a single NDResult object to a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to write the NDResult to.
ndresult (NDResult) – The NDResult object to store.
metadata (dict, optional) – Additional metadata to include in the output file.
**kwargs – Additional keyword arguments to pass to store_ndrcollection.
- Raises:
TypeError – If ndresult is not an instance of NDResult.
- skneuromsi.io.read_ndr(path_or_stream, **kwargs)
Open a single NDResult object from a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to read the NDResult from.
**kwargs – Additional keyword arguments to pass to open_ndrcollection.
- Returns:
The retrieved NDResult object.
- Return type:
- skneuromsi.io.to_ndc(path_or_stream, ndrcollection, *, metadata=None, tqdm_cls=<class 'tqdm.asyncio.tqdm_asyncio'>, **kwargs)
Store an NDResultCollection to a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to write the NDResultCollection to.
ndrcollection (NDResultCollection) – The NDResultCollection object to store.
metadata (dict, optional) – Additional metadata to include in the output file.
**kwargs – Additional keyword arguments to pass to zipfile.ZipFile.
- Raises:
TypeError – If ndrcollection is not an instance of NDResultCollection.
- skneuromsi.io.read_ndc(path_or_stream, *, compression_params=('lz4', 9), expected_size=None, tqdm_cls=<class 'tqdm.asyncio.tqdm_asyncio'>, **kwargs)
Retrieve an NDResultCollection from a file or stream.
- Parameters:
path_or_stream (str or file-like object) – The file path or stream to read the NDResultCollection from.
compression_params (dict, optional) – Compression parameters for the NDResultCollection.
expected_size (int, optional) – The expected number of NDResult objects in the collection.
tqdm_cls (callable, optional) – The tqdm class to use for progress bars.
**kwargs – Additional keyword arguments to pass to zipfile.ZipFile.
- Returns:
The retrieved NDResultCollection object.
- Return type:
- Raises:
ValueError – If the expected size doesn’t match the actual size of the collection.