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