Class AsaArrayUtils


  • public class AsaArrayUtils
    extends Object
    Utilities for manipulating arrays.
    • Constructor Summary

      Constructors 
      Constructor Description
      AsaArrayUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static float[] calculateModes​(float[] numbers, float fillVal)
      Returns the statistical mode of the given dataset denoted by numbers while ignoring entries whose values match fillVal.
      static int closestPrevious​(Long[] myArray, long checkVal, long tolerance)
      Searches the specified array for any value less than checkVal within the tolerance range defined by tolerance.
      static float[] doubleArrayToFloatArray​(double[] in)
      Converts the given primative double array to a primitive float array
      static float[][] doubleArrayToFloatArray​(double[][] in)  
      static double findNextHigher​(double[] array, double val)  
      static double findNextLower​(double[] array, double val)  
      static double[] floatArrayToDoubleArray​(float[] in)
      Converts the given primative float array to a primitive double array
      static double[][] floatArrayToDoubleArray​(float[][] in)  
      static float[] getSubsetArrayFloat​(float[] in, int start, int skip)
      Retrieves a subset of the given array ignoring values with an index lesser than start and pulling values at an interval denoted by skip
      static boolean isUniformInterval​(double[] array)
      Determines if the members of array are evenly spaced.
      static boolean isUniformInterval​(float[] array)
      Determines if the members of array are evenly spaced.
      static boolean isUniformInterval​(int[] array)
      Determines if the members of array are evenly spaced.
      static boolean isUniformInterval​(long[] array)
      Determines if the members of array are evenly spaced.
      static double[] leftRightLongitude​(double[] array)  
      static int lonQuadrant​(double lon)  
      static int[] lonQuadrantCounts​(double[] array)  
      static double[] minMax​(double[] array)
      Determines the minimum and maximum values in the array.
      static double[] minMax​(double[][] multi)
      Determines the minimum and maximum values in the two dimensional array multi.
      static double[] minMax​(double[][] multi, double noDataValue)
      Determines the minimum and maximum values in the two dimensional array multi, ignoring any instances of noDataValue .
      static double[] minMax​(double[] array, double noDataValue)
      Determines the minimum and maximum values in the array, ignoring any instances of noDataValue.
      static float[] minMax​(float[] array)
      Determines the minimum and maximum values in the array.
      static float[] minMax​(float[][] multi)
      Determines the minimum and maximum values in the two dimensional array multi.
      static float[] minMax​(float[][] multi, float noDataValue)
      Determines the minimum and maximum values in the two dimensional array multi, ignoring any instances of noDataValue .
      static float[] minMax​(float[] array, float noDataValue)
      Determines the minimum and maximum values in the array, ignoring any instances of noDataValue.
      static double[] minMaxSigned​(double[] array, boolean positive)
      Get the minimum and maximum values of an array restricting the values to either positive or negative.
      static float[] swapDimensions​(float[] original, int dim1, int dim2)
      Recreates the array specified by original as a two dimensional set with dimension sizes defined by dim1 and dim2.
    • Constructor Detail

      • AsaArrayUtils

        public AsaArrayUtils()
    • Method Detail

      • lonQuadrantCounts

        public static int[] lonQuadrantCounts​(double[] array)
      • lonQuadrant

        public static int lonQuadrant​(double lon)
      • minMaxSigned

        public static double[] minMaxSigned​(double[] array,
                                            boolean positive)
        Get the minimum and maximum values of an array restricting the values to either positive or negative. If positive is true, only positive numbers will be addressed. If positive is false, only negative numbers will be addressed.
        Parameters:
        array - the array to process
        positive - If true, negative numbers are ignored. If false, positive numbers are ignored.
        Returns:
        a double[] where [0]==minimum and [1]==maximum
      • findNextLower

        public static double findNextLower​(double[] array,
                                           double val)
      • findNextHigher

        public static double findNextHigher​(double[] array,
                                            double val)
      • leftRightLongitude

        public static double[] leftRightLongitude​(double[] array)
      • minMax

        public static double[] minMax​(double[] array)
        Determines the minimum and maximum values in the array. Calls minMax(double[], double) with Double.NaN as the noDataValue.
        Parameters:
        array -
        Returns:
        a double[] where [0]==minimum and [1]==maximum
        See Also:
        minMax(double[], double)
      • minMax

        public static double[] minMax​(double[] array,
                                      double noDataValue)
        Determines the minimum and maximum values in the array, ignoring any instances of noDataValue.
        Parameters:
        array -
        noDataValue -
        Returns:
        a double[] where [0]==minimum and [1]==maximum
      • minMax

        public static double[] minMax​(double[][] multi)
        Determines the minimum and maximum values in the two dimensional array multi. Calls minMax(double[], double) with Double.NaN as the noDataValue.
        Parameters:
        multi -
        Returns:
        a double[] where [0]==minimum and [1]==maximum
        See Also:
        minMax(double[][], double)
      • minMax

        public static double[] minMax​(double[][] multi,
                                      double noDataValue)
        Determines the minimum and maximum values in the two dimensional array multi, ignoring any instances of noDataValue .
        Parameters:
        multi -
        noDataValue -
        Returns:
        a double[] where [0]==minimum and [1]==maximum
      • minMax

        public static float[] minMax​(float[] array)
        Determines the minimum and maximum values in the array. Calls minMax(float[], float) with Float.NaN as the noDataValue.
        Parameters:
        array -
        Returns:
        a float[] where [0]==minimum and [1]==maximum
        See Also:
        minMax(float[], float)
      • minMax

        public static float[] minMax​(float[] array,
                                     float noDataValue)
        Determines the minimum and maximum values in the array, ignoring any instances of noDataValue.
        Parameters:
        array -
        noDataValue -
        Returns:
        a float[] where [0]==minimum and [1]==maximum
      • minMax

        public static float[] minMax​(float[][] multi)
        Determines the minimum and maximum values in the two dimensional array multi. Calls minMax(float[], float) with Float.NaN as the noDataValue.
        Parameters:
        multi -
        Returns:
        a float[] where [0]==minimum and [1]==maximum
        See Also:
        minMax(float[][], float)
      • minMax

        public static float[] minMax​(float[][] multi,
                                     float noDataValue)
        Determines the minimum and maximum values in the two dimensional array multi, ignoring any instances of noDataValue .
        Parameters:
        multi -
        noDataValue -
        Returns:
        a float[] where [0]==minimum and [1]==maximum
      • isUniformInterval

        public static boolean isUniformInterval​(int[] array)
        Determines if the members of array are evenly spaced.
        Parameters:
        array -
        Returns:
        true if the members have uniform intervals, false otherwise
      • isUniformInterval

        public static boolean isUniformInterval​(long[] array)
        Determines if the members of array are evenly spaced.
        Parameters:
        array -
        Returns:
        true if the members have uniform intervals, false otherwise
      • isUniformInterval

        public static boolean isUniformInterval​(float[] array)
        Determines if the members of array are evenly spaced.
        Parameters:
        array -
        Returns:
        true if the members have uniform intervals, false otherwise
      • isUniformInterval

        public static boolean isUniformInterval​(double[] array)
        Determines if the members of array are evenly spaced.
        Parameters:
        array -
        Returns:
        true if the members have uniform intervals, false otherwise
      • swapDimensions

        public static float[] swapDimensions​(float[] original,
                                             int dim1,
                                             int dim2)
        Recreates the array specified by original as a two dimensional set with dimension sizes defined by dim1 and dim2. The values of this array are then swapped along the newly defined grid and returned as a single dimension array.

        For example:
        The float array defined by the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} could be swapped by -

        • dimensions 6, 2 yielding {0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11}
        • dimensions 4, 3 yielding {0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11}
        • dimensions 3, 4 yielding {0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}

        Parameters:
        original - the float[] array to be swapped
        dim1 - the horizontal (x) dimension of the grid on which original will be swapped
        dim2 - the vertical (y) dimension of the grid on which original will be swapped
        TODO: there is no prevention for an ArrayOutOfBoundsException when accessing orig[] within the first nested For Loop
      • calculateModes

        public static float[] calculateModes​(float[] numbers,
                                             float fillVal)
        Returns the statistical mode of the given dataset denoted by numbers while ignoring entries whose values match fillVal. If multiple values yeild the same frequency of occurance, each of them will be returned.
        Parameters:
        numbers - a float array of numbers
        fillVal - the "filling" value within numbers to be ignored in determining a statistical mode.
        Returns:
        an array of values which share the same frequency as the highest occuring value from the array numbers
      • closestPrevious

        public static int closestPrevious​(Long[] myArray,
                                          long checkVal,
                                          long tolerance)
        Searches the specified array for any value less than checkVal within the tolerance range defined by tolerance. Because this returns the first value within range, when closestPrevious() is invoked for the array defined by {5l, 6l, 7l, 8l, 9l} where checkVal = 8 and tolerance = 2, the index 1 (value 6) will be returned.
        Parameters:
        myArray - the Long array within which to search
        checkVal - the long value to search for
        tolerance - a long range within which to search for the check value
        Returns:
        the index of the value from myArray which is less then checkval but no less than checkVal - tolerance. If no value is within this tolerance range and less then checkVal or all values of myArray are greater then checkVal -1 is returned.
      • doubleArrayToFloatArray

        public static float[] doubleArrayToFloatArray​(double[] in)
        Converts the given primative double array to a primitive float array
        Parameters:
        in - a primative double array
        Returns:
        a float array equivalent to the specified double array
      • doubleArrayToFloatArray

        public static float[][] doubleArrayToFloatArray​(double[][] in)
      • floatArrayToDoubleArray

        public static double[] floatArrayToDoubleArray​(float[] in)
        Converts the given primative float array to a primitive double array
        Parameters:
        in - a primative float array
        Returns:
        a double array equivalent to the specified float array
      • floatArrayToDoubleArray

        public static double[][] floatArrayToDoubleArray​(float[][] in)
      • getSubsetArrayFloat

        public static float[] getSubsetArrayFloat​(float[] in,
                                                  int start,
                                                  int skip)
        Retrieves a subset of the given array ignoring values with an index lesser than start and pulling values at an interval denoted by skip
        Parameters:
        in - a primative float array
        start - the starting index to begin parsing the given array
        skip - the "skip" interval for parsing values from the array
        Returns:
        an array subset from indices start to in.length at an interval denoted by skip