-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSunShine.py
262 lines (249 loc) · 10.3 KB
/
SunShine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# -*- coding: cp936 -*-
import os
import datetime
import math
from DayTotalRadiance import LevAstRad
from test import GetCoeffab
from test import GetCoeffAB
from test import GetLL
import numpy as np
import arcpy
from arcpy import env
outpath = 'C:\Users\George\Desktop\pythontest\htgy2012'
env.overwriteOutput=True
env.workspace= outpath
PI = math.pi
#StaSunArray = []
#testarray = []
# def getsunshinetime(folderpath):
# sunarray = []
# sourcepath = folderpath
# #year = [2008,2009,2010,2011,2012,2013]
# year = 2008
# namearray = []
# LDayTotRad = []
# LDayDirRad = []
# LDayDifRad = []
# for i in range(0,14):
# staID = LCoeffab[i][1][0]
# sLat = LCoeffab[i][1][1]
# #sLong = LCoeffab[i][1][2]
# #sHeight = LCoeffab[i][1][3]
# sLat = float(sLat)
# #sLong = float(sLong)
# #print sLat
# coeffab = LCoeffab[i]
# path = sourcepath+'\\'+staID+'\\'+'日照时数'
# print path
# #print path
# nameID = staID
# #for ii in range(len(year)):
# name = nameID+str(year)
# #print name
# namearray.append(name)
# #指定txt路径
# sDayTotRad = []
# sDayDirRad = []
# sDayDifRad = []
# for r,ds,fs in os.walk(path):
# for f in fs:
# #如果在[2008-2013],则读取文件
# if f[:-4] in namearray:
# filename = r+"\\"+f
# txthandle = open(filename,'rb')
# cline = txthandle.readlines()
# for i in range(0,len(cline)):
# sline = cline[i].split(" ")
# array = filter(None,sline)
# year = array[0]
# month = array[1]
# day = array[2]
# #shapefilename = year+month+day+".shp"
# shinetime = array[3]
# shinetime = float(shinetime)
# #jd = JD0(year,month,day)
# #print array[0],array[1],array[2],array[3]
# #计算年积日-----------
# fmt = '%Y.%m.%d'
# s = year+'.'+month+'.'+day
# jd = datetime.datetime.strptime(s, fmt).timetuple().tm_yday
# #print jd
# result = LevAstRad(sLat,jd)
# DayL = result[1]
# DayL = float(DayL)
# R = shinetime/DayL
# ARad = result[2]
# m = int(month)-1
# DayTotRad = float(ARad)*(float(coeffab[m][2])+float(R)*float(coeffab[m][3]))
# DayDirRad = float(ARad)*(R*float(arrayAB[m][0])+ math.pow(R,2)*float(arrayAB[m][1]))
# DayDifRad = DayTotRad - DayDirRad
# sDayTotRad.append(DayTotRad)
# #print len(sDayTotRad)
# sDayDirRad.append(DayDirRad)
# #print len(sDayDirRad)
# sDayDifRad.append(DayDifRad)
# #print len(sDayDifRad)
# #jd_shinetime = [jd,shinetime]
# #sunarray.append(jd)
# #sunarray.append(shinetime)
# #年积日计算结束------------
# #sDayTotRad = np.asarray(sDayTotRad)
# #sDayTotRad.T
# #print len(sDayTotRad)
# LDayTotRad.append(sDayTotRad)
# #sDayDirRad = np.asarray(sDayDirRad)
# #sDayDirRad.T
# LDayDirRad.append(sDayDirRad)
# #sDayDifRad = np.asarray(sDayDifRad)
# #sDayDifRad.T
# LDayDifRad.append(sDayDifRad)
# for ii in range(0,366):
# shapefilename = "2008"+str(ii)+".shp"
# arcpy.CreateFeatureclass_management(outpath, shapefilename, "POINT")
# arcpy.AddField_management(shapefilename, "staID", "string", field_length=20)
# arcpy.AddField_management(shapefilename, "sHeight", "string", field_length=20)
# arcpy.AddField_management(shapefilename, "DayTotRad", "float", field_length=20)
# arcpy.AddField_management(shapefilename, "DayDirRad", "float", field_length=20)
# arcpy.AddField_management(shapefilename, "DayDifRad", "float", field_length=20)
# fields = ['staID', 'sHeight', 'DayTotRad', 'DayDirRad', 'DayDifRad']
# for jj in range(0,14):
# staID = LLarray[jj][0]
# sY = LLarray[jj][1]
# sX = LLarray[jj][2]
# sHeight = LLarray[jj][3]
# #print staID,sLat,sLong,sHeight
# rowInserter = arcpy.InsertCursor(shapefilename, fields)
# pointGeometry = arcpy.Point(sY, sX)
# newPoint = rowInserter.newRow()
# newPoint.shape = pointGeometry
# print pointGeometry.X,pointGeometry.Y
# newPoint.staID = staID
# newPoint.sHeight = sHeight
# newPoint.DayTotRad = LDayTotRad[jj][ii]
# newPoint.DayDirRad = LDayDirRad[jj][ii]
# newPoint.DayDifRad = LDayDifRad[jj][ii]
# rowInserter.insertRow(newPoint)
# print "pick up Successfully...."
# #print str(ii)+"----"+str(jj)
# del rowInserter
# return 0
def getsolartime(folderpath):
sunarray = []
sourcepath = folderpath
#year = [2008,2009,2010,2011,2012,2013]
year = 2012
namearray = []
LDayTotRad = []
LDayDirRad = []
LDayDifRad = []
for i in range(0,13):
staID = LCoeffab[i][1][0]
sLat = LCoeffab[i][1][1]
#sLong = LCoeffab[i][1][2]
#sHeight = LCoeffab[i][1][3]
sLat = float(sLat)
#sLong = float(sLong)
#print sLat
coeffab = LCoeffab[i]
path = sourcepath+'\\'+staID+'.txt'
print path
#print path
nameID = staID
#for ii in range(len(year)):
name = nameID+str(year)
#print name
namearray.append(name)
#指定txt路径
sDayTotRad = []
sDayDirRad = []
sDayDifRad = []
txthandle = open(path,'rb')
cline = txthandle.readlines()
startdateline = cline[0].split(" ")
startyear = int(startdateline[1])
startmonth = int(startdateline[2])
startday = int(startdateline[3])
d1 = datetime.datetime(startyear, startmonth, startday)
d2 = datetime.datetime(2012,1,1)
days = (d2 - d1).days
print days
for i in range(days, days+366):
sline = cline[i].split(" ")
print sline
array = filter(None, sline)
year = array[1]
month = array[2]
day = array[3]
# shapefilename = year+month+day+".shp"
shinetime = array[4]
shinetime = float(shinetime)
# jd = JD0(year,month,day)
# print array[0],array[1],array[2],array[3]
# 计算年积日-----------
fmt = '%Y.%m.%d'
s = year + '.' + month + '.' + day
jd = datetime.datetime.strptime(s, fmt).timetuple().tm_yday
# print jd
result = LevAstRad(sLat, jd)
DayL = result[1]
DayL = float(DayL) R = shinetime / DayL
ARad = result[2]
m = int(month) - 1
DayTotRad = float(ARad) * (float(coeffab[m][2]) + float(R) * float(coeffab[m][3]))
DayDirRad = float(ARad) * (R * float(arrayAB[m][0]) + math.pow(R, 2) * float(arrayAB[m][1]))
DayDifRad = DayTotRad - DayDirRad
sDayTotRad.append(DayTotRad)
# print len(sDayTotRad)
sDayDirRad.append(DayDirRad)
# print len(sDayDirRad)
sDayDifRad.append(DayDifRad)
LDayTotRad.append(sDayTotRad)
#sDayDirRad = np.asarray(sDayDirRad)
#sDayDirRad.T
LDayDirRad.append(sDayDirRad)
#sDayDifRad = np.asarray(sDayDifRad)
#sDayDifRad.T
LDayDifRad.append(sDayDifRad)
for ii in range(0,366):
shapefilename = "2012"+str(ii)+".shp"
arcpy.CreateFeatureclass_management(outpath, shapefilename, "POINT")
arcpy.AddField_management(shapefilename, "staID", "string", field_length=20)
arcpy.AddField_management(shapefilename, "sHeight", "string", field_length=20)
arcpy.AddField_management(shapefilename, "DayTotRad", "float", field_length=20)
arcpy.AddField_management(shapefilename, "DayDirRad", "float", field_length=20)
arcpy.AddField_management(shapefilename, "DayDifRad", "float", field_length=20)
fields = ['staID', 'sHeight', 'DayTotRad', 'DayDirRad', 'DayDifRad']
for jj in range(0,13):
staID = LLarray[jj][0]
sY = LLarray[jj][1]
sX = LLarray[jj][2]
sHeight = LLarray[jj][3]
#print staID,sLat,sLong,sHeight
rowInserter = arcpy.InsertCursor(shapefilename, fields)
pointGeometry = arcpy.Point(sY, sX)
newPoint = rowInserter.newRow()
newPoint.shape = pointGeometry
#print pointGeometry.X,pointGeometry.Y
newPoint.staID = staID
newPoint.sHeight = sHeight
newPoint.DayTotRad = LDayTotRad[jj][ii]
newPoint.DayDirRad = LDayDirRad[jj][ii]
newPoint.DayDifRad = LDayDifRad[jj][ii]
rowInserter.insertRow(newPoint)
print "pick up Successfully...."
#print str(ii)+"----"+str(jj)
del rowInserter
return 0
if __name__ =='__main__':
txtpath1 = 'C:\Users\George\Desktop\pythontest\\abCoeff.txt'
txtpath2 = 'C:\Users\George\Desktop\pythontest\\abCoeff_LP.txt'
txtpath3 = "C:\Users\George\Desktop\pythontest\Prj_coords.txt"
folderpath = r'C:\Users\George\Desktop\solar radiation'
arrayAB = GetCoeffAB(txtpath1)
#print arrayAB
LCoeffab = GetCoeffab(txtpath2)
print LCoeffab[12][1]
LLarray = GetLL(txtpath3)
print LLarray[12]
getsolartime(folderpath)
#staID = GetCoeffab(txtpath2)