coco_pipe.io.write_transformed_embeddings#

coco_pipe.io.write_transformed_embeddings(source, embeddings, root, *, transform, fitted_on=None, view=None, token_dtype='float32')#

Write transformed embeddings as one file holding every recording.

source is what load_embeddings() returned for one label and view, one row per window, and embeddings its transform, row for row: of the same shape for a transform that keeps it (EuclideanAlign, LeaceEraser), or (window, feature) with view="cov" for RiemannAlign’s tangent vectors. The file keeps the windows, the recordings and the channels of source; its settings are those of source with Transform added, so its config_hash differs, and without NormalizeEmbeddings, which says how the source’s vectors were made, not the transformed ones. Its label is that of source followed by the transform’s (see embedding_label()), e.g. baseRandom3EaCoralCh. It is named by embedding_path(), with the task of the windows when they share one, and written to a temporary name, then moved into place.

Parameters:
  • source (DataContainer) – Embeddings read by load_embeddings(), one row per window.

  • embeddings (np.ndarray) – The transformed embeddings, one row per row of source.

  • root (path-like) – The derivative dataset, e.g. derivatives/coco-pipe-cbramod.

  • transform (SubjectAlignment) – The fitted transform that made embeddings, e.g. an EuclideanAlign. Its name, label and parameters are recorded as the setting Transform, with its fitted rank_ and n_subjects_ when it has them (LEACE).

  • fitted_on (str, optional) – What the transform was fitted on, recorded in Transform, e.g. "every window of base, both conditions".

  • view (str, optional) – The view of the file; that of source by default.

  • token_dtype ({"float32", "float16"}) – The dtype of a token file; other views are float32.

Returns:

The file written.

Return type:

BIDSPath

Raises:

ValueError – If source is not one row per window of an embedding file, or is already transformed, if embeddings does not have one row per window, has axes its view cannot have or holds non-finite values, if transform works per channel (channel_axis) along an axis of source that is not channel, or if the label is not a BIDS label.