利用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.ncols

station=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') #实际是gtdt
ws.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日

  • 9
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值