org.virbo.dataset
Class DataSetUtil

java.lang.Object
  extended by org.virbo.dataset.DataSetUtil

public class DataSetUtil
extends java.lang.Object


Constructor Summary
DataSetUtil()
           
 
Method Summary
static void addQube(MutablePropertyDataSet ds)
          add QUBE property to dataset, maybe verifying that it is a qube.
static int binarySearch(QDataSet ds, double key, int low, int high)
          perform a binary search for key within ds, constraining the search to between low and high.
static WritableDataSet canonizeFill(QDataSet ds)
          Iterate through the dataset, changing all points outside of validmin, validmax and with zero weight to fill=-1e31.
static int closest(QDataSet ds, double d, int guess)
          return the index of the closest value in ds to d, using guess as a starting point.
static java.lang.String format(QDataSet ds)
           
static java.util.Map<java.lang.String,java.lang.Object> getProperties(QDataSet ds)
          gets all the properties of the dataset.
static java.util.Map<java.lang.String,java.lang.Object> getProperties(QDataSet ds, java.util.Map def)
          gets all the properties of the dataset.
static double guessCadence(QDataSet xds)
          calculate cadence by averaging the smallest set of consistent inter-point distance.
static double guessCadence(QDataSet xds, QDataSet yds)
          calculate cadence by averaging consistent inter-point distances, taking invalid measurements into account.
static MutablePropertyDataSet indexGenDataSet(int n)
          creates a dataset of integers 0,1,2,...,n-1.
static boolean isMonotonic(QDataSet ds)
          returns true if the dataset is monotonically increasing, and contains no fill.
static boolean isQube(QDataSet ds)
          test to see that the dataset is a qube.
static java.lang.String[] propertyNames()
           
static void putProperties(java.util.Map<java.lang.String,java.lang.Object> properties, MutablePropertyDataSet ds)
          copy all properties into the dataset by iterating through the map.
static int[] qubeDims(QDataSet ds)
          provides a convenient way of indexing qubes, returning an int[] of length ds.rank() containing each dimension's length, or null if the dataset is not a qube.
static MutablePropertyDataSet replicateDataSet(int n, double value)
          creates a dataset with the given cadence, start and length.
static java.lang.String statsString(QDataSet ds)
          return a human readable statistical representation of the dataset.
static MutablePropertyDataSet tagGenDataSet(int n, double start, double cadence)
          creates a dataset with the given cadence, start and length.
static java.lang.String toString(QDataSet ds)
          cleans up code by doing the cast, and handles default value
static boolean validate(QDataSet ds, java.util.List<java.lang.String> problems)
          returns true if the dataset is valid, false otherwise.
static QDataSet weightsDataSet(QDataSet ds)
          Provide consistent valid logic to operators by providing a QDataSet with 1.0 where the data is valid, and 0.0 where the data is invalid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSetUtil

public DataSetUtil()
Method Detail

indexGenDataSet

public static MutablePropertyDataSet indexGenDataSet(int n)
creates a dataset of integers 0,1,2,...,n-1.


tagGenDataSet

public static MutablePropertyDataSet tagGenDataSet(int n,
                                                   double start,
                                                   double cadence)
creates a dataset with the given cadence, start and length.


replicateDataSet

public static MutablePropertyDataSet replicateDataSet(int n,
                                                      double value)
creates a dataset with the given cadence, start and length.


isMonotonic

public static boolean isMonotonic(QDataSet ds)
returns true if the dataset is monotonically increasing, and contains no fill. An empty dataset is monotonic.


binarySearch

public static int binarySearch(QDataSet ds,
                               double key,
                               int low,
                               int high)
perform a binary search for key within ds, constraining the search to between low and high.

Parameters:
ds - a rank 1 monotonic dataset.
key - the value to find.
low -
high -
Returns:
a positive index of the found value or -index-1 the insertion point.

closest

public static int closest(QDataSet ds,
                          double d,
                          int guess)
return the index of the closest value in ds to d, using guess as a starting point. This implementation ignores guess, but wise clients will supply it as a parameter.

Parameters:
ds - a rank 1, monotonic dataset.
d - the value to find.
guess - a guess at a close index, or -1 if no guess should be made. In this case, a binary search is performed.
Returns:
index of the closest.

propertyNames

public static java.lang.String[] propertyNames()

getProperties

public static java.util.Map<java.lang.String,java.lang.Object> getProperties(QDataSet ds,
                                                                             java.util.Map def)
gets all the properties of the dataset. This is a shallow copy of properties.


getProperties

public static java.util.Map<java.lang.String,java.lang.Object> getProperties(QDataSet ds)
gets all the properties of the dataset. This is a shallow copy of properties.


putProperties

public static void putProperties(java.util.Map<java.lang.String,java.lang.Object> properties,
                                 MutablePropertyDataSet ds)
copy all properties into the dataset by iterating through the map.


toString

public static java.lang.String toString(QDataSet ds)
cleans up code by doing the cast, and handles default value


guessCadence

public static double guessCadence(QDataSet xds,
                                  QDataSet yds)
calculate cadence by averaging consistent inter-point distances, taking invalid measurements into account. This number needs to be interpretted in the context of the dataset, for example using the properties UNITS and SCALE_TYPE. If SCALE_TYPE is "log", then this number should be interpreted as the ratiometric spacing in natural log space. Math.log( xds.value(1) ) - Math.log( xds.value(0) ) or Math.log( xds.value(1) / xds.value(0) )


guessCadence

public static double guessCadence(QDataSet xds)
calculate cadence by averaging the smallest set of consistent inter-point distance. Assumes all points are valid. This number needs to be interpretted in the context of the dataset, for example using the properties UNITS and SCALE_TYPE. If SCALE_TYPE is "log", then this number should be interpreted as the ratiometric spacing in natural log space. Math.log( xds.value(1) ) - Math.log( xds.value(0) ) or Math.log( xds.value(1) / xds.value(0) )


isQube

public static boolean isQube(QDataSet ds)
test to see that the dataset is a qube.

Parameters:
ds - QDataSet of any rank.
Returns:
true if the dataset is a qube.

qubeDims

public static int[] qubeDims(QDataSet ds)
provides a convenient way of indexing qubes, returning an int[] of length ds.rank() containing each dimension's length, or null if the dataset is not a qube.

Parameters:
ds -
Returns:
int[] of length ds.rank() containing each dimension's length, or null if the dataset is not a qube.

addQube

public static void addQube(MutablePropertyDataSet ds)
                    throws java.lang.IllegalArgumentException
add QUBE property to dataset, maybe verifying that it is a qube. This is intended to reduce code that builds datasets, not to verify that a dataset is a qube.

Parameters:
ds -
Throws:
java.lang.IllegalArgumentException - if the dataset is not a qube

format

public static java.lang.String format(QDataSet ds)

statsString

public static java.lang.String statsString(QDataSet ds)
return a human readable statistical representation of the dataset. Currently this is the mean, stddev ad number of points.

Parameters:
ds -
Returns:

validate

public static boolean validate(QDataSet ds,
                               java.util.List<java.lang.String> problems)
returns true if the dataset is valid, false otherwise. If problems is non-null, then problems will be indicated here.

Parameters:
ds - rank N dataset.
problems - insert problem descriptions here
Returns:
true if the dataset is valid, false otherwise

weightsDataSet

public static QDataSet weightsDataSet(QDataSet ds)
Provide consistent valid logic to operators by providing a QDataSet with 1.0 where the data is valid, and 0.0 where the data is invalid. VALID_MIN, VALID_MAX and FILL_VALUE properties are used. Note, when FILL_VALUE is not specified, -1e31 is used. This is to support legacy logic. For convenience, the property FILL_VALUE is set to the fill value used.


canonizeFill

public static WritableDataSet canonizeFill(QDataSet ds)
Iterate through the dataset, changing all points outside of validmin, validmax and with zero weight to fill=-1e31. VALID_MIN and VALID_MAX properties are cleared, and FILL_VALUE is set to -1e31.

Parameters:
ds - rank N QUBE dataset.
Returns:
ds with same geometry as ds.