Class CoordinateAxis1D

  • All Implemented Interfaces:
    Comparable<Variable>, VariableEnhanced, ProxyReader

    public class CoordinateAxis1D
    extends CoordinateAxis
    A 1-dimensional Coordinate Axis, this is a legacy class, use GridAxis1D for new code. Values must be monotonic. If CHAR valued, it will have rank 2, otherwise it will have rank 1. If String or CHAR valued, only getCoordName() can be called.

    If the coordinates are regularly spaced, isRegular() is true, and the values are equal to getStart() + i * getIncrement().

    This will also set "cell bounds" for this axis. By default, the cell bounds are midway between the coordinates values, and are therefore contiguous, and can be accessed though getCoordEdge(i).

    The only way the bounds can be set is if the coordinate variable has an attribute "bounds" that points to another variable bounds(ncoords,2), containing the cell bounds, and must lie between the coordinate values. In this case isContiguous() is true when bounds1(i+1) == bounds2(i) for all i.

    • Method Detail

      • getCoordName

        public String getCoordName​(int index)
        The "name" of the ith coordinate. If nominal, this is all there is to a coordinate. If numeric, this will return a String representation of the coordinate.
        Parameters:
        index - which one ?
        Returns:
        the ith coordinate value as a String
      • getCoordValue

        public double getCoordValue​(int index)
        Get the ith coordinate value. This is the value of the coordinate axis at which the data value is associated. These must be strictly monotonic.
        Parameters:
        index - which coordinate. Between 0 and getNumElements()-1 inclusive.
        Returns:
        coordinate value.
        Throws:
        UnsupportedOperationException - if !isNumeric()
      • getCoordEdge

        public double getCoordEdge​(int index)
        Get the ith coordinate edge. Exact only if isContiguous() is true, otherwise use getBound1() and getBound2(). This is the value where the underlying grid element switches from "belonging to" coordinate value i-1 to "belonging to" coordinate value i. In some grids, this may not be well defined, and so should be considered an approximation or a visualization hint.

          Coordinate edges must be strictly monotonic:
            coordEdge(0) < coordValue(0) < coordEdge(1) < coordValue(1) ...
            ... coordEdge(i) < coordValue(i) < coordEdge(i+1) < coordValue(i+1) ...
            ... coordEdge(n-1) < coordValue(n-1) < coordEdge(n)
         
        Parameters:
        index - which coordinate. Between 0 and getNumElements() inclusive.
        Returns:
        coordinate edge.
        Throws:
        UnsupportedOperationException - if !isNumeric()
      • getCoordValues

        public double[] getCoordValues()
        Get the coordinate values as a double array.
        Returns:
        coordinate value.
        Throws:
        UnsupportedOperationException - if !isNumeric()
      • getCoordEdges

        public double[] getCoordEdges()
        Get the coordinate edges as a double array. Exact only if isContiguous() is true, otherwise use getBound1() and getBound2().
        Returns:
        coordinate edges.
        Throws:
        UnsupportedOperationException - if !isNumeric()
      • isContiguous

        public boolean isContiguous()
        If the edges are contiguous (true) or disjoint (false). Caution: many datasets do not explicitly specify this info, this is often a guess; default is true.
      • isInterval

        public boolean isInterval()
        If this coordinate has interval values. If so, then one should use getBound1, getBound2, and not getCoordEdges()
        Returns:
        true if coordinate has interval values
      • getBound1

        public double[] getBound1()
        Get the coordinate bound1 as a double array. bound1[i] # coordValue[i] # bound2[i], where # is < if increasing (bound1[i] < bound1[i+1]) else < if decreasing.
        Returns:
        coordinate bound1.
        Throws:
        UnsupportedOperationException - if !isNumeric()
      • getBound2

        public double[] getBound2()
        Get the coordinate bound1 as a double array. bound1[i] # coordValue[i] # bound2[i], where # is < if increasing (bound1[i] < bound1[i+1]) else < if decreasing.
        Returns:
        coordinate bound2.
        Throws:
        UnsupportedOperationException - if !isNumeric()
      • getCoordBounds

        public double[] getCoordBounds​(int i)
        Get the coordinate bounds for the ith coordinate. Can use this for isContiguous() true or false.
        Parameters:
        i - coordinate index
        Returns:
        double[2] edges for ith coordinate
      • findCoordElement

        public int findCoordElement​(double coordVal)
        Given a coordinate value, find what grid element contains it. This means that
         edge[i] ≤ value < edge[i+1] (if values are ascending)
         edge[i] > value ≥ edge[i+1] (if values are descending)
         
        Parameters:
        coordVal - position in this coordinate system
        Returns:
        index of grid point containing it, or -1 if outside grid area
      • findCoordElementBounded

        public int findCoordElementBounded​(double coordVal)
        Given a coordinate position, find what grid element contains it, or is closest to it.
        Parameters:
        coordVal - position in this coordinate system
        Returns:
        index of grid point containing it, or best estimate of closest grid interval.
      • getIncrement

        public double getIncrement()
        Get increment value if isRegular()
        Returns:
        increment value if isRegular()
      • isRegular

        public boolean isRegular()
        If true, then value(i) = getStart() + i * getIncrement().
        Returns:
        if evenly spaced.