Latest Weather
Simple quick update latest weather
- switched to new sensor 8am BDA 2015-08-21 Old sensor was giving systematic bias and other weirdness.
# Tell matplotlib to plot in line
%matplotlib inline
import datetime
# 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):
""" This smoothing function is meant to spot and eliminate bad readings.
"""
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)
infile = "../files/kittycam_weather.csv"
!scp 192.168.0.121:Adafruit_Python_BMP/weather.csv $infile
!wc ../files/weather.csv
""" 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.plot()
# 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])
#data.altitude = data.altitude.clip(-100, 100)
data.altitude.plot()
data.tail()
data.describe()
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
$$Td = T - ((100 - RH)/5.)$$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:
data['dewpoint'] = data.temp - ((100. - data.humidity)/5.)
Last 24 hours:¶
print(datetime.datetime.now())
print(data.ix[-1:])
# reading is once a minute, so take last 24 * 60 readings
def plotem(data, n=-60, start=None):
if n < 0:
start = n
end = len(data)
else:
start = start or 0
end = start + n
data[['temp', 'altitude', 'humidity', 'dewpoint']][start:end].plot(subplots=True)
# last few hours
plotem(data, -24*60)
Last week¶
# reading is once a minute, so take last 7 * 24 * 60 readings
plotem(data, -7*24*60)
plotem(data)
plotem(data, -5)
Look at all the data¶
data.describe()
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.
data[['temp', 'temp_dht']].plot()
data[['temp', 'dewpoint', 'humidity']].plot()
data[['temp', 'dewpoint', 'humidity']].plot(subplots=True)
data[['temp', 'dewpoint']].plot()
from numpy import fft
data['fft_altitude'] = fft.fft(data.altitude)
data['fft_alt_real'] = data.fft_altitude.real
data['fft_alt_imag'] = data.fft_altitude.imag
data['alt_power'] = ((data.fft_alt_real ** 2.0) + (data.fft_alt_imag ** 2.0)) ** 0.5
import numpy
N = len(data)
TWELVE = N//(12*59)
def hours(pos):
return N/(pos*60.)
eleven_elevator = N/(12*59.0) # Scottish elevator
print(eleven_elevator, TWELVE)
data['pos'] = numpy.arange(N)
data[['fft_alt_imag', 'fft_alt_real', 'alt_power']][TWELVE//3:2*TWELVE].plot()
data[TWELVE//3:2*TWELVE].plot(x='pos', y='alt_power')
data[TWELVE-4: TWELVE+10].plot(x='pos', y='alt_power')
print(TWELVE, eleven_elevator)
#FIXME - the data points are probably a fraction over a minute apart.
for x in range(TWELVE-5, TWELVE+5):
print(x, "%6.4f" % hours(x))
data.tail(1)
data.tail(10*24*60).head(1)
hours(54)
data[TWELVE//3:3 + (2*TWELVE)].clip(-60000, 60000).plot(x='pos', y='alt_power')
xx = data.fft_altitude.copy()
xx[TWELVE:-TWELVE] = 0.0
data['smooth_alt'] = [x.real for x in fft.ifft(xx)]
data[['smooth_alt', 'altitude']].plot()
data.smooth_alt.plot()
def power(x, y):
return ((x ** 2.0) + (y ** 2.0)) ** 0.5
P = TWELVE
xx = data.fft_altitude.copy()
xx[:] = 0.0
xx[P:-P] = data.fft_altitude[P:-P]
data['twelve'] = [x.real for x in fft.ifft(xx)]
data['itwelve'] = [x.imag for x in fft.ifft(xx)]
data['twelve_pow'] = power(data.twelve, data.itwelve)
data['smoothed'] = data.altitude - data.twelve
data[['twelve', 'altitude', 'smoothed', 'smooth_alt']].plot(subplots=True)
Comments
Comments powered by Disqus