Class TimeSeries

java.lang.Object
llnl.gnem.core.waveform.seismogram.TimeSeries
All Implemented Interfaces:
Serializable, Cloneable, Comparable<TimeSeries>, SeismicSignal

public class TimeSeries extends Object implements Comparable<TimeSeries>, Serializable, Cloneable, SeismicSignal
See Also:
  • Field Details

  • Constructor Details

    • TimeSeries

      public TimeSeries()
      no-arg constructor only for Serialization
    • TimeSeries

      public TimeSeries(float[] data, double samprate, TimeT time)
    • TimeSeries

      public TimeSeries(BinaryData data, double samprate, TimeT time)
    • TimeSeries

      public TimeSeries(TimeSeries s)
  • Method Details

    • getPeakToPeakAmplitude

      public static double getPeakToPeakAmplitude(float[] data, double sampleInterval, double period)
      Gets the peakToPeakAmplitude attribute of an input timeseries at the specified period. Advances a sliding window of length period through the time series a point at a time. At each position, the Peak-To-Peak range of the current window is computed. The maximum value of all these values is returned.
      Parameters:
      period - The period in seconds at which to compute the value.
      data - An array of floats whose Peak-To-Peak value is to be determined.
      sampleInterval - The sample interval of the data in the data array.
      Returns:
      The maximum Peak-To-Peak value for the array.
    • rotateTraces

      public static <T extends TimeSeries> PairT<T,T> rotateTraces(T seis1, T seis2, double theta)
    • setSampleRateErrorThreshold

      public void setSampleRateErrorThreshold(double value)
    • AddAlignedSeismogram

      public boolean AddAlignedSeismogram(TimeSeries otherseis)
      A method to add this seismogram to another equal length seismogram A check is made to ensure that the epoch times are aligned.
      Parameters:
      otherseis - the other SacSeismogram object
      Returns:
    • AddScalar

      public void AddScalar(double value)
      Add a scalar to the time series of this CssSeismogram
      Specified by:
      AddScalar in interface SeismicSignal
      Parameters:
      value - The scalar value to be added to the time series
    • AddSeismogram

      public boolean AddSeismogram(TimeSeries otherseis)
      A method to add this seismogram to another equal length seismogram Note that the sample rate is not constrained and should be checked if necessary before calling this method
      Parameters:
      otherseis - the other CssSeismogram object
      Returns:
      Returns true if the operation was successful.
    • Log10

      public void Log10()
      Replaces each point in this Seismogram with its log10 value.
      Specified by:
      Log10 in interface SeismicSignal
    • MultiplyScalar

      public void MultiplyScalar(double value)
      Multiply the time series values of this CssSeismogram by a scalar constant.
      Specified by:
      MultiplyScalar in interface SeismicSignal
      Parameters:
      value - The scalar value with which to multiply the time series values
    • RemoveMean

      public void RemoveMean()
      Remove the mean of the time series of this CssSeismogram
      Specified by:
      RemoveMean in interface SeismicSignal
    • RemoveMedian

      public void RemoveMedian()
      Remove the median value of the time series of this CssSeismogram
      Specified by:
      RemoveMedian in interface SeismicSignal
    • SignedSqrt

      public void SignedSqrt()
      Replaces each point in the Seismogram its signed sqrt Note: values LT 0 are returned -1* sqrt(abs(value)).
      Specified by:
      SignedSqrt in interface SeismicSignal
    • SignedSquare

      public void SignedSquare()
      Replaces each point in the Seismogram its signed square value Note: values LT 0 are returned -1* value*value.
      Specified by:
      SignedSquare in interface SeismicSignal
    • Signum

      public void Signum()
      Convert to single bit (+1, -1 or 0)
      Specified by:
      Signum in interface SeismicSignal
    • Smooth

      public void Smooth(int halfwidth)
      Smooth the Seismogram using a sliding window of width halfWidth. replaces the data with it's smoothed result Note halfwidth refers to number of samples, not seconds
      Specified by:
      Smooth in interface SeismicSignal
      Parameters:
      halfwidth - half width in samples.
    • Sqrt

      public void Sqrt()
      Replaces each point in the Seismogram with its sqrt Note: values LT 0 are returned 0.
      Specified by:
      Sqrt in interface SeismicSignal
    • Square

      public void Square()
      Replaces each point in the Seismogram with its square value
      Specified by:
      Square in interface SeismicSignal
    • Taper

      public void Taper(double TaperPercent)
      Apply a cosine taper to the time series of this seismogram
      Specified by:
      Taper in interface SeismicSignal
      Parameters:
      TaperPercent - The (one-sided) percent of the time series to which a taper will be applied. The value ranges from 0 (no taper) to 50 ( The taper extends half the length of the CssSeismogram ). Since the taper is symmetric, a 50% taper means that all but the center value of the CssSeismogram will be scaled by some value less than 1.0.
    • WriteASCIIfile

      public void WriteASCIIfile(String filename) throws IOException
      Throws:
      IOException
    • add

      public TimeSeries add(TimeSeries other)
    • addInPlace

      public void addInPlace(TimeSeries other)
    • addListener

      public void addListener(TimeSeries.SeriesListener listener)
    • append

      public TimeSeries append(TimeSeries other)
    • compareTo

      public int compareTo(TimeSeries other)
      Specified by:
      compareTo in interface Comparable<TimeSeries>
    • computeExtremeStat

      public double computeExtremeStat()
      Specified by:
      computeExtremeStat in interface SeismicSignal
    • contains

      public boolean contains(Epoch epoch, boolean allowGaps)
      Specified by:
      contains in interface SeismicSignal
    • crop

      public TimeSeries crop(Epoch epoch)
    • crop

      public TimeSeries crop(TimeT start, TimeT end)
    • crop

      public TimeSeries crop(int start, int end)
    • cut

      public void cut(TimeT start, TimeT end)
      Truncate the Seismogram to be a subsection of itself. The time interval to which the Seismogram will be cut is specified by the start and end parameters. The Seismogram start time will be adjusted to conform to the new starting time.
      Parameters:
      start - The starting time of the desired subsection. If start is less than the Seismogram begin time, the begin time will be used. If start is GT than the Seismogram endtime, then an IllegalArgumentException will be thrown.
      end - The end time of the desired subsection. If end is GT than the Seismogram end, then the Seismogram end will be used. If end is less than start then an IllegalArgumentException will be thrown.
    • cut

      public void cut(double start, double end)
      Truncate the CssSeismogram to be a subsection of itself. The time interval to which the CssSeismogram will be cut is specified by the start and end parameters. The CssSeismogram start time will be adjusted to conform to the new starting time. Note that, in this method, start and end are in seconds relative to the current Seismogram time
      Parameters:
      start - The start time in seconds after the start of the uncut seismogram
      end - The end time in seconds after the start of the uncut seismogram
    • cut

      public void cut(int idx0, int idx1)
    • cutAfter

      public void cutAfter(TimeT end)
    • cutBefore

      public void cutBefore(TimeT start)
    • decimate

      public void decimate(int decimationfactor)

      Decimate the data (Note this should be interchangeable with the interpolate methods)

      The data series it is decimated so that only every Nth point is retained where N is the decimationfactor

      Note the samprate and number of points in the data series changes
      Parameters:
      decimationfactor - The amount by which to decimate the series.
    • differentiate

      public void differentiate()
      Differentiate the time series of this CssSeismogram. First two points are differentiated using a forward-difference with error Oh2, Last two points using a backward-difference operator with error Oh2. Remaining points differentiated using a central-difference operator with order Oh4 (page 397 - 399 of Applied Numerical Methods for Digital Computation by James et al. ) Must be at least 4 points in series for this to work.
      Specified by:
      differentiate in interface SeismicSignal
    • divide

      public TimeSeries divide(TimeSeries other)
    • Envelope

      public void Envelope()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • fill

      public void fill(float[] buffer, int inc, double start, double end)
    • filter

      public void filter(double lc, double hc)
      Specified by:
      filter in interface SeismicSignal
    • filter

      public void filter(double lc, double hc, boolean twoPass)
      Specified by:
      filter in interface SeismicSignal
    • filter

      public void filter(int order, Passband passband, double cutoff1, double cutoff2, boolean two_pass)
      Description copied from interface: SeismicSignal
      Apply a Butterworth filter to the time series data of this CssSeismogram.
      Specified by:
      filter in interface SeismicSignal
      Parameters:
      order - The order of the filter to be applied
      passband - The passband of the filter. Passband is one of Passband.LOW_PASS, Passband.HIGH_PASS, Passband.BAND_PASS, Passband.BAND_REJECT
      cutoff1 - For BAND_PASS and BAND_REJECT filters this is the low corner of the filter. For HIGH_PASS and LOW_PASS filters, this is the single corner frequency
      cutoff2 - For BAND_PASS and BAND_REJECT filters, this is the high-frequency corner. For other filters, this argument is ignored.
      two_pass - When true, the filter is applied in both forward and reverse directions to achieve zero-phase.
    • findDiscontinuities

      public DiscontinuityCollection findDiscontinuities(int winLength, double factor)
      Specified by:
      findDiscontinuities in interface SeismicSignal
    • getData

      public float[] getData()
      Gets the time-series data of the CssSeismogram as a float array
      Specified by:
      getData in interface SeismicSignal
      Returns:
      The data array
    • getDataBytes

      public int getDataBytes()
    • getDelta

      public double getDelta()
      Specified by:
      getDelta in interface SeismicSignal
    • getDistinctValueRatio

      public double getDistinctValueRatio(int numSamples)
      Specified by:
      getDistinctValueRatio in interface SeismicSignal
    • getEndtime

      public TimeT getEndtime()
      Gets the endtime attribute of the CssSeismogram object
      Specified by:
      getEndtime in interface SeismicSignal
      Returns:
      The endtime value
    • getEndtimeAsDouble

      public double getEndtimeAsDouble()
    • getEpoch

      public Epoch getEpoch()
      Specified by:
      getEpoch in interface SeismicSignal
    • getExtremum

      public float getExtremum()
      Specified by:
      getExtremum in interface SeismicSignal
    • getIdentifier

      public String getIdentifier()
      Specified by:
      getIdentifier in interface SeismicSignal
    • setIdentifier

      public void setIdentifier(String identifier)
      Specified by:
      setIdentifier in interface SeismicSignal
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • getIndexForTime

      public int getIndexForTime(double epochtime)
      Specified by:
      getIndexForTime in interface SeismicSignal
    • getJdate

      public int getJdate()
      Specified by:
      getJdate in interface SeismicSignal
    • getLength

      public int getLength()
      Specified by:
      getLength in interface SeismicSignal
    • getLengthInSeconds

      public double getLengthInSeconds()
      Specified by:
      getLengthInSeconds in interface SeismicSignal
    • getMax

      public float getMax()
      Gets the maximum value of the time series of the CssSeismogram object
      Specified by:
      getMax in interface SeismicSignal
      Returns:
      The max value
    • getMaxTime

      public double[] getMaxTime()
      Gets the maximum value of the series and the time offset it occurs at.
      Specified by:
      getMaxTime in interface SeismicSignal
      Returns:
      The (time offset at the max in seconds, the max value) of the series
    • getMean

      public double getMean()
      Gets the mean value of the time series of the CssSeismogram object
      Specified by:
      getMean in interface SeismicSignal
      Returns:
      The mean value
    • getMedian

      public double getMedian()
      Gets the median value of the time series of the CssSeismogram object
      Specified by:
      getMedian in interface SeismicSignal
      Returns:
      The median value
    • getMin

      public float getMin()
      Gets the minimum value of the time series of the BasicSeismogram object
      Specified by:
      getMin in interface SeismicSignal
      Returns:
      The min value
    • getMinMax

      public MinMax getMinMax()
      Specified by:
      getMinMax in interface SeismicSignal
    • getNormalizedRMSE

      public double getNormalizedRMSE(TimeSeries other)
    • getNsamp

      public int getNsamp()
      Specified by:
      getNsamp in interface SeismicSignal
    • getNseconds

      public double getNseconds()
    • getNyquistFreq

      public double getNyquistFreq()
      Gets the Nyquist Frequency of the CssSeismogram
      Specified by:
      getNyquistFreq in interface SeismicSignal
      Returns:
      The nyquistFreq value
    • getPeakToPeakAmplitude

      public double getPeakToPeakAmplitude(double period)
      Gets the peakToPeakAmplitude attribute of the CssSeismogram's timeseries at the specified period. Advances a sliding window of length period through the time series a point at a time. At each position, the Peak-To-Peak range of the current window is computed. The maximum value of all these values is returned.
      Specified by:
      getPeakToPeakAmplitude in interface SeismicSignal
      Parameters:
      period - The period in seconds at which to compute the value.
      Returns:
      The maximum Peak-To-Peak value for the entire seismogram.
    • getPointsIn

      public int getPointsIn(TimeT start, TimeT end)
      Specified by:
      getPointsIn in interface SeismicSignal
    • getPointsIn

      public int getPointsIn(double timeRange)
      Specified by:
      getPointsIn in interface SeismicSignal
    • getPower

      public double getPower()
      Specified by:
      getPower in interface SeismicSignal
    • getRMS

      public double getRMS()
      Gets the RMS value of the CssSeismogram's time series.
      Specified by:
      getRMS in interface SeismicSignal
      Returns:
      The RMS value
    • getRMSE

      public double getRMSE(TimeSeries other)
    • getRange

      public double getRange()
      Gets the range of the time series
      Specified by:
      getRange in interface SeismicSignal
      Returns:
      The statistical range for all values in the data
    • getRange

      public double getRange(Epoch epoch)
    • getSamprate

      public double getSamprate()
      Gets the samprate attribute of the CssSeismogram object
      Specified by:
      getSamprate in interface SeismicSignal
      Returns:
      The samprate value
    • getSegmentLength

      public double getSegmentLength()
      Gets the segment Length in seconds of the CssSeismogram object
      Specified by:
      getSegmentLength in interface SeismicSignal
      Returns:
      The segmentLength value
    • getSnr

      public double getSnr(double pickEpochTime, double preSeconds, double postSeconds)
      Specified by:
      getSnr in interface SeismicSignal
    • getSnr

      public double getSnr(double pickEpochTime, Epoch epoch, double preSeconds, double postSeconds)
      Specified by:
      getSnr in interface SeismicSignal
    • getStDev

      public double getStDev()
      Gets the variance of the time series of the CssSeismogram object
      Specified by:
      getStDev in interface SeismicSignal
      Returns:
      The variance value
    • getStatistics

      public SampleStatistics getStatistics()
    • getSubSection

      public float[] getSubSection(TimeT start, TimeT end)
      Gets a float array which is a subsection of the Seismogram's time series. The start and end times must be within the Seismogram's time window or an IllegalArgument exception will be thrown
      Parameters:
      start - the starting time of the subsection
      end - the ending time of the subsection
      Returns:
      the subsection float[] array
    • getSubSection

      public float[] getSubSection(TimeT start, TimeT end, float[] result)
    • getSubSection

      public float[] getSubSection(TimeT start, double duration)
      Gets a float array which is a subsection of the CssSeismogram's time series. The subsection starts at time start (presumed to be within the CssSeismogram's time series) and has a length of duration.
      Parameters:
      start - The starting time of the subsection.
      duration - The duration in seconds of the subsection.
      Returns:
      The subSection array
    • getSubSection

      public float[] getSubSection(double startEpoch, double requesteduration)
      Gets a float array which is a subsection of the CssSeismogram's time series. The subsection starts at time start (presumed to be within the CssSeismogram's time series) and has a length of duration.
      Parameters:
      startEpoch - The starting time expressed as a double epoch time.
      requesteduration - The duration in seconds of the subsection.
      Returns:
      The subSection array
    • getSubSection

      public float[] getSubSection(double startEpoch, double requestedDuration, float[] result)
    • getSubSection

      public float[] getSubSection(int startIndex, int sampsRequired)
      Get subsection explicitly using the data indices
      Parameters:
      startIndex -
      sampsRequired -
      Returns:
    • getSubsectionStartTime

      public double getSubsectionStartTime(double startEpoch)
    • getSum

      public double getSum()
      Gets the sum of the time series values of this CssSeismogram
      Specified by:
      getSum in interface SeismicSignal
      Returns:
      The sum of the time series values
    • getTime

      public TimeT getTime()
      Gets the start time of the CssSeismogram as a TimeT object
      Specified by:
      getTime in interface SeismicSignal
      Returns:
      The time value
    • getTimeAsDouble

      public double getTimeAsDouble()
      Gets the start time of the CssSeismogram as a double holding the epoch time of the start.
      Specified by:
      getTimeAsDouble in interface SeismicSignal
      Returns:
      The CssSeismogram start epoch time value
    • getValueAt

      public float getValueAt(double epochtime)
      Get the value at a specific point in time
      Specified by:
      getValueAt in interface SeismicSignal
      Parameters:
      epochtime - The time expressed as a double epoch time.
      Returns:
      the value at the requested time
    • getValueAt

      public float getValueAt(int j)
    • getVariance

      public double getVariance()
      Gets the variance of the time series of the CssSeismogram object
      Specified by:
      getVariance in interface SeismicSignal
      Returns:
      The variance value
    • hasFlatSegments

      public boolean hasFlatSegments(int minsegmentlength)
      Check whether the data series has flat segments - where every element of the segment is identical
      Parameters:
      minsegmentlength - the shortest number of datapoints that must be identical before it qualifies as "flat"
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • interpolate

      public void interpolate(double newsamprate)
      Interpolate the data
      Parameters:
      newsamprate - is the new sample rate (Hz)

      Note the samprate changes and the number of points in the data series changes based on the new desired sample rate

    • isConstant

      public boolean isConstant()
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface SeismicSignal
    • isSubset

      public boolean isSubset(TimeSeries other)
    • multiply

      public TimeSeries multiply(TimeSeries other)
    • normalize

      public void normalize()
      Specified by:
      normalize in interface SeismicSignal
    • normalize

      public void normalize(TimeSeries.Norm norm)
      Normalize all the seismograms Usage : 'normalize', 'normalize (value)' or 'normalize (type)' where (type) is 'mean' 'min' or 'max' Traces are initially demeaned then scaled default - each trace is multiplied by abs(1/extremum) value - where value is a number - the traces are normalized so that the absolute value of the extremum equals the value entered mean - traces are multiplied by the mean of the absolute values of the trace min - traces are multiplied by -1/min max - traces are multiplied by 1/max
      Parameters:
      norm -
    • normalize

      public void normalize(double value)
    • normalize

      public void normalize(String value)
      Normalize the seismogram based on String input 1. Attempt to parse as a Double valued number and use normalize(double) 2. Attempt to parse as a Norm object and use normalize(Norm) 3. do nothing if neither 1 or 2 passes
      Parameters:
      value - a String containing either a number or a Norm type e.g. normalize("10") or normalize("EXTREMUM")
    • onModify

      public void onModify()
    • quickMedian

      public double quickMedian()
      Computed the median in O(n) time in contrast to standard O(n lg n) time. The only tradeoff is that the median is not the average of the two center points for series with even length. Rather, the median is arbitrarily selected from amongst one of those two approximate centers.
      Specified by:
      quickMedian in interface SeismicSignal
      Returns:
      The median or pseudo-median for even length series
    • rateIsComparable

      public boolean rateIsComparable(TimeSeries other)
      Performs a check to see if the sample rates of two timeseries is close enough to equal.
      Parameters:
      other - the other timeseries to compare this one with
      Returns:
      true if the sample rates are close enough
    • removeGlitches

      public void removeGlitches(double Threshhold)

      Remove glitches from the seismogram where glitches are defined by data that exceed a threshhold above the variance defined by a moving window

      value = Math.abs((data[j] - median)); if (value GT Threshhold * Math.sqrt(variance)) replace data[j] with the median value
      Specified by:
      removeGlitches in interface SeismicSignal
      Parameters:
      Threshhold - - the threshhold value
    • removeListener

      public void removeListener(TimeSeries.SeriesListener listener)
    • removeTrend

      public void removeTrend()
      Remove a linear trend from the time series data of this CssSeismogram.
      Specified by:
      removeTrend in interface SeismicSignal
    • resample

      public void resample(double newRate)
    • reverse

      public void reverse()
      Reverse the data series. This method is used in cross correlation routines. Note none of the times are being reset. The user must be careful to understand the implications
      Specified by:
      reverse in interface SeismicSignal
    • reverseAt

      public void reverseAt(TimeT mirrorTime)
    • scaleTo

      public void scaleTo(double min, double max)
      Specified by:
      scaleTo in interface SeismicSignal
    • setData

      public void setData(float[] v)
      Sets the data array of the CssSeismogram object
      Parameters:
      v - The new data value
    • setDataPoint

      public void setDataPoint(float v, int index)
      Sets the value of the data at a particular point to a value
      Parameters:
      v -
      index -
    • setDataPoints

      public void setDataPoints(float[] v, int startindex)
      Sets the data at a collection of points
      Parameters:
      v -
      startindex -
    • setMaximumRange

      public void setMaximumRange(double maxRange)
      Specified by:
      setMaximumRange in interface SeismicSignal
    • setSamprate

      public void setSamprate(double samprate)
      Specified by:
      setSamprate in interface SeismicSignal
    • setTime

      public void setTime(TimeT v)
      Sets the time attribute of the CssSeismogram object
      Parameters:
      v - The new time value
    • shift

      public TimeSeries shift(int samples)
      Shifts the values of this time series by the number of specified samples and returns the result as a new time series. this method also modifies the origin time of the new time series as appropriate.
      Parameters:
      samples - The number of samples to shift. a value less than 0 shifts data left, and greater than 0 shifts data right.
      Returns:
      a new timeseries, based on this one, shifted by the specified number of samples. The new time series will have a length different than that of this instance.
    • shift

      public TimeSeries shift(int samples, boolean keepLength)
      Shifts the values of this time series by the number of specified samples and returns the result as a new time series. this method also modifies the origin time of the new time series as appropriate.
      Parameters:
      samples - The number of samples to shift. a value less than 0 shifts data left, and greater than 0 shifts data right.
      keepLength - should the original time series data length remain unchanged regardless of shift?
      Returns:
      a new timeseries, based on this one, shifted by the specified number of samples
    • stretch

      public void stretch(double interpolationfactor)
    • subtract

      public TimeSeries subtract(TimeSeries other)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • triangleTaper

      public void triangleTaper(double taperPercent)
      Specified by:
      triangleTaper in interface SeismicSignal
    • trim

      public TimeSeries trim()
    • trimTo

      public void trimTo(Epoch epoch)
    • union

      public TimeSeries union(TimeSeries other, boolean ignoreMismatch) throws MergeException
      Throws:
      MergeException
    • doNormalize

      protected void doNormalize(double scale)
    • intersect

      protected TimeSeries intersect(TimeSeries other, TimeSeries.BivariateFunction f)
    • getZeroTimeOffsetSeconds

      public double getZeroTimeOffsetSeconds()
      Description copied from interface: SeismicSignal
      This method returns what the zero time offset of the series is for this segment. This should define where your time axis should set 0 at in the trace relative to the begin time of the segment.
      Specified by:
      getZeroTimeOffsetSeconds in interface SeismicSignal
      Returns:
      double Offset defining time in seconds that the segment should be shifted.
    • setZeroTimeOffsetSeconds

      public void setZeroTimeOffsetSeconds(double timeOffset)
      Description copied from interface: SeismicSignal
      This method sets what the zero time offset of the series is for this segment. This should define where your time axis should set 0 at in the trace relative to the begin time of the segment.
      Specified by:
      setZeroTimeOffsetSeconds in interface SeismicSignal
      Parameters:
      timeOffset - Offset defining time in seconds that the segment should be shifted.