Package ucar.nc2.dt.ugrid.utils
Class AsaArrayUtils
java.lang.Object
ucar.nc2.dt.ugrid.utils.AsaArrayUtils
Utilities for manipulating arrays.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic float[]calculateModes(float[] numbers, float fillVal) Returns the statistical mode of the given dataset denoted bynumberswhile ignoring entries whose values matchfillVal.static intclosestPrevious(Long[] myArray, long checkVal, long tolerance) Searches the specified array for any value less thancheckValwithin the tolerance range defined bytolerance.static float[]doubleArrayToFloatArray(double[] in) Converts the given primativedoublearray to a primitivefloatarraystatic float[][]doubleArrayToFloatArray(double[][] in) static doublefindNextHigher(double[] array, double val) static doublefindNextLower(double[] array, double val) static double[]floatArrayToDoubleArray(float[] in) Converts the given primativefloatarray to a primitivedoublearraystatic 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 thanstartand pulling values at an interval denoted byskipstatic booleanisUniformInterval(double[] array) Determines if the members of array are evenly spaced.static booleanisUniformInterval(float[] array) Determines if the members of array are evenly spaced.static booleanisUniformInterval(int[] array) Determines if the members of array are evenly spaced.static booleanisUniformInterval(long[] array) Determines if the members of array are evenly spaced.static double[]leftRightLongitude(double[] array) static intlonQuadrant(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 byoriginalas a two dimensional set with dimension sizes defined bydim1anddim2.
-
Constructor Details
-
AsaArrayUtils
public AsaArrayUtils()
-
-
Method Details
-
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 processpositive- 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. CallsminMax(double[], double)with Double.NaN as the noDataValue.- Parameters:
array-- Returns:
- a double[] where [0]==minimum and [1]==maximum
- See Also:
-
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. CallsminMax(double[], double)with Double.NaN as the noDataValue.- Parameters:
multi-- Returns:
- a double[] where [0]==minimum and [1]==maximum
- See Also:
-
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. CallsminMax(float[], float)with Float.NaN as the noDataValue.- Parameters:
array-- Returns:
- a float[] where [0]==minimum and [1]==maximum
- See Also:
-
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. CallsminMax(float[], float)with Float.NaN as the noDataValue.- Parameters:
multi-- Returns:
- a float[] where [0]==minimum and [1]==maximum
- See Also:
-
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 byoriginalas a two dimensional set with dimension sizes defined bydim1anddim2. The values of this array are then swapped along the newly defined grid and returned as a single dimension array.For example:
Thefloatarray 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- thefloat[]array to be swappeddim1- the horizontal (x) dimension of the grid on whichoriginalwill be swappeddim2- the vertical (y) dimension of the grid on whichoriginalwill 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 bynumberswhile ignoring entries whose values matchfillVal. If multiple values yeild the same frequency of occurance, each of them will be returned.- Parameters:
numbers- afloatarray of numbersfillVal- the "filling" value withinnumbersto 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
Searches the specified array for any value less thancheckValwithin the tolerance range defined bytolerance. Because this returns the first value within range, when closestPrevious() is invoked for the array defined by {5l, 6l, 7l, 8l, 9l} wherecheckVal = 8andtolerance = 2, the index 1 (value 6) will be returned.- Parameters:
myArray- theLongarray within which to searchcheckVal- thelongvalue to search fortolerance- alongrange within which to search for the check value- Returns:
- the index of the value from
myArraywhich is less thencheckvalbut no less thancheckVal - tolerance. If no value is within this tolerance range and less thencheckValor all values ofmyArrayare greater thencheckVal-1 is returned.
-
doubleArrayToFloatArray
public static float[] doubleArrayToFloatArray(double[] in) Converts the given primativedoublearray to a primitivefloatarray- Parameters:
in- a primativedoublearray- Returns:
- a
floatarray equivalent to the specifieddoublearray
-
doubleArrayToFloatArray
public static float[][] doubleArrayToFloatArray(double[][] in) -
floatArrayToDoubleArray
public static double[] floatArrayToDoubleArray(float[] in) Converts the given primativefloatarray to a primitivedoublearray- Parameters:
in- a primativefloatarray- Returns:
- a
doublearray equivalent to the specifiedfloatarray
-
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 thanstartand pulling values at an interval denoted byskip- Parameters:
in- a primative float arraystart- the starting index to begin parsing the given arrayskip- the "skip" interval for parsing values from the array- Returns:
- an array subset from indices
starttoin.lengthat an interval denoted byskip
-