Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extract data on a particular lat and long? #27

Open
wxguy opened this issue Jan 26, 2016 · 5 comments
Open

How to extract data on a particular lat and long? #27

wxguy opened this issue Jan 26, 2016 · 5 comments

Comments

@wxguy
Copy link

wxguy commented Jan 26, 2016

I am able to extract the data for a particular region with the help of documentation. How do I extract for a specif location say lat 13.0 and lon 80.0?

@jzalger
Copy link

jzalger commented Mar 6, 2016

I am also interested in a solution for this. Or at least documentation on the structure of the message value arrays.

@jswhit
Copy link
Owner

jswhit commented Mar 7, 2016

Understand that a grib message is a 2D array of data, and the entire message needs to be decoded at once. You can't just decode one grid point on the grid. The best way to extract one point is to grab the entire 2d grid, then use the lat and lon arrays to determine the grid index of the point you want (or interpolate to that point).

@yehelon
Copy link

yehelon commented May 25, 2016

Is there any built-in implementation for data interpolation in pygrib? e.g. something similar to the wgrib2 command:
$wgrib2 originalfile.grb2 -set_grib_type same -new_grid_winds earth -new_grid latlon -127:30:0.5 22:30:0.5 newfile.grb2

which interpolate the data to lat/lon meshgrid?
I have tried using scipy interp2d for the task, but (perhaps as I need to cover a large area), this was too heavy (compared to the wgrib command which runs in <sec).

@mavengences
Copy link

mavengences commented Jul 24, 2019

grbs_old = pygrib.open('nomads.ncep.noaa.gov/cgi-bin/'+str(grib_filename))
data=grbs_old[6].values

The command above will print a 2d array with dimmensions 720 x 360 ( my grib file is 0.5 deg * 0.5 deg).

[[ 52.87586589 52.87586589 52.87586589 ... 52.87586589 52.87586589
52.87586589]
[ 51.75276693 51.78610026 51.81443359 ... 51.61772786 51.64939453
51.72276693]
[ 49.90931641 49.96931641 50.02431641 ... 49.70261068 49.75594401
49.81427734]
...
[-11.11582031 -11.15415365 -11.18915365 ... -11.05585938 -11.08752604
-11.08082031]
[ -8.13052734 -8.10548828 -8.12048828 ... -8.08886068 -8.10219401
-8.11552734]
[ -4.54554687 -4.54554687 -4.54554687 ... -4.54554687 -4.54554687
-4.54554687]]

To find specific coordinates within this 720 x 360 array i just extrapolate the coordinates to the array. Ex: If I want to find data for New York New York coordinates ~40.5N 74 W I'll map those coordinates to the array to by doing 2x(90-40.5) and 2x (180-74) to find the following result:

grbs_old = pygrib.open('nomads.ncep.noaa.gov/cgi-bin/'+str(grib_filename))
data=grbs_old[6].values
data[99][212]

This returns the temperature result converted to Fahrenheit of (79 degrees).

@mavengences
Copy link

Right now I am performing the steps above, but my extrapolation is not correct.

To fix this problem I need to know how grib files are formatted in relation to latitude and longitude. Are they formatted top to bottom or bottom to top?

Ex if I am looking for coordinates 40.5N and 75 W do I find the corresponding grib file by doing 2x(90-40.5) North coordinate and 2x(180-74) West Coordinate to find
data[99][212] Or do I something else like 2x(180-40.5) North and 2x(360-74) west?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants