[netcdf-java] Unable to get a GeoGrid from a GridDataset

I have Java code which gets a GeoGrid object from a NetCDF GridDataset via
the variable name. It normally works correctly but for the input NetCDF
file I currently need to work with I get an error when this code runs, in
that the GeoGrid is not found, even though you can see the variable in the
NetCDF dataset using other tools such as ncdump and/or when stepping
through the code with a debugger.

This code works as expected with other NetCDF files so I assume that there
must be something in the NetCDF file itself which is preventing the fetch
of a variable's grid via a lookup of the variable name. When I view the
NetCDF file I can see the variable and it displays as a Geo2D type in
Panoply. The ncdump -h output for the file is below:

    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
    }

Is there anything about the file described above which would prevent being
able to get a GeoGrid associated with the variable named "pet"? Where is
the code that does this (knowing this might make it simple to find where
this can be fixed on my side)? I assume that there are aspects of a NetCDF
which must be just so before the Java API will create a GeoGrid for a
dataset, and my NetCDF file in this case doesn't satisfy those
requirements. If this is true then what are these requirements, i.e. which
ones am I neglecting to include in the NetCDF?

Below is the code which is failing when using the above file as input.


        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...
        }

When the above code runs and fails the arguments are the NetCDF file name
and "pet" which is the variable name in that NetCDF for which we're trying
to get the corresponding grid.

Can anyone suggest what's going wrong here? Thanks in advance...

​--James​
  • 2016 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: