打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
利用python计算太阳天顶角、方位角、高度角

在遥感计算中一般都会用到天顶角、方位角、高度角。之前都是直接在excel中输入公式,这种方式输入公式比较麻烦,而且容易出错。后来在网上看到吉林大学汪自军博士的计算程序。链接:http://blog.sciencenet.cn/home.php?mod=space&uid=43777&do=blog&id=238552
非常好用,但是我看了一下,汪博士主要用matlab、C++、FORTRAN三种语言编写的,而且输入文件是txt格式。txt文件的操作性我认为不如excel。
说一下主要改进的地方:
1、编程语言改为python
2、输入和输出文件格式均改为excel
3、以为太阳高度角与天顶角互余,这次也加进去了。
欢迎讨论,下面附上主要代码:

table = data.sheets()[0] # 打开第一张表nrows = table.nrows # 获取表的行数ncols = table.ncolsstation=table.col_values(0)[1:]year=table.col_values(1)[1:]month=table.col_values(2)[1:]day=table.col_values(3)[1:]hour=table.col_values(4)[1:]min=table.col_values(5)[1:]sec=table.col_values(6)[1:]lon=table.col_values(7)[1:]lat =table.col_values(8)[1:]TimeZone =table.col_values(9)[1:]wb = xlutils.copy.copy(data)ws = wb.get_sheet(0)ws.write(0, 11, 'Day of Year')ws.write(0, 12, 'Local Time') #实际是gtdtws.write(0, 13, 'Sun Angle')#(sitar)ws.write(0, 14, 'Declination Angle')ws.write(0, 15, 'Equation of Time')style = xlwt.easyxf('pattern: pattern solid, fore_color yellow;')ws.write(0, 16, 'ZenithAngle(deg)',style)ws.write(0, 17, 'HeightAngle(deg)',style)ws.write(0, 18, 'AzimuthAngle(deg)',style)for n in range(1,nrows):    m=n-1#年积日的计算    #儒略日 Julian day(由通用时转换到儒略日)    JD0 = int(365.25*(year[m]-1))+int(30.6001*(1+13))+1+hour[m]/24+1720981.5    if month[m]<=2:        JD2 = int(365.25*(year[m]-1))+int(30.6001*(month[m]+13))+day[m]+hour[m]/24+1720981.5    else:        JD2 = int(365.25*year[m])+int(30.6001*(month[m]+1))+day[m]+hour[m]/24+1720981.5    #年积日 Day of year    DOY = JD2-JD0+1#N0   sitar=θ    N0 = 79.6764 + 0.2422*(year[m]-1985) - int((year[m]-1985)/4.0)    sitar = 2*math.pi*(DOY-N0)/365.2422    ED1 = 0.3723 + 23.2567*math.sin(sitar) + 0.1149*math.sin(2*sitar) - 0.1712*math.sin(3*sitar)- 0.758*math.cos(sitar) + 0.3656*math.cos(2*sitar) + 0.0201*math.cos(3*sitar)    ED = ED1*math.pi/180           #ED本身有符号    if lon[m] >= 0:        if TimeZone == -13:            dLon = lon[m] - (math.floor((lon[m]*10-75)/150)+1)*15.0        else:            dLon = lon[m] - TimeZone[m]*15.0   #地球上某一点与其所在时区中心的经度差    else:        if TimeZone[m] == -13:            dLon =  (math.floor((lon[m]*10-75)/150)+1)*15.0- lon[m]        else:            dLon =  TimeZone[m]*15.0- lon[m]    #时差    Et = 0.0028 - 1.9857*math.sin(sitar) + 9.9059*math.sin(2*sitar) - 7.0924*math.cos(sitar)- 0.6882*math.cos(2*sitar)    gtdt1 = hour[m] + min[m]/60.0 + sec[m]/3600.0 + dLon/15        #地方时    gtdt = gtdt1 + Et/60.0    dTimeAngle1 = 15.0*(gtdt-12)    dTimeAngle = dTimeAngle1*math.pi/180    latitudeArc = lat[m]*math.pi/180# 高度角计算公式    HeightAngleArc = math.asin(math.sin(latitudeArc)*math.sin(ED)+math.cos(latitudeArc)*math.cos(ED)*math.cos(dTimeAngle))# 方位角计算公式    CosAzimuthAngle = (math.sin(HeightAngleArc)*math.sin(latitudeArc)-math.sin(ED))/math.cos(HeightAngleArc)/math.cos(latitudeArc)    AzimuthAngleArc = math.acos(CosAzimuthAngle)    HeightAngle = HeightAngleArc*180/math.pi    ZenithAngle = 90-HeightAngle    AzimuthAngle1 = AzimuthAngleArc *180/math.pi    if dTimeAngle < 0:        AzimuthAngle = 180 - AzimuthAngle1    else:        AzimuthAngle = 180 + AzimuthAngle1    print('站位:'+station[m]+' 太阳天顶角(deg):%f 高度角(deg):%f 方位角(deg):%f ' % (ZenithAngle,HeightAngle,AzimuthAngle))

因为最近在研究海洋遥感,在采样的时候会有站位信息,所以程序中存在站位的问题(不过这个丝毫不影响计算)。
附上运行结果:


最后,感谢汪自军博士的思路和中国气象科学研究院王炳忠研究员编写的《太阳辐射计算讲座》。
2017年4月27日                                                                                                               

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
python操作Excel读写--使用xlrd
一文看懂用Python读取Excel数据
Selenium2+python自动化58
python xlrd基础操作和示例
python selenium - 利用excel实现参数化
Python处理Excel表格
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服