ubarsc / python-fmask

A set of command line utilities and Python modules that implement the ‘fmask’ algorithm
https://www.pythonfmask.org
GNU General Public License v3.0
75 stars 21 forks source link

TypeError: numpy boolean subtract #16

Closed gillins closed 7 years ago

gillins commented 7 years ago

Original report by Xavier Corredor Llano (Bitbucket: XavierCLL, GitHub: XavierCLL).


Hi,

In some cases of run, the python-fmask stop with TypeError:

#!bash
fmask/fillminima.py, line 67, in fillMinima
    innerBoundary = nullmaskDilated - nullmask
TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

I checked the variables nullmaskDilated and nullmask and both are boolean matrix with True values. I don't know exactly what append and how fix that

Regards

gillins commented 7 years ago

Original comment by Sam Gillingham (Bitbucket: gillins, GitHub: gillins).


I can confirm this is a problem with numpy 1.13.x. The workaround suggested with the ^ operator seems to do as expected. Any thoughts Neil?

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hi Xavier,

Thanks for this, that looks like bad type usage from me in the original code. Sorry for that. I have just played with the ^ operator, and I agree, it seems to be what we want there. I will change this code as you suggested. Thanks, Sam, for also checking on this. It is very good to see that numpy are always improving their type checks.

Neil

gillins commented 7 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


OK, I have made that change to use '^' instead of '-', and tested on a real image and got identical results. Thanks again.

gillins commented 5 years ago

Original comment by Jiang Liang (Bitbucket: hugeneuron, GitHub: hugeneuron).


I have a question about the logical_xor operation. the result of logical_xor operation for np.logical_xor([1,1,0,0],[1,0,1,0]) is array([False, True, True, False]) but I'm expecting np.subtract([1,1,0,0],[1,0,1,0]) to give me array([False, True, False, False]) what kind of function should I use?

gillins commented 5 years ago

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Jiang,

your question does not really relate to python-fmask. I suggest that you read the numpy documentation. The main issue you have is that you should not mix arithmetic like subtraction with boolean values.