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