ome / omero-scripts

Core OMERO Scripts
https://pypi.org/project/omero-scripts/
12 stars 32 forks source link

Avoid division by 0 in Plot Profile. #89

Closed bpindelski closed 10 years ago

bpindelski commented 10 years ago

This PR fixes the situation in which a ZeroDivisionError is thrown when the ROI line is parallel to the X axis and hence the y1 and y2 values are equal, returning 0 in the subtraction.

The error returned was:

Traceback (most recent call last):
  File "./script", line 453, in <module>
    fileAnns, message = processImages(conn, scriptParams)
  File "./script", line 382, in processImages
    processLines(conn, scriptParams, image, lines, lineWidth, f)
  File "./script", line 264, in processLines
    lineWidth, theZ, theC, theT)
  File "./script", line 93, in getLineData
    rads = math.atan(float(lineX) / lineY)
ZeroDivisionError: float division

To test - check that the values returned from the script make sense. /cc @will-moore

joshmoore commented 10 years ago

Hmmm.... I have a feeling this should ring some Python version bell, but perhaps we've already moved passed that minimum requirement. (I know it doesn't work with 2.4)

bpindelski commented 10 years ago

@joshmoore You are right, this is a Python 2.5 feature. And I still remember the lesson that using post-2.4 features taught me. Having said that, please see http://www.openmicroscopy.org/site/support/omero5/sysadmins/system-requirements.html.

sbesson commented 10 years ago

My immediate thought is is there a reason why are we sticking to math.atan(y/x) instead of math.atan2(y,x) which is correctly handling zero values for x and or y (and would prevent our code from handling this error?)

sbesson commented 10 years ago

Apart from my comment above, the fix proposed works when running Plot_Profile on horizontal single lines of various widths.

joshmoore commented 10 years ago

Next steps?

bpindelski commented 10 years ago

@joshmoore I'll leave the call to @will-moore. I've tried looking at the code of the script, but it doesn't immediately say if X/Y-parallel lines are allowed.

will-moore commented 10 years ago

The Plot Profile script now works fine on horizontal and vertical lines. The fix above should also be applied to the Kymograph script to fix the same bug there, see: http://trac.openmicroscopy.org.uk/ome/ticket/11988 Thanks!

bpindelski commented 10 years ago

@will-moore Thanks for testing. I'm happy to go with @sbesson's suggestion in this PR and use atan2, as long as it won't impact the values produced by the script.

joshmoore commented 10 years ago

Last call? Otherwise, I'll merge and we can atan2 later.

will-moore commented 10 years ago

Fine by me ;)

bpindelski commented 10 years ago

--rebased-to #90