[6] | 1 | ;+ |
---|
| 2 | ; |
---|
[19] | 3 | ; .. _interp_erai_t2m_1989_2009.pro: |
---|
[6] | 4 | ; |
---|
[67] | 5 | ; ============================= |
---|
| 6 | ; interp_erai_t2m_1989_2009.pro |
---|
| 7 | ; ============================= |
---|
[6] | 8 | ; |
---|
[67] | 9 | ; DESCRIPTION |
---|
| 10 | ; =========== |
---|
| 11 | ; |
---|
[26] | 12 | ; Interpolation of t2 from ERA-I grid to OAFLUX grid |
---|
[6] | 13 | ; |
---|
[50] | 14 | ; :file:`${PROJECT_ID}/20c3m_erai_t2_TROP_1989_2009.nc` containing t2 from ERA-I have been produced |
---|
[26] | 15 | ; by :ref:`compute_erai_daily_region_2d.sh`. |
---|
| 16 | ; |
---|
[50] | 17 | ; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc` containing OAFLUX grid have been produced by :ref:`oaflux_mask_30N30S.pro`. |
---|
[26] | 18 | ; |
---|
| 19 | ; Interpolated t2 is written in |
---|
[50] | 20 | ; :file:`${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc` if this file not already exists. |
---|
[26] | 21 | ; |
---|
[50] | 22 | ; This output file :file:`${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc` must be processed after by :ref:`t2m_correction_ncdf.pro`. |
---|
[27] | 23 | ; |
---|
[9] | 24 | ; .. graphviz:: |
---|
| 25 | ; |
---|
| 26 | ; digraph interp_erai_t2m_1989_2009 { |
---|
[71] | 27 | ; |
---|
[50] | 28 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/20c3m_erai_t2_TROP_1989_2009.nc"]; |
---|
| 29 | ; mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"]; |
---|
[71] | 30 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc"]; |
---|
[9] | 31 | ; |
---|
| 32 | ; interp_erai_t2m_1989_2009 [shape=box, |
---|
| 33 | ; fontname=Courier, |
---|
| 34 | ; color=blue, |
---|
| 35 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/interp_erai_t2m_1989_2009.pro"", |
---|
[50] | 36 | ; label="${PROJECT}/src/interp_erai_t2m_1989_2009.pro"]; |
---|
[9] | 37 | ; |
---|
[71] | 38 | ; {file_in mask} -> {interp_erai_t2m_1989_2009} -> {file_out} |
---|
[9] | 39 | ; |
---|
| 40 | ; } |
---|
| 41 | ; |
---|
[6] | 42 | ; SEE ALSO |
---|
| 43 | ; ======== |
---|
| 44 | ; |
---|
[25] | 45 | ; :ref:`interpolate_data` |
---|
| 46 | ; |
---|
[50] | 47 | ; :ref:`project_profile.sh` |
---|
[19] | 48 | ; |
---|
[26] | 49 | ; :ref:`compute_erai_daily_region_2d.sh` |
---|
| 50 | ; |
---|
| 51 | ; :ref:`oaflux_mask_30N30S.pro` |
---|
| 52 | ; |
---|
[20] | 53 | ; :func:`report <saxo:report>` |
---|
| 54 | ; :func:`isadirectory <saxo:isadirectory>` |
---|
| 55 | ; :func:`isafile <saxo:isafile>` |
---|
| 56 | ; :func:`initncdf <saxo:initncdf>` |
---|
| 57 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
[26] | 58 | ; :func:`ncdf_lec <saxo:ncdf_lec>` |
---|
[20] | 59 | ; :func:`domdef <saxo:domdef>` |
---|
| 60 | ; :func:`call_interp2d <saxo:call_interp2d>` |
---|
| 61 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
[27] | 62 | ; :func:`ncdf_getatt <saxo:ncdf_getatt>` |
---|
[20] | 63 | ; |
---|
[27] | 64 | ; :ref:`t2m_correction_ncdf.pro` |
---|
| 65 | ; |
---|
[6] | 66 | ; EXAMPLES |
---|
| 67 | ; ======== |
---|
| 68 | ; |
---|
| 69 | ; :: |
---|
| 70 | ; |
---|
[24] | 71 | ; IDL> .compile file_interp |
---|
[6] | 72 | ; IDL> interp_erai_t2m_1989_2009 |
---|
| 73 | ; |
---|
| 74 | ; TODO |
---|
| 75 | ; ==== |
---|
| 76 | ; |
---|
[73] | 77 | ; make it work : pb on loholt1 idl8:: |
---|
[71] | 78 | ; |
---|
| 79 | ; t2m[longitude,latitude,*time]=t2mout:t2m_attr; longitude[]=lon:lon_attr; latitude[]=lat:lat_attr; time[]=timein:time_attr @globattr |
---|
| 80 | ; % NCDF_DIMDEF: 0 is not a valid cdfid. |
---|
| 81 | ; % Stop encountered: INTERP_ERAI_T2M_1989_2009 1 |
---|
| 82 | ; /home/pinsard/tropflux_ws/src/interp_erai_t2m_1989_2009.pro |
---|
| 83 | ; |
---|
[73] | 84 | ; loholt1 idl6 : end without error but looking with ncview all brown ! |
---|
| 85 | ; |
---|
[26] | 86 | ; strange view (lat and lon shift with ncview) : check grid init |
---|
[24] | 87 | ; |
---|
[73] | 88 | ; remove useless netcdf_read or choose between read_ncdf and ncdf_lec |
---|
[26] | 89 | ; |
---|
| 90 | ; check time values |
---|
| 91 | ; |
---|
[24] | 92 | ; why use :func:`call_interp2d <saxo:call_interp2d>` : this is an hidden function of SAXO |
---|
| 93 | ; see :func:`file_interp <saxo:file_interp>` |
---|
| 94 | ; |
---|
| 95 | ; use as input a file produced by compute_erai_daily_region_2d.sh |
---|
| 96 | ; |
---|
[6] | 97 | ; coding rules |
---|
| 98 | ; |
---|
[27] | 99 | ; hard coded time in module name and in output filename |
---|
[26] | 100 | ; |
---|
| 101 | ; why two "initncdf, fullfilename_msk" |
---|
| 102 | ; |
---|
[70] | 103 | ; hard coded attributes for t2m (missing value, short name, axis) and time (origin) : use ncdf_getatt |
---|
[27] | 104 | ; |
---|
| 105 | ; CF conventions |
---|
| 106 | ; |
---|
[70] | 107 | ; check OUTMASK_IND and SET_OUTMSKVAL added to call_interp2d call |
---|
| 108 | ; |
---|
[19] | 109 | ; KNOWN ISSUES |
---|
| 110 | ; ============ |
---|
| 111 | ; |
---|
| 112 | ; test of existence of fullfilename_msk not very efficient because |
---|
| 113 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
| 114 | ; |
---|
[6] | 115 | ; EVOLUTIONS |
---|
| 116 | ; ========== |
---|
| 117 | ; |
---|
[70] | 118 | ; $Id$ |
---|
| 119 | ; |
---|
[88] | 120 | ; $URL: svn+ssh://pinsard@forge.ipsl.jussieu.fr/ipsl/forge/projets/tropflux/svn/trunk/src/interp_erai_t2m_1989_2009.pro $ |
---|
[70] | 121 | ; |
---|
[73] | 122 | ; - pinsard 2011-08-08T16:11:48Z loholt1.ipsl.polytechnique.fr (Linux) |
---|
| 123 | ; |
---|
| 124 | ; * remove ncdf_quickwrite exercices |
---|
| 125 | ; |
---|
[70] | 126 | ; - fplod 20110808T094156Z cratos (Linux) |
---|
| 127 | ; |
---|
| 128 | ; * add OUTMASK_IND and SET_OUTMSKVAL to call_interp2d call |
---|
| 129 | ; |
---|
[27] | 130 | ; - fplod 20110103T153734Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 131 | ; |
---|
| 132 | ; * computed first and last dates |
---|
| 133 | ; * start using ncdf_getatt instead of hard coded attributes |
---|
| 134 | ; |
---|
[26] | 135 | ; - fplod 20101223T130406Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 136 | ; |
---|
[27] | 137 | ; * replace /Volumes/PRAVEEN/TropFlux/input_uncor/ by ${TROPFLUX_OD} |
---|
| 138 | ; * complete documentation |
---|
| 139 | ; * get time dimension in data file |
---|
| 140 | ; * replace read_ncdf by ncdf_lec |
---|
[26] | 141 | ; |
---|
[27] | 142 | ; usage of timestep keyword in read_ncdf was not efficient because of memory problem : |
---|
| 143 | ; can not read the whole time range (ok with 7580, not ok with 7591 while need is 7670 |
---|
| 144 | ; :: |
---|
[26] | 145 | ; |
---|
[27] | 146 | ; % Unable to allocate memory: to make array. |
---|
| 147 | ; Cannot allocate memory |
---|
[26] | 148 | ; |
---|
| 149 | ; |
---|
[27] | 150 | ; When timestep keyword is not used we can see these messages:: |
---|
[26] | 151 | ; |
---|
[27] | 152 | ; /usr/work/incas/fplod/tropflux_d/20c3m_erai_t2_TROP_1989_2009.nc as no time axis variable |
---|
| 153 | ; given by Praveen |
---|
[26] | 154 | ; |
---|
[27] | 155 | ; Value of Julian date is out of allowed range |
---|
[26] | 156 | ; |
---|
[27] | 157 | ; % Array used to subscript array contains out of range subscript: DATAIN |
---|
[26] | 158 | ; |
---|
| 159 | ; |
---|
[24] | 160 | ; - fplod 20101222T163216Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 161 | ; |
---|
| 162 | ; * replace /Volumes/PRAVEEN/ERAI_global by ${TROPFLUX_ID} |
---|
| 163 | ; |
---|
[19] | 164 | ; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 165 | ; |
---|
| 166 | ; * remove hard coded directory for mask_oaflux_30N30S.nc |
---|
| 167 | ; |
---|
[9] | 168 | ; - fplod 20101215T112140Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 169 | ; |
---|
| 170 | ; * add graph in header |
---|
| 171 | ; |
---|
[6] | 172 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 173 | ; |
---|
| 174 | ; * minimal header |
---|
| 175 | ; |
---|
| 176 | ; - pbk 2008 |
---|
| 177 | ; |
---|
| 178 | ; * creation |
---|
| 179 | ; |
---|
| 180 | ;- |
---|
[5] | 181 | pro interp_erai_t2m_1989_2009 |
---|
[27] | 182 | ; |
---|
[40] | 183 | @cm_4cal |
---|
| 184 | @cm_4data |
---|
| 185 | @cm_4mesh |
---|
| 186 | @cm_4data |
---|
[50] | 187 | @cm_project |
---|
[19] | 188 | ; |
---|
[20] | 189 | ; check for input directory |
---|
[19] | 190 | ; |
---|
[50] | 191 | ; test if ${PROJECT_ID} defined |
---|
| 192 | CASE project_id_env OF |
---|
[19] | 193 | '' : BEGIN |
---|
[50] | 194 | msg = 'eee : ${PROJECT_ID} is not defined' |
---|
[19] | 195 | ras = report(msg) |
---|
| 196 | STOP |
---|
| 197 | END |
---|
| 198 | ELSE: BEGIN |
---|
[50] | 199 | msg = 'iii : ${PROJECT_ID} is ' + project_id_env |
---|
[19] | 200 | ras = report(msg) |
---|
| 201 | END |
---|
| 202 | ENDCASE |
---|
| 203 | ; |
---|
[50] | 204 | iodirin = isadirectory(project_id_env) |
---|
[19] | 205 | ; |
---|
[50] | 206 | ; existence and protection of ${PROJECT_ID} |
---|
[19] | 207 | IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
| 208 | msg = 'eee : the directory' + iodirin + ' is not accessible.' |
---|
| 209 | ras = report(msg) |
---|
| 210 | STOP |
---|
| 211 | ENDIF |
---|
| 212 | ; |
---|
| 213 | ; build mask filename |
---|
| 214 | filename_msk='mask_oaflux_30N30S.nc' |
---|
| 215 | ; |
---|
| 216 | ; check if this file exists |
---|
| 217 | fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST) |
---|
| 218 | IF fullfilename_msk[0] EQ '' THEN BEGIN |
---|
| 219 | msg = 'eee : the file ' + fullfilename_msk + ' was not found.' |
---|
| 220 | ras = report(msg) |
---|
| 221 | STOP |
---|
| 222 | ENDIF |
---|
[24] | 223 | ; |
---|
| 224 | ; build t2 filename |
---|
| 225 | filename_t2='20c3m_erai_t2_TROP_1989_2009.nc' |
---|
| 226 | ; |
---|
| 227 | ; check if this file exists |
---|
| 228 | fullfilename_t2 = isafile(iodirin + filename_t2, NEW=0, /MUST_EXIST) |
---|
| 229 | IF fullfilename_t2[0] EQ '' THEN BEGIN |
---|
| 230 | msg = 'eee : the file ' + fullfilename_t2 + ' was not found.' |
---|
| 231 | ras = report(msg) |
---|
| 232 | STOP |
---|
| 233 | ENDIF |
---|
| 234 | ; |
---|
[50] | 235 | ; test if ${PROJECT_OD} defined |
---|
| 236 | CASE project_od_env OF |
---|
[26] | 237 | '' : BEGIN |
---|
[50] | 238 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
[26] | 239 | ras = report(msg) |
---|
| 240 | STOP |
---|
| 241 | END |
---|
| 242 | ELSE: BEGIN |
---|
[50] | 243 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
[26] | 244 | ras = report(msg) |
---|
| 245 | END |
---|
| 246 | ENDCASE |
---|
| 247 | ; |
---|
| 248 | ; check if output data will be possible |
---|
[50] | 249 | iodirout = isadirectory(project_od_env) |
---|
[26] | 250 | ; |
---|
| 251 | ; existence and protection |
---|
| 252 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
| 253 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
| 254 | ras = report(msg) |
---|
| 255 | STOP |
---|
| 256 | ENDIF |
---|
| 257 | ; |
---|
| 258 | ; build output filename |
---|
| 259 | filename_out = 'erai_t2m_19890101_20091231_oafluxgrid.nc' |
---|
| 260 | fullfilename_out = iodirout + filename_out |
---|
| 261 | ; in order to avoid unexpected overwritten |
---|
| 262 | IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN |
---|
| 263 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
| 264 | ras = report(msg) |
---|
| 265 | STOP |
---|
| 266 | ENDIF |
---|
| 267 | ; |
---|
| 268 | ; define grid parameters with t2 file |
---|
[24] | 269 | initncdf, fullfilename_t2 |
---|
[5] | 270 | domdef |
---|
[70] | 271 | latin=reform(gphit(0,*)) |
---|
[27] | 272 | lonin=reform(glamt(*,0)) |
---|
[26] | 273 | print, 'lat grid from data',min(latin),max(latin),latin(1)-latin(0) |
---|
| 274 | print, 'lon grid from data',min(lonin),max(lonin),lonin(1)-lonin(0) |
---|
| 275 | ; |
---|
[27] | 276 | ; get time in t2 file |
---|
| 277 | timein=ncdf_lec(fullfilename_t2,var='time') |
---|
| 278 | jptin=n_elements(timein) |
---|
| 279 | print, 'time steps from data ', jptin |
---|
| 280 | print, 'The first 10 time values (variable timein) = ', timein[0:9] |
---|
[26] | 281 | ; |
---|
[27] | 282 | ; find first and last dates yyyymmdd |
---|
| 283 | ; they will be written in global attributes of output file |
---|
| 284 | da=jul2date(julday(01, 01, 1957,timein[0])) |
---|
| 285 | cda0=string(da,format='(i8.8)') |
---|
| 286 | da=jul2date(julday(01, 01, 1957,timein[jptin-1])) |
---|
| 287 | cda1=string(da,format='(i8.8)') |
---|
| 288 | print, 'first date ', cda0 |
---|
| 289 | print, 'last date ' , cda1 |
---|
| 290 | |
---|
[26] | 291 | ; read t2 data |
---|
[27] | 292 | ;++ pb memory t2min=read_ncdf("t2",0,jptin-1,/timestep,file=fullfilename_t2,/nostr) |
---|
[26] | 293 | ; the following line is here just to prepare replacement of read_ncdf by ncdf_lec |
---|
| 294 | t2min_read_ncdf=read_ncdf("t2",0,10,/timestep,file=fullfilename_t2,/nostr) |
---|
| 295 | help, t2min_read_ncdf |
---|
| 296 | ;++print, 'The first 10 time values (variable time) = ', time[0:9] |
---|
| 297 | ;++print, 'time steps after read_ncdf (variable jpt) ', jpt |
---|
| 298 | t2min=ncdf_lec(fullfilename_t2,var='t2') |
---|
| 299 | ; |
---|
[5] | 300 | mskin=glamt*0.+1. |
---|
| 301 | |
---|
[26] | 302 | ; define grid parameters with mask file |
---|
[19] | 303 | initncdf, fullfilename_msk |
---|
[5] | 304 | domdef |
---|
[70] | 305 | latout=reform(gphit(0,*)) |
---|
[27] | 306 | lonout=reform(glamt(*,0)) |
---|
[26] | 307 | print, 'lat grid from mask ',min(latout),max(latout),latout(1)-latout(0) |
---|
| 308 | print, 'lon grid from mask ',min(lonout),max(lonout),lonout(1)-lonout(0) |
---|
[19] | 309 | mskout=read_ncdf("msk", file=fullfilename_msk,/nostr) |
---|
[27] | 310 | ; |
---|
[5] | 311 | help, t2min,lonin,latin,mskin,lonout,latout,mskout |
---|
[27] | 312 | ; |
---|
| 313 | ; interpolation and mask |
---|
[5] | 314 | t2mout=fltarr(jpi,jpj,jptin) |
---|
| 315 | for jt=0,jptin-1 do begin |
---|
| 316 | tab=reform(t2min(*,*,jt)) |
---|
[70] | 317 | t2mout(*,*,jt)=call_interp2d(tab,lonin,latin,mskin $ |
---|
| 318 | , lonout,latout,method='bilinear' $ |
---|
| 319 | , OUTMASK_IND=mskout, SET_OUTMSKVAL=mskout) |
---|
[5] | 320 | t2mout(*,*,jt)=t2mout(*,*,jt)*mskout+(1.-mskout)*1.e20 |
---|
| 321 | endfor |
---|
| 322 | |
---|
[19] | 323 | initncdf, fullfilename_msk |
---|
[5] | 324 | |
---|
| 325 | lat=latout |
---|
| 326 | lon=lonout |
---|
[26] | 327 | ncfile='!' + fullfilename_out |
---|
| 328 | print, 'ncfile ', ncfile |
---|
[27] | 329 | ncdf_getatt, fullfilename_msk, 'longitude', units=units |
---|
| 330 | ncdf_getatt, fullfilename_msk, 'longitude', long_name=long_name |
---|
| 331 | lon_attr={units:units, long_name:long_name} |
---|
| 332 | ncdf_getatt, fullfilename_msk, 'latitude', units=units |
---|
| 333 | ncdf_getatt, fullfilename_msk, 'latitude', long_name=long_name |
---|
| 334 | lat_attr={units:units, long_name:long_name} |
---|
| 335 | ncdf_getatt, fullfilename_t2, 'time', units=units |
---|
| 336 | ncdf_getatt, fullfilename_t2, 'time', long_name=long_name |
---|
| 337 | time_attr={units:units, long_name:long_name, time_origin:' 1957-JAN-01 00:00:00'} |
---|
| 338 | ncdf_getatt, fullfilename_t2, 't2', units=units |
---|
| 339 | ncdf_getatt, fullfilename_t2, 't2', long_name=long_name |
---|
| 340 | t2m_attr={units:units, long_name:long_name, missing_value:1e20, short_name:'t2m',axis:'TYX'} |
---|
[5] | 341 | globattr={source:'Data are from ECMWF ERA-Interim reanalysis', timerange:cda0+' - '+cda1} |
---|
| 342 | |
---|
[33] | 343 | help, t2mout |
---|
| 344 | help, timein |
---|
[70] | 345 | ncfields = 't2m[longitude,latitude,*time]=t2mout:t2m_attr; ' $ |
---|
| 346 | + 'longitude[]=lon:lon_attr; ' $ |
---|
| 347 | + 'latitude[]=lat:lat_attr; ' $ |
---|
| 348 | + 'time[]=timein:time_attr ' $ |
---|
| 349 | + ' @globattr' |
---|
| 350 | @ncdf_quickwrite |
---|
[5] | 351 | |
---|
| 352 | end |
---|