1 | import numpy as N |
---|
2 | from constantes import * |
---|
3 | from functions import search_index |
---|
4 | #------------------------------------------------------------------------------------------- |
---|
5 | # function read_weather |
---|
6 | # function reading the weather fields of a yearly eddy-covariance dataset |
---|
7 | # argument : file is file name |
---|
8 | # returns a vector that contains the different weather fields |
---|
9 | def read_weather(file,qc,weather_period): |
---|
10 | nomfic = file |
---|
11 | nb_entete = 1 |
---|
12 | separateur = ',' |
---|
13 | |
---|
14 | fic = open(nomfic, 'r') |
---|
15 | |
---|
16 | header=fic.readline() |
---|
17 | colonnes = header.split(separateur) |
---|
18 | |
---|
19 | #--------------------------------------------------- |
---|
20 | # Ta_f : Air Temperature (C) |
---|
21 | # Precip_f : Precipitation (mm) |
---|
22 | # Rg_f : Global Radiation (W m-2) |
---|
23 | # VPD_f : Vapour Pressure Deficit (hPa) |
---|
24 | # WS_f : Wind horizontal speed (m s-1) |
---|
25 | # WD : Wind direction (degrees) |
---|
26 | # Rh : Relative Humidity (%) |
---|
27 | # LWin : Incomming Longwave Radiation (W m-2) |
---|
28 | #--------------------------------------------------- |
---|
29 | |
---|
30 | index_Ta_f = search_index('Ta_f',colonnes) |
---|
31 | index_Precip_f = search_index('Precip_f',colonnes) |
---|
32 | index_Rg_f = search_index('Rg_f',colonnes) |
---|
33 | index_VPD_f = search_index('VPD_f',colonnes) |
---|
34 | index_WS_f = search_index('WS_f',colonnes) |
---|
35 | index_WD = search_index('WD',colonnes) |
---|
36 | index_Rh = search_index('Rh',colonnes) |
---|
37 | index_LWin = search_index('LWin',colonnes) |
---|
38 | |
---|
39 | index_Ta_fqc = search_index('Ta_fqcOK',colonnes) |
---|
40 | index_Precip_fqc = search_index('Precip_fqcOK',colonnes) |
---|
41 | index_Rg_fqc = search_index('Rg_fqcOK',colonnes) |
---|
42 | index_VPD_fqc = search_index('VPD_fqcOK',colonnes) |
---|
43 | index_WS_fqc = search_index('WS_fqcOK',colonnes) |
---|
44 | |
---|
45 | Ta_f = [] |
---|
46 | Precip_f = [] |
---|
47 | Rg_f = [] |
---|
48 | VPD_f = [] |
---|
49 | WS_f = [] |
---|
50 | WD = [] |
---|
51 | Rh = [] |
---|
52 | LWin = [] |
---|
53 | |
---|
54 | for ligne in fic: |
---|
55 | ligne = ligne.strip() |
---|
56 | colonnes = ligne.split(separateur) |
---|
57 | if((qc==1)and(float(colonnes[index_Ta_fqc])!=1.)): |
---|
58 | Ta_f.append(-9999) |
---|
59 | else: |
---|
60 | Ta_f.append(colonnes[index_Ta_f]) |
---|
61 | if((qc==1)and(float(colonnes[index_Precip_fqc])!=1.)): |
---|
62 | Precip_f.append(-9999) |
---|
63 | else: |
---|
64 | Precip_f.append(colonnes[index_Precip_f]) |
---|
65 | if((qc==1)and(float(colonnes[index_Rg_fqc])!=1.)): |
---|
66 | Rg_f.append(-9999) |
---|
67 | else: |
---|
68 | Rg_f.append(colonnes[index_Rg_f]) |
---|
69 | if((qc==1)and(float(colonnes[index_VPD_fqc])!=1.)): |
---|
70 | VPD_f.append(-9999) |
---|
71 | else: |
---|
72 | VPD_f.append(colonnes[index_VPD_f]) |
---|
73 | if((qc==1)and(float(colonnes[index_WS_fqc])!=1.)): |
---|
74 | WS_f.append(-9999) |
---|
75 | else: |
---|
76 | WS_f.append(colonnes[index_WS_f]) |
---|
77 | WD.append(colonnes[index_WD]) |
---|
78 | Rh.append(colonnes[index_Rh]) |
---|
79 | LWin.append(colonnes[index_LWin]) |
---|
80 | |
---|
81 | Ta_f=N.array(Ta_f,N.float) |
---|
82 | Precip_f=N.array(Precip_f,N.float) |
---|
83 | Rg_f=N.array(Rg_f,N.float) |
---|
84 | VPD_f=N.array(VPD_f,N.float) |
---|
85 | WS_f=N.array(WS_f,N.float) |
---|
86 | WD=N.array(WD,N.float) |
---|
87 | Rh=N.array(Rh,N.float) |
---|
88 | LWin=N.array(LWin,N.float) |
---|
89 | # Not used yet :Psurf |
---|
90 | Psurf=N.ones(len(Ta_f))*-9999 |
---|
91 | |
---|
92 | # Conversion from hPa to Pa |
---|
93 | VPD_f=N.where(VPD_f!=-9999, VPD_f*100., VPD_f) |
---|
94 | |
---|
95 | # Conversion from Celsius to Kelvin |
---|
96 | Ta_f=N.where(Ta_f!=-9999, Ta_f+273.15, Ta_f) |
---|
97 | # Conversion from "mm per timestep" to "kg m-2 s-1" |
---|
98 | |
---|
99 | Precip_f=N.where(Precip_f!=-9999, Precip_f/(weather_period*60*60), Precip_f) |
---|
100 | # Conversion from VPD (Vapour Pressure Deficit, hPa) to Qair (Near Surface Specific Humidity, kg/kg) |
---|
101 | # for i in range(len(VPD_f)): |
---|
102 | |
---|
103 | # if((VPD_f[i] > 0.)and(Ta_f[i]!=-9999)): |
---|
104 | # Conversion from hPa to Pa |
---|
105 | # VPD_f*=100 |
---|
106 | # Magnus Tetens (Murray, 1967) http://cires.colorado.edu/~voemel/vp.html |
---|
107 | # if(Ta_f[i]<273.15): |
---|
108 | # eg=c74*exp(c70*(Ta_f[i]-273.15)/(Ta_f[i]-c71)) |
---|
109 | # else: |
---|
110 | # eg=c74*exp(c72*(Ta_f[i]-273.15)/(Ta_f[i]-c73)) |
---|
111 | |
---|
112 | # Qair[i]=(eg-VPD_f[i])*c75/(Psurf-(eg-VPD_f[i])*c76) |
---|
113 | # else: |
---|
114 | # Qair[i]=-9999 |
---|
115 | |
---|
116 | weather= [Ta_f.tolist(), Psurf.tolist(), VPD_f.tolist(), WS_f.tolist(), Precip_f.tolist(), Rg_f.tolist(), LWin.tolist()] |
---|
117 | |
---|
118 | # weather= [Ta_f, Psurf, |
---|
119 | fic.close() |
---|
120 | return weather |
---|
121 | # end function |
---|
122 | #------------------------------------------------------------------------------------------- |
---|