source: trunk/src/t2m_correction_ncdf.pro @ 70

Last change on this file since 70 was 50, checked in by pinsard, 13 years ago

replace TROPFLUX by PROJECT

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