bart.common.Utils module

Utility functions for sheye

bart.common.Utils.area_under_curve(series, sign=None, method='trapz', step='post')[source]

Return the area under the time series curve (Integral)

Parameters:
  • series (pandas.Series) – The time series to be integrated
  • sign (str) –

    Clip the data for the area in positive or negative regions. Can have two values

    • “+”
    • “-“
  • method – The method for area calculation. This can be any of the integration methods supported in numpy or rect
  • step (str) – The step behaviour for rect method

Rectangular Method

  • Step: Post

    Consider the following time series data

    2            *----*----*----+
                 |              |
    1            |              *----*----+
                 |
    0  *----*----+
       0    1    2    3    4    5    6    7
    
    import pandas as pd
    a = [0, 0, 2, 2, 2, 1, 1]
    s = pd.Series(a)
    

    The area under the curve is:

    \[\begin{split}\sum_{k=0}^{N-1} (x_{k+1} - {x_k}) \times f(x_k) \\ (2 \times 3) + (1 \times 2) = 8\end{split}\]
  • Step: Pre

    2       +----*----*----*
            |              |
    1       |              +----*----*----+
            |
    0  *----*
       0    1    2    3    4    5    6    7
    
    import pandas as pd
    a = [0, 0, 2, 2, 2, 1, 1]
    s = pd.Series(a)
    

    The area under the curve is:

    \[\begin{split}\sum_{k=1}^{N} (x_k - x_{k-1}) \times f(x_k) \\ (2 \times 3) + (1 \times 3) = 9\end{split}\]
bart.common.Utils.init_ftrace(trace)[source]

Initialize the FTrace Object

Parameters:trace (str, trappy.ftrace.FTrace) – Path for the trace file or a trace object
bart.common.Utils.interval_sum(series, value=None, step='post')[source]

A function that returns the sum of the intervals where the value of series is equal to the expected value. Consider the following time series data:

Time Value
0 0
1 0
2 1
3 1
4 1
5 1
8 0
9 1
10 0
11 1
12 1

Note

The time/index values, in general, may not be uniform. This causes difference in the the values of interval_sum() for step-pre and step-post behaviours

import pandas

values = [0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1]
index = [0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12]
series = pandas.Series(values, index=index)

The interval_sum() for the value 1 is calculated differently for step-post and step-pre behaviours as follows:

  • Step-Post

    1            *----*----*----*-------------+    *----+    *----*
                 |                            |    |    |    |
    0  *----*----+                            *----+    *----+
       0    1    2    3    4    5    6    7   8    9    10   11   12
    
    \[(8-2) + (10-9) + (12-11) = 6 + 1 + 1 = 8\]
  • Step-Pre

    1       +----*----*----*----*              +----*    +----*----*
            |                   |              |    |    |
    0  *----*                   +--------------*    +----*
       0    1    2    3    4    5    6    7    8    9    10   11   12
    
    \[(5-1) + (9-8) + (12-10) = 4 + 1 + 2 = 7\]

Note

The asterisks (*) on the plots above represent the values of the time series data and these do not vary between the two step styles

Parameters:
  • series (pandas.Series) – The time series data
  • value (element) – The value to checked for in the series. If the value is None, the truth value of the elements in the series will be used
  • step (str) –

    The step behaviour as described above

    step="post"
    step="pre
    
bart.common.Utils.listify(to_select)[source]

Utitlity function to handle both single and list inputs

bart.common.Utils.select_window(series, window)[source]

Helper Function to select a portion of pandas time series

Parameters:
  • series (pandas.Series) – Input Time Series data
  • window (tuple) – A tuple indicating a time window