simuran.recording_container module

This module provides a container for multiple recording objects.

class simuran.recording_container.RecordingContainer(container: list = <factory>, load_on_fly: bool = True, last_loaded: Recording = <factory>, attrs: dict = <factory>, invalid_recording_locations: list = <factory>, table: pd.DataFrame = <factory>)

Bases: simuran.core.base_container.GenericContainer

A class to hold recording objects.

load_on_fly

Should information be loaded at the start in bulk, or as needed.

Type:bool
last_loaded

A reference to the last used recording.

Type:simuran.recording.Recording
_last_loaded_idx

The index of the last loaded recording.

Type:int
attrs

Dictionary of metadata.

Type:dict
invalid_recording_locations

Index of recordings that could not be set up.

Type:list of int
table

A table which describes each recording in the container. For example, each row could contain metadata about the session, and a path to a source NWB file to load the data for that session.

Type:Dataframe
dump(filename, results_only=True)

Dump recording_container to file with pickle.

Parameters:
  • filename (str or Path) – The output path.
  • results_only (bool, optional) – Only save the results
Returns:

Return type:

None

filter_table(rows: Union[List[int], slice], loader: Union[BaseLoader, Iterable[BaseLoader], None] = None, inplace: bool = False) → simuran.recording_container.RecordingContainer

Filter the table by rows.

Parameters:
  • rows (list of int or slice) – The rows to keep.
  • loader (BaseLoader or list of BaseLoader) – The loader(s) to use to parse the table. If None, it is assumed that the first loader in the container is the correct one.
  • inplace (bool, optional) – Whether to modify the current container, by default False
Returns:

The filtered container.

Return type:

RecordingContainer

find_recording_by_attribute(key: str, value: Any) → simuran.recording.Recording

Return the recording(s) with self.attrs[key] matching value.

Parameters:
  • key (str) – The attribute to match by.
  • value (Any) – The value to match by.
Returns:

The matched recording (first match)

Return type:

Recording

find_recording_with_source(source_file) → Union[int, List[T]]

Return the index of the recording in the container with the given source file.

Parameters:source_file (str) – The source file to search for.
Returns:The index of the recording in the container. or a list of indices of the recordings if multiple matches are found. or None if the source file is not found.
Return type:int, list, or None
classmethod from_table(table: pd.DataFrame, loader: Union[BaseLoader, Iterable[BaseLoader]], load_on_fly: bool = True) → simuran.recording_container.RecordingContainer

Create a Recording container from a pandas dataframe.

Parameters:
  • df (pandas.DataFrame) – The dataframe to load from.
  • loader (BaseLoader or iterable of BaseLoader) – The loader to use for all recordings if one passed Otherwise a different loader to use for each recording.
  • load_on_fly (bool, optional) – Whether to load the data for the recording container on the fly. Defaults to True (best for memory usage).
Returns:

Return type:

simuran.RecordingContainer

get_results(idx=None)

Get the results stored on the objects in the container.

Parameters:idx (int, optional) – If passed, the index of the item to get the results for, by default None.
Returns:If idx is None, a list of dictionaries, else a single dictionary.
Return type:list of dict, or dict
load(idx: Optional[int] = None, force_reload=False) → Recording

Get the item at the specified index, and load it if not already loaded.

Parameters:
  • idx (int) – The index of the the item to retrieve.
  • force_reload (bool) – Whether to force reload if loading on the fly.
Returns:

The recording at the specified index.

Return type:

simuran.recording.Recording

load_iter()

Iterator through the container that loads data on item retrieval.

load_on_fly = True
save_results_to_table(filename=None)

Dump recording_container results to file with pandas.

Parameters:filename (str or Path) – The output path.
Returns:The resulting dataframe
Return type:Dataframe
class simuran.recording_container.RecordingContainerLoadIterator(recording_container: RecordingContainer)

Bases: object

An iterator for loading recording container on the fly.