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

Fail to read ome_metadata from certain czi files #22

Open
manerotoni opened this issue Dec 4, 2024 · 1 comment
Open

Fail to read ome_metadata from certain czi files #22

manerotoni opened this issue Dec 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@manerotoni
Copy link

Describe the Bug

Data recorded with a Zeiss LSM880 ZEN black Airyscan detector
Data Airy Processed with ZEN blue 3.8.89. It is a multiposition TZYX.

Attached is the metadata as extracted with Bioformats imageJ

Original Metadata - TCZYX_live_3scenes.zip

The error is also mentioned in https://forum.image.sc/t/extract-elapsed-time-timestamp-from-czi-metadata/84700/10

When performing

img = bioio.BioImage(fpath)
img.ome_metadata

I get the following error from ome_metadata and at a certain point it seems that bioio-czi.utils.transform_metadata_with_xslt unable to parse. Ideally it should just try and pass.

C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\converter.py:108: ConverterWarning: Failed to convert value `` to one of (<class 'float'>,)
  warnings.warn(
C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\pydantic\main.py:212: UserWarning: Casting invalid LightSourceID 'MTBLKM980LaserLine488' to 'LightSource:0'
  validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
Traceback (most recent call last):
  File "D:\Code\chunkformat\test\test_util.py", line 28, in <module>
    img.ome_metadata
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\bioio\bio_image.py", line 943, in ome_metadata
    return self.reader.ome_metadata
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\bioio_czi\reader.py", line 912, in ome_metadata
    return metadata_utils.transform_metadata_with_xslt(
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\bioio_czi\utils.py", line 144, in transform_metadata_with_xslt
    ome = OME.from_xml(str(ome_etree))
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\ome_types\_mixins\_base_type.py", line 192, in from_xml
    return cast(T, from_xml(xml, **kwargs))
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\ome_types\_conversion.py", line 132, in from_xml
    return parser.parse(xml_2016, OME_type)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\dataclass\parsers\bases.py", line 56, in parse
    result = handler.parse(source)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\dataclass\parsers\handlers\lxml.py", line 40, in parse
    return self.process_context(ctx)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\dataclass\parsers\handlers\lxml.py", line 62, in process_context
    self.parser.end(
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\dataclass\parsers\bases.py", line 151, in end
    return item.bind(qname, text, tail, objects)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\dataclass\parsers\nodes\element.py", line 105, in bind
    obj = self.config.class_factory(self.meta.clazz, params)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\xsdata\formats\dataclass\parsers\config.py", line 19, in default_class_factory
    return cls(**params)  # type: ignore
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\ome_types\_mixins\_kinded.py", line 20, in __init__
    return super().__init__(**data)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\ome_types\_mixins\_base_type.py", line 104, in __init__
    super().__init__(**data)
  File "C:\Users\apoliti\Miniconda3\envs\chunk_format_kosti\lib\site-packages\pydantic\main.py", line 212, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Laser
wavelength
  Input should be a valid number, unable to parse string as a number [type=float_parsing, input_value='', input_type=str]
    For further information visit https://errors.pydantic.dev/2.9/v/float_parsing

Expected Behavior

No error

Reproduction

The data set is too big. I have to generate a smaller set. I do not see the behavior with all files. It seems something specific with the data set acquired on a particular machine and processed with a particular software.

Environment

  • OS Version: windows 1-
  • bioio-czi Version: 1.0.1
@manerotoni manerotoni added the bug Something isn't working label Dec 4, 2024
@BrianWhitneyAI
Copy link
Contributor

@manerotoni Thank you for submitting this! If I am understanding your issue correctly you want to try to access .ome_metadata for your czi, bioio-czi fails to interpret this metadata and raises an error.

This is a little confusing but for our czi plugin .ome_metadata is just a transformation of the existing .metadata field using the xslt file.

    @property
    def ome_metadata(self) -> OME:
        return metadata_utils.transform_metadata_with_xslt(
            self.metadata,
            Path(__file__).parent / "czi-to-ome-xslt/xslt/czi-to-ome.xsl",
        )

so if you wanted the unprocessed metadata you can just access .metadata . Otherwise I think raising an error here makes sense as we could not get to a OME metadata output. Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants