Class SpectrumUtils


  • public class SpectrumUtils
    extends adams.data.container.DataContainerUtils
    Utility class for spectrums.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • SpectrumUtils

        public SpectrumUtils()
    • 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 in
        p - 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 in
        waveno - 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 in
        waveno - 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 in
        waveno - 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 on
        lastEnd - 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 on
        start - 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 sign
        start - the wave number to start with
        end - 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 regions
        start - the wave number to start with
        end - the last wave number
        positive - 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 spectrum
        b - 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" spectrum
        b - 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 spectrum
        b - 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" spectrum
        b - 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 fill
        reference - the reference spectrum to get the missing data from
        type - 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 pool
        s - 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 spectrum
        s2 - 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 spectrum
        s2 - the second spectrum
        diff - the spectrum to store the difference
        absolute - 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 pad
        numPoints - the number of points to have at least
        padLeft - whether to pad on the left or right
        waveStepSize - the increment for the wave numbers
        amplitude - the amplitude to use for the padded data points
        Returns:
        the updated copy of the spectrum