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 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 38 | .. class:: DerivedMeasurements |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 39 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 40 | The ``DerivedMeasurements`` class provides an API for post-processing |
| 41 | instrument output offline (i.e. without a connection to the target device) to |
| 42 | generate additional metrics. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 43 | |
| 44 | .. method:: DerivedMeasurements.process(measurement_csv) |
| 45 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 46 | Process a :class:`MeasurementsCsv`, returning a list of |
| 47 | :class:`DerivedMetric` and/or :class:`MeasurementsCsv` objects that have been |
| 48 | derived from the input. The exact nature and ordering of the list memebers |
| 49 | is specific to indivial 'class'`DerivedMeasurements` implementations. |
| 50 | |
| 51 | .. method:: DerivedMeasurements.process_raw(\*args) |
| 52 | |
| 53 | Process raw output from an instrument, returnin a list :class:`DerivedMetric` |
| 54 | and/or :class:`MeasurementsCsv` objects that have been derived from the |
| 55 | input. The exact nature and ordering of the list memebers is specific to |
| 56 | indivial 'class'`DerivedMeasurements` implewmentations. |
| 57 | |
| 58 | The arguents to this method should be paths to raw output files generated by |
| 59 | an instrument. The number and order of expected arguments is specific to |
| 60 | particular implmentations. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 61 | |
| 62 | |
Sergei Trofimov | dd26b43 | 2017-09-07 11:13:34 +0100 | [diff] [blame] | 63 | Derived Metric |
| 64 | ~~~~~~~~~~~~~~ |
| 65 | |
| 66 | .. class:: DerivedMetric |
| 67 | |
| 68 | Represents a metric derived from previously collected ``Measurement``s. |
| 69 | Unlike, a ``Measurement``, this was not measured directly from the target. |
| 70 | |
| 71 | |
| 72 | .. attribute:: DerivedMetric.name |
| 73 | |
| 74 | The name of the derived metric. This uniquely defines a metric -- two |
| 75 | ``DerivedMetric`` objects with the same ``name`` represent to instances of |
| 76 | the same metric (e.g. computed from two different inputs). |
| 77 | |
| 78 | .. attribute:: DerivedMetric.value |
| 79 | |
| 80 | The ``numeric`` value of the metric that has been computed for a particular |
| 81 | input. |
| 82 | |
| 83 | .. attribute:: DerivedMetric.measurement_type |
| 84 | |
| 85 | The ``MeasurementType`` of the metric. This indicates which conceptual |
| 86 | category the metric falls into, its units, and conversions to other |
| 87 | measurement types. |
| 88 | |
| 89 | .. attribute:: DerivedMetric.units |
| 90 | |
| 91 | The units in which the metric's value is expressed. |
| 92 | |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 93 | |
| 94 | Available Derived Measurements |
| 95 | ------------------------------- |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 96 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 97 | .. note:: If a method of the API is not documented for a particular |
| 98 | implementation, that means that it s not overriden by that |
| 99 | implementation. It is still safe to call it -- an empty list will be |
| 100 | returned. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 101 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 102 | Energy |
| 103 | ~~~~~~ |
| 104 | |
| 105 | .. class:: DerivedEnergyMeasurements |
| 106 | |
| 107 | The ``DerivedEnergyMeasurements`` class is used to calculate average power and |
| 108 | cumulative energy for each site if the required data is present. |
| 109 | |
| 110 | The calculation of cumulative energy can occur in 3 ways. If a |
| 111 | ``site`` contains ``energy`` results, the first and last measurements are extracted |
| 112 | and the delta calculated. If not, a ``timestamp`` channel will be used to calculate |
| 113 | the energy from the power channel, failing back to using the sample rate attribute |
| 114 | of the :class:`MeasurementCsv` file if timestamps are not available. If neither |
| 115 | timestamps or a sample rate are available then an error will be raised. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 116 | |
| 117 | |
| 118 | .. method:: DerivedEnergyMeasurements.process(measurement_csv) |
| 119 | |
Sergei Trofimov | adf25f9 | 2017-09-07 14:19:24 +0100 | [diff] [blame] | 120 | This will return total cumulative energy for each energy channel, and the |
| 121 | average power for each power channel in the input CSV. The output will contain |
| 122 | all energy metrics followed by power metrics. The ordering of both will match |
| 123 | the ordering of channels in the input. The metrics will by named based on the |
| 124 | sites of the coresponding channels according to the following patters: |
| 125 | ``"<site>_total_energy"`` and ``"<site>_average_power"``. |
Marc Bonnici | 60e69fc | 2017-08-18 17:23:18 +0100 | [diff] [blame] | 126 | |