0

Using xarray I have subsetted surface current data from the https://resources.marine.coperncus.eu OPeNDAP server. I save the subset as a NetCDF4 file. I am able to add the NetCDF file as a store in GeoServer (2.21.2) but when I try to publish a new layer based on the variables, individually or as a coverage view, a Java Exception is triggered.

The file opens fine in Panoply and NetCDF Tools. The dimensions are longitude, latitude, depth, time, utotal, and vtotal. There is only one depth level.

I've tried multiple iterations of the file: changing the units from ms-1 to m/s, dtype of lat and lon, scaling, among others. A downloaded file of identical data from their ftp site works perfectly.

Any insight?

Below are what I think are the relevant lines of the exception:

java.util.NoSuchElementException
    at java.base/java.util.TreeMap.key(TreeMap.java:1324)
    at java.base/java.util.TreeMap.firstKey(TreeMap.java:289)
    at java.base/java.util.TreeSet.first(TreeSet.java:394)
    at org.geotools.imageio.netcdf.cv.CoordinateVariable$CoordinateAxisGeneralHelper.getMinimum(CoordinateVariable.java:174)
    at org.geotools.imageio.netcdf.cv.CoordinateVariable.getMinimum(CoordinateVariable.java:386)
    at org.geotools.imageio.netcdf.VariableAdapter$UnidataVerticalDomain.getVerticalExtent(VariableAdapter.java:290)
    at org.geotools.coverage.io.netcdf.NetCDFRequest.checkRequest(NetCDFRequest.java:226)
    at org.geotools.coverage.io.netcdf.NetCDFRequest.<init>(NetCDFRequest.java:89)
    at org.geotools.coverage.io.netcdf.NetCDFSource.read(NetCDFSource.java:62)
    at org.geotools.coverage.io.netcdf.NetCDFReader.read(NetCDFReader.java:487)
    at org.geoserver.catalog.SingleGridCoverage2DReader.read(SingleGridCoverage2DReader.java:140)
    at org.geoserver.catalog.CoverageViewReader.read(CoverageViewReader.java:305)
    at org.geoserver.catalog.CoverageViewReader.read(CoverageViewReader.java:833)
    at org.geoserver.catalog.SingleGridCoverage2DReader.read(SingleGridCoverage2DReader.java:147)
    at org.geoserver.catalog.CoverageDimensionCustomizerReader.read(CoverageDimensionCustomizerReader.java:234)
    at org.geoserver.catalog.SingleGridCoverage2DReader.read(SingleGridCoverage2DReader.java:140)
    at org.geoserver.catalog.CatalogBuilder.getCoverageSampleDimensions(CatalogBuilder.java:1219)
    at org.geoserver.catalog.CatalogBuilder.buildCoverageInternal(CatalogBuilder.java:1067)
    at org.geoserver.catalog.CatalogBuilder.buildCoverage(CatalogBuilder.java:988)
    at org.geoserver.catalog.CoverageView.buildCoverageInfo(CoverageView.java:382)
    at org.geoserver.catalog.CoverageView.createCoverageInfo(CoverageView.java:391)
    at org.geoserver.web.data.layer.CoverageViewNewPage.onSave(CoverageViewNewPage.java:58)
    at org.geoserver.web.data.layer.CoverageViewAbstractPage$1.onSubmit(CoverageViewAbstractPage.java:181)

Here is the ncdump output:

    netcdf /forecast_currents_nrtcmems_global.nc {
      dimensions:
        longitude = 4320;
        latitude = 2041;
        depth = 1;
        time = 237;
      variables:
        short utotal(time=237, depth=1, latitude=2041, longitude=4320);
          :_FillValue = -32768S; // short
          :long_name = "Eastward total velocity (Eulerian + Waves + Tide)";
          :standard_name = "surface_sea_water_x_velocity";
          :units = "ms-1";
          :_ChunkSizes = 48U, 1U, 511U, 1080U; // uint
          :scale_factor = 0.001; // double
    
        short vtotal(time=237, depth=1, latitude=2041, longitude=4320);
          :_FillValue = -32768S; // short
          :long_name = "Northward total velocity (Eulerian + Waves + Tide) ";
          :standard_name = "surface_sea_water_y_velocity";
          :units = "ms-1";
          :_ChunkSizes = 48U, 1U, 511U, 1080U; // uint
          :scale_factor = 0.001; // double
    
        float longitude(longitude=4320);
          :least_significant_digit = 3L; // long
          :valid_min = -180.0; // double
          :long_name = "longitude coordinate";
          :standard_name = "longitude";
          :units = "degrees_east";
          :step = 0.08332825; // double
          :_ChunkSizes = 4320U; // uint
    
        float latitude(latitude=2041);
          :least_significant_digit = 3L; // long
          :valid_max = 90.0; // double
          :valid_min = -80.0; // double
          :long_name = "latitude coordinate";
          :standard_name = "latitude";
          :units = "degrees_north";
          :step = 0.08332825; // double
          :_ChunkSizes = 2041U; // uint
    
        float depth(depth=1);
          :_FillValue = NaNf; // float
          :valid_min = 0.494025; // double
          :valid_max = 0.494025; // double
          :long_name = "Depth";
          :standard_name = "depth";
          :units = "m";
          :positive = "down";
    
        double time(time=237);
          :least_significant_digit = 3L; // long
          :long_name = "time";
          :standard_name = "time";
          :step = 1L; // long
          :_ChunkSizes = 1024L; // long
          :units = "hours since 1950-01-01";
          :calendar = "standard";
    
      // global attributes:
      :product = "GLOBAL_ANALYSIS_FORECAST_PHY_001_024";
      :producer = "CMEMS - Global Monitoring and Forecasting Centre";
      :title = "hourly mean merged surface currents from oceanic circulation, tides and waves";
      :area = "GLOBAL";
      :quality_information_document = "http://marine.copernicus.eu/documents/QUID/CMEMS-GLO-QUID-001-024.pdf";
      :Conventions = "CF-1.6";
      :credit = "E.U. Copernicus Marine Service Information (CMEMS)";
      :contact = "[email protected]";
      :references = "http://marine.copernicus.eu";
      :source = "MERCATOR PSY4QV3R1, mfwamglo, FES2014";
      :licence = "http://marine.copernicus.eu/services-portfolio/service-commitments-and-licence/";
      :dataset = "global-analysis-forecast-phy-001-024-hourly-merged-u-v";
      :product_user_manual = "http://marine.copernicus.eu/documents/PUM/CMEMS-GLO-PUM-001-024.pdf";
      :institution = "MERCATOR OCEAN";
      :julian_day_unit = "hours since 1950-01-01 00:00:00";
      :latitude_min = -80L; // long
      :latitude_max = 90.0; // double
      :longitude_min = -180.0; // double
      :longitude_max = 179.91667175293; // double
}

1 Answer 1

0

I can't say exactly what the problem was other than it had to do with the attributes of the 'depth' dimension in the saved NetCDF file from xarray. To make sure all attributes were identical to a similar working NetCDF file I simply copied the attributes from the example file to the new file before saving it. Here is a simplified example of how I accomplished this:

import xarray as xr
nc_example = xr.open_dataset('working_example.nc')
with xr.open_mfdataset('/path_to_files/*.nc') as nc:
    for vrbl in nc.variables.items():
        var_name = vrbl[0]
        nc.variables[var_name].attrs = nc_example.variables[var_name].attrs
nc.to_netcdf('new_file.nc')

Here is the ncdump output after:

netcdf forecast_currents_nrtcmems_global.nc {
  dimensions:
    longitude = 4320;
    latitude = 2041;
    depth = 1;
    time = 32;
  variables:
    short utotal(time=32, depth=1, latitude=2041, longitude=4320);
      :_FillValue = -32768S; // short
      :long_name = "Eastward total velocity (Eulerian + Waves + Tide)";
      :standard_name = "surface_sea_water_x_velocity";
      :units = "ms-1";
      :_ChunkSizes = 11U, 1U, 681U, 1440U; // uint
      :scale_factor = 0.001; // double

    short vtotal(time=32, depth=1, latitude=2041, longitude=4320);
      :_FillValue = -32768S; // short
      :long_name = "Northward total velocity (Eulerian + Waves + Tide) ";
      :standard_name = "surface_sea_water_y_velocity";
      :units = "ms-1";
      :_ChunkSizes = 11U, 1U, 681U, 1440U; // uint
      :scale_factor = 0.001; // double

    float longitude(longitude=4320);
      :valid_min = -180.0f; // float
      :long_name = "longitude coordinate";
      :standard_name = "longitude";
      :units = "degrees_east";
      :step = 0.08332825; // double
      :_ChunkSizes = 4320U; // uint

    float latitude(latitude=2041);
      :valid_max = 90.0f; // float
      :valid_min = -80.0f; // float
      :long_name = "latitude coordinate";
      :standard_name = "latitude";
      :units = "degrees_north";
      :step = 0.08332825; // double
      :_ChunkSizes = 2041U; // uint

    float depth(depth=1);
      :valid_min = 0.494025f; // float
      :valid_max = 0.494025f; // float
      :long_name = "Depth";
      :standard_name = "depth";
      :units = "m";
      :positive = "down";

    double time(time=32);
      :least_significant_digit = 3L; // long
      :long_name = "time";
      :standard_name = "time";
      :step = 1L; // long
      :_ChunkSizes = 1024L; // long
      :units = "hours since 1950-01-01";
      :calendar = "standard";

  // global attributes:
  :product = "GLOBAL_ANALYSIS_FORECAST_PHY_001_024";
  :producer = "CMEMS - Global Monitoring and Forecasting Centre";
  :title = "hourly mean merged surface currents from oceanic circulation, tides and waves";
  :area = "GLOBAL";
  :quality_information_document = "http://marine.copernicus.eu/documents/QUID/CMEMS-GLO-QUID-001-024.pdf";
  :Conventions = "CF-1.6";
  :credit = "E.U. Copernicus Marine Service Information (CMEMS)";
  :contact = "[email protected]";
  :references = "http://marine.copernicus.eu";
  :source = "MERCATOR PSY4QV3R1, mfwamglo, FES2014";
  :licence = "http://marine.copernicus.eu/services-portfolio/service-commitments-and-licence/";
  :dataset = "global-analysis-forecast-phy-001-024-hourly-merged-u-v";
  :product_user_manual = "http://marine.copernicus.eu/documents/PUM/CMEMS-GLO-PUM-001-024.pdf";
  :institution = "MERCATOR OCEAN";
  :julian_day_unit = "hours since 1950-01-01 00:00:00";
  :latitude_min = -80L; // long
  :latitude_max = 90.0; // double
  :longitude_min = -180.0; // double
  :longitude_max = 179.91667175293; // double
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.