具有 Java 的 NetCDF:如何使用变量名称查找从 GridDataset 获取 GeoGrid
NetCDF with Java: how to get GeoGrid from GridDataset using variable name lookup
我有 Java 代码,它通过变量名从 NetCDF GridDataset 获取 GeoGrid 对象。它通常可以正常工作,但是对于我当前需要使用的输入 NetCDF 文件,运行此代码时出现错误,因为未找到 GeoGrid,即使您可以使用其他工具(例如 ncdump)在 NetCDF 数据集中看到该变量and/or 使用调试器单步执行代码时。
我假设 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 中的变量名。
这里出了什么问题?
经度和纬度变量的单位看起来很糟糕,这可能会弄乱您显然正在调用的 netCDF-Java 库代码。你的 CDL 片段说 lon 有单位 "degrees_north" 和 lat "degrees_west"。那可能应该是 lon "degrees_east" 和 lat "degrees_north".
我有 Java 代码,它通过变量名从 NetCDF GridDataset 获取 GeoGrid 对象。它通常可以正常工作,但是对于我当前需要使用的输入 NetCDF 文件,运行此代码时出现错误,因为未找到 GeoGrid,即使您可以使用其他工具(例如 ncdump)在 NetCDF 数据集中看到该变量and/or 使用调试器单步执行代码时。
我假设 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 中的变量名。
这里出了什么问题?
经度和纬度变量的单位看起来很糟糕,这可能会弄乱您显然正在调用的 netCDF-Java 库代码。你的 CDL 片段说 lon 有单位 "degrees_north" 和 lat "degrees_west"。那可能应该是 lon "degrees_east" 和 lat "degrees_north".