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

Handle image loading errors #532

Merged
merged 3 commits into from
Dec 14, 2023

Conversation

will-moore
Copy link
Member

See https://forum.image.sc/t/misleading-error-message-in-omero-figure/68642

Also fixes #347.

This aims to improve the handling of errors when adding Images to Figures.
We try to avoid the errors reported on that issue, so that Images can load OK with missing pixel size info.
Also, if there is any Exception message coming from https://github.com/ome/omero-web/blob/604d5279c96909a6862e4b1fc67de4f0a8699298/omeroweb/webgateway/marshal.py#L178 then we display it and don't try to add the Image to the figure.

To test:
One way to trigger one of the exception on #347 is to use the script below to unset pixelsize-Y. They should now be added to OMERO.figure OK (no error).

Invalid images (failed imports etc) should now give an appropriate error and NOT be added to the figure, but I don't know an easy way to generate such images?

import argparse
import sys

import omero
import omero.clients
from omero.model.enums import UnitsLength
from omero.cli import cli_login
from omero.gateway import BlitzGateway

def set_pixels_size(conn, image):

    pixelSize = omero.model.LengthI(5, UnitsLength.MICROMETER)
    pixels = image.getPrimaryPixels()._obj
    pixels.setPhysicalSizeX(pixelSize)
    pixels.setPhysicalSizeY(None)
    pixels.setPhysicalSizeZ(pixelSize)
    conn.getUpdateService().saveObject(pixels)

def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('image', help='Image ID')
    args = parser.parse_args(argv)

    with cli_login() as cli:
        conn = BlitzGateway(client_obj=cli._client)
        image = conn.getObject("Image", args.image)
        set_pixels_size(conn, image)

if __name__ == '__main__':  
    main(sys.argv[1:])

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/misleading-error-message-in-omero-figure/68642/7

rv['pixel_size']['valueX'] = px.getValue()
rv['pixel_size']['symbolX'] = px.getSymbol()
rv['pixel_size']['unitX'] = str(px.getUnit())
if px is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, I would have assumed in the JS code that valueX, valueY, symbolX, symbolY, unitX and unitY are always defined.

Does OMERO.figure still works fine when either or both X and Y aren't defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's quite possible if you import a jpg or regular tiff file etc that OMERO won't have any pixel sizes set. In this case OMERO.figure lets you enter a value (so you can still create a scalebar)

@will-moore will-moore added this to the 6.1.0 milestone Dec 1, 2023
@pwalczysko
Copy link
Member

Works fine with https://merge-ci.openmicroscopy.org/web/webclient/?show=image-4617 user-3 (with this PR) - this image has no physical sizeY set.
An image with no physical sizeY set on outreach server (without this PR) causes error in OMERO.figure, see below.

Screenshot 2023-12-13 at 17 46 22

lgtm

@will-moore will-moore merged commit e9b01f7 into ome:master Dec 14, 2023
1 check passed
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 this pull request may close these issues.

KeyError: 'pixel_size' on /figure/imgData/ID/
4 participants