Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read a whole slide image into sopa #137

Open
asmitaL99 opened this issue Oct 8, 2024 · 4 comments
Open

Unable to read a whole slide image into sopa #137

asmitaL99 opened this issue Oct 8, 2024 · 4 comments

Comments

@asmitaL99
Copy link

Description

I am trying to use the sopa.io.wsi function to read a ome.tif file

Reproducing the issue

image = sopa.io.wsi("Xenium_V1_hPancreas_Cancer_Add_on_FFPE_he_image.ome.tif", as_image=True)

Expected behavior

A clear and concise description of what you expected to happen.
the image should be read !

System

  • OS: [e.g. Linux]
  • Python version [e.g. 3.9.7]
Dependencies versions
Paste here what 'pip list' gives you.

Error : ValueError Traceback (most recent call last)
Cell In[21], line 2
1 # reading the H&E image
----> 2 image = sopa.io.wsi("Xenium_V1_hPancreas_Cancer_Add_on_FFPE_he_image.ome.tif", as_image=True)

File ~/.local/lib/python3.10/site-packages/sopa/io/reader/wsi.py:55, in wsi(path, chunks, as_image, backend)
52 images[f"scale{key}"] = scale_image
54 multiscale_image = DataTree.from_dict(images)
---> 55 sdata = SpatialData(images={image_name: multiscale_image})
56 sdata[image_name].attrs["metadata"] = slide_metadata
57 sdata[image_name].attrs["backend"] = backend

File ~/.local/lib/python3.10/site-packages/spatialdata/_utils.py:261, in _deprecation_alias..deprecation_decorator..wrapper(*args, **kwargs)
259 raise ValueError("version for deprecation must be specified")
260 rename_kwargs(f.name, kwargs, alias_copy, class_name, library, version)
--> 261 return f(*args, **kwargs)

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/spatialdata.py:142, in SpatialData.init(self, images, labels, points, shapes, tables)
140 if images is not None:
141 for k, v in images.items():
--> 142 self.images[k] = v
144 if labels is not None:
145 for k, v in labels.items():

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/_elements.py:62, in Images.setitem(self, key, value)
61 def setitem(self, key: str, value: Raster_T) -> None:
---> 62 self._check_key(key, self.keys(), self._shared_keys)
63 schema = get_model(value)
64 if schema not in (Image2DModel, Image3DModel):

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/_elements.py:44, in Elements._check_key(key, element_keys, shared_keys)
42 @staticmethod
43 def _check_key(key: str, element_keys: Iterable[str], shared_keys: set[str | None]) -> None:
---> 44 Elements._check_valid_name(key)
45 if key in element_keys:
46 warn(f"Key {key} already exists. Overwriting it in-memory.", UserWarning, stacklevel=2)

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/_elements.py:40, in Elements.check_valid_name(name)
38 raise ValueError("Name cannot be an empty string.")
39 if not all(c.isalnum() or c in "
-" for c in name):
---> 40 raise ValueError("Name must contain only alphanumeric characters, underscores, and hyphens.")

ValueError: Name must contain only alphanumeric characters, underscores, and hyphens.ValueError Traceback (most recent call last)
Cell In[21], line 2
1 # reading the H&E image
----> 2 image = sopa.io.wsi("Xenium_V1_hPancreas_Cancer_Add_on_FFPE_he_image.ome.tif", as_image=True)

File ~/.local/lib/python3.10/site-packages/sopa/io/reader/wsi.py:55, in wsi(path, chunks, as_image, backend)
52 images[f"scale{key}"] = scale_image
54 multiscale_image = DataTree.from_dict(images)
---> 55 sdata = SpatialData(images={image_name: multiscale_image})
56 sdata[image_name].attrs["metadata"] = slide_metadata
57 sdata[image_name].attrs["backend"] = backend

File ~/.local/lib/python3.10/site-packages/spatialdata/_utils.py:261, in _deprecation_alias..deprecation_decorator..wrapper(*args, **kwargs)
259 raise ValueError("version for deprecation must be specified")
260 rename_kwargs(f.name, kwargs, alias_copy, class_name, library, version)
--> 261 return f(*args, **kwargs)

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/spatialdata.py:142, in SpatialData.init(self, images, labels, points, shapes, tables)
140 if images is not None:
141 for k, v in images.items():
--> 142 self.images[k] = v
144 if labels is not None:
145 for k, v in labels.items():

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/_elements.py:62, in Images.setitem(self, key, value)
61 def setitem(self, key: str, value: Raster_T) -> None:
---> 62 self._check_key(key, self.keys(), self._shared_keys)
63 schema = get_model(value)
64 if schema not in (Image2DModel, Image3DModel):

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/_elements.py:44, in Elements._check_key(key, element_keys, shared_keys)
42 @staticmethod
43 def _check_key(key: str, element_keys: Iterable[str], shared_keys: set[str | None]) -> None:
---> 44 Elements._check_valid_name(key)
45 if key in element_keys:
46 warn(f"Key {key} already exists. Overwriting it in-memory.", UserWarning, stacklevel=2)

File ~/.local/lib/python3.10/site-packages/spatialdata/_core/_elements.py:40, in Elements.check_valid_name(name)
38 raise ValueError("Name cannot be an empty string.")
39 if not all(c.isalnum() or c in "
-" for c in name):
---> 40 raise ValueError("Name must contain only alphanumeric characters, underscores, and hyphens.")

ValueError: Name must contain only alphanumeric characters, underscores, and hyphens.

@wmueller4711
Copy link

wmueller4711 commented Oct 8, 2024 via email

@asmitaL99
Copy link
Author

were you able to solve it ?

@wmueller4711
Copy link

wmueller4711 commented Oct 9, 2024 via email

@quentinblampey
Copy link
Collaborator

Hello @asmitaL99, sorry for the delay!
Since you have Xenium data, can you try using the ome_tif reader, i.e. sopa.io.ome_tif("Xenium_V1_hPancreas_Cancer_Add_on_FFPE_he_image.ome.tif")?

Also, what would you like to do with this H&E image: align it to the other spatial elements? Or perform an analysis only on this H&E image? There are some functions to operate on all Xenium modalities directly, so let me know if you need more details!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants