1 | ;+ |
---|
2 | ; |
---|
3 | ; .. _t2m_correction_ncdf.pro: |
---|
4 | ; |
---|
5 | ; ======================= |
---|
6 | ; t2m_correction_ncdf.pro |
---|
7 | ; ======================= |
---|
8 | ; |
---|
9 | ; Mean correction for air temperature bias and correction for variability are |
---|
10 | ; applied. |
---|
11 | ; |
---|
12 | ; :file:`${PROJECT_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc` have been produced by :ref:`interp_erai_t2m_1989_2009.pro`. |
---|
13 | ; It contains air temperature at 2 m height from ERA-I interpolated on OAFLUX grid. |
---|
14 | ; |
---|
15 | ; Corrected air temperature at 2 m height is written in |
---|
16 | ; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc` |
---|
17 | ; if this file not already exists. |
---|
18 | ; |
---|
19 | ; This file will be used by :ref:`TropFlux_19890101_20091231.pro`. |
---|
20 | ; |
---|
21 | ; .. graphviz:: |
---|
22 | ; |
---|
23 | ; digraph t2m_correction_ncdf { |
---|
24 | ; graph [ |
---|
25 | ; rankdir="LR", |
---|
26 | ; ] |
---|
27 | ; |
---|
28 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc"]; |
---|
29 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"]; |
---|
30 | ; |
---|
31 | ; t2m_correction_ncdf [shape=box, |
---|
32 | ; fontname=Courier, |
---|
33 | ; color=blue, |
---|
34 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/t2m_correction_ncdf.pro", |
---|
35 | ; label="${PROJECT}/src/t2m_correction_ncdf.pro"]; |
---|
36 | ; |
---|
37 | ; {file_in} -> {t2m_correction_ncdf} -> {file_out} |
---|
38 | ; |
---|
39 | ; } |
---|
40 | ; |
---|
41 | ; SEE ALSO |
---|
42 | ; ======== |
---|
43 | ; |
---|
44 | ; :ref:`project_profile.sh` |
---|
45 | ; |
---|
46 | ; :ref:`mooring_corrections` |
---|
47 | ; |
---|
48 | ; :ref:`interp_erai_t2m_1989_2009.pro` |
---|
49 | ; |
---|
50 | ; :func:`initncdf <saxo:initncdf>` |
---|
51 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
52 | ; :func:`grossemoyenne <saxo:grossemoyenne>` |
---|
53 | ; :func:`caldat <saxo:caldat>` |
---|
54 | ; :func:`julday <saxo:julday>` |
---|
55 | ; :func:`jul2date <saxo:jul2date>` |
---|
56 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
57 | ; :func:`ncdf_getatt <saxo:ncdf_getatt>` |
---|
58 | ; |
---|
59 | ; EXAMPLES |
---|
60 | ; ======== |
---|
61 | ; |
---|
62 | ; :: |
---|
63 | ; |
---|
64 | ; IDL> t2m_correction_ncdf |
---|
65 | ; |
---|
66 | ; TODO |
---|
67 | ; ==== |
---|
68 | ; |
---|
69 | ; coding rules |
---|
70 | ; |
---|
71 | ; understand usage of jtt |
---|
72 | ; |
---|
73 | ; check time values |
---|
74 | ; |
---|
75 | ; hard coded time in module name and in output filename |
---|
76 | ; |
---|
77 | ; hard coded correction values |
---|
78 | ; |
---|
79 | ; check side effect of replacement of read_ncdf by ncdf_lec :: |
---|
80 | ; |
---|
81 | ; Probleme d'adequation entre les tailles du domaine nx*ny*jpt 350*60*1 et du tableau 350*60*7670 |
---|
82 | ; |
---|
83 | ; hard coded attributes |
---|
84 | ; |
---|
85 | ; CF conventions |
---|
86 | ; |
---|
87 | ; KNOWN ISSUES |
---|
88 | ; ============ |
---|
89 | ; |
---|
90 | ; test of existence of fullfilename_msk not very efficient because |
---|
91 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
92 | ; |
---|
93 | ; EVOLUTIONS |
---|
94 | ; ========== |
---|
95 | ; |
---|
96 | ; $Id$ |
---|
97 | ; |
---|
98 | ; $URL$ |
---|
99 | ; |
---|
100 | ; - fplod 20110808T130628Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
101 | ; |
---|
102 | ; * remove v50 in filename output |
---|
103 | ; * replace _ID by _OD (like other correction modules) |
---|
104 | ; |
---|
105 | ; - fplod 20110104T093758Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
106 | ; |
---|
107 | ; * complete header |
---|
108 | ; * replace /Volumes/Iomega_HDD/TropFlux/input_uncor/ by ${TROPFLUX_ID} |
---|
109 | ; * replace /Volumes/Iomega_HDD/TropFlux/input_cor/full_cor/ by |
---|
110 | ; ${TROPFLUX_OD} |
---|
111 | ; * use :func:`ncdf_getatt <saxo:ncdf_getatt>` for attributes of lat and long |
---|
112 | ; variables |
---|
113 | ; * same problem of time axis and memory like in interp_erai_t2m_1989_2009 |
---|
114 | ; using read_ncdf. |
---|
115 | ; replace read_ncdf by netcdf_lec |
---|
116 | ; |
---|
117 | ; - fplod 20101215T114503Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
118 | ; |
---|
119 | ; * add graph in header |
---|
120 | ; |
---|
121 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
122 | ; |
---|
123 | ; * minimal header |
---|
124 | ; |
---|
125 | ; - pbk 2008 |
---|
126 | ; |
---|
127 | ; * creation |
---|
128 | ; |
---|
129 | ;- |
---|
130 | pro t2m_correction_ncdf |
---|
131 | ; |
---|
132 | @cm_4cal |
---|
133 | @cm_4data |
---|
134 | @cm_4mesh |
---|
135 | @cm_4data |
---|
136 | @cm_project |
---|
137 | ; |
---|
138 | ; test if ${PROJECT_OD} defined |
---|
139 | CASE project_id_env OF |
---|
140 | '' : BEGIN |
---|
141 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
142 | ras = report(msg) |
---|
143 | STOP |
---|
144 | END |
---|
145 | ELSE: BEGIN |
---|
146 | msg = 'iii : ${PROJECT_OD} is ' + project_id_env |
---|
147 | ras = report(msg) |
---|
148 | END |
---|
149 | ENDCASE |
---|
150 | ; |
---|
151 | ; check if output data will be possible |
---|
152 | iodirout = isadirectory(project_od_env) |
---|
153 | ; |
---|
154 | ; existence and protection for reading |
---|
155 | IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
156 | msg = 'eee : the directory' + iodirout + ' is not accessible.' |
---|
157 | ras = report(msg) |
---|
158 | STOP |
---|
159 | ENDIF |
---|
160 | ; |
---|
161 | ; existence and protection for writing |
---|
162 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
163 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
164 | ras = report(msg) |
---|
165 | STOP |
---|
166 | ENDIF |
---|
167 | ; |
---|
168 | da1=19890101 |
---|
169 | da2=20091231 |
---|
170 | ; |
---|
171 | ; build uncorrected t2 filename |
---|
172 | filename_t2_uncor='erai_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_oafluxgrid.nc' |
---|
173 | ; |
---|
174 | ; check if this file exists |
---|
175 | fullfilename_t2_uncor = isafile(iodirout + filename_t2_uncor, NEW=0, /MUST_EXIST) |
---|
176 | IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN |
---|
177 | msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.' |
---|
178 | ras = report(msg) |
---|
179 | STOP |
---|
180 | ENDIF |
---|
181 | ; |
---|
182 | ; build output filename |
---|
183 | filename_out='TropFlux_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'.nc' |
---|
184 | fullfilename_out = iodirout + filename_out |
---|
185 | ; in order to avoid unexpected overwritten |
---|
186 | IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN |
---|
187 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
188 | ras = report(msg) |
---|
189 | STOP |
---|
190 | ENDIF |
---|
191 | ; |
---|
192 | ; define grid parameters with t2 file |
---|
193 | initncdf, fullfilename_t2_uncor |
---|
194 | ; |
---|
195 | ; get time in t2 file |
---|
196 | timein=ncdf_lec(fullfilename_t2_uncor,var='time') |
---|
197 | jptin=n_elements(timein) |
---|
198 | print, 'time steps from data ', jptin |
---|
199 | print, 'The first 10 time values (variable timein) = ', timein[0:9] |
---|
200 | ; |
---|
201 | ; find first and last dates yyyymmdd |
---|
202 | ; they will be written in global attributes of output file |
---|
203 | da=jul2date(julday(01, 01, 1957,timein[0])) |
---|
204 | cda0=string(da,format='(i8.8)') |
---|
205 | da=jul2date(julday(01, 01, 1957,timein[jptin-1])) |
---|
206 | cda1=string(da,format='(i8.8)') |
---|
207 | print, 'first date ', cda0 |
---|
208 | print, 'last date ' , cda1 |
---|
209 | ; |
---|
210 | ; read t2 data |
---|
211 | t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m') |
---|
212 | ; |
---|
213 | t2m=t2m-273.15 |
---|
214 | help, t2m |
---|
215 | ; |
---|
216 | jpt=jptin |
---|
217 | t2m_mean=grossemoyenne(t2m,'t',/nan) |
---|
218 | help, t2m_mean |
---|
219 | |
---|
220 | t2m_m=t2m*0. |
---|
221 | bias_cor=t2m*0. |
---|
222 | |
---|
223 | ;; line fit -> -0.0755589x + 1.71090 ;; (2000-2008) |
---|
224 | ;; line fit -> -0.0741607x + 1.67601 ;; (2000-2009) |
---|
225 | |
---|
226 | for jt=0,jptin-1 do begin |
---|
227 | caldat, julday(01, 01, 1957,timein[jt]),mon,day,yea |
---|
228 | ;++print,day |
---|
229 | jtt=(julday(01, 01, 1957,timein[jt])-julday(1,1,yea)) < 364 |
---|
230 | t=reform(t2m_mean(*,*)) |
---|
231 | t2m_m(*,*,jt)=t |
---|
232 | bias_cor(*,*,jt)=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4 ;; (2000-2009) |
---|
233 | endfor |
---|
234 | help, t2m_m,bias_cor |
---|
235 | |
---|
236 | t2m_ano=t2m-t2m_m |
---|
237 | |
---|
238 | ;; correction for mean based on scatter |
---|
239 | |
---|
240 | help, t2m_ano |
---|
241 | |
---|
242 | ;; applying the correction for varyability based on the scatter |
---|
243 | ;t2m_ano=t2m_ano*(1/0.916484) ;; (2000-2008) |
---|
244 | t2m_ano=t2m_ano*(1/0.918085) ;; (2000-2009) |
---|
245 | |
---|
246 | ;; applying the correction for varyability based on the scatter |
---|
247 | t2m_m=t2m_m+bias_cor |
---|
248 | |
---|
249 | t2m_new=t2m_m+t2m_ano+273.15 |
---|
250 | help, t2m_new |
---|
251 | |
---|
252 | ;writing field |
---|
253 | lat=reform(gphit(0,0:jpj-1)) |
---|
254 | lon=reform(glamt(0:jpi-1,0)) |
---|
255 | cda0=string(da1) |
---|
256 | cda1=string(da2) |
---|
257 | |
---|
258 | time=time-julday(1,1,1950) |
---|
259 | jpt=n_elements(time) |
---|
260 | |
---|
261 | ncfile='!' + fullfilename_out |
---|
262 | |
---|
263 | ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units |
---|
264 | ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name |
---|
265 | lon_attr={units:units, long_name:long_name} |
---|
266 | ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units |
---|
267 | ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name |
---|
268 | lat_attr={units:units, long_name:long_name} |
---|
269 | |
---|
270 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
271 | |
---|
272 | ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units |
---|
273 | ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name |
---|
274 | t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'} |
---|
275 | globattr={source:'Basic data obtained from ERAI. Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1} |
---|
276 | |
---|
277 | |
---|
278 | ncfields = 't2m[longitude,latitude,time]=t2m_new:t2m_attr; ' $ |
---|
279 | + 'longitude[]=lon:lon_attr; ' $ |
---|
280 | + 'latitude[]=lat:lat_attr; ' $ |
---|
281 | + 'time[*time]=time:time_attr ' $ |
---|
282 | + ' @ globattr' |
---|
283 | |
---|
284 | @ncdf_quickwrite |
---|
285 | |
---|
286 | end |
---|