;+ ; ; ======================= ; t2m_correction_ncdf.pro ; ======================= ; ; .. function:: t2m_correction_ncdf(yyyymmddb,yyyymmdde) ; ; DESCRIPTION ; =========== ; ; Mean correction for air temperature bias and correction for variability are ; applied. ; ; :file:`${PROJECT_ID}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; containing ; air temperature at 2 m height from ERA-I interpolated on OAFLUX grid ; has been produced by ; :func:`interp_erai_t2m`. ; ; Corrected air temperature at 2 m height ; is written in ; :file:`${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc` ; if this file not already exists. ; ; This output file ; :file:`${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc` ; will be used by ; :func:`tropflux`. ; ; .. only:: man ; ; Figure is visible on PDF and HTML documents only. ; ; .. only:: html or latex ; ; .. graphviz:: ; ; digraph t2m_correction_ncdf { ; ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.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:`mooring_corrections` ; ; Used by :ref:`tropflux.sh` ; ; :ref:`project_profile.sh` ; ; :func:`interp_erai_t2m` ; ; :func:`initncdf ` ; :func:`read_ncdf ` ; :func:`grossemoyenne ` ; :func:`caldat ` ; :func:`julday ` ; :func:`jul2date ` ; :func:`ncdf_quickwrite ` ; :func:`ncdf_getatt ` ; ; EXAMPLES ; ======== ; ; .. code-block:: idl ; ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; result = t2m_correction_ncdf(yyyymmddb, yyyymmdde) ; print, result ; ; TODO ; ==== ; ; note .5 in time value ... is this correct ? do others files ; present the same feature ? ; ; .. code-block:: bash ; ; ncks -v time -d time,0,1 /usr/work/incas/fplod/tropflux_d/TropFlux_t2m_19890101_20091231.nc ; ; .. parsed-literal:: ; ; time: type NC_DOUBLE, 1 dimension, 3 attributes, chunked? no, compressed? no, packed? no, ID = 3 ; time RAM size is 7670*sizeof(NC_DOUBLE) = 7670*8 = 61360 bytes ; time dimension 0: time, size = 7670 NC_DOUBLE, dim. ID = 2 (CRD)(REC) ; time attribute 0: units, size = 30 NC_CHAR, value = days since 1950-01-01 00:00:00 ; time attribute 1: long_name, size = 9 NC_CHAR, value = Time axis ; time attribute 2: time_origin, size = 20 NC_CHAR, value = 1950-JAN-01 00:00:00 ; ; time[0]=14244.5 days since 1950-01-01 00:00:00 ; time[1]=14245.5 days since 1950-01-01 00:00:00 ; ; coding rules ; ; understand usage of jtt ; ; check time values ; ; 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 ; ========== ; ; $Id: t2m_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $ ; ; $URL$ ; ; - fplod 20120322 ; ; * taking project_overwrite into account ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite ; * pro -> function ; * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters ; * replace t2m=ncdf_lec(... by a t2m=read_ncdf( ; ; - fplod 20110822T112525Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * correction for time values in output file ; ; - 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 ; ;- function t2m_correction_ncdf $ , yyyymmddb $ , yyyymmdde ; ;++compile_opt idl2, strictarrsubs, logical_predicate ; @cm_4cal @cm_4data @cm_4mesh @cm_4data @cm_project ; ; Return to caller if errors ON_ERROR, 2 ; result = -1 ; usage = 'result = sst_correction_ncdf(yyyymmddb, yyyymmdde)' nparam = N_PARAMS() IF (nparam NE 2) THEN BEGIN ras = report(['Incorrect number of arguments.' $ + '!C' $ + 'Usage : ' + usage]) return, result ENDIF ; test if ${PROJECT_OD} defined CASE project_id_env OF '' : BEGIN msg = 'eee : ${PROJECT_OD} is not defined' ras = report(msg) return, result 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) return, result 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) return, result ENDIF ; ; build uncorrected t2 filename filename_t2_uncor = 'erai_t2m_' $ + string(yyyymmddb,format='(i8.8)') $ + '_' $ + string(yyyymmdde,format='(i8.8)') $ + '_oafluxgrid.nc' ; ; check if this file exists msg='iii : looking for ' + filename_t2_uncor ras = report(msg) 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) return, result ENDIF ; ; build output filename filename_out = 'TropFlux_t2m_' $ + string(yyyymmddb,format='(i8.8)') $ + '_' $ + string(yyyymmdde,format='(i8.8)') $ + '.nc' ; fullfilename_out = iodirout + filename_out ; in order to avoid unexpected overwritten IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN msg = 'eee : the file ' + fullfilename_out + ' already exists.' ras = report(msg) return, result 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 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, 'for time checking first date ', cda0 print, 'for time checking last date ' , cda1 ; ; read t2 data initncdf, fullfilename_t2_uncor t2m=read_ncdf('t2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename_t2_uncor,/nostr) timein=24.d*(time-julday(1,1,1957,0,0,0)) jpt=n_elements(timein) da=jul2date(time[0]) cda0=string(da,format='(i8.8)') da=jul2date(time[jpt-1]) cda1=string(da,format='(i8.8)') print, 't2m in t2m_correction_ncdf first date ', cda0 print, 't2m in t2m_correction_ncdf last date ' , cda1 ; 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 variability 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 variability 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]) ; 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'} globattr={source:'Basic data obtained from ERAI. Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1} 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'} ; ncfields = 't2m[longitude,latitude,*time]=t2m_new:t2m_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[]=timein:time_attr ' $ + ' @ globattr' ; @ncdf_quickwrite ; result = 0 return, result ; end