nmangue / NGrib

NGrib is a .NET library to read GRIB (GRid in Binary) files. GRIB is a gridded data standard from WMO (World Meteorological Organisation) and is used by many meteorological organisation. Fork of GribCS.
GNU Lesser General Public License v3.0
17 stars 10 forks source link

Reading grib2 from AROME forecast model #1

Closed hydrique closed 4 years ago

hydrique commented 4 years ago

Hi,

First of all, let me congratulate you on the amazing work you've done trying to create a working netcore grib parser! Impressive!

I'm trying myself to "get rid of" the net461 dependance on Grib.Api nugget.

I have done some testing in one of the forecast model I'm using, namely AROME 0.025 (french model). I've tried to parse the SP1 package available here [https://donneespubliques.meteofrance.fr/?fond=produit&id_produit=131&id_rubrique=51].

I've done the test on the "Temperature" parameter and I've noticed that the values that comes out of the "Grib2Reader.ReadDataSetValues" function are not consistent with what I find using Grib.Api nuget or panoply.

I don't know if maybe you have an idea why that is ?

I'll appreciate any help 👍 and congrats again on your work! Best Philippe

Here is the code I'm using:

`using (var stream = File.OpenRead(filePath)) { var gribReader = new Grib2Reader(stream); var gribMessages = gribReader.ReadMessages().ToList();

            var selectedGribMessages =
                    gribMessages
                        .Where(
                            m => m.DataSets.Single().Parameter.HasValue && m.DataSets.Single().Parameter.Value.Name == "Temperature")
                        .ToList();

            var data = gribReader.ReadDataSetValues(selectedGribMessages.First().DataSets.Single());`

image

nmangue commented 4 years ago

Hello Philippe,

Thank you for your kind feedback.

This particular AROME dataset uses the JPEG 2000 code stream format to encode the values. However NGrib does not support this data representation format yet (only simple or complex packing of float values). It should have raised an exception instead of reading wrong values. The tricky part to add this support is to find (or adapt) a reliable, .NET Standard 2.0, open JPEG 2000 library. Would you be interested in implementing this functionality yourself ?

Best regards, (Bien cordialement si vous êtes également francophone 😉)

Nicolas

hydrique commented 4 years ago

Hello!

Thanks for your fast reply and my appologies for my late reply...

Thanks for explaining to me where the error comes from... I had a look at what exists for JPEG 2000 compression and didn't find any suitable, open source, library :( It would be interesting to integrate this functionnality to have a robust grib library in .NET.

I would be happy to help if a JPEG 2000 library comes up (even tough my coding capacity might not necessarly be enough for the task :/ ). I'll keep an eye open and if I find a possible solution I will get in touch again.

All the best and thanks again for your work 👍

Salutations :)

Philippe

nmangue commented 4 years ago

I found that the .NET Standard port of CS2JK seems like a good fit. It was not updated recently but it still does the job. I have published a 0.6.0 version with this update and some fixes. Could you try it ?

hydrique commented 4 years ago

Hi! I'm really sorry I'm only seeing your message now :( I'm not using my private account, so I don't receive any notifications...

It's very nice you found a solution! I'll try first thing in the morning and let you know how it went!

Thanks again and sorry for the delay...

hydrique commented 4 years ago

Hi again !

Your fix worked great 👍 I've tested on AROME and now the temperature are decoded correctly!

Thanks a lot for the effort ! Best