Changeset 362


Ignore:
Timestamp:
07/29/08 11:00:03 (16 years ago)
Author:
smasson
Message:

bugfix related to the used of NaN and missing values, replave nan_value by missing_value keyword

File:
1 edited

Legend:

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

    r358 r362  
    66FUNCTION call_interp2d, data, inlon, inlat, inmask, outlon, outlat $ 
    77                      , INIRR=inirr, METHOD=method, SMOOTH=smooth $ 
    8                       , WEIG=weig, ADDR=addr, NAN_VALUE=NaN_value, _EXTRA=ex 
     8                      , WEIG=weig, ADDR=addr, MISSING_VALUE=missing_value, _EXTRA=ex 
    99; 
    1010  compile_opt idl2, strictarrsubs 
     
    1515; 
    1616; take care of NaN values 
    17   mask = inmask *finite(data) 
    18 ; 
    19   IF keyword_set(NaN_value) THEN BEGIN 
     17  nanmsk = finite(data) 
     18  IF total(nanmsk) NE n_elements(nanmsk) THEN BEGIN 
     19    data[where(nanmsk EQ 0b)] = 1.e20 ; put large value to be sure they are removed during the interpolation 
     20    mask = inmask * temporary(nanmsk) 
     21  ENDIF ELSE mask = inmask 
     22; 
     23  tpmiss = size(missing_value, /type) 
     24  IF tpmiss NE 0 AND tpmiss NE 7 THEN BEGIN 
    2025    CASE 1 OF 
    21       nan_value GT 1.e6:mask = temporary(mask) * (data LT (nan_value-10.)) 
    22       nan_value LT -1.e6:mask = temporary(mask) * (data GT (nan_value+10.)) 
    23       abs(nan_value) LT 1.e-6:mask = temporary(mask) * (abs(data) GT 1.e-6) 
    24       ELSE:mask = temporary(mask) * (data NE nan_value) 
     26      missing_value GT 1.e6:mask = temporary(mask) * (data LT (missing_value-10.)) 
     27      missing_value LT -1.e6:mask = temporary(mask) * (data GT (missing_value+10.)) 
     28      abs(missing_value) LT 1.e-6:mask = temporary(mask) * (abs(data) GT 1.e-6) 
     29      ELSE:mask = temporary(mask) * (data NE missing_value) 
    2530    ENDCASE 
    2631  ENDIF 
     
    142147; @keyword INMISSING_VALUE {type=scalar} 
    143148; To define (or redefine if the attribute is already existing) the 
    144 ; missing values used with INUSEASMASK keyword. Note that this value is 
    145 ; not used if INTESTOP keyword is given and contains 2 words.   
     149; missing values used with INUSEASMASK keyword to build the input mask. 
     150; Note that this value is not used if INTESTOP keyword is given and 
     151; contains 2 words. 
     152; Note: do not mismatch with MISSING_VALUE used to detect missing 
     153; values at reach record.    
    146154; 
    147155; @keyword OUTMISSING_VALUE {type=scalar} 
     
    154162; INTESTOP can contain 1 or 2 words. The first word is the operator 
    155163; definition: "EQ" "NE" "GE" "GT" "LE" "LT" (default is NE). The 
    156 ; second word define the testing value. If TESTOP contains only 1 
     164; second word define the testing value. If INTESTOP contains only 1 
    157165; word, then the test value is denifed by 
    158 ;   1) MISSING_VALUE keyword 
    159 ;   2) attribute missing_value or _fillvalue of the variable USEASMASK 
     166;   1) INMISSING_VALUE keyword 
     167;   2) attribute missing_value or _fillvalue of the variable INUSEASMASK 
    160168;   3) !Values.f_nan (can be used only with NE and EQ operators) 
    161169; 
     
    170178; same as inaddscl_before but for output mask file maskout 
    171179; 
    172 ; @keyword NAN_VALUE {type=scalar}{default=not used} 
    173 ; define the missing value in input data (missing values are treated 
     180; @keyword MISSING_VALUE {type=scalar}{default=defined by attribute missing_value or _fillvalue} 
     181; (Re)define the missing value in input data (missing values are treated 
    174182; like masked values and will be filled with extrapolation before 
    175 ; interpolation). 
     183; interpolation).  
     184; Note: do not mismatch with (IN/OUT)MISSING_VALUE which are missing value 
     185; used (in association with (IN/OUT)USEASMASK) to built the mask (that 
     186; does not change from one record to another). 
     187; Note: this value will be apply to all interpolated variables 
    176188; 
    177189; @keyword ADDR {type=2d array or variable name} 
     
    222234; IDL> file_interp, filein, fileout, gridout, inxaxisname = 'lo', inyaxisname = 'la', keep = ['lo', 'la', 'cond_sed'] 
    223235; 
    224 ; IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, nan_value = -1000.00 
     236; IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, missing_value = -1000.00 
    225237; 
    226238; @history 
     
    241253               , OUTUSEASMASK=outuseasmask, OUTMISSING_VALUE=outmissing_value $ 
    242254               , OUTADDSCL_BEFORE=outaddscl_before, OUTTESTOP = outtestop $ 
    243                , NAN_VALUE=NaN_value, WEIG=weig, ADDR=addr $ 
     255               , MISSING_VALUE=MISSING_VALUE, WEIG=weig, ADDR=addr $ 
    244256               , INXAXISNAME=inxaxisname, INYAXISNAME=inyaxisname $ 
    245257               , OUTXAXISNAME=outxaxisname, OUTYAXISNAME=outyaxisname $ 
     
    409421        END 
    410422        ELSE:BEGIN 
     423          IF n_elements(missing_value) NE 0 THEN var_missing_value = MISSING_VALUE $ 
     424          ELSE ncdf_getatt, inid, i, MISSING_VALUE = var_missing_value 
    411425          CASE varinq.ndims OF 
    412426            0:BEGIN             ; salar 
     
    422436              IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, inmask[*, *, 0], outlon, outlat $ 
    423437                                                  , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    424                                                   , WEIG = weig, ADDR = addr, NAN_VALUE = NaN_value, _extra = ex) 
     438                                                  , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex) 
    425439              ncdf_varput, outid, outvarid[i], temporary(data) 
    426440            END 
     
    437451                IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, temporary(tmpmsk), outlon, outlat $ 
    438452                                                    , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    439                                                     , WEIG = weig, ADDR = addr, NAN_VALUE = NaN_value, _extra = ex) 
     453                                                    , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex) 
    440454                ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt 
    441455              ENDFOR 
     
    453467                  IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, temporary(tmpmsk), outlon, outlat $ 
    454468                                                      , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 
    455                                                       , WEIG = weig, ADDR = addr, NAN_VALUE = NaN_value, _extra = ex) 
     469                                                      , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex) 
    456470                  ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt 
    457471                ENDFOR 
Note: See TracChangeset for help on using the changeset viewer.