首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NetCDF与Java:如何使用变量名称查找从GridDataset获取GeoGrid

NetCDF与Java:如何使用变量名称查找从GridDataset获取GeoGrid
EN

Stack Overflow用户
提问于 2016-06-24 14:40:58
回答 1查看 219关注 0票数 0

我有Java代码,它通过变量名从GeoGrid GridDataset中获取一个NetCDF对象。它通常正常工作,但对于输入NetCDF文件,我目前需要处理的输入代码在运行此代码时出错,因为没有找到GeoGrid,即使您可以使用其他工具(如ncdump和/或在使用调试器遍历代码时看到NetCDF dataset中的变量)。

我假设NetCDF文件本身一定存在一些东西,它阻止通过查找变量名来获取变量的网格。当我查看NetCDF文件时,我可以看到变量,它以Geo2D类型显示。文件的ncdump -h输出如下:

代码语言:javascript
复制
File "prism_nidis_pet.nc"
Dataset type: NetCDF-3/CDM
 
netcdf file:/C:/home/prism/prism_nidis_pet.nc {
  dimensions:
    lon = 1405;
    lat = 621;
    time = UNLIMITED;   // (1457 currently
  variables:
    int time(time=1457);
      :long_name = "time";
      :standard_name = "time";
      :units = "days since 1800-1-1 00:00:00";
      :calendar = "gregorian";

    float lon(lon=1405);
      :long_name = "longitude";
      :standard_name = "longitude";
      :units = "degrees_north";

    float lat(lat=621);
      :long_name = "latitude";
      :standard_name = "latitude";
      :units = "degrees_west";

    float pet(time=1457, lon=1405, lat=621);
      :calibration_start_year_month = "full";
      :calibration_end_year_month = "full";
      :_FillValue = -999.9f; // float
      :missing_value = -999.9f; // float
      :valid_min = 0.0f; // float
      :valid_max = 3.4028235E38f; // float
      :units = "millimeters";
      :cell_methods = "time: potential evapotranspiration estimate, Thornthwaite equation";
      :long_name = "Potential evapotranspiration estimate, Thornthwaite equation";
      :standard_name = "Potential evapotranspiration estimate, Thornthwaite equation";

  // global attributes:
  :date_created = "2016-06-23  11:52:37";
  :date_modified = "2016-06-23  11:52:37";
  :standard_name_vocabulary = "CF Standard Name Table (v26, 08 November 2013)";
  :Conventions = "1.6";
  :geospatial_lon_min = -125.0f; // float
  :geospatial_lon_max = -66.5f; // float
  :geospatial_lat_min = 24.083334f; // float
  :geospatial_lat_max = 49.916668f; // float
}

上面描述的文件中有什么会阻止与名为“GeoGrid”的变量关联的吗?

下面是使用上述文件作为输入时失败的代码。

代码语言:javascript
复制
    private GeoGrid getGrid(final String netcdfFile,
                            final String variableName)
        throws IOException
    {
        // open the NetCDF data set
        GridDataset gridDataset = GridDataset.open(netcdfFile);

        // verify that we opened the GridDataset
        if (gridDataset == null)
        {
            String errorMessage = "Error opening the NetCDF data set using the file \'" + netcdfFile + "\'";
            logger.error(errorMessage);
            throw new RuntimeException(errorMessage);
        }

        // THIS IS WHERE THE PROBLEM OCCURS
        // get the grid based on the associated variable name
        GeoGrid geoGrid = gridDataset.findGridByShortName(variableName);

        // verify that we found the GeoGrid
        if (geoGrid == null)
        {
            String errorMessage = "Error finding the NetCDF grid from the NetCDF file \'" + netcdfFile + "\' using the variable name \'" + variableName + "\'";
            logger.error(errorMessage);
            throw new RuntimeException(errorMessage);
        }

        // more code omitted...
    }

当上面的代码运行并失败时,参数是NetCDF文件名和"pet“,这是NetCDF中的变量名,我们正试图获得相应的网格。

这里出什么问题了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-27 01:54:37

经度和纬度变量的单位看起来很糟糕,这可能会扰乱您显然正在调用的netCDF库代码。你的CDL片段说龙有单位"degrees_north“和lat "degrees_west”。那应该是龙"degrees_east“和"degrees_north”。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38016076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档