Package org.esa.snap.core.util.math
Class LookupTable
- java.lang.Object
-
- org.esa.snap.core.util.math.LookupTable
-
public class LookupTable extends Object
The classLookupTable
performs the function of multilinear interpolation for lookup tables with an arbitrary number of dimensions.todo - method for degrading a table (see C++ code below)
-
-
Constructor Summary
Constructors Constructor Description LookupTable(double[] values, double[]... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.LookupTable(double[] values, IntervalPartition... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.LookupTable(float[] values, float[]... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.LookupTable(float[] values, IntervalPartition... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
computeFracIndex(IntervalPartition partition, double coordinate, FracIndex fracIndex)
Computes theFracIndex
of a coordinate value with respect to a given interval partition.double[][]
get2DValuesArray(FracIndex[] fracIndexes)
Returns a matrix of interpolated values for the given fractional indices.IntervalPartition
getDimension(int i)
Returns the the ith dimension associated with the lookup table.int
getDimensionCount()
Returns the number of dimensions associated with the lookup table.IntervalPartition[]
getDimensions()
Returns the dimensions associated with the lookup table.protected int[]
getOffsets()
protected int[]
getStrides()
double
getValue(double... coordinates)
Returns an interpolated value for the given coordinates.double
getValue(double[] coordinates, FracIndex[] fracIndexes, double[] v)
Returns an interpolated value for the given coordinates.double
getValue(FracIndex[] fracIndexes, double[] v)
Returns an interpolated value for the given fractional indices.protected Array
getValues()
double[]
getValues(FracIndex[] fracIndexes)
Returns an array of interpolated values for the given fractional indices.
-
-
-
Constructor Detail
-
LookupTable
public LookupTable(double[] values, IntervalPartition... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.- Parameters:
values
- the lookup values. Thevalues
array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.dimensions
- the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, seeIntervalPartition
.- Throws:
IllegalArgumentException
- if the length of thevalues
array is not equal to the number of coordinate grid vertices.NullPointerException
- if thevalues
array or thedimensions
array isnull
or any dimension isnull
.
-
LookupTable
public LookupTable(float[] values, IntervalPartition... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.- Parameters:
values
- the lookup values. Thevalues
array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.dimensions
- the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, seeIntervalPartition
.- Throws:
IllegalArgumentException
- if the length of thevalues
array is not equal to the number of coordinate grid vertices.NullPointerException
- if thevalues
array or thedimensions
array isnull
or any dimension isnull
.
-
LookupTable
public LookupTable(double[] values, double[]... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.- Parameters:
values
- the lookup values. Thevalues
array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.dimensions
- the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, seeIntervalPartition
.- Throws:
IllegalArgumentException
- if the length of thevalues
array is is not equal to the number of coordinate grid vertices or any dimension is not an interval partion.NullPointerException
- if thevalues
array or thedimensions
array isnull
or any dimension isnull
.
-
LookupTable
public LookupTable(float[] values, float[]... dimensions)
Constructs a lookup table for the lookup values and dimensions supplied as arguments.- Parameters:
values
- the lookup values. Thevalues
array must be laid out in row-major order, so that the dimension associated with the last axis varies fastest.dimensions
- the interval partitions defining the dimensions associated with the lookup table. An interval partition is a strictly increasing sequence of at least two real numbers, seeIntervalPartition
.- Throws:
IllegalArgumentException
- if the length of thevalues
array is is not equal to the number of coordinate grid vertices or any dimension is not an interval partion.NullPointerException
- if thevalues
array or thedimensions
array isnull
or any dimension isnull
.
-
-
Method Detail
-
getDimensionCount
public final int getDimensionCount()
Returns the number of dimensions associated with the lookup table.- Returns:
- the number of dimensions.
-
getDimensions
public final IntervalPartition[] getDimensions()
Returns the dimensions associated with the lookup table.- Returns:
- the dimensions.
-
getStrides
protected int[] getStrides()
-
getOffsets
protected int[] getOffsets()
-
getValues
protected Array getValues()
-
getDimension
public final IntervalPartition getDimension(int i)
Returns the the ith dimension associated with the lookup table.- Parameters:
i
- the index number of the dimension of interest- Returns:
- the ith dimension.
-
getValue
public final double getValue(double... coordinates) throws IllegalArgumentException, NullPointerException
Returns an interpolated value for the given coordinates.- Parameters:
coordinates
- the coordinates of the lookup point.- Returns:
- the interpolated value.
- Throws:
IllegalArgumentException
- if the length of thecoordinates
array is not equal to the number of dimensions associated with the lookup table.NullPointerException
- if thecoordinates
array isnull
.
-
getValue
public final double getValue(double[] coordinates, FracIndex[] fracIndexes, double[] v) throws IllegalArgumentException, IndexOutOfBoundsException, NullPointerException
Returns an interpolated value for the given coordinates.- Parameters:
coordinates
- the coordinates of the lookup point.fracIndexes
- workspace array of (at least) the same length ascoordinates
.v
- workspace array of (at least) length1 << coordinates.length
.- Returns:
- the interpolated value.
- Throws:
ArrayIndexOutOfBoundsException
- if thefracIndexes
andv
arrays do not have proper length.IllegalArgumentException
- if the length of thecoordinates
array is not equal to the number of dimensions associated with the lookup table.NullPointerException
- if any parameter isnull
or exhibits any element, which isnull
.IndexOutOfBoundsException
-
getValue
public final double getValue(FracIndex[] fracIndexes, double[] v)
Returns an interpolated value for the given fractional indices.- Parameters:
fracIndexes
- workspace array of (at least) the same length ascoordinates
.v
- workspace array of (at least) length1 << coordinates.length
.- Returns:
- the interpolated value.
- Throws:
ArrayIndexOutOfBoundsException
- if thefracIndexes
andv
arrays do not have proper length.IllegalArgumentException
- if the length of thecoordinates
array is not equal to the number of dimensions associated with the lookup table.NullPointerException
- if any parameter isnull
or exhibits any element, which isnull
.
-
getValues
public final double[] getValues(FracIndex[] fracIndexes)
Returns an array of interpolated values for the given fractional indices.- Parameters:
fracIndexes
- workspace array of lengthcoordinates - 1
.- Returns:
- the interpolated values.
- Throws:
ArrayIndexOutOfBoundsException
- if thefracIndexes
andv
arrays do not have proper length.IllegalArgumentException
- if the length of thecoordinates
array is not exactly one less than the number of dimensions associated with the lookup table.NullPointerException
- iffracIndexes
isnull
or exhibits any element, which isnull
.
-
get2DValuesArray
public final double[][] get2DValuesArray(FracIndex[] fracIndexes)
Returns a matrix of interpolated values for the given fractional indices.- Parameters:
fracIndexes
- workspace array of lengthcoordinates - 2
.- Returns:
- the interpolated values.
- Throws:
ArrayIndexOutOfBoundsException
- if thefracIndexes
andv
arrays do not have proper length.IllegalArgumentException
- if the length of thecoordinates
array is not exactly two less than the number of dimensions associated with the lookup table.NullPointerException
- iffracIndexes
isnull
or exhibits any element, which isnull
.
-
computeFracIndex
public static void computeFracIndex(IntervalPartition partition, double coordinate, FracIndex fracIndex)
Computes theFracIndex
of a coordinate value with respect to a given interval partition. The integral component of the returnedFracIndex
corresponds to the index of the maximum partition member which is less than or equal to the coordinate value. The [0, 1) fractional component describes the position of the coordinate value within its bracketing subinterval.Exception: If the given coordinate value is equal to the partition maximum, the fractional component of the returned
FracIndex
is equal to 1.0, and the integral component is set to the index of the next to last partition member.- Parameters:
partition
- the interval partition.coordinate
- the coordinate value. If the coordinate value is less (greater) than the minimum (maximum) of the given interval partition, the returnedFracIndex
is the same as if the coordinate. value was equal to the partition minimum (maximum).fracIndex
- theFracIndex
.
-
-