Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 1 | Derived Measurements |
| 2 | ===================== |
| 3 | |
| 4 | |
| 5 | The ``DerivedMeasurements`` API provides a consistent way of performing post |
| 6 | processing on a provided :class:`MeasurementCsv` file. |
| 7 | |
| 8 | Example |
| 9 | ------- |
| 10 | |
| 11 | The following example shows how to use an implementation of a |
| 12 | :class:`DerivedMeasurement` to obtain a list of calculated ``Measurements``. |
| 13 | |
| 14 | .. code-block:: ipython |
| 15 | |
| 16 | # Import the relevant derived measurement module |
| 17 | # in this example the derived energy module is used. |
| 18 | In [1]: from devlib import DerivedEnergyMeasurements |
| 19 | |
| 20 | # Obtain a MeasurementCsv file from an instrument or create from |
| 21 | # existing .csv file. In this example an existing csv file is used which was |
| 22 | # created with a sampling rate of 100Hz |
| 23 | In [2]: from devlib import MeasurementsCsv |
| 24 | In [3]: measurement_csv = MeasurementsCsv('/example/measurements.csv', sample_rate_hz=100) |
| 25 | |
| 26 | # Process the file and obtain a list of the derived measurements |
| 27 | In [4]: derived_measurements = DerivedEnergyMeasurements.process(measurement_csv) |
| 28 | |
| 29 | In [5]: derived_measurements |
| 30 | Out[5]: [device_energy: 239.1854075 joules, device_power: 5.5494089227 watts] |
| 31 | |
| 32 | API |
| 33 | --- |
| 34 | |
| 35 | Derived Measurements |
| 36 | ~~~~~~~~~~~~~~~~~~~~ |
| 37 | |
| 38 | .. class:: DerivedMeasurements() |
| 39 | |
| 40 | The ``DerivedMeasurements`` class is an abstract base for implementing |
| 41 | additional classes to calculate various metrics. |
| 42 | |
| 43 | .. method:: DerivedMeasurements.process(measurement_csv) |
| 44 | |
| 45 | Returns a list of :class:`Measurement` objects that have been calculated. |
| 46 | |
| 47 | |
| 48 | |
| 49 | Available Derived Measurements |
| 50 | ------------------------------- |
| 51 | .. class:: DerivedEnergyMeasurements() |
| 52 | |
| 53 | The ``DerivedEnergyMeasurements`` class is used to calculate average power and |
| 54 | cumulative energy for each site if the required data is present. |
| 55 | |
| 56 | The calculation of cumulative energy can occur in 3 ways. If a |
| 57 | ``site`` contains ``energy`` results, the first and last measurements are extracted |
| 58 | and the delta calculated. If not, a ``timestamp`` channel will be used to calculate |
| 59 | the energy from the power channel, failing back to using the sample rate attribute |
| 60 | of the :class:`MeasurementCsv` file if timestamps are not available. If neither |
| 61 | timestamps or a sample rate are available then an error will be raised. |
| 62 | |
| 63 | |
| 64 | .. method:: DerivedEnergyMeasurements.process(measurement_csv) |
| 65 | |
| 66 | Returns a list of :class:`Measurement` objects that have been calculated for |
| 67 | the average power and cumulative energy for each site. |
| 68 | |
| 69 | |