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

Last change on this file since 236 was 236, checked in by pinsard, 17 years ago

replace some print by some report in some .pro #2

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