Topp-Roots-Lab / 3d-root-crown-analysis-pipeline

A pipeline to process 3-D volumes (.raw) of maize root crowns. Also known as XRCAP.
3 stars 1 forks source link

Divide by zero during rootCrownImageAnalysis3D #27

Closed tparkerd closed 3 years ago

tparkerd commented 3 years ago

Describe the bug 20200909ZmStd_CSU19_RPFT2_84 has an error message during rootCrownImageAnalysis3D, it’s a division by zero error. The script finishes as normal and generates a CSV output file.

To Reproduce Steps to reproduce the behavior:

  1. Run raw2img with default settings
  2. Run batch-segmentation with default settings
  3. Run rootCrownImageAnalysis3D with default settings (see error)
/opt/miniconda3/envs/python3.8/lib/python3.8/site-packages/xrcap/rootCrownImageAnalysis3D.py:116: RuntimeWarning: divide by zero encountered in log2
  entropy = -sum(probs*np.log2(probs))
/opt/miniconda3/envs/python3.8/lib/python3.8/site-packages/xrcap/rootCrownImageAnalysis3D.py:116: RuntimeWarning: invalid value encountered in multiply
  entropy = -sum(probs*np.log2(probs))

Expected behavior Error to not happen.

Screenshots n/a

Desktop (please complete the following information):

tparkerd commented 3 years ago

It appears that the values sorted in the binned end up as zero so the probability is zero. https://github.com/Topp-Roots-Lab/3d-root-crown-analysis-pipeline/blob/17ef366f3eabd4991a90e55cbdf2d982a98e8cc9/xrcap/rootCrownImageAnalysis3D.py#L107-L116

The error message presents as the following.

2021-01-08 14:35:01,723 - [INFO] - rootCrownImageAnalysis3D.py 109 - array([  0,  19,  38,  58,  77,  96, 116, 135, 155, 174, 193, 213, 232,
       251, 271, 290, 310, 329, 348, 368, 387, 406, 426, 445, 465, 484,
       503, 523, 542, 561, 581, 600, 620])
2021-01-08 14:35:01,724 - [INFO] - rootCrownImageAnalysis3D.py 111 - [15.478840916118411,
 18.284023259145197,
 18.364658576782826,
 11.755102450160667,
 5.575256270922057,
 4.542993652721081,
 3.981260238065514,
 4.223577919456062,
 3.476665191187512,
 3.1170116496489597,
 2.5802591200112595,
 1.8623231777471831,
 1.6991354445344098,
 1.6443771284358353,
 1.600798067552495,
 1.4550818193741064,
 1.2994535783616488,
 1.1743105263870943,
 1.0856749438648228,
 0.9643073317408896,
 0.876031456003089,
 0.8968131342636085,
 0.9946516746984662,
 1.1098279883669877,
 1.2357945416864764,
 0.6782473284105571,
 2.046501770523841,
 2.9538365285115837,
 12.752695195477475,
 17.18457525338836,
 2.20197614216086,
 0.0]
2021-01-08 14:35:01,724 - [INFO] - rootCrownImageAnalysis3D.py 113 - array([0.10522947, 0.12429988, 0.12484806, 0.07991446, 0.03790214,
       0.03088454, 0.02706572, 0.02871306, 0.02363534, 0.02119031,
       0.01754132, 0.01266059, 0.0115512 , 0.01117893, 0.01088267,
       0.00989205, 0.00883405, 0.00798329, 0.00738072, 0.00655563,
       0.00595551, 0.00609679, 0.00676192, 0.00754492, 0.00840128,
       0.00461091, 0.01391269, 0.020081  , 0.08669637, 0.11682553,
       0.01496965, 0.        ])

There is a chance that an N/A is reported for entropy values for N, CH, S types.

tparkerd commented 3 years ago

Reassigning zero values in numpy array: https://stackoverflow.com/questions/21610198/runtimewarning-divide-by-zero-encountered-in-log