gpt4 book ai didi

java - NetCDF 与 Java : how to get GeoGrid from GridDataset using variable name lookup

转载 作者:行者123 更新时间:2023-12-01 09:46:07 40 4
gpt4 key购买 nike

我有 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”,“pet”是我们试图获取相应网格的 NetCDF 中的变量名。

这里出了什么问题?

最佳答案

经度和纬度变量的单位看起来很糟糕,这可能会弄乱您显然正在调用的 netCDF-Java 库代码。您的 CDL 片段显示 lon 的单位为“Degrees_north”,lat 的单位为“Degrees_west”。这可能应该是经度“东度”和纬度“北度”。

关于java - NetCDF 与 Java : how to get GeoGrid from GridDataset using variable name lookup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38016076/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com