cellxgene_census.experimental.get_embedding

cellxgene_census.experimental.get_embedding(census_version: str, embedding_uri: str, obs_soma_joinids: ndarray[Any, dtype[int64]] | Array, context: SOMATileDBContext | None = None) ndarray[Any, dtype[float32]]

Read cell (obs) embeddings and return as a dense numpy.ndarray. Any cells without an embedding will return NaN values.

Parameters:
  • census_version – The Census version tag, e.g., "2023-12-15". Used to verify that the contents of the embedding contain embedded cells from the same Census version.

  • embedding_uri – The URI containing the embedding data.

  • obs_soma_joinids – The slice of the embedding to fetch and return.

  • context – A custom tiledbsoma.SOMATileDBContext which will be used to open the SOMA object. Optional, defaults to None.

Returns:

A numpy.ndarray containing the embeddings. Embeddings are positionally indexed by the obs_soma_joinids. In other words, the cell identified by obs_soma_joinids[i] corresponds to the ith position in the returned numpy.ndarray.

Raises:

ValueError – if the Census and embedding are mismatched.

Lifecycle

experimental

Examples

>>> obs_somaids_to_fetch = np.array([10,11], dtype=np.int64)
>>> emb = cellxgene_census.experimental.get_embedding('2023-12-15', embedding_uri, obs_somaids_to_fetch)
>>> emb.shape
(2, 200)
>>> emb[:, 0:4]
array([[ 0.02954102,  1.0390625 , -0.14550781, -0.40820312],
    [-0.00224304,  1.265625  ,  0.05883789, -0.7890625 ]],
    dtype=float32)