Changeset 433


Ignore:
Timestamp:
06/14/10 12:31:14 (14 years ago)
Author:
smasson
Message:

add box mean interpolation in file_interp

Location:
trunk/SRC/Interpolation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Interpolation/file_interp.pro

    r417 r433  
     1;+ 
     2; 
     3; @hidden 
     4; 
     5;- 
     6FUNCTION boxmean_interp, data, divx, divy 
     7 ; 
     8  compile_opt idl2, strictarrsubs 
     9; 
     10  sz = size(data, /dimensions ) 
     11  jpiout = sz[0] / divx 
     12  jpjout = sz[1] / divy 
     13; 
     14  data = reform(data, divx, jpiout, divy, jpjout, /overwrite) 
     15  data = total(temporary(data), 1)   ; ave along divx 
     16  data = total(temporary(data), 2)   ; ave along divy 
     17  data = temporary(data) / float(divx*divy) 
     18 
     19  RETURN, data 
     20END 
    121;+ 
    222; 
     
    727                        , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    828                        , WEIG = weig, ADDR = addr, MISSING_VALUE = missing_value $ 
     29                        , DIVX = divx, DIVY = divy $ 
    930                        , GETHAN = gethan, LETHAN = lethan, _EXTRA = ex 
    1031; 
     
    3556    IF mask[0] NE -1 THEN mask = temporary(missmask) * mask ELSE mask = temporary(missmask) 
    3657  ENDIF 
     58 
    3759; extrapolation 
    3860  IF keyword_set(smooth) THEN data = extrapsmooth(temporary(data), mask, /x_periodic, _extra = ex) $ 
    3961  ELSE data = extrapolate(temporary(data), mask, /x_periodic, _extra = ex) 
    4062; interpolation 
    41   IF NOT keyword_set(inirr) THEN BEGIN 
    42     data = fromreg(method, temporary(data), inlon, inlat, outlon, outlat, WEIG = weig, ADDR = addr, _extra = ex) 
    43   ENDIF ELSE BEGIN 
    44     data = fromirr(method, temporary(data), inlon, inlat, -1, outlon, outlat, -1, WEIG = weig, ADDR = addr) 
    45   ENDELSE 
     63  IF method EQ 'boxmean' THEN BEGIN 
     64    data = boxmean_interp(temporary(data), divx, divy) 
     65  ENDIF ELSE BEGIN  
     66    IF NOT keyword_set(inirr) THEN BEGIN 
     67      data = fromreg(method, temporary(data), inlon, inlat, outlon, outlat, WEIG = weig, ADDR = addr, _extra = ex) 
     68    ENDIF ELSE BEGIN 
     69      data = fromirr(method, temporary(data), inlon, inlat, -1, outlon, outlat, -1, WEIG = weig, ADDR = addr) 
     70    ENDELSE 
     71  ENDELSE  
    4672 
    4773  IF n_elements(gethan) EQ 1 THEN data = gethan > temporary(data) 
     
    6692; output file name (will be overwritten if already exist) 
    6793; 
    68 ; @param gridout {in}{type=scalar string} 
    69 ; output grid file name (must exist and must contain the 
    70 ; longitude and latitude axis as 1D or 2D arrays) 
     94; @param gridout {in}{type=scalar string or 2 element vector if boxmean method} 
     95; if boxmean method: 
     96;  2 elements vector defining the size of the box used to compute the 
     97;  mean value. It must divide the original grid size. 
     98; else: 
     99;  output grid file name (must exist and must contain the 
     100;  longitude and latitude axis as 1D or 2D arrays) 
    71101; 
    72102; @keyword GRIDIN {type=scalar string}{default=set to filein} 
     
    96126; 
    97127; @keyword METHOD {type=scalar string}{default='bilinear'} 
    98 ; interpolation method: can be only 'bilinear' (or 'imoms3' if the input grid 
     128; interpolation method: can be only 'bilinear', 'boxmean' (or 'imoms3' if the input grid 
    99129; is a "regular" grid). A "regular/rectangular grid" is defined as a 
    100130; grid for which each longitude lines have the same latitude and each 
    101131; latitude columns have the same longitude. 
     132; boxmean interpolation is simply the mean value over a box of nx by ny 
     133; points (see gridout definition). 
    102134; 
    103135; @keyword SMOOTH {type=scalar 0 or 1}{default=0} 
     
    248280;   IDL> file_interp, filein, fileout, gridout, inxaxisname = 'lo', inyaxisname = 'la', keep = ['lo', 'la', 'cond_sed'] 
    249281;   IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, missing_value = -1000.00 
     282;   IDL> file_interp,'sst_reg025.nc', 'sst_reg1.nc',[4,4], method = 'boxmean' 
    250283; 
    251284; @history 
     
    308341  IF keyword_set(set_yaxisname) THEN inyaxisname = set_yaxisname 
    309342; 
    310   ncdf_getaxis, gridout, outdimidx, outdimidy, outlon, outlat, xaxisname = outxaxisname, yaxisname = outyaxisname 
    311   get_gridparams, outlon, outlat, jpiout, jpjout, 2 
     343  IF method EQ 'boxmean' THEN BEGIN 
     344    IF n_elements(gridout) NE 2 THEN stop 
     345    divx = round(gridout[0]) 
     346    divy = round(gridout[1]) 
     347    IF jpiin MOD divx NE 0 THEN BEGIN  
     348      print, 'in boxmean method, the x size ('+strtrim(divx, 1)+') of the box used to average the data must devide the size of the x dimension ('+strtrim(jpiin, 1)+')' 
     349      return 
     350    ENDIF 
     351    IF jpjin MOD divy NE 0 THEN BEGIN  
     352      print, 'in boxmean method, the y size ('+strtrim(divy, 1)+') of the box used to average the data must devide the size of the y dimension ('+strtrim(jpjin, 1)+')' 
     353      return 
     354    ENDIF 
     355    jpiout = jpiin / divx 
     356    jpjout = jpjin / divy 
     357    outlon = inlon   &   outlon = boxmean_interp(outlon, divx, divy) 
     358    outlat = inlat   &   outlat = boxmean_interp(outlat, divx, divy) 
     359    IF jpiout EQ 1 OR jpjout EQ 1 THEN BEGIN    
     360      outlon = reform(outlon, jpiout, jpjout, /overwrite) 
     361      outlat = reform(outlat, jpiout, jpjout, /overwrite) 
     362    ENDIF  
     363  ENDIF ELSE BEGIN  
     364    ncdf_getaxis, gridout, outdimidx, outdimidy, outlon, outlat, xaxisname = outxaxisname, yaxisname = outyaxisname 
     365    get_gridparams, outlon, outlat, jpiout, jpjout, 2 
     366  ENDELSE  
    312367; 
    313368; masks 
     
    318373  IF size(inmask, /n_dimensions) EQ 2 THEN inmasksz = [inmasksz, 0] 
    319374  IF n_elements(inmaskname) EQ 0 THEN inmaskname = 'not defined' ; default definition 
    320   outmask = ncdf_getmask(maskout, MASKNAME = outmaskname, INVMASK = outinvmask, USEASMASK = outuseasmask $ 
    321                         , MISSING_VALUE = outmissing_value, ADDSCL_BEFORE = outaddscl_before, TESTOP = outtestop) 
     375  IF method EQ 'boxmean' THEN BEGIN 
     376    outmask = inmask 
     377    IF inmask[0] NE -1 THEN outmask = boxmean_interp(outmask, divx, divy) 
     378  ENDIF ELSE BEGIN  
     379    outmask = ncdf_getmask(maskout, MASKNAME = outmaskname, INVMASK = outinvmask, USEASMASK = outuseasmask $ 
     380                           , MISSING_VALUE = outmissing_value, ADDSCL_BEFORE = outaddscl_before, TESTOP = outtestop) 
     381  ENDELSE  
    322382; 
    323383; irregular grids? 
     
    338398  ENDCASE 
    339399 
    340   IF inirr AND method NE 'bilinear' THEN stop 
     400  IF inirr AND method EQ 'imoms3' THEN stop 
    341401; 
    342402; Dimensions 
     
    451511                                                  , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    452512                                                  , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value $ 
     513                                                  , DIVX = divx, DIVY = divy $ 
    453514                                                  , GETHAN = gethan, LETHAN = lethan, _extra = ex) 
    454515              IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout) 
     
    457518            3:BEGIN             ; 3D 
    458519              FOR k = 0, indimsz[varinq.dim[2]]-1 DO BEGIN 
     520                IF k MOD 100 EQ 0 THEN print, k 
    459521                incnt = [indimsz[varinq.dim[0: 1]], 1] 
    460522                outcnt = [outdimsz[varinq.dim[0: 1]], 1] 
     
    468530                                                    , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    469531                                                    , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value $ 
     532                                                    , DIVX = divx, DIVY = divy $ 
    470533                                                    , GETHAN = gethan, LETHAN = lethan, _extra = ex) 
    471534                IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout) 
     
    475538            4:BEGIN             ; 4D 
    476539              FOR t = 0, indimsz[varinq.dim[3]]-1 DO BEGIN 
     540                IF t MOD 100 EQ 0 THEN print, t 
    477541                FOR k = 0, indimsz[varinq.dim[2]]-1 DO BEGIN 
    478542                  incnt = [indimsz[varinq.dim[0: 1]], 1, 1] 
     
    486550                                                      , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    487551                                                      , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value $ 
     552                                                      , DIVX = divx, DIVY = divy $ 
    488553                                                      , GETHAN = gethan, LETHAN = lethan, _extra = ex) 
    489554                  IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout) 
  • trunk/SRC/Interpolation/fromirr.pro

    r372 r433  
    121121  ENDIF 
    122122;--------------- 
    123 ; to the interpolation 
     123; do the interpolation 
    124124;--------------- 
    125   dataout = total(weig*datain[addr], 1) 
     125  intype = size(datain, /type) 
     126  if intype LE 3 THEN dataout = total(weig*float(datain[addr]), 1) $ 
     127  ELSE                dataout = total(weig*      datain[addr] , 1) 
    126128  dataout = reform(dataout, jpio, jpjo, /over) 
     129  IF intype LE 3 THEN dataout = round(temporary(dataout)) 
    127130; 
    128131  RETURN, dataout 
  • trunk/SRC/Interpolation/fromreg.pro

    r372 r433  
    126126  ENDIF 
    127127; 
    128   dataout = total(weig*datain[addr], 1) 
     128;--------------- 
     129; do the interpolation 
     130;--------------- 
     131  intype = size(datain, /type) 
     132  if intype LE 3 THEN dataout = total(weig*float(datain[addr]), 1) $ 
     133  ELSE                dataout = total(weig*      datain[addr] , 1) 
    129134  dataout = reform(dataout, jpio, jpjo, /over) 
     135  IF intype LE 3 THEN dataout = round(temporary(dataout)) 
    130136; 
    131137  RETURN, dataout 
Note: See TracChangeset for help on using the changeset viewer.