- 积分
- 55965
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2018-9-5 19:33 编辑
micaps 1类数据是地面全要素观测数据,每个时次一个文件,每个文件包含很多站点。要提取某个站点的时间序列数据需要用循环读取多个时次的micaps 1数据,循环中用addfile_micaps函数读取micaps文件对象,然后用文件对象的read_dataframe函数将数据读入一个DataFrame对象,再从中提取一个或者多个站点的数据(也可以对提取那些要素进行限定),用DataFrame的append方法合并不同时次的数据。最终的DataFrame对象用to_csv方法保存到文件中。
- #---- Set stations
- stids = ['54511']
- #---- Set variables
- # Avialable variables in MICAPS 1 data:
- # "Altitude", "Grade", "CloudCover", "WindDirection", "WindSpeed", "Pressure",
- # "PressVar3h", "WeatherPast1", "WeatherPast2", "Precipitation6h", "LowCloudShape",
- # "LowCloudAmount", "LowCloudHeight", "DewPoint", "Visibility", "WeatherNow",
- # "Temperature", "MiddleCloudShape", "HighCloudShape"
- variables = ['Visibility','WeatherNow','WindDirection','WindSpeed','Temperature','DewPoint']
- #Read data
- datadir = r'D:\Temp\micaps'
- year = 2016
- month = 1
- day = 1
- t = datetime.datetime(year, month, day)
- rdf = None
- for hour in range(2, 24, 3):
- t = t.replace(hour=hour)
- fn = os.path.join(datadir, t.strftime('%y%m%d%H') + '.000')
- print fn
- f = addfile_micaps(fn)
- df = f.read_dataframe()
- t = f.gettime(0)
- r = df.loc[stids,variables]
- r.insert(0, 'Time', t)
- if rdf is None:
- rdf = r
- else:
- rdf = rdf.append(r)
- rdf.index = rdf['Time']
- rdf = rdf.drop('Time')
- print rdf
- rdf.to_csv('D:/Temp/test/test.csv')
输出的数据: Visibility WeatherNow WindDirection WindSpeed Temperature DewPoint
2016-01-01 02 26.0 0 360.0 1.0 -3.4 -18.1
2016-01-01 05 30.0 0 340.0 2.0 -4.8 -18.6
2016-01-01 08 1.8 10 70.0 1.0 -4.9 -9.0
2016-01-01 11 3.8 5 20.0 1.0 1.4 -8.4
2016-01-01 14 2.8 5 90.0 1.0 4.9 -8.2
2016-01-01 17 1.7 5 180.0 1.0 2.8 -6.3
2016-01-01 20 1.1 10 180.0 1.0 -1.2 -6.5
2016-01-01 23 0.9 10 0.0 0.0 -2.9 -6.5
|
|