天气工具包
PySk的Python项目详细描述
pysky是一个python天气工具包,它提供对许多公共可用天气数据库的访问。pysky的目标是以pythonic的方式提供一个快速、易用的气象数据接口。目前的实施重点是美国国家海洋和大气管理局(noaa)的天气数据,不过未来的天气系统将被纳入其中。特别是,它提供每小时和每天的预测摘要。
使用模块
该工具包有几个命令行脚本,用于返回格式化的天气数据。
要获取预测数据,请使用forecast.py。对于快速而不可靠的预测,forecast.py将使用noaa xml web服务来获取预测信息。对于更健壮的应用程序,forecast.py的用户将希望使用grib2选项。grib2选项下载noaa grib2文件,该文件为整个美国提供预测元素。查询grib2数据比查询xml web服务快得多,效率也高得多。
python bin/download (--grib2-dir=DIR)(--verbose) python bin/forecast (--hourly)(--grib2-dir=DIR)(--verbose) LATITUDE LONGITUDE
示例:
python bin/download # download to current directory python bin/download --grib2-dir=/tmp # download data files to /tmp python bin/forecast --grib2-dir=/tmp -- 38 -81 # get forecast for latitude 38 and longitude -81
forecast操作的输出是以下格式的json编码值:
{ 'daily' : [ { 'date' : *date* 'high' : *high*, 'low' : *low*, 'humidity' : *humidity*, 'precip_day' : *daytime % chance of precip*, 'precip_night' : *night time % chance of precip*, 'rain_amount' : *rain amount in inches*, 'snow_amount' : *snow amount in inches*, 'weather': *weather description*, 'symbol': *weather symbol used by NOAA*, 'wind_sustained': *sustained wind in MPH*, 'wind_gust': *wind gusts in MPH* }, ... ], 'hourly' : [ { 'date' : *date*, 'time' : *time*, 'temp' : *temperature*, 'humidity' : *% humidity*, 'precip' : *% chance of precipitation*, 'rain_amount' : *rain amount in inches*, 'snow_amount' : *snow amount in inches*, 'sky' : *% cloud cover*: 'weather: *weather description*, 'wind_sustained': *sustained wind in MPH*, 'wind_gust': *wind guests in MPH }, ... ] ]
要求
如果使用grib2文件(不是web服务),则必须安装noaa degrib库http://www.nws.noaa.gov/mdl/degrib/。此外,degrib源中包含的geodata目录必须复制到grib2数据目录。