coco_pipe.io.write_recording_embeddings#
- coco_pipe.io.write_recording_embeddings(results, root, *, label, source, source_dataset, bad_channels=(), token_dtype='float32', skip_up_to_date=False)#
Write one recording’s embeddings, one file per view.
Each view the results hold (
window_embeddings,token_embeddings, and so on, seeEMBEDDING_VIEWS) goes to its own file, named byembedding_path()after the source recording, with the labelembedding_label()gives for the weights and pooling: e.g.baseRandom3for random weights of seed 3. The window vectors of each other pooling (extra_window_embeddings, e.g. REVE’s attention read-out) go to a window file of their own label (baseAttention), whose settings name that pooling. A file holds every condition, its windows in epoch order. Nothing is written if any check fails, and each file is written to a temporary name and then moved into place, so an existing file is replaced whole or not at all.- Parameters:
results (mapping of str to FoundationEmbeddingResult) – The extractor’s result for each condition of the recording. Its
window_indexholds the epoch numbers.root (path-like) – The derivative dataset, e.g.
derivatives/coco-pipe-cbramod.label (str) – The label of the data embedded, e.g.
"base"for epochs labelleddesc-base.source (path-like) – The file the epochs were read from, in its datatype folder of a BIDS dataset: the
sourcecoordinate of the BIDS loader’s rows, or aBIDSPath’sfpath. Its entities name the recording, and the embedding files go in the same datatype folder.source_dataset (str) – The name of the source dataset in
DatasetLinks, e.g."preproc", for the BIDS URI ofsource.bad_channels (str | sequence of str) – The recording’s bad channels, or the BIDS loader’s
bad_channelscoordinate (comma-separated).token_dtype ({"float32", "float16"}) – The dtype of the token file;
"float16"halves its size. The other views are float32.skip_up_to_date (bool) – Keep a file that already holds the same windows with the same
config_hash, asembeddings_up_to_date()tells, instead of replacing it. Its values are not compared.
- Returns:
The path of each label and view, e.g.
paths["baseRandom3", "window"].- Return type:
- Raises:
ValueError – If the conditions come from different models or settings (their
config_hash), differ in views, poolings, feature size or channels, hold non-finite values or share epoch numbers, if a channel axis does not matchmodel_channels, if a pooling’s name is not letters and digits, iflabelis not a BIDS label, ifsourceis not a file in a datatype folder of a subject, or iftoken_dtypeis not"float32"or"float16".
Notes
The
embeddingsvariable holds the view, as float32 (tokens astoken_dtype; values beyond float16’s range are refused). Alongwindoware the coordinatesobs(<recording_id>_epoch-NNNN, as the BIDS loader names observations),recording_id,subject,session,task,run,condition,epoch,startandstop. Alongrecordingare itssource(a BIDS URI), sampling rate, channels, bad channels and the channels the model interpolated, zero-filled or dropped. A view with achannelaxis names it with thechannelcoordinate: the channels the model saw (model_channels). The attributes aremodel_key,config(the extraction settings that are the same for every recording, as JSON text, seeEMBEDDING_CONFIG_KEYS),config_hash(their hash) anddescription(the file’s label); a token file addstoken_sourceandtoken_feature_axis, the other token axes being the observation axes. Other metadata in the results is not stored.