从netcdf4.5grib2record中提取天气预报数据

ruoxqz4g  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(283)

更新:更改此问题以更好地反映我当前的理解。
我有一个netcdfversion4.5grib2record对象。给定一个(x,y)网格点和一个变量名,我想按预测时间从对象中提取该变量的所有预测数据(如果记录包含该变量的预测)。由于写入磁盘索引文件的默认行为,我不想使用更高级别的netcdffile接口。
我试过寻找较低级别的代码(grib2rectilyser,grib2customizer等),但代码太密集,我正在寻找帮助从哪里开始。
如果你能给我一些建议,我会很感激的。检查其中是否包含特定的预测变量,以及2。如果是,则根据给定x-y网格点和z级别的预测有效时间提取预测数据。

gkl3eglg

gkl3eglg1#

我使用grib2文件进行风预测,这是我如何获得记录以及如何处理它以获得风(vu分量)

Grib2Input input = new Grib2Input(getRandomAccessFile());
if (!input.scan(false, false)) {
    logger.error("Failed to successfully scan grib file");
    return;
}
Grib2Data data = new Grib2Data(getRandomAccessFile());

List<Grib2Record> records = input.getRecords();

for (Grib2Record record : records) {    
    Grib2IndicatorSection is = record.getIs();
    Grib2IdentificationSection id = record.getId();
    Grib2Pds pdsv = record.getPDS().getPdsVars();
    Grib2GDSVariables gdsv = record.getGDS().getGdsVars();

    long time = id.getRefTime() + (record.getPDS().getForecastTime() * 3600000);

    logger.debug("Record description at " + pdsv.getReferenceDate() + " forecast "
    + new Date(time)    + ": " + ParameterTable.getParameterName(is.getDiscipline(), pdsv.getParameterCategory(), pdsv.getParameterNumber()));

    float[] values = data.getData(record.getGdsOffset(), record.getPdsOffset(), 0);

     if ((is.getDiscipline() == 0) && (pdsv.getParameterCategory() == 2) && (pdsv.getParameterNumber() == 2)) {
        // U-component_of_wind
        int c = 0;
        for (double lat = gdsv.getLa1(); lat >= gdsv.getLa2(); lat = lat - gdsv.getDy()) {
            for (double lon = gdsv.getLo1(); lon <= gdsv.getLo2(); lon = lon + gdsv.getDx()) {
                logger.debug(lat + "\t" + lon + "\t" +
                values[c]);
                c++;
            }
        }
    } else if ((is.getDiscipline() == 0) && (pdsv.getParameterCategory() == 2) && (pdsv.getParameterNumber() == 3)) {
        // V-component_of_wind
        int c = 0;
        for (double lat = gdsv.getLa1(); lat >= gdsv.getLa2(); lat = lat - gdsv.getDy()) {
            for (double lon = gdsv.getLo1(); lon <= gdsv.getLo2(); lon = lon + gdsv.getDx()) {
                logger.debug(lat + "\t" + lon + "\t" +
                values[c]);
                c++;
            }
        }
    }
}
private RandomAccessFile getRandomAccessFile() {
    RandomAccessFile raf = null;
    try {
        raf = new RandomAccessFile(path, "r");
        raf.order(RandomAccessFile.BIG_ENDIAN);
    } catch (IOException e) {
        logger.error("Error opening file " + path, e);
    }
    return raf;
}

相关问题