Simple quick update latest weather


In [1]:
# Tell matplotlib to plot in line
%matplotlib inline

# import pandas
import pandas

# seaborn magically adds a layer of goodness on top of Matplotlib
# mostly this is just changing matplotlib defaults, but it does also
# provide some higher level plotting methods.
import seaborn

# Tell seaborn to set things up
seaborn.set()

def smooth(data, thresh=None):
    
    means = data.mean()

    if thresh is None:
        sds = data.std()
    else:
        sds = thresh
    
    delta = data - data.shift()
    
    good = delta[abs(delta) < sds]

    #print(good.describe())
    
    return delta.where(good, 0.0)

In [2]:
infile = "../files/pijessie_weather.csv"

!scp 192.168.0.127:Adafruit_Python_BMP/weather.csv $infile


weather.csv                                   100% 9738KB   4.8MB/s   00:02    

In [3]:
""" assume it is csv and let pandas do magic

  index_col tells it to use the 'date' column in the data
  as the row index, plotting picks up on this and uses the
  date on the x-axis

  The *parse_dates* bit just tells it to try and figure out
  the date/time in the columne labeled 'date'.
"""
data = pandas.read_csv(infile, index_col='date', parse_dates=['date'])
#data = smooth(data)

# smooth the data to filter out bad temps and pressures
#data.altitude = (smooth(data.altitude, 5.0).cumsum() + data.altitude[0])
#data.temp = (smooth(data.temp, 5.0).cumsum() + data.temp[0])

In [4]:
data.altitude.plot()


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fad2da1f470>

Last 24 hours:


In [5]:
# reading is once a minute, so take last 24 * 60 readings
def plotem(data, n=-60):
    
    
    if n < 0:
        start = n
        end = len(data)
    else:
        start = 0
        end = n
        
    data[['temp', 'altitude', 'humidity']][n:].plot(subplots=True)
        
plotem(data, -24*60)



In [6]:
data.altitude[-8*60:].plot()


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fad2c484be0>

Last week


In [7]:
# reading is once a minute, so take last 7 * 24 * 60 readings
plotem(data, -7*24*60)



In [8]:
plotem(data)


Look at all the data


In [9]:
data.describe()


Out[9]:
temp pressure altitude sealevel_pressure humidity temp_dht
count 100438.000000 100438.000000 100438.000000 100438.000000 100435.000000 100435.000000
mean 28.103434 101170.554601 12.803701 101172.068430 67.049273 27.682661
std 1.591392 445.294878 33.830090 441.515484 9.264247 1.570824
min 22.300000 50042.000000 -51.241934 48765.000000 36.599998 1.200000
25% 27.400000 100961.000000 -11.981775 100963.000000 62.400002 26.900000
50% 28.300000 101164.000000 13.329265 101166.000000 68.400002 27.900000
75% 29.100000 101468.000000 30.265359 101470.000000 72.500000 28.700001
max 121.400000 117173.000000 2740.700691 101941.000000 98.000000 30.700001

In [10]:
data.tail()


Out[10]:
temp pressure altitude sealevel_pressure humidity temp_dht
date
2015-10-05 20:34:29.211961 27.8 100151 97.698400 100157 85.300003 27.400000
2015-10-05 20:35:29.854177 27.8 100160 96.858035 100173 85.400002 27.299999
2015-10-05 20:36:33.024635 27.8 100158 97.110138 100166 85.500000 27.400000
2015-10-05 20:37:33.666956 27.8 100158 96.353849 100167 85.599998 27.400000
2015-10-05 20:38:34.309141 27.8 100163 96.942069 100164 85.800003 27.400000

I currently have two temperature sensors:

  • DHT22 sensor which gives temperature and humidity.
  • BMP180 sensor which gives pressure and temperature.

The plot below shows the two temperature plots.

Both these sensors are currently in my study. For temperature and humidity I would like to have some readings from outside. If I can solder them to a phone jack then I can just run phone cable to where they need to be.

Below plots the current values from these sensors. This is handy for calibration.


In [11]:
data[['temp', 'temp_dht']].plot()


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fad2c37e438>

Dew Point

The warmer air is, the more moisture it can hold. The dew point is the temperature at which air would be totally saturated if it had as much moisture as it currently does.

Given the temperature and humidity the dew point can be calculated, the actual formula is pretty complex.

It is explained in more detail here: http://iridl.ldeo.columbia.edu/dochelp/QA/Basic/dewpoint.html

If you are interested in a simpler calculation that gives an approximation of dew point temperature if you know >the observed temperature and relative humidity, the following formula was proposed in a 2005 article by Mark G. >Lawrence in the Bulletin of the American Meteorological Society:

$$Td = T - ((100 - RH)/5.)$$

In [12]:
data['dewpoint'] = data.temp - ((100. - data.humidity)/5.)

In [13]:
data[['temp', 'dewpoint', 'humidity']].plot()


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fad2c4194e0>

In [14]:
data[['temp', 'dewpoint', 'humidity']].plot(subplots=True)


Out[14]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7fad2c30ccc0>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7fad2c427048>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7fad2c3dc390>], dtype=object)

In [15]:
data[['temp', 'dewpoint']].plot()


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fad2b753a58>

In [16]:
data.altitude.plot()


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fad2af40400>