Re: [netcdf-java] Question on GRIB GDS values precision (float) on computations

Hi John,
Indeed, in some other methods we use similar compares, as an instance when
checking if the dataset resolution is almost the same...
Comparing 5000000 meters against 5000000.02 isn't the same as comparing
0.0000045 degrees with 0.000004502.

Anyway, thanks you all for the suggestions.
Cheers,
Daniele



==
GeoServer Professional Services from the experts! Visit
http://goo.gl/NWWaa2 for more information.
==

Ing. Daniele Romagnoli
Senior Software Engineer

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054  Massarosa (LU)
Italy
phone: +39 0584 962313
fax:      +39 0584 1660272

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

-------------------------------------------------------

*AVVERTENZE AI SENSI DEL D.Lgs. 196/2003*

Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.



The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility  for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.


On Tue, Apr 21, 2015 at 5:33 PM, John Caron <caron@xxxxxxxx> wrote:

> No, that is exact. More like ucar.nc2.Misc
>
> public static boolean closeEnough(float v1, float v2, float maxRelDiff)
> {
>     if(Float.isNaN(v1) && Float.isNaN(v2)) return true;
>     if(Float.isNaN(v1) || Float.isNaN(v2)) return false;   // prob not needed
>
>     float diff = Math.abs(v1 - v2);
>     float largest = Math.max(Math.abs(v1), Math.abs(v2));
>     return diff <= largest * maxRelDiff;
> }
>
>
> see:
>
> http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
>
> http://floating-point-gui.de/errors/comparison/
>
>
> On Tue, Apr 21, 2015 at 9:22 AM, Antonio Rodriges <antonio.rrz@xxxxxxxxx>
> wrote:
>
>> Like
>> Float.compare(a. b) and
>> Double.compare(a, b)
>>
>> 2015-04-21 17:14 GMT+03:00 John Caron <caron@xxxxxxxx>:
>> > ok, and you always have to compare floats with a tolerance, not exact.
>> ive
>> > been bitten many times by that.
>> >
>> > John
>> >
>> > On Tue, Apr 21, 2015 at 8:02 AM, Daniele Romagnoli
>> > <daniele.romagnoli@xxxxxxxxxxxxxxxx> wrote:
>> >>
>> >> Hi John,
>> >> thanks for your reply.
>> >>
>> >> The problem I have with this is that I'm setting up a predefined set of
>> >> custom CoordinateReferenceSystem definitions:
>> >> as an instance, a LambertConformal projection where standard parallels
>> is
>> >> 25.
>> >> Then, I'm parsing the gridMapping attributes in order to try to
>> recognize
>> >> a known custom CRS and I'm getting no matches since it is expecting 25
>> >> instead of 25.00002. (CRS matching checks use WKT parsing).
>> >>
>> >> In the meantime, I will investigate more on this.
>> >> Cheers,
>> >> Daniele
>> >>
>> >>
>> >>
>> >> ==
>> >> GeoServer Professional Services from the experts! Visit
>> >> http://goo.gl/NWWaa2 for more information.
>> >> ==
>> >>
>> >> Ing. Daniele Romagnoli
>> >> Senior Software Engineer
>> >>
>> >> GeoSolutions S.A.S.
>> >> Via Poggio alle Viti 1187
>> >> 55054  Massarosa (LU)
>> >> Italy
>> >> phone: +39 0584 962313
>> >> fax:      +39 0584 1660272
>> >>
>> >> http://www.geo-solutions.it
>> >> http://twitter.com/geosolutions_it
>> >>
>> >> -------------------------------------------------------
>> >>
>> >> AVVERTENZE AI SENSI DEL D.Lgs. 196/2003
>> >>
>> >> Le informazioni contenute in questo messaggio di posta elettronica e/o
>> >> nel/i file/s allegato/i sono da considerarsi strettamente riservate.
>> Il loro
>> >> utilizzo è consentito esclusivamente al destinatario del messaggio,
>> per le
>> >> finalità indicate nel messaggio stesso. Qualora riceviate questo
>> messaggio
>> >> senza esserne il destinatario, Vi preghiamo cortesemente di darcene
>> notizia
>> >> via e-mail e di procedere alla distruzione del messaggio stesso,
>> >> cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
>> divulgarlo
>> >> anche in parte, distribuirlo ad altri soggetti, copiarlo, od
>> utilizzarlo per
>> >> finalità diverse, costituisce comportamento contrario ai principi
>> dettati
>> >> dal D.Lgs. 196/2003.
>> >>
>> >>
>> >>
>> >> The information in this message and/or attachments, is intended solely
>> for
>> >> the attention and use of the named addressee(s) and may be
>> confidential or
>> >> proprietary in nature or covered by the provisions of privacy act
>> >> (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
>> >> Code).Any use not in accord with its purpose, any disclosure,
>> reproduction,
>> >> copying, distribution, or either dissemination, either whole or
>> partial, is
>> >> strictly forbidden except previous formal approval of the named
>> >> addressee(s). If you are not the intended recipient, please contact
>> >> immediately the sender by telephone, fax or e-mail and delete the
>> >> information in this message that has been received in error. The
>> sender does
>> >> not give any warranty or accept liability as the content, accuracy or
>> >> completeness of sent messages and accepts no responsibility  for
>> changes
>> >> made after they were sent or for other risks which arise as a result of
>> >> e-mail transmission, viruses, etc.
>> >>
>> >>
>> >>
>> >> On Tue, Apr 21, 2015 at 2:15 AM, John Caron <caron@xxxxxxxx> wrote:
>> >>>
>> >>> Hi Daniele:
>> >>>
>> >>> GRIB projection info is stored in the GRIB file in (at most) 3 bytes,
>> so
>> >>> has a maximum precision of 24 bits.
>> >>>
>> >>> Im surprised that you are seeing a problem, it seems unlikely that a
>> >>> roundoff in the low order bit of a float should matter.
>> >>>
>> >>> But theres not really a good reason that we couldnt use doubles if
>> >>> needed.
>> >>>
>> >>> John
>> >>>
>> >>>
>> >>> On Mon, Apr 20, 2015 at 3:45 AM, Daniele Romagnoli
>> >>> <daniele.romagnoli@xxxxxxxxxxxxxxxx> wrote:
>> >>>>
>> >>>> Hi List,
>> >>>> I'm using NetCDF Java 4.5.5.
>> >>>> I have noticed that when computing the LambertConformal projection
>> >>>> components (such as latin1, latin2...) in Grib1Gds I'm getting:
>> >>>>
>> >>>> latin1 = 25.00001
>> >>>> latin2 = 25.05002
>> >>>> dx1 = 13.545001
>> >>>> dy1 = 13.545001
>> >>>>
>> >>>> Instead of:
>> >>>> latin1 = 25
>> >>>> latin2 = 25.05
>> >>>> dx1 = 13.545
>> >>>> dy1 = 13.545
>> >>>>
>> >>>> Plus, I'm getting some additional precision loss when extracting
>> these
>> >>>> attributes
>> >>>> from the associated grid_mapping variable, as numbers (double
>> values).
>> >>>> I will surely investigate more on the topic to become more confident
>> >>>> with that code and I will read again about representation errors on
>> floating
>> >>>> point arithmetics so my question could sounds trivial: Why these
>> variables
>> >>>> and scale constants are floats instead of doubles? (is it for size
>> and
>> >>>> performance issues?)
>> >>>>
>> >>>> Regards,
>> >>>> Daniele
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> ==
>> >>>> GeoServer Professional Services from the experts! Visit
>> >>>> http://goo.gl/NWWaa2 for more information.
>> >>>> ==
>> >>>>
>> >>>> Ing. Daniele Romagnoli
>> >>>> Senior Software Engineer
>> >>>>
>> >>>> GeoSolutions S.A.S.
>> >>>> Via Poggio alle Viti 1187
>> >>>> 55054  Massarosa (LU)
>> >>>> Italy
>> >>>> phone: +39 0584 962313
>> >>>> fax:      +39 0584 1660272
>> >>>>
>> >>>> http://www.geo-solutions.it
>> >>>> http://twitter.com/geosolutions_it
>> >>>>
>> >>>> -------------------------------------------------------
>> >>>>
>> >>>> AVVERTENZE AI SENSI DEL D.Lgs. 196/2003
>> >>>>
>> >>>> Le informazioni contenute in questo messaggio di posta elettronica
>> e/o
>> >>>> nel/i file/s allegato/i sono da considerarsi strettamente riservate .
>> Il loro
>> >>>> utilizzo è consentito esclusivamente al destinatario del messaggio,
>> per le
>> >>>> finalità indicate nel messaggio stesso. Qualora riceviate questo
>> messaggio
>> >>>> senza esserne il destinatario, Vi preghiamo cortesemente di darcene
>> notizia
>> >>>> via e-mail e di procedere alla distruzione del messaggio stesso,
>> >>>> cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
>> divulgarlo
>> >>>> anche in parte, distribuirlo ad altri soggetti, copiarlo, od
>> utilizzarlo per
>> >>>> finalità diverse, costituisce comportamento contrario ai principi
>> dettati
>> >>>> dal D.Lgs. 196/2003.
>> >>>>
>> >>>>
>> >>>>
>> >>>> The information in this message and/or attachments, is intended
>> solely
>> >>>> for the attention and use of the named addressee(s) and may be
>> confidential
>> >>>> or proprietary in nature or covered by the provisions of privacy act
>> >>>> (Legislative Decree June, 30 2003, no.196 - Italy's New Data
>> Protection
>> >>>> Code).Any use not in accord with its purpose, any disclosure,
>> reproduction,
>> >>>> copying, distribution, or either dissemination, either whole or
>> partial, is
>> >>>> strictly forbidden except previous formal approval of the named
>> >>>> addressee(s). If you are not the intended recipient, please contact
>> >>>> immediately the sender by telephone, fax or e-mail and delete the
>> >>>> information in this message that has been received in error. The
>> sender does
>> >>>> not give any warranty or accept liability as the content, accuracy or
>> >>>> completeness of sent messages and accepts no responsibility  for
>> changes
>> >>>> made after they were sent or for other risks which arise as a result
>> of
>> >>>> e-mail transmission, viruses, etc.
>> >>>>
>> >>>>
>> >>>>
>> >>>> _______________________________________________
>> >>>> netcdf-java mailing list
>> >>>> netcdf-java@xxxxxxxxxxxxxxxx
>> >>>> For list information or to unsubscribe, visit:
>> >>>> http://www.unidata.ucar.edu/mailing_lists/
>> >>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > netcdf-java mailing list
>> > netcdf-java@xxxxxxxxxxxxxxxx
>> > For list information or to unsubscribe, visit:
>> > http://www.unidata.ucar.edu/mailing_lists/
>>
>
>
  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: