source: trunk/src/interp_erai_t2m.pro @ 178

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

an other bunch of new functions

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