- 积分
- 915
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-4-24
- 最后登录
- 1970-1-1
|
发表于 2022-12-31 21:47:39
|
显示全部楼层
import os
dir="E:/1106/20211106"
of = open(r"E:\1106.csv", 'w+')
for parentdir, dirname, filenames in os.walk(dir):
for filename in filenames:
inFiles = '%s/%s' % (dir, filename)
#print inFiles
f=addfile(inFiles, keepopen=True)
obs=f["obs"]
#print(obs)
lon=obs.member_array("Longitude_high_accuracy")
lat=obs.member_array("Latitude_high_accuracy")
lon=(lon-1.87E7)*1.E-5
lat=(lat-9.E6)*1.E-5
#print(lon,lat)
st_id=obs.member_array("WMO_station_number")
seq1=obs.member_array("seq1")
#print(seq1.get_members())
#88888888888888
time=seq1.member_array("Short_time_increment")
#print(time)
#999999999999999
seq2=seq1.member_array("seq2")
#print(seq2.get_members())
seq3=seq2.member_array("seq3")
#print(seq3.get_members())
n_raindrop=seq3.member_array(u"雨滴个数")
n_raindropbm=seq3.member_array(u"谱图数据编号")
#print(n_raindropbm)
print(filename[15:29],n_raindrop,n_raindropbm)
if isinstance(n_raindrop,int):
#print(filename[15:29],n_raindrop,type(n_raindrop))
of.write(filename[15:29]+",个数")
of.write("%s" %(n_raindrop))
of.write("\n")
of.write(filename[15:29]+",编码")
of.write("%s" %(n_raindropbm))
of.write("\n")
else:
ll=len(n_raindrop)
if ll>0:
#print("******",ll)
of.write(filename[15:29]+",个数")
for i in range(ll):
nn=n_raindrop
nn1=n_raindropbm
#print("@@@@@",nn,nn1)
line="%s%d" %(",",nn)
of.write(line)
of.write("\n")
of.write(filename[15:29]+",编码")
for i in range(ll):
nn1=n_raindropbm
line1="%s%d" %(",",nn1)
of.write(line1)
of.write("\n")
f.close()
of.close()
改了楼主代码,可以批量解析雨滴谱,发现有些时次只有一个或一个普段数据,那么个数和编码会解码成一个int数据,没有降水或超过1个时候是保存的数组,然后把没有雨滴数据剔除掉 |
|