Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Markus Metz
A note about the usage of GRASS_EPSILON = 1.0e-15:

The range of single precision floating point is about 1.4012984643e−45 to
3.4028234664e38
That means for large numbers, using GRASS_EPSILON will also detect floating
point precision limits, not only meaningful differences. For small numbers,
GRASS_EPSILON will not detect meaningful differences. GRASS_EPSILON could
instead be modified with something like "max(abs(map_A), abs(map_B)) *
1.0e-15" to test for meaningful differences.

Markus M


On Sun, Jan 24, 2021 at 5:32 PM Markus Metz 
wrote:
>
>
>
> On Sun, Jan 24, 2021 at 5:06 PM ming han  wrote:
> >
> > Hi Everyone
> >
> >Many thanks for your help. Is if(fabs(map_A - map_B) <= 1.0e-15, ...
) approach may increase the runtime compare to '==' way?
>
> The formulas are very simple, I don't think that differences in runtime
can be reliably measured. (De-)compression of the data and the operating
system's file cache have a much stronger influence on the runtime.
>
> Markus M
> >
> > Thanks
> > Ming
> >
> > Markus Metz  于2021年1月24日周日 上午10:57写道:
> >>
> >> Trying to answer the original question: with a DCELL map
"cat1_acc_riv" and a FCELL map "cat1_minacc", why is "float(cat1_acc_riv)
== float(cat1_minacc)" not equal to "int(cat1_acc_riv) == int(cat1_minacc)"
?
> >>
> >> int truncates to integer while float converts to single precision
floating point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = 1.9,
"float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == 1.9" whereas
"int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 == 1", thus the results
are different.
> >>
> >> Another reason for possible differences is that float can only
represent max 7 decimal digits. E.g. float(194320567) becomes 194320560 but
int(194320567) preserves the value 194320567.
> >>
> >> Thus the safest is to cast everything to the type with the highest
precision. In this case with FCELL and DCELL, use "double(cat1_acc_riv) ==
double(cat1_minacc)" or even better the suggestion of Markus N.
> >>
> >> Markus M
> >>
> >>
> >> On Sun, Jan 24, 2021 at 3:51 PM ming han  wrote:
> >> >
> >> > Hi Markus and Micha
> >> >
> >> >  I am just trying to find grids have the same values in these
two rasters, I will try the threshold approach.
> >> >
> >> > Thanks
> >> > Ming
> >> >
> >> > Markus Neteler  于2021年1月24日周日 上午6:58写道:
> >> >>
> >> >> Hi Ming,
> >> >>
> >> >> On Sun, Jan 24, 2021 at 10:49 AM ming han 
wrote:
> >> >> >
> >> >> > Hi Micha
> >> >> >
> >> >> >  Many thanks for your reply.
> >> >> >  Here is the command I am using:
> >> >> >
> >> >> >  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
> >> >> >
> >> >> >   The str_r is a CELL raster. the result is different when I
change it to:
> >> >> >if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
> >> >>
> >> >> Note that numerical "equality" is better tested with a threshold
test
> >> >> against the map pixel difference.
> >> >> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
> >> >>
> >> >> Hence the test needs to be implemented in a different way, i.e. by
> >> >> using an epsilon.
> >> >> Essentially something like this:
> >> >>
> >> >> if(fabs(map_A - map_B) <= 1.0e-15, ... )
> >> >>
> >> >> In your case (untested):
> >> >> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r ,
null())
> >> >>
> >> >> See related discussions here: [1], [2] and elsewhere.
> >> >>
> >> >> [1] Comment by Glynn:
https://trac.osgeo.org/grass/ticket/2854#comment:9
> >> >> [2] Comment by Glynn:
> >> >>
https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html
> >> >>
> >> >> Best,
> >> >> Markus
> >> >
> >> > ___
> >> > grass-dev mailing list
> >> > grass-dev@lists.osgeo.org
> >> > https://lists.osgeo.org/mailman/listinfo/grass-dev
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Zoltan
No inconvenience - general list etiquette usually says start with 'user' 
and then move to 'dev' if it looks like a SW issue.

But I am NOT lecturing you, so please do not take offense.

Keep well,
Zoltan

On 2021-01-24 18:28, ming han wrote:
sorry for the inconvenience. I was just not sure if it is problem that 
needs developers to answer.

Best regards
Ming

Zoltan mailto:zolt...@geograph.co.za>> 
于2021年1月24日周日 上午11:13写道:


Hi,
Is it important to cross-post this discussion on both dev and user
lists?

Regards,
Zoltan


On 2021-01-24 17:56, Markus Metz wrote:

Trying to answer the original question: with a DCELL map
"cat1_acc_riv" and a FCELL map "cat1_minacc", why is
"float(cat1_acc_riv) == float(cat1_minacc)" not equal to
"int(cat1_acc_riv) == int(cat1_minacc)" ?

int truncates to integer while float converts to single precision
floating point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc =
1.9, "float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 ==
1.9" whereas "int(cat1_acc_riv) == int(cat1_minacc)" becomes "1
== 1", thus the results are different.

Another reason for possible differences is that float can only
represent max 7 decimal digits. E.g. float(194320567) becomes
194320560 but int(194320567) preserves the value 194320567.

Thus the safest is to cast everything to the type with the
highest precision. In this case with FCELL and DCELL, use
"double(cat1_acc_riv) == double(cat1_minacc)" or even better the
suggestion of Markus N.

Markus M


On Sun, Jan 24, 2021 at 3:51 PM ming han mailto:dustm...@gmail.com>> wrote:
>
> Hi Markus and Micha
>
>      I am just trying to find grids have the same values in
these two rasters, I will try the threshold approach.
>
> Thanks
> Ming
>
> Markus Neteler mailto:nete...@osgeo.org>>
于2021年1月24日周日 上午6:58写道:
>>
>> Hi Ming,
>>
>> On Sun, Jan 24, 2021 at 10:49 AM ming han mailto:dustm...@gmail.com>> wrote:
>> >
>> > Hi Micha
>> >
>> >      Many thanks for your reply.
>> >      Here is the command I am using:
>> >
>> >      if(float(cat1_acc_riv) == float(cat1_minacc), str_r,
null())
>> >
>> >       The str_r is a CELL raster. the result is different
when I change it to:
>> >        if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
>>
>> Note that numerical "equality" is better tested with a
threshold test
>> against the map pixel difference.
>> As the threshold, we use GRASS_EPSILON which is defined as
1.0e-15.
>>
>> Hence the test needs to be implemented in a different way, i.e. by
>> using an epsilon.
>> Essentially something like this:
>>
>> if(fabs(map_A - map_B) <= 1.0e-15, ... )
>>
>> In your case (untested):
>> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15,
str_r , null())
>>
>> See related discussions here: [1], [2] and elsewhere.
>>
>> [1] Comment by Glynn:
https://trac.osgeo.org/grass/ticket/2854#comment:9

>> [2] Comment by Glynn:
>>
https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html

>>
>> Best,
>> Markus
>
> ___
> grass-dev mailing list
> grass-dev@lists.osgeo.org 
> https://lists.osgeo.org/mailman/listinfo/grass-dev


___
grass-dev mailing list
grass-dev@lists.osgeo.org  
https://lists.osgeo.org/mailman/listinfo/grass-dev  



-- 


=
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

Cape Town, South Africa.

Mobile: +27-83-6004028
www.geograph.co.za  
=

___
grass-dev mailing list
grass-dev@lists.osgeo.org 
https://lists.osgeo.org/mailman/listinfo/grass-dev




--

=
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

Cape Town, South Africa.

Mobile: +27-83-6004028
www.geograph.co.za
=

___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Markus Metz
On Sun, Jan 24, 2021 at 5:06 PM ming han  wrote:
>
> Hi Everyone
>
>Many thanks for your help. Is if(fabs(map_A - map_B) <= 1.0e-15, ... )
approach may increase the runtime compare to '==' way?

The formulas are very simple, I don't think that differences in runtime can
be reliably measured. (De-)compression of the data and the operating
system's file cache have a much stronger influence on the runtime.

Markus M
>
> Thanks
> Ming
>
> Markus Metz  于2021年1月24日周日 上午10:57写道:
>>
>> Trying to answer the original question: with a DCELL map "cat1_acc_riv"
and a FCELL map "cat1_minacc", why is "float(cat1_acc_riv) ==
float(cat1_minacc)" not equal to "int(cat1_acc_riv) == int(cat1_minacc)" ?
>>
>> int truncates to integer while float converts to single precision
floating point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = 1.9,
"float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == 1.9" whereas
"int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 == 1", thus the results
are different.
>>
>> Another reason for possible differences is that float can only represent
max 7 decimal digits. E.g. float(194320567) becomes 194320560 but
int(194320567) preserves the value 194320567.
>>
>> Thus the safest is to cast everything to the type with the highest
precision. In this case with FCELL and DCELL, use "double(cat1_acc_riv) ==
double(cat1_minacc)" or even better the suggestion of Markus N.
>>
>> Markus M
>>
>>
>> On Sun, Jan 24, 2021 at 3:51 PM ming han  wrote:
>> >
>> > Hi Markus and Micha
>> >
>> >  I am just trying to find grids have the same values in these two
rasters, I will try the threshold approach.
>> >
>> > Thanks
>> > Ming
>> >
>> > Markus Neteler  于2021年1月24日周日 上午6:58写道:
>> >>
>> >> Hi Ming,
>> >>
>> >> On Sun, Jan 24, 2021 at 10:49 AM ming han  wrote:
>> >> >
>> >> > Hi Micha
>> >> >
>> >> >  Many thanks for your reply.
>> >> >  Here is the command I am using:
>> >> >
>> >> >  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
>> >> >
>> >> >   The str_r is a CELL raster. the result is different when I
change it to:
>> >> >if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
>> >>
>> >> Note that numerical "equality" is better tested with a threshold test
>> >> against the map pixel difference.
>> >> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
>> >>
>> >> Hence the test needs to be implemented in a different way, i.e. by
>> >> using an epsilon.
>> >> Essentially something like this:
>> >>
>> >> if(fabs(map_A - map_B) <= 1.0e-15, ... )
>> >>
>> >> In your case (untested):
>> >> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r ,
null())
>> >>
>> >> See related discussions here: [1], [2] and elsewhere.
>> >>
>> >> [1] Comment by Glynn:
https://trac.osgeo.org/grass/ticket/2854#comment:9
>> >> [2] Comment by Glynn:
>> >> https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html
>> >>
>> >> Best,
>> >> Markus
>> >
>> > ___
>> > grass-dev mailing list
>> > grass-dev@lists.osgeo.org
>> > https://lists.osgeo.org/mailman/listinfo/grass-dev
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread ming han
sorry for the inconvenience. I was just not sure if it is problem that
needs developers to answer.
Best regards
Ming

Zoltan  于2021年1月24日周日 上午11:13写道:

> Hi,
> Is it important to cross-post this discussion on both dev and user lists?
>
> Regards,
> Zoltan
>
>
> On 2021-01-24 17:56, Markus Metz wrote:
>
> Trying to answer the original question: with a DCELL map "cat1_acc_riv"
> and a FCELL map "cat1_minacc", why is "float(cat1_acc_riv) ==
> float(cat1_minacc)" not equal to "int(cat1_acc_riv) == int(cat1_minacc)" ?
>
> int truncates to integer while float converts to single precision floating
> point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = 1.9,
> "float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == 1.9" whereas
> "int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 == 1", thus the results
> are different.
>
> Another reason for possible differences is that float can only represent
> max 7 decimal digits. E.g. float(194320567) becomes 194320560 but
> int(194320567) preserves the value 194320567.
>
> Thus the safest is to cast everything to the type with the highest
> precision. In this case with FCELL and DCELL, use "double(cat1_acc_riv) ==
> double(cat1_minacc)" or even better the suggestion of Markus N.
>
> Markus M
>
>
> On Sun, Jan 24, 2021 at 3:51 PM ming han  wrote:
> >
> > Hi Markus and Micha
> >
> >  I am just trying to find grids have the same values in these two
> rasters, I will try the threshold approach.
> >
> > Thanks
> > Ming
> >
> > Markus Neteler  于2021年1月24日周日 上午6:58写道:
> >>
> >> Hi Ming,
> >>
> >> On Sun, Jan 24, 2021 at 10:49 AM ming han  wrote:
> >> >
> >> > Hi Micha
> >> >
> >> >  Many thanks for your reply.
> >> >  Here is the command I am using:
> >> >
> >> >  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
> >> >
> >> >   The str_r is a CELL raster. the result is different when I
> change it to:
> >> >if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
> >>
> >> Note that numerical "equality" is better tested with a threshold test
> >> against the map pixel difference.
> >> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
> >>
> >> Hence the test needs to be implemented in a different way, i.e. by
> >> using an epsilon.
> >> Essentially something like this:
> >>
> >> if(fabs(map_A - map_B) <= 1.0e-15, ... )
> >>
> >> In your case (untested):
> >> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r ,
> null())
> >>
> >> See related discussions here: [1], [2] and elsewhere.
> >>
> >> [1] Comment by Glynn:
> https://trac.osgeo.org/grass/ticket/2854#comment:9
> >> [2] Comment by Glynn:
> >> https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html
> >>
> >> Best,
> >> Markus
> >
> > ___
> > grass-dev mailing list
> > grass-dev@lists.osgeo.org
> > https://lists.osgeo.org/mailman/listinfo/grass-dev
>
> ___
> grass-dev mailing 
> listgrass-dev@lists.osgeo.orghttps://lists.osgeo.org/mailman/listinfo/grass-dev
>
>
> --
>
> =
> Zoltan Szecsei GPrGISc 0031
> Geograph (Pty) Ltd.
> GIS and Photogrammetric Services
>
> Cape Town, South Africa.
>
> Mobile: +27-83-6004028www.geograph.co.za
> =
>
> ___
> grass-dev mailing list
> grass-dev@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev
>
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Zoltan

Hi,
Is it important to cross-post this discussion on both dev and user lists?

Regards,
Zoltan


On 2021-01-24 17:56, Markus Metz wrote:
Trying to answer the original question: with a DCELL map 
"cat1_acc_riv" and a FCELL map "cat1_minacc", why is 
"float(cat1_acc_riv) == float(cat1_minacc)" not equal to 
"int(cat1_acc_riv) == int(cat1_minacc)" ?


int truncates to integer while float converts to single precision 
floating point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = 1.9, 
"float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == 1.9" 
whereas "int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 == 1", thus 
the results are different.


Another reason for possible differences is that float can only 
represent max 7 decimal digits. E.g. float(194320567) becomes 
194320560 but int(194320567) preserves the value 194320567.


Thus the safest is to cast everything to the type with the highest 
precision. In this case with FCELL and DCELL, use 
"double(cat1_acc_riv) == double(cat1_minacc)" or even better the 
suggestion of Markus N.


Markus M


On Sun, Jan 24, 2021 at 3:51 PM ming han > wrote:

>
> Hi Markus and Micha
>
>      I am just trying to find grids have the same values in these 
two rasters, I will try the threshold approach.

>
> Thanks
> Ming
>
> Markus Neteler mailto:nete...@osgeo.org>> 
于2021年1月24日周日 上午6:58写道:

>>
>> Hi Ming,
>>
>> On Sun, Jan 24, 2021 at 10:49 AM ming han > wrote:

>> >
>> > Hi Micha
>> >
>> >      Many thanks for your reply.
>> >      Here is the command I am using:
>> >
>> >      if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
>> >
>> >       The str_r is a CELL raster. the result is different when I 
change it to:

>> >        if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
>>
>> Note that numerical "equality" is better tested with a threshold test
>> against the map pixel difference.
>> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
>>
>> Hence the test needs to be implemented in a different way, i.e. by
>> using an epsilon.
>> Essentially something like this:
>>
>> if(fabs(map_A - map_B) <= 1.0e-15, ... )
>>
>> In your case (untested):
>> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r , 
null())

>>
>> See related discussions here: [1], [2] and elsewhere.
>>
>> [1] Comment by Glynn: 
https://trac.osgeo.org/grass/ticket/2854#comment:9 


>> [2] Comment by Glynn:
>> 
https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html 


>>
>> Best,
>> Markus
>
> ___
> grass-dev mailing list
> grass-dev@lists.osgeo.org 
> https://lists.osgeo.org/mailman/listinfo/grass-dev 



___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


--

=
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

Cape Town, South Africa.

Mobile: +27-83-6004028
www.geograph.co.za
=

___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread ming han
Hi Everyone

   Many thanks for your help. Is if(fabs(map_A - map_B) <= 1.0e-15, ... )
approach may increase the runtime compare to '==' way?

Thanks
Ming

Markus Metz  于2021年1月24日周日 上午10:57写道:

> Trying to answer the original question: with a DCELL map "cat1_acc_riv"
> and a FCELL map "cat1_minacc", why is "float(cat1_acc_riv) ==
> float(cat1_minacc)" not equal to "int(cat1_acc_riv) == int(cat1_minacc)" ?
>
> int truncates to integer while float converts to single precision floating
> point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = 1.9,
> "float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == 1.9" whereas
> "int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 == 1", thus the results
> are different.
>
> Another reason for possible differences is that float can only represent
> max 7 decimal digits. E.g. float(194320567) becomes 194320560 but
> int(194320567) preserves the value 194320567.
>
> Thus the safest is to cast everything to the type with the highest
> precision. In this case with FCELL and DCELL, use "double(cat1_acc_riv) ==
> double(cat1_minacc)" or even better the suggestion of Markus N.
>
> Markus M
>
>
> On Sun, Jan 24, 2021 at 3:51 PM ming han  wrote:
> >
> > Hi Markus and Micha
> >
> >  I am just trying to find grids have the same values in these two
> rasters, I will try the threshold approach.
> >
> > Thanks
> > Ming
> >
> > Markus Neteler  于2021年1月24日周日 上午6:58写道:
> >>
> >> Hi Ming,
> >>
> >> On Sun, Jan 24, 2021 at 10:49 AM ming han  wrote:
> >> >
> >> > Hi Micha
> >> >
> >> >  Many thanks for your reply.
> >> >  Here is the command I am using:
> >> >
> >> >  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
> >> >
> >> >   The str_r is a CELL raster. the result is different when I
> change it to:
> >> >if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
> >>
> >> Note that numerical "equality" is better tested with a threshold test
> >> against the map pixel difference.
> >> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
> >>
> >> Hence the test needs to be implemented in a different way, i.e. by
> >> using an epsilon.
> >> Essentially something like this:
> >>
> >> if(fabs(map_A - map_B) <= 1.0e-15, ... )
> >>
> >> In your case (untested):
> >> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r ,
> null())
> >>
> >> See related discussions here: [1], [2] and elsewhere.
> >>
> >> [1] Comment by Glynn:
> https://trac.osgeo.org/grass/ticket/2854#comment:9
> >> [2] Comment by Glynn:
> >> https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html
> >>
> >> Best,
> >> Markus
> >
> > ___
> > grass-dev mailing list
> > grass-dev@lists.osgeo.org
> > https://lists.osgeo.org/mailman/listinfo/grass-dev
>
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Markus Metz
Trying to answer the original question: with a DCELL map "cat1_acc_riv" and
a FCELL map "cat1_minacc", why is "float(cat1_acc_riv) ==
float(cat1_minacc)" not equal to "int(cat1_acc_riv) == int(cat1_minacc)" ?

int truncates to integer while float converts to single precision floating
point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = 1.9,
"float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == 1.9" whereas
"int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 == 1", thus the results
are different.

Another reason for possible differences is that float can only represent
max 7 decimal digits. E.g. float(194320567) becomes 194320560 but
int(194320567) preserves the value 194320567.

Thus the safest is to cast everything to the type with the highest
precision. In this case with FCELL and DCELL, use "double(cat1_acc_riv) ==
double(cat1_minacc)" or even better the suggestion of Markus N.

Markus M


On Sun, Jan 24, 2021 at 3:51 PM ming han  wrote:
>
> Hi Markus and Micha
>
>  I am just trying to find grids have the same values in these two
rasters, I will try the threshold approach.
>
> Thanks
> Ming
>
> Markus Neteler  于2021年1月24日周日 上午6:58写道:
>>
>> Hi Ming,
>>
>> On Sun, Jan 24, 2021 at 10:49 AM ming han  wrote:
>> >
>> > Hi Micha
>> >
>> >  Many thanks for your reply.
>> >  Here is the command I am using:
>> >
>> >  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
>> >
>> >   The str_r is a CELL raster. the result is different when I
change it to:
>> >if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
>>
>> Note that numerical "equality" is better tested with a threshold test
>> against the map pixel difference.
>> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
>>
>> Hence the test needs to be implemented in a different way, i.e. by
>> using an epsilon.
>> Essentially something like this:
>>
>> if(fabs(map_A - map_B) <= 1.0e-15, ... )
>>
>> In your case (untested):
>> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r ,
null())
>>
>> See related discussions here: [1], [2] and elsewhere.
>>
>> [1] Comment by Glynn: https://trac.osgeo.org/grass/ticket/2854#comment:9
>> [2] Comment by Glynn:
>> https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html
>>
>> Best,
>> Markus
>
> ___
> grass-dev mailing list
> grass-dev@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread ming han
Hi Markus and Micha

 I am just trying to find grids have the same values in these two
rasters, I will try the threshold approach.

Thanks
Ming

Markus Neteler  于2021年1月24日周日 上午6:58写道:

> Hi Ming,
>
> On Sun, Jan 24, 2021 at 10:49 AM ming han  wrote:
> >
> > Hi Micha
> >
> >  Many thanks for your reply.
> >  Here is the command I am using:
> >
> >  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
> >
> >   The str_r is a CELL raster. the result is different when I change
> it to:
> >if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
>
> Note that numerical "equality" is better tested with a threshold test
> against the map pixel difference.
> As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.
>
> Hence the test needs to be implemented in a different way, i.e. by
> using an epsilon.
> Essentially something like this:
>
> if(fabs(map_A - map_B) <= 1.0e-15, ... )
>
> In your case (untested):
> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r , null())
>
> See related discussions here: [1], [2] and elsewhere.
>
> [1] Comment by Glynn: https://trac.osgeo.org/grass/ticket/2854#comment:9
> [2] Comment by Glynn:
> https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html
>
> Best,
> Markus
>
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Markus Neteler
Hi Ming,

On Sun, Jan 24, 2021 at 10:49 AM ming han  wrote:
>
> Hi Micha
>
>  Many thanks for your reply.
>  Here is the command I am using:
>
>  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
>
>   The str_r is a CELL raster. the result is different when I change it to:
>if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())

Note that numerical "equality" is better tested with a threshold test
against the map pixel difference.
As the threshold, we use GRASS_EPSILON which is defined as 1.0e-15.

Hence the test needs to be implemented in a different way, i.e. by
using an epsilon.
Essentially something like this:

if(fabs(map_A - map_B) <= 1.0e-15, ... )

In your case (untested):
r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, str_r , null())

See related discussions here: [1], [2] and elsewhere.

[1] Comment by Glynn: https://trac.osgeo.org/grass/ticket/2854#comment:9
[2] Comment by Glynn:
https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html

Best,
Markus
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Micha Silver
I can see that the maximum values are different. Have a look at the
Range values.

What are you trying to do? Maybe there's a simpler approach...

On Sun, Jan 24, 2021 at 11:49 AM ming han  wrote:
>
> Hi Micha
>
>  Many thanks for your reply.
>  Here is the command I am using:
>
>  if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())
>
>   The str_r is a CELL raster. the result is different when I change it to:
>if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())
>
> Here is output of r.info for first DCELL raster
>
> ++
>  | Map:  cat1_acc_riv@PERMANENT Date: Sat Jan 23 22:58:42 2021
> |
>  | Mapset:   PERMANENT  Login of Creator: m43han  
> |
>  | Location: main_working_location
> |
>  | DataBase: C:\Users\m43han\Documents\Routing_Prod\Prod01\grassdb
> |
>  | Title:cat1_acc_riv 
> |
>  | Timestamp: none
> |
>  
> ||
>  |
> |
>  |   Type of Map:  raster   Number of Categories: 19432056
> |
>  |   Data Type:DCELL  
> |
>  |   Rows: 4239   
> |
>  |   Columns:  9254   
> |
>  |   Total Cells:  39227706   
> |
>  |Projection: Latitude-Longitude  
> |
>  |N:  50:52:39NS:  40:16:48N   Res: 0:00:09   
> |
>  |E:  70:10:39WW:  93:18:45W   Res: 0:00:09   
> |
>  |   Range of data:min = 250752  max = 19432056   
> |
>  |
> |
>  |   Data Description:
> |
>  |generated by r.mapcalc  
> |
>  |
> |
>  |   Comments:
> |
>  |if(isnull(str_r), null(), acc)  
> |
>  |
> |
>  
> ++
> (Sun Jan 24 04:45:38 2021) Command finished (0 sec)
>
>
> Here is r.info output for second raster
>  
> ++
>  | Map:  cat1_minacc@PERMANENT  Date: Sat Jan 23 22:58:48 2021
> |
>  | Mapset:   PERMANENT  Login of Creator: m43han  
> |
>  | Location: main_working_location
> |
>  | DataBase: C:\Users\m43han\Documents\Routing_Prod\Prod01\grassdb
> |
>  | Title:cat1_minacc  
> |
>  | Timestamp: none
> |
>  
> ||
>  |
> |
>  |   Type of Map:  raster   Number of Categories: 0   
> |
>  |   Data Type:FCELL  
> |
>  |   Rows: 4239   
> |
>  |   Columns:  9254   
> |
>  |   Total Cells:  39227706   
> |
>  |Projection: Latitude-Longitude  
> |
>  |N:  50:52:39NS:  40:16:48N   Res: 0:00:09   
> |
>  |E:  70:10:39WW:  93:18:45W   Res: 0:00:09   
> |
>  |   Range of data:min = 250752  max = 1.817303e+007  
> |
>  |
> |
>  |   Data Description:
> |
>  |generated by r.stats.zonal  
> |
>  |
> |
>  |   Comments:
> |
>  |r.stats.zonal --overwrite base="str_r" cover="cat1_acc_riv" method="\   
> |
>  |min" output="cat1_minacc"   
> |
>  | 

Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread ming han
Hi Micha

 Many thanks for your reply.
 Here is the command I am using:

 if(float(cat1_acc_riv) == float(cat1_minacc), str_r, null())

  The str_r is a CELL raster. the result is different when I change it
to:
   if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null())

Here is output of r.info for first DCELL raster

++
 | Map:  cat1_acc_riv@PERMANENT Date: Sat Jan 23 22:58:42 2021
   |
 | Mapset:   PERMANENT  Login of Creator: m43han
   |
 | Location: main_working_location
   |
 | DataBase: C:\Users\m43han\Documents\Routing_Prod\Prod01\grassdb
   |
 | Title:cat1_acc_riv
  |
 | Timestamp: none
   |
 ||
 |
   |
 |   Type of Map:  raster   Number of Categories: 19432056
   |
 |   Data Type:DCELL
   |
 |   Rows: 4239
  |
 |   Columns:  9254
  |
 |   Total Cells:  39227706
  |
 |Projection: Latitude-Longitude
   |
 |N:  50:52:39NS:  40:16:48N   Res: 0:00:09
  |
 |E:  70:10:39WW:  93:18:45W   Res: 0:00:09
  |
 |   Range of data:min = 250752  max = 19432056
  |
 |
   |
 |   Data Description:
   |
 |generated by r.mapcalc
   |
 |
   |
 |   Comments:
   |
 |if(isnull(str_r), null(), acc)
   |
 |
   |
 ++
(Sun Jan 24 04:45:38 2021) Command finished (0 sec)



Here is r.info output for second raster
 ++
 | Map:  cat1_minacc@PERMANENT  Date: Sat Jan 23 22:58:48 2021
   |
 | Mapset:   PERMANENT  Login of Creator: m43han
   |
 | Location: main_working_location
   |
 | DataBase: C:\Users\m43han\Documents\Routing_Prod\Prod01\grassdb
   |
 | Title:cat1_minacc
   |
 | Timestamp: none
   |
 ||
 |
   |
 |   Type of Map:  raster   Number of Categories: 0
  |
 |   Data Type:FCELL
   |
 |   Rows: 4239
  |
 |   Columns:  9254
  |
 |   Total Cells:  39227706
  |
 |Projection: Latitude-Longitude
   |
 |N:  50:52:39NS:  40:16:48N   Res: 0:00:09
  |
 |E:  70:10:39WW:  93:18:45W   Res: 0:00:09
  |
 |   Range of data:min = 250752  max = 1.817303e+007
   |
 |
   |
 |   Data Description:
   |
 |generated by r.stats.zonal
   |
 |
   |
 |   Comments:
   |
 |r.stats.zonal --overwrite base="str_r" cover="cat1_acc_riv" method="\
  |
 |min" output="cat1_minacc"
  |
 |
   |
 ++
(Sun Jan 24 04:46:50 2021) Command finished (0 sec)

Thanks
Ming


Micha Silver  于2021年1月24日周日 上午3:29写道:

> Is there some reason that you expect the rasters to be the same? Maybe
> begin by posting the outputs of `r.info` for both rasters, and what
> command you used to compare them?
>
> On Sun, Jan 24, 2021 at 6:13 AM ming han  wrote:
> >
> > Hi Everyone
> >
> > I tried to compare if grids in two rasters are the same, one raster
> is FCELL and another raster is DCELL. I got different result  when I int
> both raster first before comparing them; and when I float() both raster
> first before I comparing them
> >
> > Is there any reason for this?
> >
> > Thanks
> > Ming
> > ___
> > grass-user mailing list
> > grass-u...@lists.osgeo.org
> > https://lists.osgeo.org/mailman/listinfo/grass-user
>
>
>
> --
> Micha Silver
> Ben Gurion Univ
> Sde-Boker Remote Sensing Lab
> cell: +972 (52) 3665918
>
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] [GRASS-user] compare a DCELL and FCELL question

2021-01-24 Thread Micha Silver
Is there some reason that you expect the rasters to be the same? Maybe
begin by posting the outputs of `r.info` for both rasters, and what
command you used to compare them?

On Sun, Jan 24, 2021 at 6:13 AM ming han  wrote:
>
> Hi Everyone
>
> I tried to compare if grids in two rasters are the same, one raster is 
> FCELL and another raster is DCELL. I got different result  when I int both 
> raster first before comparing them; and when I float() both raster first 
> before I comparing them
>
> Is there any reason for this?
>
> Thanks
> Ming
> ___
> grass-user mailing list
> grass-u...@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user



-- 
Micha Silver
Ben Gurion Univ
Sde-Boker Remote Sensing Lab
cell: +972 (52) 3665918
___
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev