Dividing areas: "cannot convert float NaN to integer"

Hi,

I am using a simple CellProfiler pipeline to compute the ratio between the area of the nucleus to the total cell area. To do this, I identify primary objects (nuclei), expand them by 40 pixels to determine secondary objects (cells), MeasureObjectSizeShape and compute the ratio [nucleus area]/[cell area] in a CalculateMath module. However, when CellProfiler tries to compute the ratio, I get the error message below (even though areas are positive numbers).
I would appreciate any suggestion on what is causing the problem. The pipeline is attached to this post, as well as sample images.

=====================================================================
Encountered error while processing. Do you want to stop processing?
Error:
Error while processing CalculateMath:
cannot convert float NaN to integer

Do you want to stop processing?
Traceback (most recent call last):
File “cellprofiler\gui\pipelinecontroller.pyc”, line 932, in do_step
File “cellprofiler\modules\calculatemath.pyc”, line 304, in run
ValueError: cannot convert float NaN to integer

Many thanks,
Hugo






test.cp (8.78 KB)

I have fixed this problem with Hugo. It appears this is already fixed in later versions on github.

I had to change the following lines around line 304 in calculatemath.py

elif self.operation == O_DIVIDE:
if np.isscalar(values[1]):
if values[1] == 0:
if np.isscalar(values[0]):
result = np.NaN
else:
result = np.array([np.NaN] * len(values[0]))
else:
result = values[0] / values[1]
else:
result = values[0].astype(‘float’) / values[1].astype(‘float’)
#result = values[0] / values[1]
result[values[1] == 0] = np.NaN
else:

This is not a complete fix as the problem likely persists for scalar values.

Hi,

Would you mind posting the images that go along with the test pipeline? I’d like to confirm that whether this issue is indeed fixed for scalars in our current code.

Regards,
-Mark

Hi Mark,

I just uploaded some sample images in the original post.
Could you please let us know if this issue is expected to be fixed in the next version of CP?

Thanks!
Hugo

Hi Hugo,

I gave this pipeline and images a test run on our developer code, and CalculateMath does not give an error in this case. So, yes, it has been fixed for the next release.

If you’d like to work with a pre-release version that has this fix, you can try one of our “Trunk Builds” here and download a ‘bleeding-edge’ version of CellProfiler. There are lots of caveats in the text on this page, so please read them if you take this path!

Regards,
-Mark

Thanks Mark. Your feedback is greatly appreciated.
Cheers,
Hugo

Hi Hugo,
Have you tried this with the new 2.1 release? It should resolve the error.
-Mark

Hi Mark,
Yes, this is now solved in 2.1. Thank you!
It took me some extra days to test this because my previous *.cp pipeline wasn’t properly converted to *.cpproj…
Cheers,
Hugo