Anybody here doing meteorological or earth-sciences work? I am trying to work with GRIB2 format data files. There are libraries available, in particul开发者_JAVA技巧ar the Unidata GRIB Java Decoder. And I can see exactly how to extract data in a big linear array, but what I want to do is access values by lat/long. Can't find any simple example on how to do that. Suggestions?
TIA!
Using python with the pygrib module usually works like a charm. You can extract lats/lons and data with the following code.
import pygrib
gr=pygrib.open(file)
data=values.(gr[key]) #use the key to the variable of interest to extract its data
lats,lons=(gr.readline()).latlons() #extract coordinates
Now its easy visualize the data with basemap toolkit or export it to a suitable file:)
You will need to get the projection type along with parameters, then use that to map the coordinates from lat/long to grid x/y (see f.e. the class CoordinateReferenceSystem
from the geotools website).
You can use the DEGRIB tool to probe data at a specified lat/long. See here http://www.weather.gov/mdl/degrib/txtview.php?file=degrib.txt&dir=base A windows example would be 'degrib.exe myfile.grib -P -pnt 40.0,-10.0 -Interp 2'. If you need DEGRIB.EXE you can find it in the installation directory of a program called VRTOOL http://www.tecepe.com.br/nav/vrtool/
The wgrib2 program allows you to extract a time series at a chosen lat/lon location using the -lon option, for example:
wgrib2.exe input_file.grb2 -lon 360 90 > output_file.txt
You can use the GRIB2Tools, see https://github.com/philippphb/GRIB2Tools. After reading in a GRIB2 file from an InputStream like
RandomAccessGribFile gribFile = new RandomAccessGribFile("", "");
gribFile.importFromStream(inputstream, 0);
you can access the data of the GRIB file based on lat/lon:
double longitude = ... // in degrees
double latitude = ... // in degrees
float val = gribFile.getValueAt(0, GribFile.degToUnits(latitude), GribFile.degToUnits(longiude));
You can also get interpolated data for lat/lon positions that are not exactly on the grid:
double longitude = ... // in degrees
double latitude = ... // in degrees
float val = gribFile.interpolateValueAt(0, GribFile.degToUnits(latitude), GribFile.degToUnits(longiude));
精彩评论