;+ ; ; .. _t2m_correction_ncdf.pro: ; ; ======================= ; t2m_correction_ncdf.pro ; ======================= ; ; Mean correction for air temperature bias and correction for variability are ; applied. ; ; :file:`${PROJECT_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc` have been produced by :ref:`interp_erai_t2m_1989_2009.pro`. ; It contains air temperature at 2 m height from ERA-I interpolated on OAFLUX grid. ; ; Corrected air temperature at 2 m height is written in ; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc` ; if this file not already exists. ; ; This file will be used by :ref:`TropFlux_19890101_20091231.pro`. ; ; .. graphviz:: ; ; digraph t2m_correction_ncdf { ; graph [ ; rankdir="LR", ; ] ; ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc"]; ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"]; ; ; t2m_correction_ncdf [shape=box, ; fontname=Courier, ; color=blue, ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/t2m_correction_ncdf.pro", ; label="${PROJECT}/src/t2m_correction_ncdf.pro"]; ; ; {file_in} -> {t2m_correction_ncdf} -> {file_out} ; ; } ; ; SEE ALSO ; ======== ; ; :ref:`project_profile.sh` ; ; :ref:`mooring_corrections` ; ; :ref:`interp_erai_t2m_1989_2009.pro` ; ; :func:`initncdf ` ; :func:`read_ncdf ` ; :func:`grossemoyenne ` ; :func:`caldat ` ; :func:`julday ` ; :func:`jul2date ` ; :func:`ncdf_quickwrite ` ; :func:`ncdf_getatt ` ; ; EXAMPLES ; ======== ; ; :: ; ; IDL> t2m_correction_ncdf ; ; TODO ; ==== ; ; coding rules ; ; understand usage of jtt ; ; check time values ; ; hard coded time in module name and in output filename ; ; hard coded correction values ; ; check side effect of replacement of read_ncdf by ncdf_lec :: ; ; Probleme d'adequation entre les tailles du domaine nx*ny*jpt 350*60*1 et du tableau 350*60*7670 ; ; hard coded attributes ; ; CF conventions ; ; KNOWN ISSUES ; ============ ; ; test of existence of fullfilename_msk not very efficient because ; MUST_EXIST keyword of :func:`isafile ` not yet implemented ; ; EVOLUTIONS ; ========== ; ; - fplod 20110808T130628Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * remove v50 in filename output ; * replace _ID by _OD (like other correction modules) ; ; - fplod 20110104T093758Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * complete header ; * replace /Volumes/Iomega_HDD/TropFlux/input_uncor/ by ${TROPFLUX_ID} ; * replace /Volumes/Iomega_HDD/TropFlux/input_cor/full_cor/ by ; ${TROPFLUX_OD} ; * use :func:`ncdf_getatt ` for attributes of lat and long ; variables ; * same problem of time axis and memory like in interp_erai_t2m_1989_2009 ; using read_ncdf. ; replace read_ncdf by netcdf_lec ; ; - fplod 20101215T114503Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * add graph in header ; ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * minimal header ; ; - pbk 2008 ; ; * creation ; ;- pro t2m_correction_ncdf ; @cm_4cal @cm_4data @cm_4mesh @cm_4data @cm_project ; ; test if ${PROJECT_OD} defined CASE project_id_env OF '' : BEGIN msg = 'eee : ${PROJECT_OD} is not defined' ras = report(msg) STOP END ELSE: BEGIN msg = 'iii : ${PROJECT_OD} is ' + project_id_env ras = report(msg) END ENDCASE ; ; check if output data will be possible iodirout = isadirectory(project_od_env) ; ; existence and protection for reading IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirout + ' is not accessible.' ras = report(msg) STOP ENDIF ; ; existence and protection for writing IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirout + ' was not found.' ras = report(msg) STOP ENDIF ; da1=19890101 da2=20091231 ; ; build uncorrected t2 filename filename_t2_uncor='erai_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_oafluxgrid.nc' ; ; check if this file exists fullfilename_t2_uncor = isafile(iodirout + filename_t2_uncor, NEW=0, /MUST_EXIST) IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.' ras = report(msg) STOP ENDIF ; ; build output filename filename_out='TropFlux_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'.nc' fullfilename_out = iodirout + filename_out ; in order to avoid unexpected overwritten IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN msg = 'eee : the file ' + fullfilename_out + ' already exists.' ras = report(msg) STOP ENDIF ; ; define grid parameters with t2 file initncdf, fullfilename_t2_uncor ; ; get time in t2 file timein=ncdf_lec(fullfilename_t2_uncor,var='time') jptin=n_elements(timein) print, 'time steps from data ', jptin print, 'The first 10 time values (variable timein) = ', timein[0:9] ; ; find first and last dates yyyymmdd ; they will be written in global attributes of output file da=jul2date(julday(01, 01, 1957,timein[0])) cda0=string(da,format='(i8.8)') da=jul2date(julday(01, 01, 1957,timein[jptin-1])) cda1=string(da,format='(i8.8)') print, 'first date ', cda0 print, 'last date ' , cda1 ; ; read t2 data t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m') ; t2m=t2m-273.15 help, t2m ; jpt=jptin t2m_mean=grossemoyenne(t2m,'t',/nan) help, t2m_mean t2m_m=t2m*0. bias_cor=t2m*0. ;; line fit -> -0.0755589x + 1.71090 ;; (2000-2008) ;; line fit -> -0.0741607x + 1.67601 ;; (2000-2009) for jt=0,jptin-1 do begin caldat, julday(01, 01, 1957,timein[jt]),mon,day,yea ;++print,day jtt=(julday(01, 01, 1957,timein[jt])-julday(1,1,yea)) < 364 t=reform(t2m_mean(*,*)) t2m_m(*,*,jt)=t bias_cor(*,*,jt)=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4 ;; (2000-2009) endfor help, t2m_m,bias_cor t2m_ano=t2m-t2m_m ;; correction for mean based on scatter help, t2m_ano ;; applying the correction for varyability based on the scatter ;t2m_ano=t2m_ano*(1/0.916484) ;; (2000-2008) t2m_ano=t2m_ano*(1/0.918085) ;; (2000-2009) ;; applying the correction for varyability based on the scatter t2m_m=t2m_m+bias_cor t2m_new=t2m_m+t2m_ano+273.15 help, t2m_new ;writing field lat=reform(gphit(0,0:jpj-1)) lon=reform(glamt(0:jpi-1,0)) cda0=string(da1) cda1=string(da2) time=time-julday(1,1,1950) jpt=n_elements(time) ncfile='!' + fullfilename_out ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name lon_attr={units:units, long_name:long_name} ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name lat_attr={units:units, long_name:long_name} time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'} globattr={source:'Basic data obtained from ERAI. Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1} ncfields = 't2m[longitude,latitude,time]=t2m_new:t2m_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[*time]=time:time_attr ' $ + ' @ globattr' @ncdf_quickwrite end