Scripting > Math Functions


Snap Irregular Times to Nearest Regular Period


snapToRegularInterval(string timeIntervalString,

      string timeOffsetString,

      string timeBackwardString,

      string timeForwardString )

 

"Snap" data from the current irregular or regular interval time series to form a new regular interval time series of the specified interval and offset.   For example, a time series record from a gauge recorder collects readings 6 minutes past the hour.  The function may be used to “snap” or shift the time points to the top of the hour.

 

The regular interval time of the resultant time series is specified by timeIntervalString.  timeIntervalString is a valid HEC time increment string (e.g. “1MIN”, “15MIN”, “1HOUR”, “6HOUR”,  “1DAY”, “1MONTH”). 

 

Times in the resultant time series may be shifted (offset) from the regular interval time by the increment specified by timeOffsetString.  As an example, the offset could be used to shift times from the top of the hour to instead 6 minutes past the hour. Data from the original time series is "snapped" to the regular interval if the time of the data falls within the time window set by the timeBackwardString and the timeForwardString.  That is, if the new regular interval is at the top of the hour and the time window extends to 9 minutes before the hour and 15 minutes after the hour, an original data point at 0852 would be snapped to the time 0900 while a point at 0916 would be ignored.

 

timeOffsetString, timeBackwardString and timeForwardString are time increment strings expressed as "nT”, where "n" is an integer number and "T" is one of the time increments: "M(INUTES)”, "D(AYS)" or "H(OUR) (characters in the parenthesis are optional).  For the example of the previous paragraph, timeIntervalString would be "1HOUR”, timeOffsetString would be "0M”, timeBackwardString would be "9M" (or "9min") and timeForwardString would be "15M.”   A blank string (“  ”) is equivalent to “0M.”

 

By default values in the resultant regular interval time series data set are set to missing unless matched to times in the current time series data set within the time window tolerance set by timeBackwardString and timeForwardString.

 

Parameters:

timeIntervalString – A string specifying the regular time interval for the resultant time series.

timeOffsetString – A string specifying the offset of the new time points from the regular interval time. This variable may be an empty string (“  ”) or None.

timeBackwardString – A string specifying the time to look backwards from the regular time interval for valid time points.

timeForwardString – A string specifying the time to look forward from the regular time interval for valid time points.

Example:

rtsData = itsData.snapToRegularInterval(

      “1HOUR”,

      None,

      “5Min”,

      “5Min”)

Returns: A new regular interval TimeSeriesMath object.