For Windows, install the following and add C:\Program Files (x86)\GnuWin32\bin to your PATH
http://gnuwin32.sourceforge.net/packages/wget.htmimport math
import os
import datetime
import numpy
import pandas
import matplotlib.pyplot as plt
%matplotlib inline
def tofloat(x):
try:
return float(x)
except ValueError:
return None
Cities were hand-selected, with WBAN manually looked up from http://cdo.ncdc.noaa.gov/qclcd/QCLCD?prior=N
dfcities = pandas.DataFrame([{'City':'Centennial', 'WBAN':93067},
{'City':'San Diego', 'WBAN':3131}])
os.mkdir("TempBarometerFiles")
os.chdir("TempBarometerFiles")
processingyear = datetime.date.today().year
processingmonth = datetime.date.today().month
dfdiff=pandas.DataFrame(numpy.zeros(0,dtype=[('WBAN', 'i4'),('Range', 'f8')]))
for x in range(0, 12):
dt = datetime.datetime(processingyear, processingmonth, 1) - datetime.timedelta(days=1)
processingyear = dt.year
processingmonth = dt.month
os.system("wget -q http://cdo.ncdc.noaa.gov/qclcd_ascii/QCLCD" + str(processingyear) + str(processingmonth).zfill(2) + ".zip")
os.system("unzip QCLCD" + str(processingyear) + str(processingmonth).zfill(2) + ".zip")
df=pandas.read_csv(str(processingyear) + str(processingmonth).zfill(2) + "hourly.txt",low_memory=False)
dfsp = df.merge(dfcities, on="WBAN").ix[:,("WBAN", "Date", "StationPressure")]
dfsp["StationPressureFloat"] = dfsp["StationPressure"].apply(lambda x: tofloat(x))
del dfsp["StationPressure"]
dfsp = dfsp.ix[dfsp["StationPressureFloat"].apply(lambda x: not math.isnan(x))]
gb = dfsp.groupby(["WBAN","Date"])
dfminmax = gb.min().join(gb.max(), lsuffix="Min", rsuffix="Max")
dfdiffcur = pandas.DataFrame(dfminmax["StationPressureFloatMax"] - dfminmax["StationPressureFloatMin"], columns=["Range"])
dfdiffcur.reset_index(level=0, inplace=True)
dfdiff = dfdiff.append(dfdiffcur)
os.system("rm *.txt")
hist = numpy.histogram(dfdiff.ix[dfdiff["WBAN"]==93067,"Range"],range=(0,0.6))
pandas.DataFrame({'delta inches':hist[1][1:],'Denver (Days)':hist[0]}).plot(x='delta inches',kind='bar', ylim=(0,300))
<matplotlib.axes.AxesSubplot at 0xedcde10>
hist = numpy.histogram(dfdiff.ix[dfdiff["WBAN"]==3131,"Range"],range=(0,0.6))
pandas.DataFrame({'delta inches':hist[1][1:],'San Diego (Days)':hist[0]}).plot(x='delta inches',kind='bar', ylim=(0,300))
<matplotlib.axes.AxesSubplot at 0xee77a20>
os.chdir("..")
!rm -rf TempBarometerFiles