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

image_to_html always fails to find pixelSize #436

Open
Tom-TBT opened this issue Nov 27, 2024 · 2 comments · May be fixed by #441
Open

image_to_html always fails to find pixelSize #436

Tom-TBT opened this issue Nov 27, 2024 · 2 comments · May be fixed by #441

Comments

@Tom-TBT
Copy link

Tom-TBT commented Nov 27, 2024

An example of the issue from image.sc
https://forum.image.sc/t/fetch-and-save-ome-tiff-from-omero-to-local-directory-with-metadata/105507/3

It seems to me that something changed about image.getPixelSizeX() (and Y and Z)

With older versions of omero-py I was used to get this output:

object #0 (::omero::model::Length)
{
    _value = 0.16249999999999787
    _unit = MICROMETER
}

but it now only returns a float, so 0.16249999999999787 in this case.
What happens with image_to_html is that it tries to get the unit of the value from the returned pixel size. But since we get a float, it throws an error. The error is caught and the output defaults to (na, na, an)

It's still possible to get the old output by specifying the pixel units: image.getPixelSizeX(units="MICROMETER").

In the case of image_to_html, it would thus need to find the most appropriate unit to express the pixel size with as few 0s as possible.

I had a look with git blame to https://github.com/ome/omero-py/blame/master/src/omero/gateway/__init__.py#L9997 and https://github.com/ome/omero-py/blame/master/src/omero/gateway/__init__.py#L292 but everything is 10yo.
I don't know what happened in between.

@jo-mueller

@sbesson
Copy link
Member

sbesson commented Dec 19, 2024

@Tom-TBT I tried to reproduce the issue using the following example code:

from omero.gateway import BlitzGateway

with BlitzGateway(
        host='localhost', username=<username>, passwd=<password>) as conn:
    conn.connect()
    conn.SERVICE_OPTS['omero.group']='-1'

    i=conn.getObject('Image',185001)
    print(i.getPixelSizeX())
    print(i.getPixelSizeX(units="MICROMETER"))

All OMERO.py versions between 5.13.0 and 5.19.5 produced the following output:

0.5933762649494021
0.5933762649494021 MICROMETER

Older versions failed to connect due to SSL issues.

Matching your code history review, it looks like this has been the behavior of the API for the last decade. Do you have more specifics on which version of OMERO.py would have been returning the Length object by default? Or is the issue not about the getPixelSize API but rather the image_to_html?

@Tom-TBT
Copy link
Author

Tom-TBT commented Dec 19, 2024

Hi @sbesson, thank you for the thorough testing.

It seems to me that something changed about image.getPixelSizeX() (and Y and Z)

I was wrong, nothing changed then. As you say it's just about image_to_html

I checked in the history of commit in the PR and the last commit introduced the error, that was not shown in the screenshots above.
The commit b0a7fad replaced
{image.getPixelSizeX(units=True).getUnit()}
with
UnitX = image.getPixelSizeX().getUnit()

thus getting a float instead of the expected omero.model.LengthI.

Adding back units=True gave me the expected output:

image

@jo-mueller could you add that to your current fixing PR?
I can open another PR myself, sorry. This is different enough from that PR
#429

def image_to_html(image):
    import base64

    try:
        pixsizeX = '{:.3f}'.format(image.getPixelSizeX())
        pixsizeY = '{:.3f}'.format(image.getPixelSizeY())
        pixsizeZ = '{:.3f}'.format(image.getPixelSizeZ())
        UnitX = image.getPixelSizeX(units=True).getUnit()
        UnitY = image.getPixelSizeY(units=True).getUnit()
        UnitZ = image.getPixelSizeZ(units=True).getUnit()
    except:
        pixsizeX, pixsizeY, pixsizeZ = 'na', 'na', 'na'
        UnitX, UnitY, UnitZ = 'na', 'na', 'na'

@Tom-TBT Tom-TBT linked a pull request Dec 19, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants