Package adams.data.spectrum
Class SpectrumUtils
- java.lang.Object
-
- adams.data.container.DataContainerUtils
-
- adams.data.spectrum.SpectrumUtils
-
public class SpectrumUtils extends adams.data.container.DataContainerUtils
Utility class for spectrums.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description protected static SpectrumPointComparator
m_Comparator
comparator for finding wavenumbers.
-
Constructor Summary
Constructors Constructor Description SpectrumUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void
add(Hashtable<Float,SpectrumPoint> pool, Spectrum s)
Merges the given spectrum with the current data pool.static int
countRegions(List<SpectrumPoint> points, long start, long end, boolean positive)
Counts the positive or negative regions between the given points (incl.static int
countSignChanges(List<SpectrumPoint> points, long start, long end)
Counts the sign changes in the given data between the given points (incl.static String
diff(Spectrum s1, Spectrum s2, Spectrum diff, boolean absolute)
Computes the difference between two spectra.static Spectrum
fillGaps(Spectrum gaps, Spectrum reference, adams.data.container.DataContainerUtils.GapFilling type)
Fills the gaps in the "gaps" spectrum with the data from the "reference" spectrum and the type of gap-filling.static int
findClosestWaveNumber(List<SpectrumPoint> points, float waveno)
Returns the index in points closest to the given wave number.static int[]
findEnclosingWaveNumbers(List<SpectrumPoint> points, float waveno)
Returns the indices of points in m_Points that enclose the given wave number.static int
findWaveNumber(List<SpectrumPoint> points, float waveno)
Returns the index in points of the given wave number.static int
findWaveNumber(List<SpectrumPoint> points, SpectrumPoint p)
Returns the index in points of the given spectrum point, -1 if not found.static SpectrumPointComparator
getComparator()
Returns the comparator used for finding wave numbers.static Spectrum
getConsecutiveRegion(List<SpectrumPoint> points, SpectrumPoint lastEnd, SpectrumPoint end)
Returns a region for the given range, starting just after the wave number of "lastEnd" and ending (including) at "end".protected static Spectrum
getHeader(List<SpectrumPoint> points)
Creates a header based on the given spectrum points.static List<Spectrum>
getMissingRegions(Spectrum a, Spectrum b)
Returns all the regions that are in "a", but not in "b".static Spectrum
getRegion(List<SpectrumPoint> points, SpectrumPoint start, SpectrumPoint end)
Returns a region for the given range, including both, start and end point.static Spectrum
intersect(Spectrum a, Spectrum b)
Returns a spectrum that contains all the points that are in "a" and in "b".static Spectrum
merge(Spectrum s1, Spectrum s2)
Merges the two spectrums.static Spectrum
merge(List<Spectrum> list)
Merges the given spectrums.static Spectrum
minus(Spectrum a, Spectrum b)
Returns a spectrum that contains all the points that are in "a" but not in "b".static Spectrum
pad(Spectrum data, int numPoints, boolean padLeft, float waveStepSize, float amplitude)
Pads the spectrum either on left or right to have at least the specified number of points.static double[]
toDoubleArray(Spectrum c)
Returns the amplitudes as double array.static double[]
toDoubleArray(List<SpectrumPoint> data)
Returns the amplitudes as double array.static Spectrum
union(Spectrum a, Spectrum b)
Returns the union of the two spectrums "a" and "b".
-
-
-
Field Detail
-
m_Comparator
protected static SpectrumPointComparator m_Comparator
comparator for finding wavenumbers.
-
-
Method Detail
-
getComparator
public static SpectrumPointComparator getComparator()
Returns the comparator used for finding wave numbers.- Returns:
- the comparator
-
getHeader
protected static Spectrum getHeader(List<SpectrumPoint> points)
Creates a header based on the given spectrum points.- Parameters:
points
- the spectrum points to create the header for- Returns:
- the generated header
-
findWaveNumber
public static int findWaveNumber(List<SpectrumPoint> points, SpectrumPoint p)
Returns the index in points of the given spectrum point, -1 if not found.- Parameters:
points
- the vector of spectrum points to search inp
- the point to get the index for- Returns:
- the index or -1 if not found
-
findWaveNumber
public static int findWaveNumber(List<SpectrumPoint> points, float waveno)
Returns the index in points of the given wave number.- Parameters:
points
- the vector of spectrum points to search inwaveno
- the wave number to get the index for- Returns:
- the index
-
findClosestWaveNumber
public static int findClosestWaveNumber(List<SpectrumPoint> points, float waveno)
Returns the index in points closest to the given wave number.- Parameters:
points
- the vector of spectrum points to search inwaveno
- the wave number to get the closest index for- Returns:
- the index
-
findEnclosingWaveNumbers
public static int[] findEnclosingWaveNumbers(List<SpectrumPoint> points, float waveno)
Returns the indices of points in m_Points that enclose the given wave number. If the given wave number happens to be an exact point, then this points will be stored at index 0. If no index could be determined, then -1 will be stored.- Parameters:
points
- the vector of spectrum points to search inwaveno
- the wave number to get the enclosing indices for- Returns:
- the indices
-
getConsecutiveRegion
public static Spectrum getConsecutiveRegion(List<SpectrumPoint> points, SpectrumPoint lastEnd, SpectrumPoint end)
Returns a region for the given range, starting just after the wave number of "lastEnd" and ending (including) at "end".- Parameters:
points
- the spectrum points to work onlastEnd
- the last end point, if null then the first spectrum point will be the first point included.end
- the last point to include in the region, if null then the last point in the data is used.- Returns:
- the generated region
-
getRegion
public static Spectrum getRegion(List<SpectrumPoint> points, SpectrumPoint start, SpectrumPoint end)
Returns a region for the given range, including both, start and end point.- Parameters:
points
- the spectrum points to work onstart
- the starting point, if null the first point in the data is used.end
- the last point to include in the region, if null then the last point in the data is used.- Returns:
- the generated region
-
countSignChanges
public static int countSignChanges(List<SpectrumPoint> points, long start, long end)
Counts the sign changes in the given data between the given points (incl. the borders).- Parameters:
points
- the data to check for changes in signstart
- the wave number to start withend
- the last wave number- Returns:
- the number of changes in sign
-
countRegions
public static int countRegions(List<SpectrumPoint> points, long start, long end, boolean positive)
Counts the positive or negative regions between the given points (incl. the borders).- Parameters:
points
- the data to check for regionsstart
- the wave number to start withend
- the last wave numberpositive
- if true then positive regions are counted otherwise negative ones- Returns:
- the number of positive/negative regions
-
union
public static Spectrum union(Spectrum a, Spectrum b)
Returns the union of the two spectrums "a" and "b". All spectrum points from "a" are used, plus the ones from "b" that are not in "a".- Parameters:
a
- the first spectrumb
- the second spectrum- Returns:
- the union
-
minus
public static Spectrum minus(Spectrum a, Spectrum b)
Returns a spectrum that contains all the points that are in "a" but not in "b". It is assumed that "b" is a subset of "a" and does not contain other wave numbers.- Parameters:
a
- the "full" spectrumb
- the "subset" spectrum- Returns:
- the points missing in "b"
-
intersect
public static Spectrum intersect(Spectrum a, Spectrum b)
Returns a spectrum that contains all the points that are in "a" and in "b". The spectrum points in the result are taken from "a".- Parameters:
a
- the first spectrumb
- the second spectrum- Returns:
- the points in "a" and "b"
-
getMissingRegions
public static List<Spectrum> getMissingRegions(Spectrum a, Spectrum b)
Returns all the regions that are in "a", but not in "b". It is assumed that "b" is a subset of "a" and does not contain other wave numbers.- Parameters:
a
- the "full" spectrumb
- the "subset" spectrum- Returns:
- the missing regions
-
fillGaps
public static Spectrum fillGaps(Spectrum gaps, Spectrum reference, adams.data.container.DataContainerUtils.GapFilling type)
Fills the gaps in the "gaps" spectrum with the data from the "reference" spectrum and the type of gap-filling.- Parameters:
gaps
- the spectrum with gaps to fillreference
- the reference spectrum to get the missing data fromtype
- the type of gap-filling to perform- Returns:
- the processed spectrum (a copy of it)
-
add
protected static void add(Hashtable<Float,SpectrumPoint> pool, Spectrum s)
Merges the given spectrum with the current data pool. New spectrum points don't override ones already in the pool, they only get added.- Parameters:
pool
- the current data pools
- the spectrum to merge with the pool
-
merge
public static Spectrum merge(Spectrum s1, Spectrum s2)
Merges the two spectrums. The header of the first one is used for the output.- Parameters:
s1
- the first spectrums2
- the second spectrum- Returns:
- the merged spectrum
-
merge
public static Spectrum merge(List<Spectrum> list)
Merges the given spectrums. THe header of the first one is used for the output.- Parameters:
list
- the spectrums to merge- Returns:
- the merged spectrum
-
toDoubleArray
public static double[] toDoubleArray(Spectrum c)
Returns the amplitudes as double array.- Parameters:
c
- the spectrum to turn into a double array- Returns:
- the amplitudes as double array
-
toDoubleArray
public static double[] toDoubleArray(List<SpectrumPoint> data)
Returns the amplitudes as double array.- Parameters:
data
- the spectrum points to turn into a double array- Returns:
- the amplitudes as double array
-
diff
public static String diff(Spectrum s1, Spectrum s2, Spectrum diff, boolean absolute)
Computes the difference between two spectra.- Parameters:
s1
- the first spectrums2
- the second spectrumdiff
- the spectrum to store the differenceabsolute
- whether to compute the absolute difference- Returns:
- null if successful, otherwise error message
-
pad
public static Spectrum pad(Spectrum data, int numPoints, boolean padLeft, float waveStepSize, float amplitude)
Pads the spectrum either on left or right to have at least the specified number of points.- Parameters:
data
- the spectrum to padnumPoints
- the number of points to have at leastpadLeft
- whether to pad on the left or rightwaveStepSize
- the increment for the wave numbersamplitude
- the amplitude to use for the padded data points- Returns:
- the updated copy of the spectrum
-
-