source: trunk/src/t2m_correction_ncdf.pro @ 85

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

restart consolidation of paper01 software

File size: 7.6 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.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;-
130pro 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
139CASE 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
149ENDCASE
150;
151; check if output data will be possible
152iodirout = isadirectory(project_od_env)
153;
154; existence and protection for reading
155IF (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
159ENDIF
160;
161; existence and protection for writing
162IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
163    msg = 'eee : the directory' + iodirout  + ' was not found.'
164    ras = report(msg)
165    STOP
166ENDIF
167;
168da1=19890101
169da2=20091231
170;
171; build uncorrected t2 filename
172filename_t2_uncor='erai_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_oafluxgrid.nc'
173;
174; check if this file exists
175fullfilename_t2_uncor = isafile(iodirout + filename_t2_uncor, NEW=0, /MUST_EXIST)
176IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN
177   msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.'
178   ras = report(msg)
179   STOP
180ENDIF
181;
182; build output filename
183filename_out='TropFlux_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'.nc'
184fullfilename_out = iodirout + filename_out
185; in order to avoid unexpected overwritten
186IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
187   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
188   ras = report(msg)
189   STOP
190ENDIF
191;
192; define grid parameters with t2 file
193initncdf, fullfilename_t2_uncor
194;
195; get time in t2 file
196timein=ncdf_lec(fullfilename_t2_uncor,var='time')
197jptin=n_elements(timein)
198print, 'time steps from data ', jptin
199print, '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
203da=jul2date(julday(01, 01, 1957,timein[0]))
204cda0=string(da,format='(i8.8)')
205da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
206cda1=string(da,format='(i8.8)')
207print, 'first date ', cda0
208print, 'last date ' , cda1
209;
210; read t2 data
211t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m')
212;
213t2m=t2m-273.15
214help, t2m
215;
216jpt=jptin
217t2m_mean=grossemoyenne(t2m,'t',/nan)
218help, t2m_mean
219
220t2m_m=t2m*0.
221bias_cor=t2m*0.
222
223;; line fit ->  -0.0755589x + 1.71090   ;; (2000-2008)
224;; line fit ->  -0.0741607x + 1.67601   ;; (2000-2009)
225
226for 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)
233endfor
234help, t2m_m,bias_cor
235
236t2m_ano=t2m-t2m_m
237
238;; correction for mean based on scatter
239
240help, t2m_ano
241
242;; applying the correction for varyability based on the scatter
243;t2m_ano=t2m_ano*(1/0.916484)    ;; (2000-2008)
244t2m_ano=t2m_ano*(1/0.918085)     ;; (2000-2009)
245
246;; applying the correction for varyability based on the scatter
247t2m_m=t2m_m+bias_cor
248
249t2m_new=t2m_m+t2m_ano+273.15
250help, t2m_new
251
252;writing field
253lat=reform(gphit(0,0:jpj-1))
254lon=reform(glamt(0:jpi-1,0))
255cda0=string(da1)
256cda1=string(da2)
257
258time=time-julday(1,1,1950)
259jpt=n_elements(time)
260
261ncfile='!' + fullfilename_out
262
263ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units
264ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name
265lon_attr={units:units, long_name:long_name}
266ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units
267ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name
268lat_attr={units:units, long_name:long_name}
269
270time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
271
272ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units
273ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name
274t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'}
275globattr={source:'Basic data obtained from ERAI.  Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1}
276
277
278ncfields = '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
286end
Note: See TracBrowser for help on using the repository browser.