Pawan Tejwani
Pawan Tejwani

Reputation: 109

Extracting data from grib file based on latitude and longitude

If i have a grib2 file that contains information for whole world (for some parameters) and I want to extract data from it using wgrib2 based on latitude and longitude given by user (client software to server). I tried following command but I am getting complete grib2 file only:

wgrib2.exe input.grb -undefine out-box 10:90 -10:10 -grib output.grb

Please tell me where am I going wrong? Thanks.

Upvotes: 3

Views: 12322

Answers (4)

user1165471
user1165471

Reputation: 69

This is still the top hit on Google, so even though it is a bit old, here is a more detailed explanation.

First, you need wgrib2 from the National Weather Service Climate Prediction Centre. (The installation of that is straightforward, but not too well explained. See this page, or this gist for help.)

Next, you need to use the lola function (for LOngitude-LAtitude grid).

You need to give wgrib2 several arguments:

  • the grib file that has the data
  • the longitude information:
    • the longitude of the southwest corner of your bounding box
    • the length of the bounding box in degrees
    • the spacing of the points in this direction
  • the latitude information, the same as above
    • the latitude of the southwest corner of your bounding box
    • the length of the bounding box in degrees
    • the spacing of the points in this direction
  • the file name to write to
  • the format of the file to write (either bin for binary, text for simple text, spread for spreadsheet format, or grib for grib2).

For example:

wgrib2 input.grb 220:100:1 20:50:1 output.grb2 grib

will create an output file that covers north america (220 E - 320 E; 20 N - 70 N) at 1 degree intervals in both directions.

Rob

Upvotes: 1

ClimateUnboxed
ClimateUnboxed

Reputation: 8087

I think you can also use cdo directly on grib for this

cdo sellonlatbox,lon1,lon2,lat1,lat2 in.grb out.grb

If the grib file is on a reduced gaussian grid you may need to specify that you want a regular lat-lon output. I usually convert the output format to netcdf myself using "-f nc" as I find it easier to process in other software.

Upvotes: 0

KAE
KAE

Reputation: 855

If your chosen longitude was 360 and latitude was 90:

wgrib2.exe input_file.grb2 -lon 360 90 > output_file.txt

Upvotes: 0

Pawan Tejwani
Pawan Tejwani

Reputation: 109

I used the following command to extract information from grib2 file.

wgrib2.exe input_file.grib2 -lola LonSW:#lon:dlon LatSW:#lat:dlat file format

assuming that we are having following co-ordinates for selection:

Top: (x0,y0) (x1,y0)

Bottom: (x0,y1) (x1,y1)

"LongSW"=x0, #lon = (x0~x1), "LatSW"=y0, #lat = (y0~y1). and dlon and dlan can be kept as 1. 'file' is the output file name and format can be grib, csv, text etc.

Substitute above values in the command shown above and you should get the answer.

Upvotes: 0

Related Questions