source: trunk/src/t2m_correction_ncdf.pro @ 155

Last change on this file since 155 was 155, checked in by pinsard, 12 years ago

interp_erai_t2m is now a function

  • Property svn:keywords set to URL
File size: 8.9 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`
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;-
158pro 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
167CASE 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
177ENDCASE
178;
179; check if output data will be possible
180iodirout = isadirectory(project_od_env)
181;
182; existence and protection for reading
183IF (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
187ENDIF
188;
189; existence and protection for writing
190IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
191    msg = 'eee : the directory' + iodirout  + ' was not found.'
192    ras = report(msg)
193    STOP
194ENDIF
195;
196da1=19890101
197da2=20091231
198;
199; build uncorrected t2 filename
200filename_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
207msg='iii : looking for ' + filename_t2_uncor
208ras = report(msg)
209fullfilename_t2_uncor = isafile(iodirout + filename_t2_uncor, NEW=0, /MUST_EXIST)
210IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN
211   msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.'
212   ras = report(msg)
213   STOP
214ENDIF
215;
216; build output filename
217filename_out = 'TropFlux_t2m_' $
218    + string(da1,format='(i8.8)') $
219    + '_' $
220    + string(da2,format='(i8.8)') $
221    + '.nc'
222;
223fullfilename_out = iodirout + filename_out
224; in order to avoid unexpected overwritten
225IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
226   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
227   ras = report(msg)
228   STOP
229ENDIF
230;
231; define grid parameters with t2 file
232initncdf, fullfilename_t2_uncor
233;
234; get time in t2 file
235timein=ncdf_lec(fullfilename_t2_uncor,var='time')
236jptin=n_elements(timein)
237print, 'time steps from data ', jptin
238print, '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
242da=jul2date(julday(01, 01, 1957,timein[0]))
243cda0=string(da,format='(i8.8)')
244da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
245cda1=string(da,format='(i8.8)')
246print, 'first date ', cda0
247print, 'last date ' , cda1
248;
249; read t2 data
250t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m')
251;
252t2m=t2m-273.15
253help, t2m
254;
255jpt=jptin
256t2m_mean=grossemoyenne(t2m,'t',/nan)
257help, t2m_mean
258;
259t2m_m=t2m*0.
260bias_cor=t2m*0.
261;
262; line fit ->  -0.0755589x + 1.71090   ; (2000-2008)
263; line fit ->  -0.0741607x + 1.67601   ; (2000-2009)
264;
265for 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)
272endfor
273help, t2m_m,bias_cor
274;
275t2m_ano=t2m-t2m_m
276;
277; correction for mean based on scatter
278;
279help, t2m_ano
280;
281; applying the correction for varyability based on the scatter
282;t2m_ano=t2m_ano*(1/0.916484)    ; (2000-2008)
283t2m_ano=t2m_ano*(1/0.918085)     ; (2000-2009)
284;
285; applying the correction for varyability based on the scatter
286t2m_m=t2m_m+bias_cor
287;
288t2m_new=t2m_m+t2m_ano+273.15
289help, t2m_new
290;
291;writing field
292lat=reform(gphit(0,0:jpj-1))
293lon=reform(glamt(0:jpi-1,0))
294cda0=string(da1)
295cda1=string(da2)
296;
297; conversion for hours since 19570101 to days from 19500101
298time=julday(01, 01, 1957,timein)-julday(1,1,1950)
299jpt=n_elements(time)
300;
301ncfile='!' + fullfilename_out
302;
303ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units
304ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name
305lon_attr={units:units, long_name:long_name}
306ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units
307ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name
308lat_attr={units:units, long_name:long_name}
309time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
310globattr={source:'Basic data obtained from ERAI.  Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1}
311ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units
312ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name
313t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'}
314;
315ncfields = '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;
323end
Note: See TracBrowser for help on using the repository browser.