Changeset 28 for trunk/src


Ignore:
Timestamp:
01/04/11 12:34:16 (13 years ago)
Author:
pinsard
Message:

start to work on correction tools

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/t2m_correction_ncdf.pro

    r20 r28  
    66; t2m_correction_ncdf.pro 
    77; ======================= 
     8; 
     9; Mean correction for air temperature bias and correction for variability are 
     10; applied. 
     11; 
     12; :file:`${TROPFLUX_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc` have been produced by :ref:`interp_erai_t2m_1989_2009.pro`. 
     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 
     16; :file:`${TROPFLUX_OD}/TropFlux_t2m_19890101_20091231_v50.nc`. 
    817; 
    918;     .. graphviz:: 
     
    1423;           ] 
    1524; 
    16 ;           file_t2m [shape=ellipse,fontname=Courier,label="/Volumes/Iomega_HDD/TropFlux/input_uncor/erai_t2m_19890101_20091231_oafluxgrid.nc"]; 
    17 ; 
    18 ;           ncfile [shape=ellipse,fontname=Courier,label="/Volumes/Iomega_HDD/TropFlux/input_cor/full_cor/TropFlux_t2m_19890101_20091231_v20.nc"]; 
     25;           file_t2m [shape=ellipse,fontname=Courier,label="${TROPFLUX_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc"]; 
     26; 
     27;           ncfile [shape=ellipse,fontname=Courier,label="${TROPFLUX_OD}/TropFlux_t2m_19890101_20091231_v50.nc"]; 
    1928; 
    2029;           t2m_correction_ncdf [shape=box, 
     
    3039; SEE ALSO 
    3140; ======== 
     41; 
     42; :ref:`tropflux_profile.sh` 
     43; 
     44; :ref:`mooring_corrections` 
     45; 
     46; :ref:`interp_erai_t2m_1989_2009.pro` 
    3247; 
    3348; :func:`initncdf <saxo:initncdf>` 
     
    3853; :func:`jul2date <saxo:jul2date>` 
    3954; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` 
     55; :func:`ncdf_getatt <saxo:ncdf_getatt>` 
    4056; 
    4157; EXAMPLES 
     
    4965; ==== 
    5066; 
    51 ; hard coded directory - usage of ${TROPFLUX_ID} 
     67; make it work !! 
    5268; 
    5369; coding rules 
     70; 
     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 
    5495; 
    5596; EVOLUTIONS 
    5697; ========== 
    5798; 
     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; 
    58111; - fplod 20101215T114503Z aedon.locean-ipsl.upmc.fr (Darwin) 
    59112; 
     
    70123;- 
    71124pro t2m_correction_ncdf 
     125; 
    72126@common 
    73 da1=19890101 & da2=20091231 
    74  
    75 file='/Volumes/Iomega_HDD/TropFlux/input_uncor/erai_t2m_19890101_20091231_oafluxgrid.nc' 
    76 initncdf, file 
    77 t2m=read_ncdf('t2m',da1,da2,file=file,/nostr) & t2m=t2m-273.15 
     127; check for input directory 
     128; 
     129; test if ${TROPFLUX_ID} defined 
     130tropflux_id_env=GETENV('TROPFLUX_ID') 
     131CASE tropflux_id_env OF 
     132    ''  :  BEGIN 
     133     msg = 'eee : ${TROPFLUX_ID} is not defined' 
     134     ras = report(msg) 
     135     STOP 
     136           END 
     137 ELSE: BEGIN 
     138     msg = 'iii : ${TROPFLUX_ID} is ' + tropflux_id_env 
     139     ras = report(msg) 
     140       END 
     141ENDCASE 
     142; 
     143iodirin = isadirectory(tropflux_id_env) 
     144; 
     145; existence and protection of ${TROPFLUX_ID} 
     146IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN 
     147   msg = 'eee : the directory' + iodirin  + ' is not accessible.' 
     148   ras = report(msg) 
     149   STOP 
     150ENDIF 
     151; 
     152; build uncorrected t2 filename 
     153da1=19890101 
     154da2=20091231 
     155filename_t2_uncor='erai_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_oafluxgrid.nc' 
     156; 
     157; check if this file exists 
     158fullfilename_t2_uncor = isafile(iodirin + filename_t2_uncor, NEW=0, /MUST_EXIST) 
     159IF fullfilename_t2_uncor[0] EQ '' THEN BEGIN 
     160   msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.' 
     161   ras = report(msg) 
     162   STOP 
     163ENDIF 
     164; test if ${TROPFLUX_OD} defined 
     165tropflux_od_env=GETENV('TROPFLUX_OD') 
     166CASE tropflux_od_env OF 
     167  '' : BEGIN 
     168         msg = 'eee : ${TROPFLUX_OD} is not defined' 
     169         ras = report(msg) 
     170       STOP 
     171       END 
     172  ELSE: BEGIN 
     173          msg = 'iii : ${TROPFLUX_OD} is ' + tropflux_od_env 
     174          ras = report(msg) 
     175        END 
     176 ENDCASE 
     177; 
     178; check if output data will be possible 
     179iodirout = isadirectory(tropflux_od_env) 
     180; 
     181; existence and protection 
     182IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN 
     183    msg = 'eee : the directory' + iodirout  + ' was not found.' 
     184    ras = report(msg) 
     185    STOP 
     186ENDIF 
     187; 
     188; build output filename 
     189filename_out='TropFlux_t2m_'+ string(da1,format='(i8.8)')+'_'+ string(da2,format='(i8.8)')+'_v50.nc' 
     190fullfilename_out = iodirout + filename_out 
     191; in order to avoid unexpected overwritten 
     192IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN 
     193   msg = 'eee : the file ' + fullfilename_out  + ' already exists.' 
     194   ras = report(msg) 
     195   STOP 
     196ENDIF 
     197; 
     198; define grid parameters with t2 file 
     199initncdf, fullfilename_t2_uncor 
     200; 
     201; get time in t2 file 
     202timein=ncdf_lec(fullfilename_t2_uncor,var='time') 
     203jptin=n_elements(timein) 
     204print, 'time steps from data ', jptin 
     205print, '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 
     209da=jul2date(julday(01, 01, 1957,timein[0])) 
     210cda0=string(da,format='(i8.8)') 
     211da=jul2date(julday(01, 01, 1957,timein[jptin-1])) 
     212cda1=string(da,format='(i8.8)') 
     213print, 'first date ', cda0 
     214print, 'last date ' , cda1 
     215; 
     216; read t2 data 
     217t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m') 
     218; 
     219t2m=t2m-273.15 
    78220help, t2m 
    79  
     221; 
     222jpt=jptin 
    80223t2m_mean=grossemoyenne(t2m,'t',/nan) 
    81 help, w_mean 
    82  
    83 tt=time & jpt=n_elements(time) 
    84 caldat, time,mon,day,yea 
     224help, t2m_mean 
     225 
    85226t2m_m=t2m*0. 
    86227bias_cor=t2m*0. 
     
    89230;; line fit ->  -0.0741607x + 1.67601   ;; (2000-2009) 
    90231 
    91 for jt=0,jpt-1 do begin 
    92   jtt=(time(jt)-julday(1,1,yea(jt))) < 364 
     232for 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 
    93236  t=reform(t2m_mean(*,*)) 
    94237  t2m_m(*,*,jt)=t 
     
    116259lat=reform(gphit(0,0:jpj-1)) 
    117260lon=reform(glamt(0:jpi-1,0)) 
    118 time=timegen(7670, units='days', start=julday(1,1,1989)) & jpt=n_elements(time) 
    119  
    120 cda0=string(jul2date(time(0)),format='(i8.8)') 
    121 cda1=string(jul2date(time(jpt-1)),format='(i8.8)') 
    122  
    123 time=time-julday(1,1,1950) & jpt=n_elements(time) 
    124  
    125 ;ncfile='!/Volumes/Iomega_HDD/TropFlux/input_cor/full_cor/TropFlux_t2m_19890101_20091231_v20.nc' 
    126 ncfile='!/Users/pkb/data/TropFlux/TropFlux_t2m_19890101_20091231_v50.nc' 
    127 lon_attr={units:'degrees_east',long_name:'Longitude'} 
    128 lat_attr={units:'degrees_north',long_name:'Latitude'} 
     261cda0=string(da1) 
     262cda1=string(da2) 
     263 
     264time=time-julday(1,1,1950) 
     265jpt=n_elements(time) 
     266 
     267ncfile='!' + fullfilename_out 
     268 
     269ncdf_getatt, fullfilename_t2_uncor, 'longitude', units=units 
     270ncdf_getatt, fullfilename_t2_uncor, 'longitude', long_name=long_name 
     271lon_attr={units:units, long_name:long_name} 
     272ncdf_getatt, fullfilename_t2_uncor, 'latitude', units=units 
     273ncdf_getatt, fullfilename_t2_uncor, 'latitude', long_name=long_name 
     274lat_attr={units:units, long_name:long_name} 
     275 
    129276time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} 
    130 t2m_attr={units:'degK',missing_value:1.e20,long_name:'Air Temperature at 2m',short_name:'t2m',axis:'TYX'} 
     277 
     278ncdf_getatt, fullfilename_t2_uncor, 't2m', units=units 
     279ncdf_getatt, fullfilename_t2_uncor, 't2m', long_name=long_name 
     280t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'} 
    131281globattr={source:'Basic data obtained from ERAI.  Mean correction for air temperautre bias and correction for variability are applied',timerange:cda0+' - '+cda1} 
    132282 
Note: See TracChangeset for help on using the changeset viewer.