爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 14163|回复: 4

[源代码] 关于github上那个代码没有read_AWS.py的统一回复

[复制链接]

新浪微博达人勋

发表于 2015-11-2 15:24:10 | 显示全部楼层 |阅读模式

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

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

x
那个代码其实就是read_AWS.py

我在barb_plot.py里面只是调用了其中的一个函数AWS_extract

大家把 barb_plot.py里面from read_AWS import AWS_extract 改成 from AWS_converter import AWS_extract 就好了


为方便还是传上来吧。
  1. # -*- coding: utf-8 -*-"""read CMA AWS data@author: qzhang"""import numpy as npimport stringfrom array import array# read datadef AWS_extract(input_file_path):        aws_flag=open(input_file_path,"r")        data_raw=aws_flag.read().split("\n")        file_record=data_raw[1].split(" ")        data_main_str=[]        data_main_str=[cell.split(" ") for cell in data_raw[2:]][:-1]        data_main=np.empty([int(string.atof(file_record[-1])),9])        station_num=[]        count=0        for cell in data_main_str:                station_num=station_num+["%8d" % string.atof(cell[0])]                data_main[count,0]=string.atof(cell[2])                data_main[count,1]=string.atof(cell[1])                data_main[count,2]=string.atof(cell[3])                data_main[count,3]=string.atof(cell[6])                data_main[count,4]=string.atof(cell[7])                data_main[count,5]=string.atof(cell[8])                data_main[count,6]=string.atof(cell[12])                data_main[count,7]=string.atof(cell[16])                data_main[count,8]=string.atof(cell[19])                count+=1        aws_flag.close()        return station_num,data_main,string.atof(file_record[-1])"""data_main type:        [:,0]:lat                                                                        [:,1]:lon                                                                        [:,2]:height                                                                        [:,3]:wind direction                                                                        [:,4]:wind speed                                                                        [:,5]:pressure                                                                        [:,6]:precipitation                                                                        [:,7]:td                                                                        [:,8]:temperaturestring.atof(file_record[-1]):         AWS record number"""# write as grads readabledef grads_compile(input_station_num,input_data,record_num):        count=0        record=[]        while count<=int(record_num)-1:                stid=input_station_num[count]                lat=float(input_data[count,0])                lon=float(input_data[count,1])                t=0.0                if count==int(record_num)-1:                        nlev=0                else:                        nlev=1                flag=1                record=record+[[stid,lat,lon,t,nlev,flag,float(input_data[count,2]),float(input_data[count,3]),\                                                                                float(input_data[count,4]),float(input_data[count,5]),float(input_data[count,6]),\                                                                                float(input_data[count,7]),float(input_data[count,8])]]                count+=1        return record# save datadef grads_save(data_to_write,output_file_path):        flag_output_file_path=open(output_file_path,"wb")        for cell in data_to_write:                #save station id                float_array = array('c', cell[0])                float_array.tofile(flag_output_file_path)                #save lat lon time                float_array = array('f', cell[1:4])                float_array.tofile(flag_output_file_path)                #save flags                float_array = array('i', cell[4:6])                float_array.tofile(flag_output_file_path)                #save variables                float_array = array('f', cell[6:13])                float_array.tofile(flag_output_file_path)        flag_output_file_path.close()        return flag_output_file_path#create ctl filedef ctl_create(input_file_path,date_tm):        flag_input_file_path=open(input_file_path,"w")        flag_input_file_path.write("DSET /home/qzhang/2011_07_18/AWS/"+date_tm+".dat\n")        flag_input_file_path.write("DTYPE station\n")        flag_input_file_path.write("STNMAP /home/qzhang/2011_07_18/AWS/"+date_tm+".map\n")        flag_input_file_path.write("UNDEF 9999.00000\n")        flag_input_file_path.write("TITLE Station Data\n")        if string.atof(date_tm[2:4])==1.0:                mnth="Jan"        if string.atof(date_tm[2:4])==2.0:                mnth="Feb"        if string.atof(date_tm[2:4])==3.0:                mnth="Mar"        if string.atof(date_tm[2:4])==4.0:                mnth="Apr"        if string.atof(date_tm[2:4])==5.0:                mnth="May"        if string.atof(date_tm[2:4])==6.0:                mnth="Jun"        if string.atof(date_tm[2:4])==7.0:                mnth="Jul"        if string.atof(date_tm[2:4])==8.0:                mnth="Aug"        if string.atof(date_tm[2:4])==9.0:                mnth="Sep"        if string.atof(date_tm[2:4])==10.0:                mnth="Oct"        if string.atof(date_tm[2:4])==11.0:                mnth="Nov"        if string.atof(date_tm[2:4])==12.0:                mnth="Dec"        flag_input_file_path.write("TDEF 1 linear "+date_tm[6:8]+"z"+date_tm[4:6]+mnth+"20"+date_tm[0:2]+" 1hr\n")        flag_input_file_path.write("VARS 7\n")        flag_input_file_path.write("hgt 0 99 heigt\n")        flag_input_file_path.write("uwnd 0 99 wind direction\n")        flag_input_file_path.write("vwnd 0 99 wind speed\n")        flag_input_file_path.write("pres 0 99 pressure\n")        flag_input_file_path.write("rain 0 99 rain\n")        flag_input_file_path.write("td 0 99 dew point temprature\n")        flag_input_file_path.write("t 0 99 temperature\n")        flag_input_file_path.write("ENDVARS\n")        flag_input_file_path.close()        return flag_input_file_path# creat grid file and it's ctl filedef grd_gen(stndata,res,output_file_path,date_tm,input_file_path):        flag_output_file_path=open(output_file_path,"wb")        #calculate grid region        """        maxlat=np.ceil(np.max(stndata[:,0]))        maxlon=np.ceil(np.max(stndata[:,1]))        minlat=np.floor(np.min(stndata[:,0]))        minlon=np.floor(np.min(stndata[:,1]))        """        maxlat=90        maxlon=180        minlat=-90        minlon=-180        #calculate grid number        nx=(maxlon-minlon)/float(res)+1        ny=(maxlat-minlat)/float(res)+1        """print nx,ny"""        #save data        data=list(np.random.random([nx,ny]))        for cell in data:                flag_output_file_path.write(array("d",cell))        flag_output_file_path.close()        # generate ctl file        flag_input_file_path=open(input_file_path,"w")        flag_input_file_path.write("DSET /home/qzhang/2011_07_18/AWS/"+date_tm+"_grd.dat\n")        flag_input_file_path.write("UNDEF 9999.00000\n")        flag_input_file_path.write("TITLE Basemap Data\n")        flag_input_file_path.write("XDEF "+str(int(nx))+" linear "+str(minlon)+" "+str(res)+"\n")        flag_input_file_path.write("YDEF "+str(int(ny))+" linear "+str(minlat)+" "+str(res)+"\n")        flag_input_file_path.write("ZDEF 1 levels 1000\n")        if string.atof(date_tm[2:4])==1.0:                mnth="Jan"        if string.atof(date_tm[2:4])==2.0:                mnth="Feb"        if string.atof(date_tm[2:4])==3.0:                mnth="Mar"        if string.atof(date_tm[2:4])==4.0:                mnth="Apr"        if string.atof(date_tm[2:4])==5.0:                mnth="May"        if string.atof(date_tm[2:4])==6.0:                mnth="Jun"        if string.atof(date_tm[2:4])==7.0:                mnth="Jul"        if string.atof(date_tm[2:4])==8.0:                mnth="Aug"        if string.atof(date_tm[2:4])==9.0:                mnth="Sep"        if string.atof(date_tm[2:4])==10.0:                mnth="Oct"        if string.atof(date_tm[2:4])==11.0:                mnth="Nov"        if string.atof(date_tm[2:4])==12.0:                mnth="Dec"        flag_input_file_path.write("TDEF 1 linear "+date_tm[6:8]+"z"+date_tm[4:6]+mnth+"20"+date_tm[0:2]+" 1hr\n")        flag_input_file_path.write("VARS 1\n")        flag_input_file_path.write("grid 1 99 grid_value\n")        flag_input_file_path.write("ENDVARS\n")        flag_input_file_path.close()        return 0""""""#test!test!"""count=0while count<24:        cvt_flie_path="/media/qzhang/240E5CF90E5CC608/2011_07_18/AWS/110718"        if count<10:                cvt_full_path=cvt_flie_path+"0"+str(int(string.atof(count)))        else:                cvt_full_path=cvt_flie_path+str(int(string.atof(count)))        station_num,data,record=AWS_extract(cvt_full_path+".AWS")        #calculate U conponent wind and V conponent Wind        for cell in data:                if cell[3]==9999.0 or cell[4]==9999.0:                        uwnd=9999.0                        vwnd=9999.0                else:                        if cell[3]<=90:                                uwnd=-cell[4]*np.sin(cell[3]*np.pi/180)                                vwnd=-cell[4]*np.cos(cell[3]*np.pi/180)                        if cell[3]>90 and cell[3]<=180:                                uwnd=-cell[4]*np.sin((180-cell[3])*np.pi/180)                                vwnd=cell[4]*np.cos((180-cell[3])*np.pi/180)                        if cell[3]>180 and cell[3]<=270:                                uwnd=cell[4]*np.sin((cell[3]-180)*np.pi/180)                                vwnd=cell[4]*np.cos((cell[3]-180)*np.pi/180)                        if cell[3]>270 and cell[3]<=360:                                uwnd=cell[4]*np.sin((360-cell[3])*np.pi/180)                                vwnd=-cell[4]*np.cos((360-cell[3])*np.pi/180)                        cell[3]=uwnd                        cell[4]=vwnd        rslt=grads_compile(station_num,data,record)        grads_save(rslt,cvt_full_path+".dat")        ctl_create(cvt_full_path+".ctl",cvt_full_path[46:])        grd_gen(data,0.05,cvt_full_path+"_grd.dat",cvt_full_path[46:],cvt_full_path+"_bsmp.ctl")        print cvt_full_path        count+=1"""

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

新浪微博达人勋

 楼主| 发表于 2015-11-2 15:25:05 | 显示全部楼层
这个代码自动识别怎么成了这个鸟样子
密码修改失败请联系微信:mofangbao

新浪微博达人勋

0
早起挑战累计收入
发表于 2015-11-2 16:43:41 | 显示全部楼层
张__QI 发表于 2015-11-2 15:25
这个代码自动识别怎么成了这个鸟样子

python的貌似坏掉了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-11-5 08:33:58 | 显示全部楼层
额。。。。代码识别的的确有点。。。。。
{:eb315:}{:eb315:}
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2021-8-5 16:15:30 | 显示全部楼层
大神,您好。
我现在用aws的数据,正好找到您的脚本。
但是Python是新手,我读了您的脚本后,发现我手里的aws文件和您的不一样。
我的是这样的:有11列:
295
54398    40.127   116.615        29  2013010111      -4.7    1020.5      22.0     312.0       4.0       0.0
.


我想看看您的数据文件,然后我尝试着在您脚本的基础上做些修正和改动。或者请您受累,得空更新下您的脚本,我拿来好好学习。

谢谢您,希望得到帮助。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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