dannycochran / windable

Add a wind visualization to your map.
MIT License
40 stars 14 forks source link

How to convert GRIB2 files to JSON automatically. #7

Closed divyanshu-rawat closed 8 years ago

divyanshu-rawat commented 8 years ago

First of all Great work . Now I wan to ask that the link that you have provided (https://raw.githubusercontent.com/dannycochran/windable/master/data/2016040900_700.json ) has data already data in JSON format but I want to ask is there any script that will automatically convert the data that I download from NOMADS to json format. In order to convert Grib2 to json I have already tried cambecc grib2json utility but it requires all the commands to be executed on terminal. I want to ask is it possible to write some script that will automatically convert grib2 format to json format.

dannycochran commented 8 years ago

It is definitely possible and there's a number of ways you could achieve dynamic loading of data. It depends on what you want to do.

What kind of server are you running? Node? Python? Rails? Basically, you should send a request from the client that looks like this:

$.ajax({
  url: '/wind_data',
  data: {
    timestamp: '2016070106',   // this is July 1st, 2016 at 6 a.m. UTC-0 YYYYMMDDHH
    millibars: 1000 // pressure altitude
  }
});

Then, let's say you had a nodeJS server, you'd do:

app.get('/wind_data', (req, res) => {
  const timestamp = req.query.timestamp;
  const millibars = req.query.millibars;
  const url =   `http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_1p00.pl?file=gfs.t00z.pgrb2.1p00.f000&lev_${millibars}_mb=on&var_UGRD=on&var_VGRD=on&dir=%2Fgfs.${timestamp}`;

  // curl the data with node-curl
  curl(url, function(err) {
    // Then, use npm shell to run a shell command, converting the data with grib2json, this means
    // you'd have to have grib2json installed on whichever machine is running the server.
    shellCommand('grib2json gfs.t00z.pgrb2.1p00.f000 output.json');
    res.json(output.json);
  });
});

This process would look similar with whichever server you have. grib2json is a fairly small library and doesn't have any modules for node, python, or ruby as far as I know, so you'll have to have your server run a shell command assuming that grib2json is installed on your machine.

If your server is in Java, however, it would be easier since the grib2json module is written in Java. Let me know if the above pseudo code makes sense and if you have any other questions, happy to help get you set up.

divyanshu-rawat commented 8 years ago

thanks issue solved.

divyanshu-rawat commented 8 years ago

Hey Hi while reading your code I encountered something that i am unable to understand. like in this line i just want to ask that _panes is not declared anywhere in the code and even it is not any method or property of map in leaflet documentation. var tilePane = this._map._panes.tilePane ; similarly, map.dragging._draggable.... what is _draggable it is not defined anywhere.

NgocHoang2017 commented 5 years ago

hi how to convert grib to json with php and javascript

subhadeep-maishal commented 5 years ago

Flow below this link.i think its help you lots. https://github.com/cambecc/grib2json

On Mon, Jun 24, 2019 at 10:10 AM Nguyen Ngoc Hoang notifications@github.com wrote:

hi how to convert grib to json with php and javascript

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dannycochran/windable/issues/7?email_source=notifications&email_token=AECJR5OEENQTXLNHJ3OGT2TP4BF2BA5CNFSM4CJFKWLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYLXRZI#issuecomment-504854757, or mute the thread https://github.com/notifications/unsubscribe-auth/AECJR5LVXJDABFDKUVTJCRDP4BF2BANCNFSM4CJFKWLA .

--

With Best Regards--- Subhadeep MaishalBirla Institute of Technology,MesraRanchi,Jharkhand,835215Phone number of voice mail :+91 8597838182Primary email address: mtrs10006.17@bitmesra.ac.in mtrs10006.17@bitmesra.ac.inSecondary email address :subhabitrs@gmail.com subhabitrs@gmail.comPassport number : S5333282 , Country code:INDPermanent address : Digha,West Bengal,721446.GitHub Link : https://github.com/subhadeep-maishal https://github.com/subhadeep-maishalLinkedin profile url : https://in.linkedin.com/in/subhadeep-maishal-6020a7b3 https://in.linkedin.com/in/subhadeep-maishal-6020a7b3website :https://www.cfdforall.com/ https://www.cfdforall.com/