1 |
gforget |
1.6 |
function []=example_smooth(fld); |
2 |
gforget |
1.7 |
% EXAMPLE_SMOOTH(fld) applies smoothing filters to fld |
3 |
|
|
% |
4 |
|
|
% Example: |
5 |
|
|
% fld=example_bin_average; |
6 |
|
|
% example_smooth(fld); |
7 |
gforget |
1.6 |
|
8 |
|
|
gcmfaces_global; |
9 |
gforget |
1.1 |
|
10 |
gforget |
1.7 |
if myenv.verbose>0; |
11 |
|
|
gcmfaces_msg('==============================================='); |
12 |
|
|
gcmfaces_msg('*** entering example_smooth : apply smoother to gridded data'); |
13 |
|
|
end; |
14 |
|
|
|
15 |
|
|
%%%%%%%% apply land mask %%%%%%%% |
16 |
|
|
|
17 |
gforget |
1.2 |
if myenv.verbose>0; |
18 |
|
|
gcmfaces_msg('* apply land mask (1/NaN) to gridded before smoothing'); |
19 |
|
|
end; |
20 |
gforget |
1.6 |
fld=fld.*mygrid.mskC(:,:,1); |
21 |
gforget |
1.1 |
|
22 |
gforget |
1.3 |
%%%%%%%% isotropic diffusion %%%%%%%% |
23 |
|
|
|
24 |
gforget |
1.1 |
%choose smoothing scale: here 3 X grid spacing |
25 |
gforget |
1.2 |
if myenv.verbose>0; |
26 |
gforget |
1.7 |
gcmfaces_msg('** set the smoothing scale to 3 grid points'); |
27 |
gforget |
1.2 |
end; |
28 |
gforget |
1.1 |
distXC=3*mygrid.DXC; distYC=3*mygrid.DYC; |
29 |
|
|
|
30 |
|
|
%do the smoothing: |
31 |
gforget |
1.2 |
if myenv.verbose>0; |
32 |
|
|
gcmfaces_msg(['* call diffsmoth2D : apply smoothing operator ' ... |
33 |
|
|
'that consists in time stepping a diffusion equation ' ... |
34 |
|
|
'with accordingly chosen diffusivity and duration. In particular ' ... |
35 |
|
|
'diffsmoth2D illustrates gradient computations (using calc_T_grad) ' ... |
36 |
gforget |
1.4 |
'and convergence computations (using calc_UV_conv).']); |
37 |
gforget |
1.2 |
end; |
38 |
gforget |
1.6 |
fld_smooth=diffsmooth2D(fld,distXC,distYC); |
39 |
gforget |
1.1 |
|
40 |
|
|
%display results: |
41 |
gforget |
1.2 |
if myenv.verbose>0; |
42 |
gforget |
1.7 |
gcmfaces_msg('* display results on sphere'); |
43 |
gforget |
1.2 |
end; |
44 |
gforget |
1.1 |
|
45 |
gforget |
1.8 |
figureL; set(gca,'FontSize',16); |
46 |
|
|
gcmfaces_sphere(fld_smooth); caxis([-1 1]*0.4); colorbar; |
47 |
|
|
title('smoothed bin averaged data') |
48 |
gforget |
1.3 |
|
49 |
|
|
%%%%%%%% rotated diffusion %%%%%%%% |
50 |
|
|
|
51 |
|
|
%choose smoothing scale: here 3 X grid spacing |
52 |
|
|
if myenv.verbose>0; |
53 |
gforget |
1.7 |
gcmfaces_msg('** set anisotropic and rotated smoothing'); |
54 |
gforget |
1.3 |
end; |
55 |
|
|
distLarge=3*sqrt(mygrid.RAC); distSmall=1*sqrt(mygrid.RAC); |
56 |
|
|
fldRef=mygrid.YC; |
57 |
|
|
|
58 |
|
|
%do the smoothing: |
59 |
|
|
if myenv.verbose>0; |
60 |
|
|
gcmfaces_msg(['* call diffsmoth2Drotated : apply anisotropic smoothing operator ' ... |
61 |
|
|
'that acts preferentially along contours of a reference field (here latitude).']); |
62 |
|
|
end; |
63 |
gforget |
1.6 |
fld_smooth2=diffsmooth2Drotated(fld,distLarge,distSmall,mygrid.YC); |
64 |
gforget |
1.3 |
|
65 |
|
|
%display results: |
66 |
|
|
if myenv.verbose>0; |
67 |
gforget |
1.7 |
gcmfaces_msg('* display results on sphere'); |
68 |
gforget |
1.3 |
end; |
69 |
|
|
|
70 |
gforget |
1.8 |
figureL; set(gca,'FontSize',16); |
71 |
|
|
gcmfaces_sphere(fld_smooth2); caxis([-1 1]*0.4); colorbar; |
72 |
|
|
title('anisotropic smoother result') |
73 |
gforget |
1.3 |
|
74 |
|
|
|
75 |
gforget |
1.7 |
if myenv.verbose>0; |
76 |
|
|
gcmfaces_msg('*** leaving example_smooth'); |
77 |
|
|
gcmfaces_msg('==============================================='); |
78 |
|
|
end; |
79 |
|
|
|