爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 8895|回复: 14

MeteoInfoLab脚本示例:中国地面国际交换站气候资料日值数据集(V3.0)

[复制链接]

新浪微博达人勋

发表于 2016-5-20 15:14:45 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 MeteoInfo 于 2016-6-7 22:40 编辑

中国地面国际交换站气候资料日值数据集(V3.0)可以在“中国气象数据网”上下载,每个月每个要素一个文件(ASCII),具体格式说明见网站的相关文档。以2012年5月温度数据文件为例,各列分别为站号、纬度、经度、高度、年、月、日、平均温度、最低温度、最高温度、平均温度质量控制码、最低温度质量控制码、最高温度质量控制码。

50353 5143 12639   1774 2012  5  1    103    164     19 0 0 0
50353 5143 12639   1774 2012  5  2    126    192     31 0 0 0
50353 5143 12639   1774 2012  5  3     90    126     67 0 0 0
50353 5143 12639   1774 2012  5  4     87    139     70 0 0 0
50353 5143 12639   1774 2012  5  5     98    165     39 0 0 0
50353 5143 12639   1774 2012  5  6    110    149     68 0 0 0
50353 5143 12639   1774 2012  5  7    103    131     86 0 0 0
50353 5143 12639   1774 2012  5  8    115    165     39 0 0 0
50353 5143 12639   1774 2012  5  9    133    196     79 0 0 0
50353 5143 12639   1774 2012  5 10    128    200     47 0 0 0
50353 5143 12639   1774 2012  5 11    141    240     22 0 0 0
50353 5143 12639   1774 2012  5 12    181    254     75 0 0 0

...

MeteoInfoLab有readtable()函数,很适合读取这种表格式的文本数据,文件中没有列名,需要设置headlines=-1,可以用colnames参数设置各数据列的名称。数据被读入一个表格后,可以用列名来获取某一列的数据。

下面示例从表格中利用sql()函数获取各站点2012年5月1日的数据表格,然后绘制平均气温的站点分布图。需要注意的是数据中经纬度是度分格式,要转化为度。
  1. #Read table data
  2. fn = 'D:/Temp/ascii/st_dayave/SURF_CLI_CHN_MUL_DAY_CES-TEM-12001-201205.txt'
  3. col_names = ['Stid','Lat','Lon','Alt','Year','Month','Day','T_Ave','T_Max',\
  4.     'T_Min','Code_Ave','Code_Max','Code_Min']
  5. table = readtable(fn, headerlines=-1, format='%s%3f%3i%3f%3i', colnames=col_names)
  6. #Sql - only select rows with 'Day = 1'
  7. table = table.sql('Day = 1')
  8. #Get data from table
  9. stid = table['Stid']
  10. lon = table['Lon']
  11. d = (lon / 100).astype('int')
  12. m = (lon - d * 100) / 60
  13. lon = d + m
  14. lat = table['Lat']
  15. d = (lat / 100).astype('int')
  16. m = (lat - d * 100) / 60
  17. lat = d + m
  18. temp = table['T_Ave'] * 0.1
  19. #Plot
  20. axesm()
  21. bou2_layer = shaperead('D:/Temp/map/bou2_4p.shp')
  22. bou1_layer = shaperead('D:/Temp/map/bou1_4l.shp')
  23. geoshow(bou2_layer, edgecolor='lightgray')
  24. geoshow(bou1_layer, facecolor=(0,0,255))
  25. layer = scatterm(lon, lat, temp, 20)
  26. title('Temperature (2012-05-01)')
  27. colorbar(layer)
  28. xlim(72, 136)
  29. ylim(16, 55)
  30. #Add south China Sea
  31. sc_layer = bou1_layer.clone()
  32. axesm(position=[0.14,0.15,0.15,0.2], axison=False, frameon=True)
  33. geoshow(sc_layer, facecolor=(0,0,255))
  34. xlim(106, 123)
  35. ylim(2, 23)


surf_dayave_1.png

下面示例用sql()函数提取54511站的整月数据表格,并绘制气温变化图。
  1. #Read table data
  2. fn = 'D:/Temp/ascii/st_dayave/SURF_CLI_CHN_MUL_DAY_CES-TEM-12001-201205.txt'
  3. col_names = ['Stid','Lat','Lon','Alt','Year','Month','Day','T_Ave','T_Max',\
  4.     'T_Min','Code_Ave','Code_Max','Code_Min']
  5. table = readtable(fn, headerlines=-1, format='%s%3f%3i%3f%3i', colnames=col_names)
  6. #Sql - only select rows with 'Stid = "54511"'
  7. table = table.sql('Stid = "54511"')
  8. #Get data from table
  9. day = table['Day']
  10. t_ave = table['T_Ave'] * 0.1
  11. t_min = table['T_Min'] * 0.1
  12. t_max = table['T_Max'] * 0.1
  13. #Plot
  14. plot(day, t_ave, 'r-o', label=u'平均温度')
  15. plot(day, t_min, 'g-^', label=u'最低温度')
  16. plot(day, t_max, 'b-s', label=u'最高温度')
  17. xlim(1, 31)
  18. ylim(10, 40)
  19. legend(loc='upper center', fontname=u'宋体', orientation='horizontal', frameon=False)
  20. xlabel(u'日', fontname=u'宋体')
  21. ylabel(u'温度(摄氏度)', fontname=u'宋体')
  22. xaxis(minortick=True)
  23. yaxis(minortick=True)
  24. title(u'站点54511日温度变化(2012年5月)', fontname=u'黑体')


surf_dayave_st.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-20 16:11:29 | 显示全部楼层
纯粹为了抢个沙发,哈哈,这不算灌水,这不为赚钱
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-20 19:37:45 | 显示全部楼层
数据在哪里下载呢
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-5-20 21:55:58 | 显示全部楼层
YF2015 发表于 2016-5-20 19:37
数据在哪里下载呢

自己上网搜一下吧
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-26 20:43:32 | 显示全部楼层
漂亮的图,赶紧来学习
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-9-24 12:00:52 | 显示全部楼层
王老师,周末好!
请问一下:readtable()函数和sql()函数联合使用,提取某一个台站(如54511)数据后,怎么保存输出为.txt或.csv或.xlsx等格式的数据?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-9-24 13:50:38 | 显示全部楼层
rceclx 发表于 2016-9-24 12:00
王老师,周末好!
请问一下:readtable()函数和sql()函数联合使用,提取某一个台站(如54511)数据后,怎 ...

用PyTableData的savefile方法,比如:
table.savefile('C:/Temp/test.cvs')
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-9-25 00:08:35 | 显示全部楼层
MeteoInfo 发表于 2016-9-24 13:50
用PyTableData的savefile方法,比如:
table.savefile('C:/Temp/test.cvs')


谢谢王老师!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-9-25 00:37:06 | 显示全部楼层
MeteoInfo 发表于 2016-9-24 13:50
用PyTableData的savefile方法,比如:
table.savefile('C:/Temp/test.cvs')


王老师,您好!
V3.0这样的日值数据集中没有单独的时间列(日期),要计算月平均或年平均的话,ave_month或ave_year函数无法使用,是不是需要在table中新增加一个时间列?有没有这样的函数?谢谢!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-9-25 08:47:19 | 显示全部楼层
学习了,谢谢分享!!!
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表