Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
On Fri, Oct 23, 2015 at 12:20 AM, G. Allegriwrote: > Thanks for the clear explanation Glynn. Maybe this behaviour could be > esplicited inside the docs... Yes. I'm happy to add a summary of this discussion to the manual if someone sends it to me. thanks Markus ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
Ah ok Glynn, I always meant logical operators. Probably I copied the error from a different test. If logical operator is applied to, sat, Byte data it gives true/false results, e.g. if(A && B,1, 0) behaves correctly even with cell values values greater then 1. That's why I expected it to work with floats operands too. >From a user perspective if it works for a cell with value 2 it should also work for a cell with value 2.0. That'all. giovanni Il 22/ott/2015 02:44, "Glynn Clements"ha scritto: > > G. Allegri wrote: > > > > This isn't about the if() function. The bitand() function (to which > > > the error message refers) corresponds to the bitwise-and operator "&". > > > > > > The if() function accepts either integer or floating-point values for > > > its arguments. > > > > That's what disappointed my client (and me) Glynn: why integer yes and > not > > floats? Is it a technical limitation or there's a ratio behind it? > > Anyway did I miss something from the docs? I couldn't find it. > > What would you expect the value of (x & y) to be if x and/or y were > floating-point values? > > > Why do you that I'm confusing the operators? I've always talked about > > logical operators... > > Because you quote an error message which specifically refers to a > *bitwise* operator: > > > "Incorrect argument types to function bitand()". > > in a message which otherwise only mentions logical operators. > > "bitand()" is the name of the bitwise-and function, which corresponds to > the infix "&" operator. I.e. (x & y) is exactly equivalent to bitand(x, y). > > This is the same as the "&" operator in C or C++: it evaluates to an > integer where each bit in the result is set (one) if the corresponding > bit is set in both operands, and unset (zero) otherwise. E.g. (23 & 34) > is > 00010111 (23) > & 00100010 (34) > > = 0010 ( 2) > > Perhaps it would help if you posted the exact expression which is > causing you problems. > > -- > Glynn Clements > ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
G. Allegri wrote: > If logical operator is applied to, sat, Byte data it gives true/false > results, e.g. if(A && B,1, 0) behaves correctly even with cell values > values greater then 1. > That's why I expected it to work with floats operands too. > >From a user perspective if it works for a cell with value 2 it should also > work for a cell with value 2.0. > That'all. r.mapcalc's interpretation of booleans is borrowed from C. Booleans are just integers where zero is false and non-zero is true. But that doesn't necessarily make much sense for floats; the conventional wisdom is that comparing a float for equality with zero is usually a mistake, as results which should mathematically be equal to zero often aren't actually equal to zero due to intermediate rounding errors. In some cases, simply subtracting a number from itself won't yield zero (e.g. due to the x87 FPU using 80 bits for floating-point registers while values stored in memory use 32 or 64 bits). You can obtain C-like behaviour by converting to an integer with the int() function then using that; the result is that any value between -1.0 and 1.0 (excluding both endpoints) will be considered false while anything else is true. Or you can convert to an integer with the round() function and use that, in which case any value between -0.5 and 0.5 (including both endpoints) will be false while anything else is true. Or you can compare for equality with 0.0, in which case -0.0 and 0.0 will be false while anything else is true. Or you can compare the magnitude (obtained using abs()) to an "epsilon" value so that anything smaller than the expsilon is false while anything larger is true. That's four different possibilities, none of which is any more "correct" than any of the others. Choosing one of them would just mean that r.mapcalc was probably using the "wrong" one, and doing so silently. The current behaviour forces the user to be explicit. -- Glynn Clements___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
Thanks for the clear explanation Glynn. Maybe this behaviour could be esplicited inside the docs... giovanni Il 22/ott/2015 23:35, "Glynn Clements"ha scritto: > > G. Allegri wrote: > > > If logical operator is applied to, sat, Byte data it gives true/false > > results, e.g. if(A && B,1, 0) behaves correctly even with cell values > > values greater then 1. > > That's why I expected it to work with floats operands too. > > >From a user perspective if it works for a cell with value 2 it should > also > > work for a cell with value 2.0. > > That'all. > > r.mapcalc's interpretation of booleans is borrowed from C. Booleans > are just integers where zero is false and non-zero is true. > > But that doesn't necessarily make much sense for floats; the > conventional wisdom is that comparing a float for equality with zero > is usually a mistake, as results which should mathematically be equal > to zero often aren't actually equal to zero due to intermediate > rounding errors. In some cases, simply subtracting a number from > itself won't yield zero (e.g. due to the x87 FPU using 80 bits for > floating-point registers while values stored in memory use 32 or 64 > bits). > > You can obtain C-like behaviour by converting to an integer with the > int() function then using that; the result is that any value between > -1.0 and 1.0 (excluding both endpoints) will be considered false while > anything else is true. Or you can convert to an integer with the > round() function and use that, in which case any value between -0.5 > and 0.5 (including both endpoints) will be false while anything else > is true. Or you can compare for equality with 0.0, in which case -0.0 > and 0.0 will be false while anything else is true. Or you can compare > the magnitude (obtained using abs()) to an "epsilon" value so that > anything smaller than the expsilon is false while anything larger is > true. > > That's four different possibilities, none of which is any more > "correct" than any of the others. Choosing one of them would just mean > that r.mapcalc was probably using the "wrong" one, and doing so > silently. The current behaviour forces the user to be explicit. > > -- > Glynn Clements > ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
G. Allegri wrote: > > This isn't about the if() function. The bitand() function (to which > > the error message refers) corresponds to the bitwise-and operator "&". > > > > The if() function accepts either integer or floating-point values for > > its arguments. > > That's what disappointed my client (and me) Glynn: why integer yes and not > floats? Is it a technical limitation or there's a ratio behind it? > Anyway did I miss something from the docs? I couldn't find it. What would you expect the value of (x & y) to be if x and/or y were floating-point values? > Why do you that I'm confusing the operators? I've always talked about > logical operators... Because you quote an error message which specifically refers to a *bitwise* operator: > "Incorrect argument types to function bitand()". in a message which otherwise only mentions logical operators. "bitand()" is the name of the bitwise-and function, which corresponds to the infix "&" operator. I.e. (x & y) is exactly equivalent to bitand(x, y). This is the same as the "&" operator in C or C++: it evaluates to an integer where each bit in the result is set (one) if the corresponding bit is set in both operands, and unset (zero) otherwise. E.g. (23 & 34) is 00010111 (23) & 00100010 (34) = 0010 ( 2) Perhaps it would help if you posted the exact expression which is causing you problems. -- Glynn Clements___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
Moritz Lennert wrote: > >> Doing a logical operation with a DCELL raster within an if(x,a) statement > >> produces an error: "Incorrect argument types to function bitand()". > > > > First, you're confusing bitwise operators and logical operators. & and > > | are bitwise operators, while && and || (and &&& and |||) are logical > > operators. > > > > Second, both bitwise and logical operators only work on integer > > values. If you want to use floating-point values as boolean values, > > you need to explicitly convert them to integers (either via int(x) or > > round(x), or x==0.0, or abs(x)<1e-30, or whatever). > > ??? > > On my grass71 and grass64release, these work (using NC demo data set): > > r.mapcalc "test = if(elevation == 100.0, 1)" > r.mapcalc "test = if(elevation > 100.0, 1)" > > where elevation is FCELL. I would expect those to work. What won't work is using bitwise operators (& and |) or logical operators (&& and ||, &&& and |||) on floats. -- Glynn Clements___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
On 20/10/15 09:44, Moritz Lennert wrote: On 19/10/15 21:16, Glynn Clements wrote: G. Allegri wrote: Doing a logical operation with a DCELL raster within an if(x,a) statement produces an error: "Incorrect argument types to function bitand()". First, you're confusing bitwise operators and logical operators. & and | are bitwise operators, while && and || (and &&& and |||) are logical operators. Second, both bitwise and logical operators only work on integer values. If you want to use floating-point values as boolean values, you need to explicitly convert them to integers (either via int(x) or round(x), or x==0.0, or abs(x)<1e-30, or whatever). ??? On my grass71 and grass64release, these work (using NC demo data set): r.mapcalc "test = if(elevation == 100.0, 1)" r.mapcalc "test = if(elevation > 100.0, 1)" where elevation is FCELL. Sorry, forget that. I missed the "logical" part... Moritz ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
On 19/10/15 21:16, Glynn Clements wrote: G. Allegri wrote: Doing a logical operation with a DCELL raster within an if(x,a) statement produces an error: "Incorrect argument types to function bitand()". First, you're confusing bitwise operators and logical operators. & and | are bitwise operators, while && and || (and &&& and |||) are logical operators. Second, both bitwise and logical operators only work on integer values. If you want to use floating-point values as boolean values, you need to explicitly convert them to integers (either via int(x) or round(x), or x==0.0, or abs(x)<1e-30, or whatever). ??? On my grass71 and grass64release, these work (using NC demo data set): r.mapcalc "test = if(elevation == 100.0, 1)" r.mapcalc "test = if(elevation > 100.0, 1)" where elevation is FCELL. Moritz ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
On Mon, Oct 19, 2015 at 5:18 PM, G. Allegriwrote: > Doing a logical operation with a DCELL raster within an if(x,a) statement > produces an error: "Incorrect argument types to function bitand()". > This doesn't seem to be described inside the docs, is it? > That sounds like a bug to me. I just tried it out and it runs fine (using GRASS 7.1). What GRASS version are you using? > > When the if() function is described it only states its behaviour in case > of NULL, 0 or "otherwise" values. > It works correctly if the maps are CELL (i.e. e value not eqaul 0 is > treated correctly whatever it is) and it's quite confusing for users having > a different behaviour, and sepcifically an error, in case of floating point > rasters, don't you think? > > Regards, > giovanni > > -- > Giovanni Allegri > http://about.me/giovanniallegri > Gis3W - http://gis3w.it > Ikare - http://ikare.it > Twitter: https://twitter.com/_giohappy_ > blog: http://blog.spaziogis.it > GEO+ geomatica in Italia http://bit.ly/GEOplus > > ___ > grass-user mailing list > grass-user@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/grass-user > ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
GRASS 6.4.4 on Windows. giovanni Il 19/ott/2015 17:52, "Paulo van Breugel"ha scritto: > > > On Mon, Oct 19, 2015 at 5:18 PM, G. Allegri wrote: > >> Doing a logical operation with a DCELL raster within an if(x,a) statement >> produces an error: "Incorrect argument types to function bitand()". >> This doesn't seem to be described inside the docs, is it? >> > > That sounds like a bug to me. I just tried it out and it runs fine (using > GRASS 7.1). What GRASS version are you using? > > >> >> When the if() function is described it only states its behaviour in case >> of NULL, 0 or "otherwise" values. >> It works correctly if the maps are CELL (i.e. e value not eqaul 0 is >> treated correctly whatever it is) and it's quite confusing for users having >> a different behaviour, and sepcifically an error, in case of floating point >> rasters, don't you think? >> >> Regards, >> giovanni >> >> -- >> Giovanni Allegri >> http://about.me/giovanniallegri >> Gis3W - http://gis3w.it >> Ikare - http://ikare.it >> Twitter: https://twitter.com/_giohappy_ >> blog: http://blog.spaziogis.it >> GEO+ geomatica in Italia http://bit.ly/GEOplus >> >> ___ >> grass-user mailing list >> grass-user@lists.osgeo.org >> http://lists.osgeo.org/mailman/listinfo/grass-user >> > > ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
That's what disappointed my client (and me) Glynn: why integer yes and not floats? Is it a technical limitation or there's a ratio behind it? Anyway did I miss something from the docs? I couldn't find it. Why do you that I'm confusing the operators? I've always talked about logical operators... giovanni Il 19/ott/2015 21:19, "Glynn Clements"ha scritto: > > > G. Allegri wrote: > > > Doing a logical operation with a DCELL raster within an if(x,a) statement > > produces an error: "Incorrect argument types to function bitand()". > > First, you're confusing bitwise operators and logical operators. & and > | are bitwise operators, while && and || (and &&& and |||) are logical > operators. > > Second, both bitwise and logical operators only work on integer > values. If you want to use floating-point values as boolean values, > you need to explicitly convert them to integers (either via int(x) or > round(x), or x==0.0, or abs(x)<1e-30, or whatever). > > > This doesn't seem to be described inside the docs, is it? > > > > When the if() function is described it only states its behaviour in case of > > NULL, 0 or "otherwise" values. > > This isn't about the if() function. The bitand() function (to which > the error message refers) corresponds to the bitwise-and operator "&". > > The if() function accepts either integer or floating-point values for > its arguments. > > -- > Glynn Clements ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] map algebra logical operators on DCELL rasters not admitted? maybe docs should outline it
G. Allegri wrote: > Doing a logical operation with a DCELL raster within an if(x,a) statement > produces an error: "Incorrect argument types to function bitand()". First, you're confusing bitwise operators and logical operators. & and | are bitwise operators, while && and || (and &&& and |||) are logical operators. Second, both bitwise and logical operators only work on integer values. If you want to use floating-point values as boolean values, you need to explicitly convert them to integers (either via int(x) or round(x), or x==0.0, or abs(x)<1e-30, or whatever). > This doesn't seem to be described inside the docs, is it? > > When the if() function is described it only states its behaviour in case of > NULL, 0 or "otherwise" values. This isn't about the if() function. The bitand() function (to which the error message refers) corresponds to the bitwise-and operator "&". The if() function accepts either integer or floating-point values for its arguments. -- Glynn Clements___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user