datalogd.plugins.polynomialfunction_datafilter module

class datalogd.plugins.polynomialfunction_datafilter.PolynomialFunctionDataFilter(sinks=[], match_keyvals=[['type', '.*'], ['id', '.*']], value='value', coeffs=[0.0, 1.0], rounding=None, units=None)[source]

Bases: datalogd.DataFilter

Select data based on key–value pairs, then apply a polynomial function to a value.

Any data which matches all of the match_keyvals key–value pairs will be processed. The format of the match_keyvals parameter is a list in the form [[key, value], [key2, value2]...]. For example, match_keyvals=[["type", "temperature"], ["id", "123"]] will process any data which has a "type" field of "temperature" and an "id" field of "123". A value of the python special NotImplemented will match any value for the given key. In the case that values are strings, they will be matched as regular expressions, for example ".*" will match any string.

Once a data item is matched, a value will be selected to apply the polynomial function to, selected by the value parameter. By default this is the value stored under the "value" key.

The polynomial function is defined by a set of coefficients, given by the coeffs parameter. This is an array of \(n\) coefficients, \(c_n\), which forms the function \(x^\prime = \sum_n c_n x^{(n-1)} \equiv c_0 + c_1x + c_2x^2 \ldots c_nx^n\). For example, coeffs=[1.23, 1.0] would add 1.23 to a value, while coeffs=[0, 10] would multiply a value by 10. Specifying additional coefficients include quadratic, cubic terms etc.

Rounding may be applied to the result by supplying the number of decimal places in the rounding parameter. Rounding behaviour is determined by the numpy around() function. Negative numbers specify positions to the left of the decimal point.

The value of the data entry’s "units" field can be modified or created using the units parameter. For example, units="V" might be used to indicate that an analogue measurement in arbitrary units now equates to voltage, determined by the polynomial function calibration curve.

Parameters:
  • match_keyvals – Key–value pairs to match to data items.
  • value – Key from data item containing the value to modify.
  • coeffs – Coefficients of the polynomial function to apply.
  • rounding – Number of decimal places to round the result.
  • units – New value of units field for the modified data item.
receive(data)[source]

Accept the provided data, select based on key/value pairs, apply function, and pass onto connected sinks.

The selection is based upon the parameters provided to the constructor of this PolynomialFunctionDataFilter.

Parameters:data – Data to correct.