pecos.utils module

The utils module contains helper functions.

pecos.utils.index_to_datetime(index, unit='s', origin='unix')[source]

Convert DataFrame index from int/float to datetime, rounds datetime to the nearest millisecond

Parameters:
  • index (pandas Index) – DataFrame index in int or float

  • unit (str, optional) – Units of the original index

  • origin (str) – Reference date used to define the starting time. If origin = ‘unix’, the start time is ‘1970-01-01 00:00:00’ The origin can also be defined using a datetime string in a similar format (i.e. ‘2019-05-17 16:05:45’)

Returns:

pandas Index – DataFrame index in datetime

pecos.utils.datetime_to_elapsedtime(index, origin=0.0)[source]

Convert DataFrame index from datetime to elapsed time in seconds

Parameters:
  • index (pandas Index) – DataFrame index in datetime

  • origin (float) – Reference for elapsed time

Returns:

pandas Index – DataFrame index in elapsed seconds

pecos.utils.datetime_to_clocktime(index)[source]

Convert DataFrame index from datetime to clocktime (seconds past midnight)

Parameters:

index (pandas Index) – DataFrame index in datetime

Returns:

pandas Index – DataFrame index in clocktime

pecos.utils.datetime_to_epochtime(index)[source]

Convert DataFrame index from datetime to epoch time

Parameters:

index (pandas Index) – DataFrame index in datetime

Returns:

pandas Index – DataFrame index in epoch time

pecos.utils.round_index(index, frequency, how='nearest')[source]

Round DataFrame index

Parameters:
  • index (pandas Index) – Datetime index

  • frequency (int) – Expected time series frequency, in seconds

  • how (string, optional) –

    Method for rounding, default = ‘nearest’. Options include:

    • nearest = round the index to the nearest frequency

    • floor = round the index to the smallest expected frequency

    • ceiling = round the index to the largest expected frequency

Returns:

pandas Index – DataFrame index with rounded values

pecos.utils.evaluate_string(string_to_eval, data=None, trans=None, specs=None, col_name='eval')[source]

Returns an evaluated Python string. WARNING this function calls ‘eval’. Strings of Python code should be thoroughly tested by the user.

This function can be useful when defining quality control configuration options in a file, such as:

  • Time filters that depend on the data index

  • Quality control bounds that depend on system constants

  • Composite signals that are defined using existing data

For each {keyword} in string_to_eval, {keyword} is expanded in the following order:

  • If keyword is ELAPSED_TIME, CLOCK_TIME or EPOCH_TIME then data.index is converted to seconds (elapsed time, clock time, or epoch time) and used in the evaluation (requires data)

  • If keyword is used to select a column (or columns) of data, then data[keyword] is used in the evaluation (requires data)

  • If a translation dictionary is used to select a column (or columns) of data, then data[trans[keyword]] is used in the evaluation (requires data and trans)

  • If the keyword is a key in a dictionary of constants, specs, then specs[keyword] is used in the evaluation (requires specs)

Parameters:
  • string_to_eval (string) – String to evaluate, the string can included multiple keywords and numpy (np.*) and pandas (pd.*) functions

  • data (pandas DataFrame, optional) – Data, indexed by datetime

  • trans (dictionary, optional) – Translation dictionary

  • specs (dictionary, optional) – Keyword:value pairs used to define constants

  • col_name (string, optional) – Column name used in the returned DataFrame. If the DataFrame has more than one column, columns are named col_name 0, col_name 1, …

Returns:

pandas DataFrame or float – Evaluated string