-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis.pro
315 lines (290 loc) · 7.51 KB
/
analysis.pro
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
pro aread,fin
common xdata
line=''
openr,1,fin
;readf,1,line
;print,line
;readf,1,line
nband=0S & v1=fltarr(2) & v2=fltarr(2) & penv=fltarr(3)
pquick=fltarr(2)
dr1=0s & dr2=0s
while ~eof(1) do begin
readf,1,line
case line of
"sun position:": begin
readf,1,line
reads,strmid(line,10),sun_el readf,1,line
reads,strmid(line,10),sun_az
end "number of bands:": begin
readf,1,line
reads,strmid(line,10),nband
offset = fltarr(nband)
gain = fltarr(nband) readf,1,line
readf,1,line
reads,strmid(line,10),offset
readf,1,line
reads,strmid(line,10),gain
end "clear area:":begin readf,1,line
reads,strmid(line,12),per end "median filter:":begin readf,1,line
reads,strmid(line,10),dr1,dr2
end
"initial ref:":begin
readf,1,line
reads,strmid(line,10),penv
end
"initial depth:":begin
readf,1,line
reads,strmid(line,10),aero0x
end
"vegetation index:":begin
readf,1,line
reads,strmid(line,10),v1
readf,1,line
reads,strmid(line,10),v2
end
"quick look:":begin readf,1,line
reads,strmid(line,12),pquick
end else: print,line
endcase
endwhile close,1
end
function seppen,fname
temp1=fltarr(4)
temp2=fltarr(6)
temp3=fltarr(7)
command = 'info.awk '+fname
spawn,command,result
reads,result[0],temp1
reads,result[1],temp2
reads,result[2],temp3
return,[temp1,temp2,temp3]
end
function read_height,fname
data=fltarr(17,20)
text=''
temp1=fltarr(4)
temp2=fltarr(6)
temp3=fltarr(7)
openr,1,fname
for i=0,19 do begin
readf,1,text
readf,1,temp1
data[0:3,i]=temp1
readf,1,temp2
data[4:9,i]=temp2
readf,1,temp3
data[10:16,i]=temp3
endfor
close,1
return,data
end
function set_coeff,xx,data
d_coeff=fltarr(3,17)
x2=xx^2
xxx=transpose([[xx],[x2]])
result=regress(xxx,reform(data[4,*],20),const=c0)
d_coeff[*,4]=[c0,reform(result)] ; Direct light
result=regress(xxx,reform(data[5,*],20),const=c0)
d_coeff[*,5]=[c0,reform(result)] ; Sky light
result=regress(xxx,reform(data[6,*],20),const=c0)
d_coeff[*,6]=[c0,reform(result)] ; Environment light
result=regress(xxx,reform(data[7,*],20),const=c0)
d_coeff[*,7]=[c0,reform(result)] ; Path radiance
result=regress(xxx,reform(data[8,*],20),const=c0)
d_coeff[*,8]=[c0,reform(result)] ; Background radiance
result=regress(xxx,reform(data[10,*],20),const=c0)
d_coeff[*,10]=[data[10,0],0,0] ; Gas transmission down
result=regress(xxx,reform(data[11,*],20),const=c0)
d_coeff[*,11]=[data[11,0],0,0] ; Gas transmission up
result=regress(xxx,reform(data[15,*],20),const=c0)
d_coeff[*,15]=[c0,reform(result)] ; Optical depth
result=regress(xxx,reform(data[16,*],20),const=c0)
d_coeff[*,16]=[c0,reform(result)] ; Spherical albedo
return,d_coeff
end
function set_coeff2,xx,yy,data
d_coeff=fltarr(6,17)
x2=xx^2 & y2=yy^2 & xy=xx*yy
xxx=transpose([[xx],[yy],[x2],[xy],[y2]])
result=regress(xxx,reform(data[7,*],10),const=c0)
d_coeff[*,7]=[c0,reform(result)] ; Path radiance
result=regress(xxx,reform(data[8,*],10),const=c0)
d_coeff[*,8]=[c0,reform(result)] ; Background radiance
result=regress(xxx,reform(data[15,*],10),const=c0)
d_coeff[*,15]=[c0,reform(result)] ; Optical depth
result=regress(xxx,reform(data[16,*],10),const=c0)
d_coeff[*,16]=[c0,reform(result)] ; Spherical albedo
return,d_coeff
end
function p_height,data,datax,height,height0
slope=(data[*,6]-datax)/height0
return,datax+slope*height
end
pro h_plot,data,datax,n
xx=findgen(20)*0.5
plot,xx,data[n,*],yrange=[0.0,0.3]
oplot,[0.0,3.0],data[n,[0,6]],color=255*256L
oplot,[0.0,3.0],[datax[n],data[n,6]],color=255*256L
end
function reflectance,data,rad
path=data[7]
back=data[8]
gtrans=data[10]
edir=data[4]
esky=data[5]
eenv=data[6]
odepth=data[15]
return,!dpi*(rad-path-back)/gtrans/(edir+esky+eenv)*exp(odepth)
end
function second,x,y
xx=transpose([[x],[x^2]])
temp=regress(xx,y,const=c0)
return,[c0,reform(temp,2)]
end
function e_depth,ref,coeff
d0=coeff[0]-ref
d1=coeff[1]
d2=coeff[2]
return,-d1/d2/2+sqrt(d1^2/d2^2/4-d0/d2)
end
function adjust,depth,height
common rdata
adata=[1.0,depth,depth^2]##transpose(d_coeff)
;print,reflectance(d_data[*,4],100.0)
;print,reflectance(adata,100.0)
return,adata+(-adata+hdata)*height/4.0
end
function adjust2x,depth,height,cosb1,penv1
common rdata
hdata2=hdata
adata=[1.0,depth,depth^2]##transpose(d_coeff)
adata[4]=adata[4]*cosb1/cosb0 ; direct irradiance
hdata2[4]=hdata[4]*cosb1/cosb0
temp=(1-penv0*adata[16])*penv1/(1-penv1*adata[16])/penv0
temp2=(1-penv0*hdata[16])*penv1/(1-penv1*hdata[16])/penv0
adata[6]=adata[6]*temp ; env irradiance
hdata2[6]=hdata[6]*temp2
adata[8]=adata[8]*temp ; back radiance
hdata2[8]=hdata[8]*temp2
;print,reflectance(d_data[*,4],100.0)
;print,reflectance(adata,100.0)
return,adata+(-adata+hdata2)*height/4.0
end
function adjust2,depth,height,cosb1,penv1
common rdata
hdata2=hdata
adata=[1.0,depth,depth^2]##transpose(d_coeff)
adata[4]=adata[4]*cosb1/cosb0 ; direct irradiance
hdata2[4]=hdata[4]*cosb1/cosb0
temp=(1-penv0*adata[16])*penv1/(1-penv1*adata[16])/penv0
temp2=(1-penv0*hdata[16])*penv1/(1-penv1*hdata[16])/penv0
adata[6]=adata[6]*temp ; env irradiance
hdata2[6]=hdata[6]*temp2
adata[8]=adata[8]*temp ; back radiance
hdata2[8]=hdata[8]*temp2
return,adata+(-adata+hdata2)*height/4.0
end
function set_ref,height,rad,cosb1,penv1
common rdata
ref=fltarr(20)
for i=0,19 do begin
adata=adjust2(0.05*i,height,cosb1,penv1)
ref[i]=reflectance(adata,rad)
endfor
;print,ref
xx=findgen(20)*0.05
x2=xx^2
xxx=transpose([[xx],[x2]])
result=regress(xxx,ref,const=c0)
return,[c0,reform(result)]
end
function set_ref2,height,rad,cosb1,penv1
common rdata
x0=0.2 & x1=0.4 & x2=0.6
adata=adjust2(x0,height,cosb1,penv1)
y0=reflectance(adata,rad)
adata=adjust2(x1,height,cosb1,penv1)
y1=reflectance(adata,rad)
adata=adjust2(x2,height,cosb1,penv1)
y2=reflectance(adata,rad)
;print,y0,y1,y2
;c0=(x1*x2*y0-2*x2*x0*y1+x0*x1*y2)/0.08
c0=3*y0-3*y1+y2
;c1=(-(x1+x2)*y0+2*(x2+x0)*y1-(x0+x1)*y2)/0.08
c1=(-y0+1.6*y1-0.6*y2)/0.08
c2=(y0-2*y1+y2)/0.08
return,[c0,c1,c2]
end
function set_ref2x,height,rad,cosb1,penv1
common rdata
x0=0.2 & x1=0.4
adata=adjust2(x0,height,cosb1,penv1)
y0=reflectance(adata,rad)
adata=adjust2(x1,height,cosb1,penv1)
y1=reflectance(adata,rad)
c1=(y1-y0)/(x1-x0)
c0=(y0*x1-y1*x0)/(x1-x0)
return,[c0,c1]
end
function estimate,dem,inc,rad,penv1
rcoef=fltarr(2,1200,1200)
for j=0,1199 do begin
;if (j mod 100) eq 0 then print,j
for i=0,1199 do begin
temp=set_ref2x(dem[i,j],rad[i,j],inc[i,j],penv1[i,j])
rcoef[*,i,j]=temp
endfor
endfor
return,rcoef
end
function estimate2,dem,inc,rad,penv1
rcoef=fltarr(3,1200,1200)
for j=0,1199 do begin
;if (j mod 100) eq 0 then print,j
for i=0,1199 do begin
temp=set_ref2(dem[i,j],rad[i,j],inc[i,j],penv1[i,j])
rcoef[*,i,j]=temp
endfor
endfor
return,rcoef
end
function iestimate,wm,rcoef
aero=fltarr(1200,1200)+!values.f_nan
a0=reform((rcoef[0,*,*]-wm)/rcoef[2,*,*],1200,1200)
a1=reform(rcoef[1,*,*]/rcoef[2,*,*],1200,1200)
for i=0,1199 do begin
for j=0,1199 do begin
temp=a1[i,j]^2/4-a0[i,j]
if temp lt 0 then continue
x1=-a1[i,j]/2+sqrt(temp)
x2=-a1[i,j]/2-sqrt(temp)
if (x1 ge 0) and (x1 le 1.0) then begin
aero[i,j]=x1
if (x2 ge 0) and (x2 le 1.0) then aero[i,j]=!values.f_nan
endif else if (x2 ge 0) and (x2 le 1.0) then aero[i,j]=x2
endfor
endfor
return,aero
end
function re_est,ref_0,wm
aero2=fltarr(2,1200,1200)
for j=0,1199 do begin
if (j mod 100) eq 0 then print,j
for i=0,1199 do begin
temp=set_ref2x(dem[i,j],inc[i,j],rad[i,j],aero[i,j])
aero2[i,j]=temp
endfor
endfor
return,rcoef
end