[6] | 1 | ;+ |
---|
| 2 | ; |
---|
| 3 | ; .. _t2m_correction_ncdf.pro: |
---|
| 4 | ; |
---|
| 5 | ; ======================= |
---|
| 6 | ; t2m_correction_ncdf.pro |
---|
| 7 | ; ======================= |
---|
| 8 | ; |
---|
[28] | 9 | ; Mean correction for air temperature bias and correction for variability are |
---|
| 10 | ; applied. |
---|
| 11 | ; |
---|
[50] | 12 | ; :file:`${PROJECT_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc` have been produced by :ref:`interp_erai_t2m_1989_2009.pro`. |
---|
[28] | 13 | ; It contains air temperature at 2 m height from ERA-I interpolated on OAFLUX grid. |
---|
| 14 | ; |
---|
| 15 | ; Corrected air temperature at 2 m height is written in |
---|
[50] | 16 | ; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231_v50.nc`. |
---|
[28] | 17 | ; |
---|
[9] | 18 | ; .. graphviz:: |
---|
| 19 | ; |
---|
| 20 | ; digraph t2m_correction_ncdf { |
---|
| 21 | ; graph [ |
---|
| 22 | ; rankdir="LR", |
---|
| 23 | ; ] |
---|
| 24 | ; |
---|
[50] | 25 | ; file_t2m [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc"]; |
---|
[9] | 26 | ; |
---|
[50] | 27 | ; ncfile [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231_v50.nc"]; |
---|
[9] | 28 | ; |
---|
| 29 | ; t2m_correction_ncdf [shape=box, |
---|
| 30 | ; fontname=Courier, |
---|
| 31 | ; color=blue, |
---|
| 32 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/t2m_correction_ncdf.pro", |
---|
[50] | 33 | ; label="${PROJECT}/src/t2m_correction_ncdf.pro"]; |
---|
[9] | 34 | ; |
---|
| 35 | ; {file_t2m} -> {t2m_correction_ncdf} -> {ncfile} |
---|
| 36 | ; |
---|
| 37 | ; } |
---|
| 38 | ; |
---|
[6] | 39 | ; SEE ALSO |
---|
| 40 | ; ======== |
---|
| 41 | ; |
---|
[50] | 42 | ; :ref:`project_profile.sh` |
---|
[28] | 43 | ; |
---|
| 44 | ; :ref:`mooring_corrections` |
---|
| 45 | ; |
---|
| 46 | ; :ref:`interp_erai_t2m_1989_2009.pro` |
---|
| 47 | ; |
---|
[20] | 48 | ; :func:`initncdf <saxo:initncdf>` |
---|
| 49 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
| 50 | ; :func:`grossemoyenne <saxo:grossemoyenne>` |
---|
| 51 | ; :func:`caldat <saxo:caldat>` |
---|
| 52 | ; :func:`julday <saxo:julday>` |
---|
| 53 | ; :func:`jul2date <saxo:jul2date>` |
---|
| 54 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
[28] | 55 | ; :func:`ncdf_getatt <saxo:ncdf_getatt>` |
---|
[20] | 56 | ; |
---|
[6] | 57 | ; EXAMPLES |
---|
| 58 | ; ======== |
---|
| 59 | ; |
---|
| 60 | ; :: |
---|
| 61 | ; |
---|
| 62 | ; IDL> t2m_correction_ncdf |
---|
| 63 | ; |
---|
| 64 | ; TODO |
---|
| 65 | ; ==== |
---|
| 66 | ; |
---|
[28] | 67 | ; make it work !! |
---|
[6] | 68 | ; |
---|
| 69 | ; coding rules |
---|
| 70 | ; |
---|
[28] | 71 | ; understand usage of jtt |
---|
| 72 | ; |
---|
| 73 | ; check time values |
---|
| 74 | ; |
---|
| 75 | ; hard coded time in module name and in output filename |
---|
| 76 | ; |
---|
| 77 | ; why v50 in filename output |
---|
| 78 | ; |
---|
| 79 | ; hard coded correction values |
---|
| 80 | ; |
---|
| 81 | ; check side effect of replacement of read_ncdf by ncdf_lec :: |
---|
| 82 | ; |
---|
| 83 | ; Probleme d'adequation entre les tailles du domaine nx*ny*jpt 350*60*1 et du tableau 350*60*7670 |
---|
| 84 | ; |
---|
| 85 | ; |
---|
| 86 | ; hard coded attributes |
---|
| 87 | ; |
---|
| 88 | ; CF conventions |
---|
| 89 | ; |
---|
| 90 | ; KNOWN ISSUES |
---|
| 91 | ; ============ |
---|
| 92 | ; |
---|
| 93 | ; test of existence of fullfilename_msk not very efficient because |
---|
| 94 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
| 95 | ; |
---|
[6] | 96 | ; EVOLUTIONS |
---|
| 97 | ; ========== |
---|
| 98 | ; |
---|
[28] | 99 | ; - fplod 20110104T093758Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 100 | ; |
---|
| 101 | ; * complete header |
---|
| 102 | ; * replace /Volumes/Iomega_HDD/TropFlux/input_uncor/ by ${TROPFLUX_ID} |
---|
| 103 | ; * replace /Volumes/Iomega_HDD/TropFlux/input_cor/full_cor/ by |
---|
| 104 | ; ${TROPFLUX_OD} |
---|
| 105 | ; * use :func:`ncdf_getatt <saxo:ncdf_getatt>` for attributes of lat and long |
---|
| 106 | ; variables |
---|
| 107 | ; * same problem of time axis and memory like in interp_erai_t2m_1989_2009 |
---|
| 108 | ; using read_ncdf. |
---|
| 109 | ; replace read_ncdf by netcdf_lec |
---|
| 110 | ; |
---|
[9] | 111 | ; - fplod 20101215T114503Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 112 | ; |
---|
| 113 | ; * add graph in header |
---|
| 114 | ; |
---|
[6] | 115 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 116 | ; |
---|
| 117 | ; * minimal header |
---|
| 118 | ; |
---|
| 119 | ; - pbk 2008 |
---|
| 120 | ; |
---|
| 121 | ; * creation |
---|
| 122 | ; |
---|
| 123 | ;- |
---|
[5] | 124 | pro t2m_correction_ncdf |
---|
[28] | 125 | ; |
---|
[5] | 126 | @common |
---|
[50] | 127 | @cm_project |
---|
| 128 | ; |
---|
[28] | 129 | ; check for input directory |
---|
| 130 | ; |
---|
[50] | 131 | ; test if ${PROJECT_ID} defined |
---|
| 132 | CASE project_id_env OF |
---|
[28] | 133 | '' : BEGIN |
---|
[50] | 134 | msg = 'eee : ${PROJECT_ID} is not defined' |
---|
[28] | 135 | ras = report(msg) |
---|
| 136 | STOP |
---|
| 137 | END |
---|
| 138 | ELSE: BEGIN |
---|
[50] | 139 | msg = 'iii : ${PROJECT_ID} is ' + project_id_env |
---|
[28] | 140 | ras = report(msg) |
---|
| 141 | END |
---|
| 142 | ENDCASE |
---|
| 143 | ; |
---|
[50] | 144 | iodirin = isadirectory(project_id_env) |
---|
[28] | 145 | ; |
---|
[50] | 146 | ; existence and protection of ${PROJECT_ID} |
---|
[28] | 147 | IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
| 148 | msg = 'eee : the directory' + iodirin + ' is not accessible.' |
---|
| 149 | ras = report(msg) |
---|
| 150 | STOP |
---|
| 151 | ENDIF |
---|
| 152 | ; |
---|
| 153 | ; build uncorrected t2 filename |
---|
| 154 | da1=19890101 |
---|
| 155 | da2=20091231 |
---|
| 156 | filename_t2_uncor='erai_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_oafluxgrid.nc' |
---|
| 157 | ; |
---|
| 158 | ; check if this file exists |
---|
| 159 | fullfilename_t2_uncor = isafile(iodirin + filename_t2_uncor, NEW=0, /MUST_EXIST) |
---|
| 160 | IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN |
---|
| 161 | msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.' |
---|
| 162 | ras = report(msg) |
---|
| 163 | STOP |
---|
| 164 | ENDIF |
---|
[50] | 165 | ; test if ${PROJECT_OD} defined |
---|
| 166 | CASE project_od_env OF |
---|
[28] | 167 | '' : BEGIN |
---|
[50] | 168 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
[28] | 169 | ras = report(msg) |
---|
| 170 | STOP |
---|
| 171 | END |
---|
| 172 | ELSE: BEGIN |
---|
[50] | 173 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
[28] | 174 | ras = report(msg) |
---|
| 175 | END |
---|
| 176 | ENDCASE |
---|
| 177 | ; |
---|
| 178 | ; check if output data will be possible |
---|
[50] | 179 | iodirout = isadirectory(project_od_env) |
---|
[28] | 180 | ; |
---|
| 181 | ; existence and protection |
---|
| 182 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
| 183 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
| 184 | ras = report(msg) |
---|
| 185 | STOP |
---|
| 186 | ENDIF |
---|
| 187 | ; |
---|
| 188 | ; build output filename |
---|
| 189 | filename_out='TropFlux_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_v50.nc' |
---|
| 190 | fullfilename_out = iodirout + filename_out |
---|
| 191 | ; in order to avoid unexpected overwritten |
---|
| 192 | IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN |
---|
| 193 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
| 194 | ras = report(msg) |
---|
| 195 | STOP |
---|
| 196 | ENDIF |
---|
| 197 | ; |
---|
| 198 | ; define grid parameters with t2 file |
---|
| 199 | initncdf, fullfilename_t2_uncor |
---|
| 200 | ; |
---|
| 201 | ; get time in t2 file |
---|
| 202 | timein=ncdf_lec(fullfilename_t2_uncor,var='time') |
---|
| 203 | jptin=n_elements(timein) |
---|
| 204 | print, 'time steps from data ', jptin |
---|
| 205 | print, 'The first 10 time values (variable timein) = ', timein[0:9] |
---|
| 206 | ; |
---|
| 207 | ; find first and last dates yyyymmdd |
---|
| 208 | ; they will be written in global attributes of output file |
---|
| 209 | da=jul2date(julday(01, 01, 1957,timein[0])) |
---|
| 210 | cda0=string(da,format='(i8.8)') |
---|
| 211 | da=jul2date(julday(01, 01, 1957,timein[jptin-1])) |
---|
| 212 | cda1=string(da,format='(i8.8)') |
---|
| 213 | print, 'first date ', cda0 |
---|
| 214 | print, 'last date ' , cda1 |
---|
| 215 | ; |
---|
| 216 | ; read t2 data |
---|
| 217 | t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m') |
---|
| 218 | ; |
---|
| 219 | t2m=t2m-273.15 |
---|
[5] | 220 | help, t2m |
---|
[28] | 221 | ; |
---|
| 222 | jpt=jptin |
---|
[5] | 223 | t2m_mean=grossemoyenne(t2m,'t',/nan) |
---|
[28] | 224 | help, t2m_mean |
---|
[5] | 225 | |
---|
| 226 | t2m_m=t2m*0. |
---|
| 227 | bias_cor=t2m*0. |
---|
| 228 | |
---|
| 229 | ;; line fit -> -0.0755589x + 1.71090 ;; (2000-2008) |
---|
| 230 | ;; line fit -> -0.0741607x + 1.67601 ;; (2000-2009) |
---|
| 231 | |
---|
[28] | 232 | for jt=0,jptin-1 do begin |
---|
| 233 | caldat, julday(01, 01, 1957,timein[jt]),mon,day,yea |
---|
| 234 | ;++print,day |
---|
| 235 | jtt=(julday(01, 01, 1957,timein[jt])-julday(1,1,yea)) < 364 |
---|
[5] | 236 | t=reform(t2m_mean(*,*)) |
---|
| 237 | t2m_m(*,*,jt)=t |
---|
| 238 | bias_cor(*,*,jt)=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4 ;; (2000-2009) |
---|
| 239 | endfor |
---|
| 240 | help, t2m_m,bias_cor |
---|
| 241 | |
---|
| 242 | t2m_ano=t2m-t2m_m |
---|
| 243 | |
---|
| 244 | ;; correction for mean based on scatter |
---|
| 245 | |
---|
| 246 | help, t2m_ano |
---|
| 247 | |
---|
| 248 | ;; applying the correction for varyability based on the scatter |
---|
| 249 | ;t2m_ano=t2m_ano*(1/0.916484) ;; (2000-2008) |
---|
| 250 | t2m_ano=t2m_ano*(1/0.918085) ;; (2000-2009) |
---|
| 251 | |
---|
| 252 | ;; applying the correction for varyability based on the scatter |
---|
| 253 | t2m_m=t2m_m+bias_cor |
---|
| 254 | |
---|
| 255 | t2m_new=t2m_m+t2m_ano+273.15 |
---|
| 256 | help, t2m_new |
---|
| 257 | |
---|
| 258 | ;writing field |
---|
| 259 | lat=reform(gphit(0,0:jpj-1)) |
---|
| 260 | lon=reform(glamt(0:jpi-1,0)) |
---|
[28] | 261 | cda0=string(da1) |
---|
| 262 | cda1=string(da2) |
---|
[5] | 263 | |
---|
[28] | 264 | time=time-julday(1,1,1950) |
---|
| 265 | jpt=n_elements(time) |
---|
[5] | 266 | |
---|
[28] | 267 | ncfile='!' + fullfilename_out |
---|
[5] | 268 | |
---|
[28] | 269 | ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units |
---|
| 270 | ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name |
---|
| 271 | lon_attr={units:units, long_name:long_name} |
---|
| 272 | ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units |
---|
| 273 | ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name |
---|
| 274 | lat_attr={units:units, long_name:long_name} |
---|
| 275 | |
---|
[5] | 276 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
[28] | 277 | |
---|
| 278 | ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units |
---|
| 279 | ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name |
---|
| 280 | t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'} |
---|
[5] | 281 | globattr={source:'Basic data obtained from ERAI. Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1} |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | ncfields = 't2m[longitude,latitude,time]=t2m_new:t2m_attr; ' $ |
---|
| 285 | + 'longitude[]=lon:lon_attr; ' $ |
---|
| 286 | + 'latitude[]=lat:lat_attr; ' $ |
---|
| 287 | + 'time[*time]=time:time_attr ' $ |
---|
| 288 | + ' @ globattr' |
---|
| 289 | |
---|
| 290 | @ncdf_quickwrite |
---|
| 291 | |
---|
| 292 | end |
---|