Prospect5AndD

 1from pypro4sail import prospect
 2import math
 3
 4
 5def prospectD(wl, N, Car, BP, Cm, Cab, Anth, Cw):
 6    ws, rs, ts = prospect.prospectd(N, Cab, Car, BP, Cw, Cm, Anth)
 7    if type(wl) is float or type(wl) is int:
 8        wl = [wl]
 9    reflectances = []
10    transmittances = []
11    r, t = 0, 0
12    for wavelengthStr in wl:
13        wavelength = float(wavelengthStr)
14        # interpolation
15        if wavelength <= 400:
16            r, t = rs[0], ts[0]
17        elif wavelength >= 2500:
18            r, t = rs[2500], ts[2500]
19        else:
20            wavelength_int = math.floor(wavelength)
21            extra = wavelength - wavelength_int
22            left_r = rs[wavelength_int - 400]
23            right_r = rs[wavelength_int - 400 + 1]
24            k = (right_r - left_r)
25            r = k * extra + left_r
26
27            left_t = ts[wavelength_int - 400]
28            right_t = ts[wavelength_int - 400 + 1]
29            k = right_t - left_t
30            t = k * extra + left_t
31
32        reflectances.append(r)
33        transmittances.append(t)
34    return reflectances, transmittances
35
36
37if __name__ == "__main__":
38    print(prospectD([600, 900], 1.5, 8.0, 0, 0.015, 50, 0, 0.015))
def prospectD(wl, N, Car, BP, Cm, Cab, Anth, Cw):
 7def prospectD(wl, N, Car, BP, Cm, Cab, Anth, Cw):
 8    ws, rs, ts = prospect.prospectd(N, Cab, Car, BP, Cw, Cm, Anth)
 9    if type(wl) is float or type(wl) is int:
10        wl = [wl]
11    reflectances = []
12    transmittances = []
13    r, t = 0, 0
14    for wavelengthStr in wl:
15        wavelength = float(wavelengthStr)
16        # interpolation
17        if wavelength <= 400:
18            r, t = rs[0], ts[0]
19        elif wavelength >= 2500:
20            r, t = rs[2500], ts[2500]
21        else:
22            wavelength_int = math.floor(wavelength)
23            extra = wavelength - wavelength_int
24            left_r = rs[wavelength_int - 400]
25            right_r = rs[wavelength_int - 400 + 1]
26            k = (right_r - left_r)
27            r = k * extra + left_r
28
29            left_t = ts[wavelength_int - 400]
30            right_t = ts[wavelength_int - 400 + 1]
31            k = right_t - left_t
32            t = k * extra + left_t
33
34        reflectances.append(r)
35        transmittances.append(t)
36    return reflectances, transmittances