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 |
Sergei Trofimov | dd26b43 | 2017-09-07 11:13:34 +0100 | [diff] [blame^] | 12 | :class:`DerivedMeasurement` to obtain a list of calculated ``DerivedMetric``'s. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 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 | |
Sergei Trofimov | dd26b43 | 2017-09-07 11:13:34 +0100 | [diff] [blame^] | 45 | Returns a list of :class:`DerivedMetric` objects that have been calculated. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 46 | |
| 47 | |
Sergei Trofimov | dd26b43 | 2017-09-07 11:13:34 +0100 | [diff] [blame^] | 48 | Derived Metric |
| 49 | ~~~~~~~~~~~~~~ |
| 50 | |
| 51 | .. class:: DerivedMetric |
| 52 | |
| 53 | Represents a metric derived from previously collected ``Measurement``s. |
| 54 | Unlike, a ``Measurement``, this was not measured directly from the target. |
| 55 | |
| 56 | |
| 57 | .. attribute:: DerivedMetric.name |
| 58 | |
| 59 | The name of the derived metric. This uniquely defines a metric -- two |
| 60 | ``DerivedMetric`` objects with the same ``name`` represent to instances of |
| 61 | the same metric (e.g. computed from two different inputs). |
| 62 | |
| 63 | .. attribute:: DerivedMetric.value |
| 64 | |
| 65 | The ``numeric`` value of the metric that has been computed for a particular |
| 66 | input. |
| 67 | |
| 68 | .. attribute:: DerivedMetric.measurement_type |
| 69 | |
| 70 | The ``MeasurementType`` of the metric. This indicates which conceptual |
| 71 | category the metric falls into, its units, and conversions to other |
| 72 | measurement types. |
| 73 | |
| 74 | .. attribute:: DerivedMetric.units |
| 75 | |
| 76 | The units in which the metric's value is expressed. |
| 77 | |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 78 | |
| 79 | Available Derived Measurements |
| 80 | ------------------------------- |
| 81 | .. class:: DerivedEnergyMeasurements() |
| 82 | |
| 83 | The ``DerivedEnergyMeasurements`` class is used to calculate average power and |
| 84 | cumulative energy for each site if the required data is present. |
| 85 | |
| 86 | The calculation of cumulative energy can occur in 3 ways. If a |
| 87 | ``site`` contains ``energy`` results, the first and last measurements are extracted |
| 88 | and the delta calculated. If not, a ``timestamp`` channel will be used to calculate |
| 89 | the energy from the power channel, failing back to using the sample rate attribute |
| 90 | of the :class:`MeasurementCsv` file if timestamps are not available. If neither |
| 91 | timestamps or a sample rate are available then an error will be raised. |
| 92 | |
| 93 | |
| 94 | .. method:: DerivedEnergyMeasurements.process(measurement_csv) |
| 95 | |
Sergei Trofimov | dd26b43 | 2017-09-07 11:13:34 +0100 | [diff] [blame^] | 96 | Returns a list of :class:`DerivedMetric` objects that have been calculated for |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 97 | the average power and cumulative energy for each site. |
| 98 | |
| 99 | |