scverse / scverse/spatialdata-io

cosmx - ValueError: Affine matrix must be homogeneous.

Open
#213 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
103
Forks
65
Avg merge
1h 8m
Merged PRs (30d)
3

Description

Hi,

I'm trying to read in some CosMx data - I have a dataset formatted into a folder with the CellLabels and CellComposite directories and then the relevant CSV files. When I execute the code below:

adata3 = sp.cosmx(sample_dir,
                  dataset_id = 'GCIN10692_TMA2')

I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[21], line 1
----> 1 adata3 = sp.cosmx(sample_dir,
      2                   dataset_id = 'GCIN10692_TMA2')

File [/path/to/in839/analysis/init-rocker-renv/venv/lib/python3.12/site-packages/spatialdata_io/readers/cosmx.py:148](http://localhost:8888/lab/tree/venv/lib/python3.12/site-packages/spatialdata_io/readers/cosmx.py#line=147), in cosmx(path, dataset_id, transcripts, imread_kwargs, image_models_kwargs)
    146     glob = table[idx, :].obs[[CosmxKeys.X_GLOBAL_CELL, CosmxKeys.Y_GLOBAL_CELL]].values
    147     out = estimate_transform(ttype="affine", src=loc, dst=glob)
--> 148     affine_transforms_to_global[fov] = Affine(
    149         # out.params, input_coordinate_system=input_cs, output_coordinate_system=output_cs
    150         out.params,
    151         input_axes=("x", "y"),
    152         output_axes=("x", "y"),
    153     )
    155 table.obsm["global"] = table.obs[[CosmxKeys.X_GLOBAL_CELL, CosmxKeys.Y_GLOBAL_CELL]].to_numpy()
    156 table.obsm["spatial"] = table.obs[[CosmxKeys.X_LOCAL_CELL, CosmxKeys.Y_LOCAL_CELL]].to_numpy()

File [/path/to/in839/analysis/init-rocker-renv/venv/lib/python3.12/site-packages/spatialdata/transformations/transformations.py:523](http://localhost:8888/lab/tree/venv/lib/python3.12/site-packages/spatialdata/transformations/transformations.py#line=522), in Affine.__init__(self, matrix, input_axes, output_axes)
    521     raise ValueError("Invalid shape for affine matrix.")
    522 if not np.array_equal(self.matrix[-1, :-1], np.zeros(len(input_axes))):
--> 523     raise ValueError("Affine matrix must be homogeneous.")
    524 assert self.matrix[-1, -1] == 1.0

ValueError: Affine matrix must be homogeneous.

Any recommendations on how to address this?

Cheers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with sp.cosmx(sample_dir, dataset_id='GCIN10692_TMA2') and inspect spatialdata_io/readers/cosmx.py around line 148. Then read spatialdata/transformations/transformations.py around line 523 to understand the matrix validation; done means the reported CosMx dataset loads without the homogeneous-affine error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.