ClearAnatomics / ClearMap

ClearMap 2 with WobblyStitcher, TubeMap and CellMap
https://clearanatomics.github.io/ClearMapDocumentation/
GNU General Public License v3.0
111 stars 46 forks source link

Problem with measure_expression() #59

Open PTRRupprecht opened 3 years ago

PTRRupprecht commented 3 years ago

There seems to be a problem when using the function measure_expression() in the graph analysis part of the Tubemap.py script:

expression = me.measure_expression(artery_raw, coordinates, radii_measure, 
                                     method='max', verbose=True);

The function actually works properly when applied to the binary file (few lines above that), but it does not work when applied to the raw data. The error message is the following:

File "ClearMap/ParallelProcessing/DataProcessing/MeasurePointListCode.pyx", line 138, in ClearMap.ParallelProcessing.DataProcessing.MeasurePointListCode.__pyx_fused_cpdef
    cpdef void measure_mean(source_t[:] source, index_t[:] shape, index_t[:] strides, point_t[:,:] points, index_t[:,:] search, index_t[:] max_search, value_t[:] sink, int processes) nogil:
TypeError: Function call with ambiguous argument types

There might be an error in the MeasurePointListCode file, maybe related to some data type-specific issue. Do you also see this on your system, @ChristophKirst ?

Best, Peter

ChristophKirst commented 3 years ago

Thanks for pointing this out, I have not tested this further, and sorry for the late reply. Its hard to keep up with debugging here while setting up a research lab.

the allowed file types are:

ctypedef fused source_t: np.int32_t np.int64_t np.uint8_t np.uint16_t np.uint32_t np.uint64_t np.float32_t np.float64_t

according to here: https://github.com/ChristophKirst/ClearMap2/blob/e09f44943064f4b10f55510f8c7b385c26b84566/ClearMap/ParallelProcessing/DataProcessing/MeasurePointListCode.pyx

What are the file types of the data sets you pass into the function (also for the results) ?

PTRRupprecht commented 3 years ago

Thanks for coming back to this. I'm right now not working on this part of the code, but I will do so in a couple of weeks. I will let you know whether I can solve this using your pointer about the file types.

And good luck with setting up your lab!

PTRRupprecht commented 1 year ago

I have finally come back to this piece of code, and unfortunately the bug is still there. I've checked your suggestions, and the data types I used should be allowed according to the *.pyx file. So this does not seem to be the issue.

I can also reproduce the error with this minimal code example, maybe you can use it to quickly identify the problem:

  from ClearMap.Environment import *       

  import numpy as np
  import ClearMap.ParallelProcessing.DataProcessing.MeasurePointList as mpl
  import ClearMap.Analysis.Measurements.MeasureExpression as me

  from importlib import reload
  reload(mpl);
  reload(mpl.code);

  # Generate random values
  source = np.random.randint(0,255,(200,200,200)).astype(np.uint16)
  # Generate random coordinates
  points = np.random.randint(0,200,(6,3))
  # Generate random search radii
  search_radius = np.random.randint(3,9,(6,3))

  ndim = 3
  indices, radii_indices = me.search_indices(search_radius, ndim);

  # The following step does not work
  mpl.measure_mean(source, points, radii_indices, search_radius)

I tried out different data types for source but with no improvement. Interestingly, when I used a non-allowed data type for source, .astype(np.bool_), I got a different error message: TypeError: No matching signature found.

Do you have an idea where the original error could come from? I would really like to use the measure-functions from ClearMap, but they are not so helpful when they cannot be applied to raw data. Any help would be greatly appreciated!

PTRRupprecht commented 1 year ago

Hi @ChristophKirst, I think I found the problem. The problem is located very likely in MeasurePointList.py. The function measure_mean() shows a couple of differences compared to e.g. measure_max() when processing the inputs to the cython function code.measure_mean(). Adapting changes here fixed the problem for me. My guess is that you made some changes to the code and checked the changes only for the measure_max function, so the backwards incompatibility with the other measure functions remained undetected.