ome / omero-py

Python project containing Ice remoting code for OMERO
https://www.openmicroscopy.org/omero
GNU General Public License v2.0
20 stars 33 forks source link

roi utils zero division fix #278

Closed will-moore closed 3 years ago

will-moore commented 3 years ago

This fixes an error I saw on outreach server during today's training (see below).

To test:

Should run without an error and generate a csv file.

Traceback (most recent call last):
  File "./script", line 305, in <module>
    run_script()
  File "./script", line 293, in run_script
    file_anns, message = process_images(conn, script_params)
  File "./script", line 224, in process_images
    conn, script_params, image, polylines, line_width, f)
  File "./script", line 65, in process_polylines
    the_z, the_c, the_t)
  File "/opt/omero/server/venv3/lib64/python3.6/site-packages/omero/util/roi_handling_utils.py", line 54, in get_line_data
    rads = math.atan(old_div(float(line_x),line_y))
  File "/opt/omero/server/venv3/lib64/python3.6/site-packages/past/utils/__init__.py", line 95, in old_div
    return a / b
ZeroDivisionError: float division by zero
jburel commented 3 years ago

I drew a line on https://outreach.openmicroscopy.org/webclient/?show=image-9539 (trainer-1) but I did not get an error when running the script

will-moore commented 3 years ago

@jburel I realise that the error I got from image: https://outreach.openmicroscopy.org/webclient/?show=image-11110 was actually due to the PolyLine, since we try to calculate the Plot Profile for each section in a PolyLine, and there are horizontal lines within that PolyLine. So, you will see the error with this image.

When you try to draw a "horizontal" line in iviewer, it's almost impossible since it doesn't snap to integer pixel values. The Y coordinates of the lines you drew are shown in the iviewer as "72.0" but are actually saved as:

"Y1": 71.95605468749991,
"Y2": 72.03339843749991

I used a script to add horizontal line to that image https://outreach.openmicroscopy.org/webclient/?show=image-9539 so that you will see the error with that image now.

jburel commented 3 years ago

I managed to reproduce the error against outreach now

jburel commented 3 years ago

Could you add tests to https://github.com/ome/openmicroscopy/blob/develop/components/tools/OmeroPy/test/integration/scriptstest/test_roi_handling_utils.py?

will-moore commented 3 years ago

Tests added in https://github.com/ome/openmicroscopy/pull/6264

jburel commented 3 years ago

https://merge-ci.openmicroscopy.org/jenkins/job/OMERO-test-integration/687/ tests are green