source: trunk/src/t2m_correction_ncdf.pro @ 79

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

start to work on correction tools

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; - fplod 20110808T130628Z aedon.locean-ipsl.upmc.fr (Darwin)
97;
98;   * remove v50 in filename output
99;   * replace _ID by _OD (like other correction modules)
100;
101; - fplod 20110104T093758Z aedon.locean-ipsl.upmc.fr (Darwin)
102;
103;   * complete header
104;   * replace /Volumes/Iomega_HDD/TropFlux/input_uncor/ by ${TROPFLUX_ID}
105;   * replace /Volumes/Iomega_HDD/TropFlux/input_cor/full_cor/ by
106;     ${TROPFLUX_OD}
107;   * use :func:`ncdf_getatt <saxo:ncdf_getatt>` for attributes of lat and long
108;     variables
109;   * same problem of time axis and memory like in interp_erai_t2m_1989_2009
110;     using read_ncdf.
111;     replace read_ncdf by netcdf_lec
112;
113; - fplod 20101215T114503Z aedon.locean-ipsl.upmc.fr (Darwin)
114;
115;   * add graph in header
116;
117; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
118;
119;   * minimal header
120;
121; - pbk 2008
122;
123;   * creation
124;
125;-
126pro t2m_correction_ncdf
127;
128@cm_4cal
129@cm_4data
130@cm_4mesh
131@cm_4data
132@cm_project
133;
134; test if ${PROJECT_OD} defined
135CASE project_id_env OF
136    ''  :  BEGIN
137     msg = 'eee : ${PROJECT_OD} is not defined'
138     ras = report(msg)
139     STOP
140           END
141 ELSE: BEGIN
142     msg = 'iii : ${PROJECT_OD} is ' + project_id_env
143     ras = report(msg)
144       END
145ENDCASE
146;
147; check if output data will be possible
148iodirout = isadirectory(project_od_env)
149;
150; existence and protection for reading
151IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
152   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
153   ras = report(msg)
154   STOP
155ENDIF
156;
157; existence and protection for writing
158IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
159    msg = 'eee : the directory' + iodirout  + ' was not found.'
160    ras = report(msg)
161    STOP
162ENDIF
163;
164da1=19890101
165da2=20091231
166;
167; build uncorrected t2 filename
168filename_t2_uncor='erai_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_oafluxgrid.nc'
169;
170; check if this file exists
171fullfilename_t2_uncor = isafile(iodirout + filename_t2_uncor, NEW=0, /MUST_EXIST)
172IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN
173   msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.'
174   ras = report(msg)
175   STOP
176ENDIF
177;
178; build output filename
179filename_out='TropFlux_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'.nc'
180fullfilename_out = iodirout + filename_out
181; in order to avoid unexpected overwritten
182IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
183   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
184   ras = report(msg)
185   STOP
186ENDIF
187;
188; define grid parameters with t2 file
189initncdf, fullfilename_t2_uncor
190;
191; get time in t2 file
192timein=ncdf_lec(fullfilename_t2_uncor,var='time')
193jptin=n_elements(timein)
194print, 'time steps from data ', jptin
195print, 'The first 10 time values (variable timein) = ', timein[0:9]
196;
197; find first and last dates yyyymmdd
198; they will be written in global attributes of output file
199da=jul2date(julday(01, 01, 1957,timein[0]))
200cda0=string(da,format='(i8.8)')
201da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
202cda1=string(da,format='(i8.8)')
203print, 'first date ', cda0
204print, 'last date ' , cda1
205;
206; read t2 data
207t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m')
208;
209t2m=t2m-273.15
210help, t2m
211;
212jpt=jptin
213t2m_mean=grossemoyenne(t2m,'t',/nan)
214help, t2m_mean
215
216t2m_m=t2m*0.
217bias_cor=t2m*0.
218
219;; line fit ->  -0.0755589x + 1.71090   ;; (2000-2008)
220;; line fit ->  -0.0741607x + 1.67601   ;; (2000-2009)
221
222for jt=0,jptin-1 do begin
223  caldat, julday(01, 01, 1957,timein[jt]),mon,day,yea
224  ;++print,day
225  jtt=(julday(01, 01, 1957,timein[jt])-julday(1,1,yea)) < 364
226  t=reform(t2m_mean(*,*))
227  t2m_m(*,*,jt)=t
228  bias_cor(*,*,jt)=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4     ;; (2000-2009)
229endfor
230help, t2m_m,bias_cor
231
232t2m_ano=t2m-t2m_m
233
234;; correction for mean based on scatter
235
236help, t2m_ano
237
238;; applying the correction for varyability based on the scatter
239;t2m_ano=t2m_ano*(1/0.916484)    ;; (2000-2008)
240t2m_ano=t2m_ano*(1/0.918085)     ;; (2000-2009)
241
242;; applying the correction for varyability based on the scatter
243t2m_m=t2m_m+bias_cor
244
245t2m_new=t2m_m+t2m_ano+273.15
246help, t2m_new
247
248;writing field
249lat=reform(gphit(0,0:jpj-1))
250lon=reform(glamt(0:jpi-1,0))
251cda0=string(da1)
252cda1=string(da2)
253
254time=time-julday(1,1,1950)
255jpt=n_elements(time)
256
257ncfile='!' + fullfilename_out
258
259ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units
260ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name
261lon_attr={units:units, long_name:long_name}
262ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units
263ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name
264lat_attr={units:units, long_name:long_name}
265
266time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
267
268ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units
269ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name
270t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'}
271globattr={source:'Basic data obtained from ERAI.  Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1}
272
273
274ncfields = 't2m[longitude,latitude,time]=t2m_new:t2m_attr; ' $
275                      + 'longitude[]=lon:lon_attr; ' $
276                      + 'latitude[]=lat:lat_attr; ' $
277                      + 'time[*time]=time:time_attr ' $
278                      + ' @ globattr'
279
280@ncdf_quickwrite
281
282end
Note: See TracBrowser for help on using the repository browser.