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