我有Java代码,它通过变量名从NetCDF GridDataset获取GeoGrid对象。它通常可以正常工作但是对于我目前需要处理的输入NetCDF文件,我在运行此代码时遇到错误,因为找不到GeoGrid,即使您可以使用其他工具(如ncdump)查看NetCDF数据集中的变量和/或使用调试器单步执行代码时。
我假设NetCDF文件中必定存在某些内容,这会阻止通过查找变量名来获取变量的网格。当我查看NetCDF文件时,我可以看到变量,它在Panoply中显示为Geo2D类型。该文件的ncdump -h输出如下:
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
}
上面描述的文件是否会阻止能够获得与名为" pet"?
的变量关联的GeoGrid以下是使用上述文件作为输入时失败的代码。
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中的变量名,我们正试图获取相应的网格。
有人能说出这里出了什么问题吗?提前谢谢......
答案 0 :(得分:1)
经度和纬度变量的单位看起来很糟糕,这可能会弄乱您显然正在调用的netCDF-Java库代码。你的CDL片段说lon有单位“degrees_north”和lat“degrees_west”。那应该是lon“degrees_east”和lat“degrees_north”。