[101] | 1 | ;+ |
---|
| 2 | ; @file_comments extrapolate data (zinput) where maskinput eq 0 by filling step by |
---|
| 3 | ; step the coastline points with the mean value of the 8 neighbourgs. |
---|
| 4 | ; |
---|
| 5 | ;- |
---|
[59] | 6 | FUNCTION extrapolate, zinput, maskinput, nb_iteration, x_periodic = x_periodic, MINVAL = minval, MAXVAL = maxval |
---|
| 7 | ; |
---|
| 8 | compile_opt strictarr, strictarrsubs |
---|
| 9 | ; |
---|
| 10 | ; check the number of iteration used in the extrapolation. |
---|
| 11 | IF n_elements(nb_iteration) EQ 0 THEN nb_iteration = 10.E20 |
---|
| 12 | IF nb_iteration EQ 0 THEN return, zinput |
---|
| 13 | nx = (size(zinput))[1] |
---|
| 14 | ny = (size(zinput))[2] |
---|
| 15 | ; take care of the boundary conditions... |
---|
| 16 | ; |
---|
| 17 | ; for the x direction, we put 2 additional columns at the left and |
---|
| 18 | ; right side of the array. |
---|
| 19 | ; for the y direction, we put 2 additional lines at the bottom and |
---|
| 20 | ; top side of the array. |
---|
| 21 | ; These changes allow us to use shift function without taking care of |
---|
| 22 | ; the x and y periodicity. |
---|
| 23 | ; |
---|
| 24 | ztmp = bytarr(nx+2, ny+2) |
---|
| 25 | ztmp[1:nx, 1:ny] = byte(maskinput) |
---|
| 26 | msk = temporary(ztmp) |
---|
| 27 | ; |
---|
| 28 | ztmp = replicate(1.e20, nx+2, ny+2) |
---|
| 29 | ztmp[1:nx, 1:ny] = zinput |
---|
| 30 | if keyword_set(x_periodic) then begin |
---|
| 31 | ztmp[0, 1:ny] = zinput[nx-1, *] |
---|
| 32 | ztmp[nx+1, 1:ny] = zinput[0, *] |
---|
| 33 | ENDIF |
---|
| 34 | ; remove NaN points if there is some... |
---|
| 35 | nan = where(finite(ztmp) EQ 0, cnt_nan) |
---|
| 36 | IF cnt_nan NE 0 THEN ztmp[temporary(nan)] = 1.e20 |
---|
| 37 | z = temporary(ztmp) |
---|
| 38 | nx2 = nx+2 |
---|
| 39 | ny2 = ny+2 |
---|
| 40 | ;--------------------------------------------------------------- |
---|
| 41 | ;--------------------------------------------------------------- |
---|
| 42 | ; extrapolation |
---|
| 43 | ;--------------------------------------------------------------- |
---|
| 44 | sqrtinv = 1./sqrt(2) |
---|
| 45 | ; |
---|
[69] | 46 | cnt = 1 |
---|
[59] | 47 | ; When we look for the coast line, we don't whant to select the |
---|
| 48 | ; borderlines of the array. -> we force the value of the mask for |
---|
| 49 | ; those lines. |
---|
| 50 | msk[0, *] = 1b |
---|
| 51 | msk[nx+1, *] = 1b |
---|
| 52 | msk[*, 0] = 1b |
---|
| 53 | msk[*, ny+1] = 1b |
---|
| 54 | ; find the land points |
---|
| 55 | land = where(msk EQ 0, cnt_land) |
---|
| 56 | ;--------------------------------------------------------------- |
---|
| 57 | WHILE cnt LE nb_iteration AND cnt_land NE 0 DO BEGIN |
---|
| 58 | ;--------------------------------------------------------------- |
---|
| 59 | ; find the coast line points... |
---|
| 60 | ;--------------------------------------------------------------- |
---|
| 61 | ; Once the land points list has been found, we change back the the |
---|
| 62 | ; mask values for the boundary conditions. |
---|
| 63 | msk[0, *] = 0b |
---|
| 64 | msk[nx+1, *] = 0b |
---|
| 65 | msk[*, 0] = 0b |
---|
| 66 | msk[*, ny+1] = 0b |
---|
| 67 | if keyword_set(x_periodic) then begin |
---|
| 68 | msk[0, *] = msk[nx, *] |
---|
| 69 | msk[nx+1, *] = msk[1, *] |
---|
| 70 | endif |
---|
| 71 | ; |
---|
| 72 | ; we compute the weighted number of sea neighbourgs. |
---|
| 73 | ; those 4 neighbours have a weight of 1: |
---|
| 74 | ; * |
---|
| 75 | ; *+* |
---|
| 76 | ; * |
---|
| 77 | ; |
---|
| 78 | ; those 4 neighbours have a weight of 1/sqrt(2): |
---|
| 79 | ; |
---|
| 80 | ; * * |
---|
| 81 | ; + |
---|
| 82 | ; * * |
---|
| 83 | ; |
---|
| 84 | ; As we make sure that none of the land points are located on the |
---|
| 85 | ; border of the array, we can compute the weight without shift |
---|
| 86 | ; (faster). |
---|
| 87 | ; |
---|
| 88 | weight = msk[land+1]+msk[land-1]+msk[land+nx2]+msk[land-nx2] $ |
---|
| 89 | +sqrtinv*(msk[land+nx2+1]+msk[land+nx2-1] $ |
---|
| 90 | +msk[land-nx2+1]+msk[land-nx2-1]) |
---|
| 91 | ; list all the points that have sea neighbourgs |
---|
| 92 | ok = where(weight GT 0) |
---|
| 93 | ; the coastline points |
---|
| 94 | coast = land[ok] |
---|
| 95 | ; their weighted number of sea neighbourgs. |
---|
| 96 | weight = weight[temporary(ok)] |
---|
| 97 | ;--------------------------------------------------------------- |
---|
| 98 | ; fill the coastine points |
---|
| 99 | ;--------------------------------------------------------------- |
---|
| 100 | z = temporary(z)*msk |
---|
| 101 | ; |
---|
| 102 | zcoast = z[1+coast]+z[-1+coast]+z[nx2+coast]+z[-nx2+coast] $ |
---|
| 103 | +1./sqrt(2)*(z[nx2+1+coast]+z[nx2-1+coast] $ |
---|
| 104 | +z[-nx2+1+coast]+z[-nx2-1+coast]) |
---|
| 105 | ; |
---|
| 106 | IF n_elements(minval) NE 0 THEN zcoast = minval > temporary(zcoast) |
---|
| 107 | IF n_elements(maxval) NE 0 THEN zcoast = temporary(zcoast) < maxval |
---|
| 108 | z[coast] = temporary(zcoast)/temporary(weight) |
---|
| 109 | ; we update the the boundary conditions of z |
---|
| 110 | if keyword_set(x_periodic) then begin |
---|
| 111 | z[0, *] = z[nx, *] |
---|
| 112 | z[nx+1, *] = z[1, *] |
---|
| 113 | endif |
---|
| 114 | ;--------------------------------------------------------------- |
---|
| 115 | ; we update the mask |
---|
| 116 | ;--------------------------------------------------------------- |
---|
| 117 | msk[temporary(coast)] = 1 |
---|
| 118 | ; |
---|
| 119 | cnt = cnt + 1 |
---|
| 120 | ; When we look for the coast line, we don't whant to select the |
---|
| 121 | ; borderlines of the array. -> we force the value of the mask for |
---|
| 122 | ; those lines. |
---|
| 123 | msk[0, *] = 1b |
---|
| 124 | msk[nx+1, *] = 1b |
---|
| 125 | msk[*, 0] = 1b |
---|
| 126 | msk[*, ny+1] = 1b |
---|
| 127 | ; find the land points |
---|
| 128 | land = where(msk EQ 0, cnt_land) |
---|
| 129 | ; |
---|
| 130 | ENDWHILE |
---|
| 131 | ;--------------------------------------------------------------- |
---|
| 132 | ; we return the original size of the array |
---|
| 133 | ;--------------------------------------------------------------- |
---|
| 134 | |
---|
| 135 | return, z[1:nx, 1:ny] |
---|
| 136 | END |
---|
| 137 | |
---|