Class CdmUtils


  • public final class CdmUtils
    extends Object
    Contains static helper methods for reading data and metadata from NetCDF files, OPeNDAP servers and other data sources using the Unidata Common Data Model.
    Author:
    Jon Blower, Guy Griffiths, Mike Grant, Plymouth Marine Labs
    • Method Detail

      • getGridDataset

        public static ucar.nc2.dt.grid.GridDataset getGridDataset​(ucar.nc2.dataset.NetcdfDataset ncDataset)
                                                           throws DataReadingException,
                                                                  IOException
        Parameters:
        ncDataset - The NetcdfDataset to get a GridDataset from
        Returns:
        A GridDataset from the given NetcdfDataset
        Throws:
        DataReadingException - If the given NetcdfDataset doesn't contain any GridDatasets
        IOException
      • getOptimumDataReadingStrategy

        public static DataReadingStrategy getOptimumDataReadingStrategy​(ucar.nc2.dataset.NetcdfDataset nc)
        Estimates the optimum DataReadingStrategy from the given NetcdfDataset. Essentially, if the data are remote (e.g. OPeNDAP) or compressed, this will return DataReadingStrategy.BOUNDING_BOX, which makes a single i/o call, minimizing the overhead. If the data are local and uncompressed this will return DataReadingStrategy.SCANLINE, which reduces the amount of data read.
        Parameters:
        nc - The NetcdfDataset from which data will be read.
        Returns:
        an optimum DataReadingStrategy for reading from the dataset
      • createHorizontalGrid

        public static HorizontalGrid createHorizontalGrid​(ucar.nc2.dt.GridCoordSystem coordSys)
        Parameters:
        coordSys - The GridCoordSystem to create a HorizontalGrid from
        Returns:
        two-dimensional referenceable grid from the given grid coordinate system. Will return more specific subclasses ( RectilinearGrid or RegularGrid) if appropriate for the passed-in coordinate system. The grid's coordinate system will be a WGS84 longitude-latitude system. TODO May want to be careful about datum shifts - model data is often in spherical coordinates, not strict WGS84
      • get2DCoordinateValues

        public static Array2D<Number> get2DCoordinateValues​(ucar.nc2.dataset.CoordinateAxis2D axis)
      • createVerticalAxis

        public static VerticalAxis createVerticalAxis​(ucar.nc2.dataset.CoordinateAxis1D zAxis,
                                                      boolean isPositive)
        Parameters:
        zAxis - the CoordinateAxis1D to create a VerticalAxis from
        isPositive - Whether increasing values
        Returns:
        The resulting VerticalAxis
      • createTimeAxis

        public static TimeAxis createTimeAxis​(ucar.nc2.dataset.CoordinateAxis1DTime timeAxis)
        Creates a time axis from the given GridCoordSystem
        Parameters:
        timeAxis - the CoordinateAxis1DTime defining the axis
        Returns:
        a new TimeAxis
      • createReferenceableAxis

        public static ReferenceableAxis<Double> createReferenceableAxis​(ucar.nc2.dataset.CoordinateAxis1D axis)
        Creates a ReferenceableAxis from the given CoordinateAxis1D. Creates a longitude axis if axis.getAxisType()==AxisType.Lon.
        Parameters:
        axis - The CoordinateAxis1D to convert to a ReferenceableAxis
        Returns:
        An equivalent ReferenceableAxis
      • createReferenceableAxis

        public static ReferenceableAxis<Double> createReferenceableAxis​(ucar.nc2.dataset.CoordinateAxis1D axis,
                                                                        boolean isLongitude)
        Creates a ReferenceableAxis from the given CoordinateAxis1D.
        Parameters:
        axis - The CoordinateAxis1D to convert to a ReferenceableAxis
        isLongitude - true if this is a longitude axis (i.e. wraps at 360 degrees).
        Returns:
        The equivalent ReferenceableAxis
      • expandGlobExpression

        public static List<File> expandGlobExpression​(String globExpression)
        Expands a glob expression to give a List of paths to files. This method recursively searches directories, allowing for glob expressions like "c:\\data\\200[6-7]\\*\\1*\\A*.nc".
        Parameters:
        globExpression - The expression to expand
        Returns:
        a List of Files matching the given glob expression