source: trunk/SRC/Interpolation/extrapsmooth.pro @ 378

Last change on this file since 378 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1;+
2;
3; @file_comments
4; similar to <pro>extrapolate</pro> but could to the job in a better way
5; because the extrapolated values are smoothed...
6; takes more time than <pro>extrapolate</pro>.
7; extrapolate data where mskin is equal 0 by filling
8; step by step the coastline points with the mean value of the 8 neighbors.
9;
10; @categories
11; Interpolation
12;
13; @param in {in}{required}{type=2d array}
14; data to be extrapolate
15;
16; @param mskin {in}{required}{type=2d array or -1}
17; a 2D array, the land-sea mask of the output data (1 on ocean, 0 on land)
18; put -1 if input data are not masked
19;
20; @keyword MINVAL {type=scalar}{default=not used}
21; to specify a minimum value to the extrapolated values
22;
23; @keyword MAXVAL {type=scalar}{default=not used}
24; to specify a maximum value to the extrapolated values
25;
26; @keyword GE0 {type=scalar 0 or 1}{default=0}
27; put 1 to force the extrapolated values to be larger than 0, same as using minval=0.
28;
29; @keyword
30; _EXTRA to be able to call extrapsmooth with _extra keyword
31;
32; @returns
33; the extrapolated array with no more masked values
34;
35; @restrictions
36; You cannot specify the number of iterations done in the extrapolation process
37;
38; @examples
39;
40;   IDL> a=extrapsmooth(dist(jpi,jpj),tmask[*,*,0],/x_periodic)
41;   IDL> tvplus, a
42;
43; compare to extrapolate result:
44;
45;   IDL> b=extrapolate(dist(jpi,jpj),tmask[*,*,0],/x_periodic)
46;   IDL> tvplus, b, window = 1
47;
48; @history
49;  January 2007: Sebastien Masson (smasson\@lodyc.jussieu.fr)
50;
51; @version
52; $Id$
53;-
54FUNCTION extrapsmooth, in, mskin, X_PERIODIC=x_periodic $
55                     , MINVAL=minval, MAXVAL=maxval, GE0=ge0, _EXTRA=ex
56;
57  compile_opt strictarr, strictarrsubs
58;
59  sz = size(reform(in))
60  IF sz[0] NE 2 THEN BEGIN
61    ras = report('Input arrays must have 2 dimensions')
62    return, -1
63  ENDIF
64  nx = sz[1]
65  ny = sz[2]
66  IF n_elements(mskin) EQ 1 AND mskin[0] EQ -1 THEN mskin = replicate(1b, nx, ny)
67  IF n_elements(mskin) NE nx*ny THEN BEGIN
68    ras = report('input grid mask do not have the good size')
69    return, -1
70  ENDIF
71;
72  out = reform(in)
73  whmsk = where(mskin EQ 0, nbr)
74  IF nbr NE 0 THEN out[temporary(whmsk)] = !values.f_nan
75; add values on each side of the array to avoid boundary effects
76  nx2 = nx/2
77  ny2 = ny/2
78  add = replicate(!values.f_nan, nx, ny2)
79  out = [[add], [temporary(out)], [add]]
80  IF keyword_set(x_periodic)  THEN BEGIN
81    add1 = out[0:nx2, *]
82    add2 = out[nx-nx2:nx-1, *]
83    out = [add2, [temporary(out)], add1]
84  ENDIF ELSE BEGIN
85    add = replicate(!values.f_nan, nx2, ny+2*ny2)
86    out = [add, [temporary(out)], add]
87  ENDELSE
88;
89  msk0 = where(finite(out) EQ 0)
90  nnan = total(finite(out, /nan))
91  i = 1
92  WHILE nnan NE 0 DO BEGIN
93    tmp = smooth(out, 2*i + 1, /nan)
94    ; find only the changed values that where on land
95    new = where(finite(out) EQ 0 AND finite(tmp) EQ 1, nnew)
96    IF nnew EQ 0 then nnan = 0 ELSE BEGIN
97      IF keyword_set(ge0) THEN tmp = 0. > temporary(tmp)
98      IF n_elements(minval) NE 0 THEN tmp = minval > temporary(tmp)
99      IF n_elements(maxval) NE 0 THEN tmp = temporary(tmp) < maxval
100      out[new] = tmp[new]
101      i = i+1
102      nnan = total(finite(out, /nan))
103    ENDELSE
104  ENDWHILE
105; a final smooth is needed
106  out = smooth(temporary(out), 5, /nan)
107  IF keyword_set(ge0) THEN out = 0. > temporary(out)
108  IF n_elements(minval) NE 0 THEN out = minval > temporary(out)
109  IF n_elements(maxval) NE 0 THEN out = temporary(out) < maxval
110; get back to the original domain
111  out = (temporary(out))[nx2:nx+nx2-1, ny2:ny+ny2-1]
112; put back the non-maskqed values
113  whmsk = where(mskin NE 0)
114  out[whmsk] = in[whmsk]
115;
116  return, out
117END
Note: See TracBrowser for help on using the repository browser.