这里有从事气象或地球科学工作的人吗?我正在尝试使用 GRIB2 格式的数据文件。有可用的库,特别是 Unidata GRIB Java 解码器。而且我可以确切地看到如何在一个大的线性数组中提取数据,但我想做的是按纬度/经度访问值。找不到任何简单的例子来说明如何做到这一点。建议?
蒂亚!
将 python 与 pygrib 模块一起使用通常就像一个魅力。您可以使用以下代码提取纬度/经度和数据。
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
现在可以使用底图工具包轻松可视化数据或将其导出到合适的文件:)
您可以使用 DEGRIB 工具来探测指定纬度/经度的数据。请参阅此处http://www.weather.gov/mdl/degrib/txtview.php?file=degrib.txt&dir=base Windows 示例为 'degrib.exe myfile.grib -P -pnt 40.0,-10.0 -Interp 2 '。如果您需要 DEGRIB.EXE,您可以在名为 VRTOOL 的程序的安装目录中找到它http://www.tecepe.com.br/nav/vrtool/
wgrib2程序允许您使用-lon选项在选定的纬度/经度位置提取时间序列,例如:
wgrib2.exe input_file.grb2 -lon 360 90 > output_file.txt
您将需要获取投影类型以及参数,然后使用它将坐标从纬度/经度映射到网格 x/y(请参阅geotools 网站上CoordinateReferenceSystem
的fe 类)。
您可以使用 GRIB2Tools,请参阅https://github.com/philippphb/GRIB2Tools。从像这样的 InputStream 读取 GRIB2 文件后
RandomAccessGribFile gribFile = new RandomAccessGribFile("", "");
gribFile.importFromStream(inputstream, 0);
您可以根据纬度/经度访问GRIB文件的数据:
double longitude = ... // in degrees
double latitude = ... // in degrees
float val = gribFile.getValueAt(0, GribFile.degToUnits(latitude), GribFile.degToUnits(longiude));
您还可以获得不完全在网格上的纬度/经度位置的插值数据:
double longitude = ... // in degrees
double latitude = ... // in degrees
float val = gribFile.interpolateValueAt(0, GribFile.degToUnits(latitude), GribFile.degToUnits(longiude));