This demo notebook shows how units are treated and how to apply unit conversions

Opengrid makes use of the python library pint for unit conversions


In [ ]:
import pandas as pd
import charts
from opengrid.library import misc, houseprint

Each Sensor object needs an attribute unit. For Fluksosensors, the units are as follows:

sensortype      unit
-----------------------
water       ==> liter
gas         ==> liter
electricity ==> Wh

When you obtain data, always use the get_data() methods. These are defined for object of type Houseprint, Device, Site and Sensor. Each of these calls allows you to specify

  • a resampling rate ('raw', 'min', 'hour', ...)
  • whether differentiation is needed (to go from counter to flux values, eg from Wh to W)
  • a target unit

The default resulting unit for counter values (diff=False) are:

sensortype      unit
-----------------------
water       ==> liter
gas         ==> kWh
electricity ==> kWh

The default resulting unit for flux values (diff=True) are:

sensortype      unit
-----------------------
water       ==> liter/min
gas         ==> W
electricity ==> W    

Let's look at some PV sensors.


In [ ]:
hp = houseprint.Houseprint()
sensors = hp.search_sensors(type='electricity', system='solar')

head = pd.Timestamp('20150617')
tail = pd.Timestamp('20150621')

When we use the default unit, we get Watts.


In [ ]:
df = hp.get_data(sensors=sensors, head=head, tail=tail)
charts.plot(df, stock=True, show='inline')

In [ ]:
df = hp.get_data(sensors=sensors, head=head, tail=tail, resample='day', unit='kW')
charts.plot(df, stock=True, show='inline')

You can verify the unit of the obtained dataframe. Each series has the attribute unit. However, be aware that this attribute will disappear when you do operations on df.


In [ ]:
for col in df:
    print("The unit of the data for {} is {}".format(col, df[col].unit))

If you want to convert units youself, there is a practical function in opengrid.library.misc that computes the conversion factor to go from one unit to another.


In [ ]:
misc.unit_conversion_factor(source='liter/min', target='m**3/hour')