coco_pipe.io.load_embeddings#

coco_pipe.io.load_embeddings(source, *, representation='epoch', conditions=None, subjects=None, subject_metadata_df=None, subject_key=None)#

Load embedding files into a DataContainer.

The files are read one at a time into one float32 array, so memory holds the result and a block of 1,024 windows of one file. Only the windows of conditions and subjects are read.

Parameters:
  • source (path-like or BIDSPath, or a sequence of them) – Embedding files of one model, label and view: one file holding every recording, or recordings’ files (see find_embeddings()).

  • representation ({"epoch", "recording"}) – "epoch": one row per window. "recording": one row per recording and condition, the mean of its windows.

  • conditions (str or sequence of str, optional) – The conditions to load; every condition when omitted.

  • subjects (str or sequence of str, optional) – The subjects to load, labels without sub-; every subject when omitted. A subject no file holds is not an error.

  • subject_metadata_df (DataFrame, optional) – Subject-level metadata to attach, in addition to participants.tsv.

  • subject_key (str, optional) – The column of subject_metadata_df holding the subject ID. It matches rows to subjects and is not attached itself.

Returns:

X is float32, with the file’s axes and window renamed obs: ("obs", "feature") for window and cov files, and channel, time_patch or the model’s token axes before feature for the others. ids is obs. Along obs are the file’s window coordinates (recording_id, subject, session, task, run, condition, epoch, start, stop), each recording’s bad_channels and each subject’s metadata: the columns of participants.tsv, found in the files’ dataset or, following SourceDatasets, in a dataset it comes from (see load_participants_tsv()), and those of subject_metadata_df. session and run are dropped when no recording has one. A channel axis keeps its channel names. meta holds model_key, config, config_hash, description (the label), view, representation, files, recordings (each loaded recording’s row of the files’ recording table) and, for tokens, token_source and token_feature_axis.

Return type:

DataContainer

Raises:

ValueError – If source names no file or a file that is not an embedding file; if the files differ in model, settings (config_hash), label, view, axes, shape, token layout or channel names; if a condition is in no file, no window is selected, an observation appears twice or a value is not finite; if subject_metadata_df comes without subject_key, or a subject metadata column is named like a coordinate the loader sets.

Notes

The recording level is the mean of the window vectors as stored, which are L2-normalised when the extractor normalises them; its obs is <recording_id>_cond-<condition> and epoch_count holds the number of windows. Channel axes that hold the same channels in another order are put in the first file’s order.