source: trunk/src/interp_erai_t2m.pro @ 166

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

interp_erai_dewt is now a function

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1;+
2;
3; ===================
4; interp_erai_t2m.pro
5; ===================
6;
7; .. function:: interp_erai_t2m(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Interpolation of t2 from ERA-I grid to OAFLUX grid
13;
14; :file:`${PROJECT_ID}/20c3m_erai_t2_TROP_1989_2009.nc`
15; containing
16; t2 from ERA-I
17; has been produced by
18; :ref:`compute_erai_daily_region_2d.sh`.
19;
20; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
21; containing OAFLUX grid
22; has been produced by
23; :func:`oaflux_mask_30n30s`.
24;
25; Interpolated t2
26; is written in
27; :file:`${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
28; if this file not already exists.
29;
30; This output file
31; :file:`${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
32; must be processed after by
33; :ref:`t2m_correction_ncdf.pro`.
34;
35; .. only:: man
36;
37;    Figure is visible on PDF and HTML documents only.
38;
39; .. only:: html or latex
40;
41;     .. graphviz::
42;
43;        digraph interp_erai_t2m {
44;
45;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_t2_TROP_1989_2009.nc"];
46;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
47;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
48;
49;           interp_erai_t2m [shape=box,
50;           fontname=Courier,
51;           color=blue,
52;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_t2m.pro",
53;           label="${PROJECT}/src/interp_erai_t2m.pro"];
54;
55;           {file_in mask} -> {interp_erai_t2m} -> {file_out}
56;
57;        }
58;
59; SEE ALSO
60; ========
61;
62; :ref:`interpolate_data`
63;
64; Used by :ref:`tropflux.sh`
65;
66; :ref:`project_profile.sh`
67;
68; :ref:`compute_erai_daily_region_2d.sh`
69;
70; :func:`oaflux_mask_30n30s`
71;
72; :func:`report <saxo:report>`
73; :func:`isadirectory <saxo:isadirectory>`
74; :func:`isafile <saxo:isafile>`
75; :func:`initncdf <saxo:initncdf>`
76; :func:`read_ncdf <saxo:read_ncdf>`
77; :func:`ncdf_lec <saxo:ncdf_lec>`
78; :func:`domdef <saxo:domdef>`
79; :func:`call_interp2d <saxo:call_interp2d>`
80; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
81; :func:`ncdf_getatt <saxo:ncdf_getatt>`
82;
83; :ref:`t2m_correction_ncdf.pro`
84;
85; EXAMPLES
86; ========
87;
88; ::
89;
90;  IDL> .compile file_interp
91;  IDL> yyyymmddb = 19890101
92;  IDL> yyyymmdde = 20091231
93;  IDL> result = interp_erai_t2m(yyyymmddb, yyymmdde)
94;  IDL> print, result
95;
96; TODO
97; ====
98;
99; scientific validation (strange look of data with ncview now)
100;
101; check [yyyymmddb,yyyymmdde] validity
102;
103; check if [yyyymmddb,yyyymmdde] is included in ERA-I file
104;
105; what happen if yyyymmdde > 20091231 : need to read an other ERA-I file
106;
107; add an example with only one month (ie 200001)
108;
109; make it work : pb on loholt1 idl8
110;
111; reach end but bad time and t2m values ::
112;
113;   $ ncks -v t2m  -d time,0,1 -d latitude,0,1 -d longitude,0,1 /homedata/pinsard/tropflux_d/erai_t2m_19890101_20091231_oafluxgrid.nc
114;     latitude[0]=-29.5 degrees_north
115;     latitude[1]=-28.5 degrees_north
116;
117;     longitude[0]=30.5 degrees_east
118;     longitude[1]=31.5 degrees_east
119;
120;     time[0]=9.96920996839e+36 latitude[0]=-29.5 longitude[0]=30.5 t2m[0]=9.96921e+36 degK
121;     time[0]=9.96920996839e+36 latitude[0]=-29.5 longitude[1]=31.5 t2m[1]=9.96921e+36 degK
122;     time[0]=9.96920996839e+36 latitude[1]=-28.5 longitude[0]=30.5 t2m[350]=9.96921e+36 degK
123;     time[0]=9.96920996839e+36 latitude[1]=-28.5 longitude[1]=31.5 t2m[351]=9.96921e+36 degK
124;     time[1]=9.96920996839e+36 latitude[0]=-29.5 longitude[0]=30.5 t2m[21000]=9.96921e+36 degK
125;     time[1]=9.96920996839e+36 latitude[0]=-29.5 longitude[1]=31.5 t2m[21001]=9.96921e+36 degK
126;     time[1]=9.96920996839e+36 latitude[1]=-28.5 longitude[0]=30.5 t2m[21350]=9.96921e+36 degK
127;     time[1]=9.96920996839e+36 latitude[1]=-28.5 longitude[1]=31.5 t2m[21351]=9.96921e+36 degK
128;
129;     time[0]=9.96920996839e+36 hours since 1957-01-01 00:00:0.0
130;     time[1]=9.96920996839e+36 hours since 1957-01-01 00:00:0.0
131;
132; loholt1 idl6 : end without error but looking with ncview all brown !
133;
134; strange view (lat and lon shift with ncview) : check grid init
135;
136; remove useless netcdf_read or choose between read_ncdf and ncdf_lec
137;
138; check time values
139;
140; why use :func:`call_interp2d <saxo:call_interp2d>` : this is an hidden function of SAXO
141; see :func:`file_interp <saxo:file_interp>`
142;
143; use as input a file produced by compute_erai_daily_region_2d.sh or
144; get_erai.py + grib to netcdf conversion
145;
146; coding rules
147;
148; hard coded time in module name and in output filename
149;
150; why two "initncdf, fullfilename_msk"
151;
152; hard coded attributes for t2m (missing value, short name, axis) and time (origin) : use ncdf_getatt
153;
154; CF conventions
155;
156; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call
157;
158; KNOWN ISSUES
159; ============
160;
161; test of existence of fullfilename_msk not very efficient because
162; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
163;
164; EVOLUTIONS
165; ==========
166;
167; $Id$
168;
169; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_t2m.pro $
170;
171; - fplod 20120319
172;
173;   * taking project_overwite into account
174;
175; - fplod 20120306
176;
177;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
178;   * pro -> function
179;
180; - pinsard 2011-08-23T09:09:16Z loholt1.ipsl.polytechnique.fr (Linux)
181;
182;   * retry on loholt1 with idl8 and idl6
183;
184; - pinsard 2011-08-08T16:11:48Z loholt1.ipsl.polytechnique.fr (Linux)
185;
186;   * remove ncdf_quickwrite exercices
187;
188; - fplod 20110808T094156Z cratos (Linux)
189;
190;   * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call
191;
192; - fplod 20110103T153734Z aedon.locean-ipsl.upmc.fr (Darwin)
193;
194;   * computed first and last dates
195;   * start using ncdf_getatt instead of hard coded attributes
196;
197; - fplod 20101223T130406Z aedon.locean-ipsl.upmc.fr (Darwin)
198;
199;   * replace /Volumes/PRAVEEN/TropFlux/input_uncor/ by ${TROPFLUX_OD}
200;   * complete documentation
201;   * get time dimension in data file
202;   * replace read_ncdf by ncdf_lec
203;
204;     usage of timestep keyword in read_ncdf was not efficient because of  memory problem :
205;     can not read the whole time range (ok with 7580, not ok with 7591 while need is 7670
206;     ::
207;
208;       % Unable to allocate memory: to make array.
209;       Cannot allocate memory
210;
211;     When timestep keyword is not used we can see these messages::
212;
213;        /usr/work/incas/fplod/tropflux_d/20c3m_erai_t2_TROP_1989_2009.nc as no time axis variable
214;        given by Praveen
215;
216;        Value of Julian date is out of allowed range
217;
218;        % Array used to subscript array contains out of range subscript: DATAIN
219;
220; - fplod 20101222T163216Z aedon.locean-ipsl.upmc.fr (Darwin)
221;
222;   * replace /Volumes/PRAVEEN/ERAI_global by ${TROPFLUX_ID}
223;
224; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
225;
226;   * remove hard coded directory for mask_oaflux_30N30S.nc
227;
228; - fplod 20101215T112140Z aedon.locean-ipsl.upmc.fr (Darwin)
229;
230;   * add graph in header
231;
232; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
233;
234;   * minimal header
235;
236; - pbk 2008
237;
238;   * creation
239;
240;-
241function interp_erai_t2m $
242         , yyyymmddb $
243         , yyyymmdde
244;
245;++compile_opt idl2, strictarrsubs, logical_predicate
246;
247@cm_4cal
248@cm_4data
249@cm_4mesh
250@cm_4data
251@cm_project
252;
253; Return to caller if errors
254ON_ERROR, 2
255;
256result = -1
257;
258usage = 'result = interp_erai_t2m(yyyymmddb, yyyymmdde)
259nparam = N_PARAMS()
260IF (nparam NE 2) THEN BEGIN
261   ras = report(['Incorrect number of arguments.' $
262         + '!C' $
263         + 'Usage : ' + usage])
264   return, result
265ENDIF
266
267; check for input directory
268;
269; test if ${PROJECT_ID} defined
270CASE project_id_env OF
271    ''  :  BEGIN
272     msg = 'eee : ${PROJECT_ID} is not defined'
273     ras = report(msg)
274     return, result
275           END
276 ELSE: BEGIN
277     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
278     ras = report(msg)
279       END
280ENDCASE
281;
282iodirin = isadirectory(project_id_env)
283;
284; existence and protection of ${PROJECT_ID}
285IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
286   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
287   ras = report(msg)
288   return, result
289ENDIF
290;
291; build mask filename
292filename_msk='mask_oaflux_30N30S.nc'
293;
294; check if this file exists
295msg='iii : looking for ' + filename_msk
296ras = report(msg)
297fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
298IF fullfilename_msk[0] EQ '' THEN BEGIN
299   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
300   ras = report(msg)
301   return, result
302ENDIF
303;
304; build t2 filename
305filename_t2='20c3m_erai_t2_TROP_1989_2009.nc'
306;
307; check if this file exists
308msg='iii : looking for ' + filename_t2
309ras = report(msg)
310fullfilename_t2 = isafile(iodirin + filename_t2, NEW=0, /MUST_EXIST)
311IF fullfilename_t2[0] EQ '' THEN BEGIN
312   msg = 'eee : the file ' + fullfilename_t2 + ' was not found.'
313   ras = report(msg)
314   return, result
315ENDIF
316;
317; test if ${PROJECT_OD} defined
318CASE project_od_env OF
319  '' : BEGIN
320         msg = 'eee : ${PROJECT_OD} is not defined'
321         ras = report(msg)
322       return, result
323       END
324  ELSE: BEGIN
325          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
326          ras = report(msg)
327        END
328 ENDCASE
329;
330; check if output data will be possible
331iodirout = isadirectory(project_od_env)
332;
333; existence and protection
334IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
335    msg = 'eee : the directory' + iodirout  + ' was not found.'
336    ras = report(msg)
337    return, result
338ENDIF
339;
340; build output filename
341filename_out = 'erai_t2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
342fullfilename_out = iodirout + filename_out
343; in order to avoid unexpected overwritten
344IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
345   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
346   ras = report(msg)
347   return, result
348ENDIF
349;
350; define grid parameters with t2 file
351initncdf, fullfilename_t2
352domdef
353latin=reform(gphit[0,*])
354lonin=reform(glamt[*,0])
355print, 'lat grid from data',min(latin),max(latin),latin[1]-latin[0]
356print, 'lon grid from data',min(lonin),max(lonin),lonin[1]-lonin[0]
357;
358; get time in t2 file
359timein=ncdf_lec(fullfilename_t2,var='time')
360jptin=n_elements(timein)
361print, 'time steps from data ', jptin
362print, 'The first 10 time values (variable timein) = ', timein[0:9]
363;
364; find first and last dates yyyymmdd
365; they will be written in global attributes of output file
366da=jul2date(julday(01, 01, 1957,timein[0]))
367cda0=string(da,format='(i8.8)')
368da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
369cda1=string(da,format='(i8.8)')
370print, 'first date ', cda0
371print, 'last date ' , cda1
372;
373; read t2 data
374;++ pb memory t2min=read_ncdf("t2",0,jptin-1,/timestep,file=fullfilename_t2,/nostr)
375; the following line is here just to prepare replacement of read_ncdf by ncdf_lec
376t2min_read_ncdf=read_ncdf("t2",0,10,/timestep,file=fullfilename_t2,/nostr)
377help, t2min_read_ncdf
378;++print, 'The first 10 time values (variable time) = ', time[0:9]
379;++print, 'time steps after read_ncdf (variable jpt) ', jpt
380t2min=ncdf_lec(fullfilename_t2,var='t2')
381;
382mskin=glamt*0.+1.
383;
384; define grid parameters with mask file
385initncdf, fullfilename_msk
386domdef
387latout=reform(gphit[0,*])
388lonout=reform(glamt[*,0])
389print, 'lat grid from mask ',min(latout),max(latout),latout[1]-latout[0]
390print, 'lon grid from mask ',min(lonout),max(lonout),lonout[1]-lonout[0]
391mskout=read_ncdf("msk", file=fullfilename_msk,/nostr)
392;
393help, t2min,lonin,latin,mskin,lonout,latout,mskout
394;
395; interpolation and mask
396t2mout=fltarr(jpi,jpj,jptin)
397for jt=0,jptin-1 do begin
398  tab=reform(t2min[*,*,jt])
399  t2mout[*,*,jt]=call_interp2d(tab,lonin,latin,mskin $
400      , lonout,latout,method='bilinear' $
401      , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout)
402  t2mout[*,*,jt]=t2mout[*,*,jt]*mskout+(1.-mskout)*1.e20
403endfor
404;
405initncdf, fullfilename_msk
406;
407lat=latout
408lon=lonout
409ncfile='!' + fullfilename_out
410ncdf_getatt, fullfilename_msk, 'longitude', units=units
411ncdf_getatt, fullfilename_msk, 'longitude', long_name=long_name
412lon_attr={units:units, long_name:long_name}
413ncdf_getatt, fullfilename_msk, 'latitude', units=units
414ncdf_getatt, fullfilename_msk, 'latitude', long_name=long_name
415lat_attr={units:units, long_name:long_name}
416ncdf_getatt, fullfilename_t2, 'time', units=units
417ncdf_getatt, fullfilename_t2, 'time', long_name=long_name
418time_attr={units:units, long_name:long_name, time_origin:' 1957-JAN-01 00:00:00'}
419globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1}
420ncdf_getatt, fullfilename_t2, 't2', units=units
421ncdf_getatt, fullfilename_t2, 't2', long_name=long_name
422t2m_attr={units:units, long_name:long_name, missing_value:1e20, short_name:'t2m',axis:'TYX'}
423;
424help, t2mout
425help, timein
426ncfields = 't2m[longitude,latitude,*time]=t2mout:t2m_attr; ' $
427                      + 'longitude[]=lon:lon_attr; ' $
428                      + 'latitude[]=lat:lat_attr; ' $
429                      + 'time[]=timein:time_attr ' $
430                      + ' @globattr'
431@ncdf_quickwrite
432;
433result = 0
434return, result
435;
436end
Note: See TracBrowser for help on using the repository browser.