Package skyview.util

# Class Utilities

java.lang.Object
skyview.util.Utilities

public class Utilities extends Object
utlity functions to use with SkyView

## Constructor Summary

Constructors
Constructor
Description
`Utilities()`

## Method Summary

Modifier and Type
Method
Description
`static double`
`adjustCoordX(double c)`
Ensure that a value is in the region -PI to PI.
`static double`
`adjustCoordY(double c)`
Ensure that a value is in the approrpiate range from -PI/2 to PI/2.
`static double`
`angularDistance(double cx1, double cy1, double cx2, double cy2)`
Calculates angular distance between two points on a sphere.
`static double[]`
`average3dData(double[][] data)`
Average a 2-D array over it's first dimension.
`static double`
`convertNotation(String str)`
Handle exponential notation.
`static double`
`maxInArray(double[] d)`
Find the maximum value of a double array.
`static int`
`maxInArray(int[] d)`
Find the maximum value in an integer array
`static double`
`minInArray(double[] d)`
Find the minimum value of an array.
`static double[]`
`minMaxInArray(double[] d)`
The the extremum values in an array
`static Object`
`newInstance(String cls, String pkg)`
Create an object of a given class.
`static String`
`sexagesimal(double value, int precision)`
Format a sexagesimal coordinate string.
`static int[]`
`whereInArray(double[] d, double searchValue)`
Find the indices of a double array that are equal a given value.
`static int[]`
`whereInArray(double[] d, String operation, double searchValue)`
Find the indices of a double array that satisfy the given criterion.
`static int[]`
`whereNaNInArray(double[] d)`
Find the indices of a double array that are NaNs.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Utilities

public Utilities()

## Method Details

### angularDistance

public static double angularDistance(double cx1, double cy1, double cx2, double cy2)
Calculates angular distance between two points on a sphere. All angles are measured in degrees.

Parameters:
  `cx1` - Longitude like coordinate of first point
  `cy1` - Latitude like coordinate of first point
  `cx2` - Longitude like coordinate of second point
  `cy1` - Latitude like coordinate of second point
Returns:
  distance between the two points in degrees

### minMaxInArray

public static double[] minMaxInArray(double[] d)
The the extremum values in an array

Parameters:
  `d` - An array of doubles
Returns:
  An array with two elements giving the min and max of the array. Returns null if the array is not defined or has zero length.

### maxInArray

public static int maxInArray(int[] d)
Find the maximum value in an integer array

Parameters:
  `d` - Array to be checked
Returns:
  The maximum or the smallest integer value if d is null or of zero length.

### maxInArray

public static double maxInArray(double[] d)
Find the maximum value of a double array.

Parameters:
  `d` - The array to be checked
Returns:
  The maximum value or NaN if the array is undefined or of zero length

### minInArray

public static double minInArray(double[] d)
Find the minimum value of an array.

Parameters:
  `d` - The array to be checked.
Returns:
  The minimum value or NaN if the array is null or of zero length.

### adjustCoordX

public static double adjustCoordX(double c)
Ensure that a value is in the region -PI to PI. This is appropriate for longitude like coordinates.

Parameters:
  `c` - The input value.
Returns:
  The value adjusted to the proper range.

### adjustCoordY

public static double adjustCoordY(double c)
Ensure that a value is in the approrpiate range from -PI/2 to PI/2. This is appropriate for latitude like coordinates. Note that the behavior is appropriate for going 'over' the pole. However, this should really be called in conjunction with the longitude like coordinate. E.g., (using degrees for clarity) we'd want:

    (0, -91) -> (180, -89)

but this only addresses the latitudes.

Parameters:
  `c` - The input value.
Returns:
  The value adjusted to the proper range.

### whereNaNInArray

public static int[] whereNaNInArray(double[] d)
Find the indices of a double array that are NaNs.

Parameters:
  `d` - The array
Returns:
  Array of indices where value is found

### whereInArray

public static int[] whereInArray(double[] d, double searchValue)
Find the indices of a double array that are equal a given value.

Parameters:
  `d` - The array
  `searchValue` - Value searched for.
Returns:
  Array of indices where value is found

### whereInArray

public static int[] whereInArray(double[] d, String operation, double searchValue)
Find the indices of a double array that satisfy the given criterion.

Parameters:
  `d` - The array
  `operation` - Looking for equality, <, or >.
  `searchValue` - Value searched for.
Returns:
  Array of indices where value is found

### convertNotation

public static double convertNotation(String str)
Handle exponential notation.

Parameters:
  `str` - Input string
Returns:
  The string converted to a double precision value.

### sexagesimal

public static String sexagesimal(double value, int precision)
Format a sexagesimal coordinate string.

Parameters:
  `value` - A double precision value which is to be converted to a string representation. The user should convert to hours prior to this call if needed.
  `precision` - A integer value giving the precision to which the value is to be shown.
  <= 0
    Degrees (or hours), e.g. 24
  1
    Deg.f e.g., 24.3
  2
    Deg mm e.g., 24 18
  3
    Deg mm.f e.g., 25 18.3
  4
    Deg mm ss e.g., 25 18 18
  5
    Deg mm ss.s e.g., 25 18 18.2
  6
    Deg mm ss.ss e.g., 25 18 18.24
  >6
    Deg mm ss.sss e.g., 25 18 18.238

### average3dData

public static double[] average3dData(double[][] data)
Average a 2-D array over it's first dimension. The array is assumed to be square. In practice the first dimension will be an energy dimension, while the spatial dimensions will both be incorporated in the second index.

Parameters:
  `data` - The array to be averaged.
Returns:
  The averaged array.

### newInstance

public static Object newInstance(String cls, String pkg)
Create an object of a given class. The input can be a class in a specified package, or a full specified class. We first try to instantiate the object within the specified package, then try it as a fully qualified class.