METAR REPORTS & PYTHON
- From: "PetDragon" <petdragon69-weather@xxxxxxxxxxx>
- Date: Mon, 28 Aug 2006 13:03:08 +0100
Hiya, I am not sure how many people will be interested in this. I've been
learning python for around six months and have developed a script that logs
the METAR reports given by airports around the world.
I set mine up to log Heathrow Airport as I am within around 25miles of
Heathrow, closer if you measure as the crow flies.
Anyway, it could be useful for anyone that has a weather station, or is
about to build their own(like me), to verify that the readings you are
taking are somewhat sensible. Obviously the only drawback is that you need
to live within a sensible distance from a METAR reporting site. There's a
huge list available from NOAA.
There's still some work I need to do, such as making the graphs look much
nicer and add further data etc etc.
Thanks to Tobias Klausman who wrote pymetar.py and Mr John Hunter for
matplotlib.
The script basically logs onto NOAA FTP and pulls the data in raw format.
Pymetar does all the clever work and converts the raw file to something
inteligible. Then my script logs whatever I've told it to log and produces
the graphs. YEY!!!!
Ofcourse there are websites on the net such as the Met office which will
show similar data. I only did this because I am learning, and you can't
learn by not doing!! ENJOY
#The script V0.1 - Please feel free to use and give credit where credit is
due.
# This is my weather monitor program. I wanted a live reference site so I
could check my own instruments once they are active.
# It's also to work as a sort of development script for the software that
will run when my instruments are ready.
import pymetar
import sys
import fpformat
import math
import time
import shutil
import os
print 'Downloading from NOAA FTP'
#which station would you like sir?
if len(sys.argv)<2:
station="egll"
else:
station=sys.argv[1]
rf=pymetar.ReportFetcher(station)
rep=rf.FetchReport()
rp=pymetar.ReportParser()
pr=rp.ParseReport(rep)
#Creates all the folders used for storing the data
if not os.path.exists(time.strftime('./%Y')):
os.mkdir(time.strftime('./%Y'))
if not os.path.exists(time.strftime('./%Y/%m')):
os.mkdir(time.strftime('./%Y/%m'))
if not os.path.exists(time.strftime('./%Y/%m/%d')):
os.mkdir(time.strftime('./%Y/%m/%d'))
#uses pymetar v0.12 to fetch sensible data
saveout = sys.stdout
metar = open(time.strftime('./%Y/%m/%d/%dTemp.dat'), 'a')
sys.stdout = metar
print pr.getTemperatureCelsius()
sys.stdout = saveout
metar.close()
saveout = sys.stdout
metar = open(time.strftime('./%Y/%m/%d/%dWindSpeed.dat'), 'a')
sys.stdout = metar
print pr.getWindSpeedMilesPerHour()
sys.stdout = saveout
metar.close()
saveout = sys.stdout
metar = open(time.strftime('./%Y/%m/%d/%dPressure.dat'), 'a')
sys.stdout = metar
print pr.getPressure()
sys.stdout = saveout
metar.close()
print 'Download Complete'
###############################################################
#Makes the pretty graphs from the dull data
import string
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
l = load(time.strftime('./%Y/%m/%d/%dTemp.dat'))
t = l
plot(l, 'o')
xlabel('Time')
ylabel('Temperature')
title('Temperature Log')
grid(True)
savefig(time.strftime('./%Y/%m/%d/%dTemp.png'))
close()
x = load(time.strftime('./%Y/%m/%d/%dWindSpeed.dat'))
s = x
plot(x, 'o')
xlabel('Time')
ylabel('wind speed')
title('Wind Speed')
grid(True)
savefig(time.strftime('./%Y/%m/%d/%dWind.png'))
close()
majorLocator = MultipleLocator(10)
z = load(time.strftime('./%Y/%m/%d/%dPressure.dat'))
k = z
plot(z, 'o')
ax = subplot(111)
ax.yaxis.set_major_locator(majorLocator)
ax.autoscale_view()
xlabel('Time')
ylabel('Pressure')
title('Pressure hpa')
grid(True)
savefig(time.strftime('./%Y/%m/%d/%dPressure.png'))
close()
#############################################################
print 'Graphs Complete'
.
- Prev by Date: Predict weahter from temperature and humidity?
- Next by Date: Re: [OBS] Bracknell (Tawfield) Mon 28 Aug 2006
- Previous by thread: Predict weahter from temperature and humidity?
- Next by thread: Global warming
- Index(es):
Relevant Pages
|