[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDFJava #DLU-835415]: how to extract a layer vertical item's top and bottom values


Thanks for sending in such a complete support request (sample data AND code 
snippet? Wonderful!).  

To get the information you want, what you really want is to get the 
CoordinateAxis1D object, which is in the GridCoordSystem in the GridDataType. 
I've modified your snippet to get the correct information:

        for (final GridDatatype gridDataType : dataset.getGrids()) {
            GridCoordSystem coordSys = gridDataType.getCoordinateSystem();
            CoordinateAxis1D axis = coordSys.getVerticalAxis();

            // Need to ensure that this is continuous. See:
            double[] bounds = axis.getCoordEdges();

Note that the bounds obtained in this way is the full set of edges for all 
layers, assuming the bounds are continuous (so 5 values for the 4 locations.)
CoordinateAxis1D also has options to get the bound for each layer, as well as 
methods for the top/bottom bounds; for a full breakdown of the API see here: 
The GridDatatype netCDF-java tutorial may also be of interest: 

I hope this helps.

(The bad link to BAMutil was a momentary problem from a bad documentation 
deployment. It should be back up. If this is not the case, please let me know.)


> Dear sir,
> I am using the netcdfAll-4.6 library to decode GRIB2 data, then using the
> decoded info to fill our internal format. The data that I am using has
> 4 layer vertical items, and I need some guidance on how to extract each
> layer's top value and bottom value.  For instance if the layer is "layer
> is 0-0.1m below ground" then I would like to get the values 0.0 and 0.1.
> WGRIB2 inventory on the attached grb2 file:
> 1:0:d=1997122500:TMP:0-0.1 m below ground:anl:
> 2:159205:d=1997122500:TMP:0.1-0.4 m below ground:anl:
> 3:316815:d=1997122500:TMP:0.4-1 m below ground:anl:
> 4:472582:d=1997122500:TMP:1-2 m below ground:anl:
> Z coordinate axis of this file:
> , float depth_below_surface_layer(depth_below_surface_layer=4);
> :units = "m";
> :long_name = "Depth below land surface";
> :positive = "down";
> :Grib_level_type = 106; // int
> :datum = "land surface";
> :bounds = "depth_below_surface_layer_bounds";
> :_CoordinateAxisType = "Height";
> :_CoordinateZisPositive = "down";
> Snippet of my code:
> final GridDataset dataset = GridDataset.open(fname);
> for (final GridDatatype gridDataType : dataset.getGrids()) {
> // Z-dim present, so this can be a LEVEL or LAYER.
> Dimension zdim = gridDataType.getZDimension();
> CoordinateAxis axis = findCoordinateAxis(gridDataType, zdim.getFullName());
> Array levelArray = axis.read();
> List<Float> levels = toListOfFloats(levelArray);
> ...
> }
> I was expecting to see a top value & bottom value per layer, so a
> total of 8 values for the 4 layers. But here the axis.read() returns
> an ArrayFloat$D1 object with only 4 values [0.05, 0.25, 0.7, 1.5] and
> the values do not match those from Wgrib2. Can you spot what I'm doing
> incorrectly here? I am also attaching the grib2 file for you to review.
> Thank you,
> Alice
> PS: the 4.6 javadoc link
> https://www.unidata.ucar.edu/software/thredds/v4.6/netcdf-java/javadocAll/index.html?ucar/nc2/ui/widget/BAMutil.html
> is not up anymore.  If this has moved then please point me to the current url.

Ticket Details
Ticket ID: DLU-835415
Department: Support netCDF Java
Priority: Normal
Status: Closed

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.