1 |
gforget |
1.8 |
function []=example_bin_average(choiceV3orV4,doSmooth); |
2 |
|
|
%object: a bin average example within gcmfaces |
3 |
|
|
%inputs: choiceV3orV4 ('v3' or 'v4') selects the sample GRID |
4 |
|
|
% doSmooth; if set to 1, follow on with smoothing example |
5 |
gforget |
1.1 |
|
6 |
|
|
%%%%%%%%%%%%%%%%% |
7 |
|
|
%load parameters: |
8 |
|
|
%%%%%%%%%%%%%%%%% |
9 |
|
|
|
10 |
gforget |
1.10 |
gcmfaces_global; |
11 |
|
|
dir0=[myenv.gcmfaces_dir '/sample_input/']; |
12 |
gforget |
1.8 |
dirGrid=[dir0 '/GRID' choiceV3orV4 '/']; |
13 |
|
|
dirIn=[dir0 '/SAMPLE' choiceV3orV4 '/']; |
14 |
gforget |
1.10 |
if strcmp(choiceV3orV4,'v4'); |
15 |
|
|
nF=5; fileFormat='compact'; |
16 |
|
|
else; |
17 |
|
|
nF=1; fileFormat='straight'; |
18 |
|
|
end; |
19 |
|
|
grid_load(dirGrid,nF,fileFormat); |
20 |
gforget |
1.1 |
|
21 |
gforget |
1.11 |
gcmfaces_global; |
22 |
|
|
if myenv.verbose>0; |
23 |
|
|
gcmfaces_msg('==============================================='); |
24 |
|
|
% gcmfaces_msg('*** entering example_bin_average that will define',''); |
25 |
|
|
% gcmfaces_msg('randomly distributed variable (position and value),',' '); |
26 |
|
|
% gcmfaces_msg('then bin average it to the chosen grid,',' '); |
27 |
|
|
% gcmfaces_msg('and apply a smoothing filter to it',' '); |
28 |
|
|
gcmfaces_msg(['*** entering example_bin_average that will first define ' ... |
29 |
|
|
'randomly distributed variable (position and value), ' ... |
30 |
|
|
'then bin average it to the chosen grid, ' ... |
31 |
|
|
'and finally apply a smoothing filter to it '],''); |
32 |
gforget |
1.8 |
end; |
33 |
gforget |
1.1 |
|
34 |
gforget |
1.11 |
warning('off','MATLAB:dsearch:DeprecatedFunction'); |
35 |
|
|
warning('off','MATLAB:delaunay:DuplicateDataPoints'); |
36 |
gforget |
1.1 |
|
37 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
38 |
|
|
%generate random data |
39 |
|
|
|
40 |
gforget |
1.11 |
if myenv.verbose>0; |
41 |
|
|
gcmfaces_msg('* generate random data'); |
42 |
|
|
end; |
43 |
gforget |
1.1 |
nobs=1e6; |
44 |
|
|
lat=(rand(nobs,1)-0.5)*2*90; |
45 |
gforget |
1.11 |
lon=(rand(nobs,1)-0.5)*2*180; |
46 |
|
|
%needed for 0-360 longitude convention |
47 |
|
|
if mygrid.nFaces==1; |
48 |
|
|
xx=find(lon<0);lon(xx)=lon(xx)+360; |
49 |
|
|
end; |
50 |
|
|
obsPts=(rand(nobs,1)-0.5)*2; |
51 |
|
|
|
52 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
53 |
|
|
%generate delaunay triangulation |
54 |
|
|
|
55 |
|
|
if myenv.verbose>0; |
56 |
|
|
gcmfaces_msg('* call gcmfaces_bindata : generate delaunay triangulation'); |
57 |
|
|
end; |
58 |
|
|
gcmfaces_bindata; |
59 |
gforget |
1.1 |
|
60 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%% |
61 |
|
|
%bin average random data |
62 |
|
|
|
63 |
gforget |
1.11 |
if myenv.verbose>0; |
64 |
|
|
gcmfaces_msg('* call gcmfaces_bindata : bin average data'); |
65 |
|
|
end; |
66 |
|
|
obsMap=gcmfaces_bindata(lon,lat,obsPts); |
67 |
|
|
|
68 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%% |
69 |
|
|
%format conversions |
70 |
|
|
if myenv.verbose>0; |
71 |
|
|
gcmfaces_msg('* call convert2array : convert from gcmfaces to array format'); |
72 |
|
|
end; |
73 |
|
|
obsArray=convert2array(obsMap);%put in gcmfaces format |
74 |
|
|
if myenv.verbose>0; |
75 |
|
|
gcmfaces_msg('* call convert2array : convert back to gcmfaces'); |
76 |
|
|
end; |
77 |
|
|
obsMap2=convert2array(obsArray);%put in gcmfaces format |
78 |
|
|
if myenv.verbose>0; |
79 |
|
|
gcmfaces_msg('* call convert2gcmfaces : convert from gcmfaces to file format'); |
80 |
|
|
end; |
81 |
|
|
obsOut=convert2gcmfaces(obsMap); %put in gcm input format |
82 |
|
|
if myenv.verbose>0; |
83 |
|
|
gcmfaces_msg('* summarizing data formats:'); |
84 |
|
|
aa=whos('obs*'); |
85 |
|
|
aaa=aa(4); bb=['[' num2str(aaa.size(1)) 'x' num2str(aaa.size(2)) ']']; |
86 |
|
|
bb=fprintf(' %8s %8s %12s : data points (vector)\n',aaa.name,aaa.class,bb); |
87 |
|
|
aaa=aa(2); bb=['[' num2str(aaa.size(1)) 'x' num2str(aaa.size(2)) ']']; |
88 |
|
|
bb=fprintf(' %8s %8s %12s : gridded data (gcmfaces)\n',aaa.name,aaa.class,bb); |
89 |
|
|
aaa=aa(1); bb=['[' num2str(aaa.size(1)) 'x' num2str(aaa.size(2)) ']']; |
90 |
|
|
bb=fprintf(' %8s %8s %12s : array format\n',aaa.name,aaa.class,bb); |
91 |
|
|
aaa=aa(3); bb=['[' num2str(aaa.size(1)) 'x' num2str(aaa.size(2)) ']']; |
92 |
|
|
bb=fprintf(' %8s %8s %12s : output format\n',aaa.name,aaa.class,bb); |
93 |
|
|
end; |
94 |
|
|
|
95 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
96 |
|
|
%quick display |
97 |
|
|
if myenv.verbose>0; |
98 |
|
|
gcmfaces_msg('* crude display of results in array format'); |
99 |
|
|
end; |
100 |
|
|
figure; imagescnan(obsArray','nancolor',[1 1 1]*0.8); axis xy; caxis([-1 1]*0.4); colorbar; |
101 |
|
|
title('bin averaged data'); |
102 |
gforget |
1.1 |
|
103 |
gforget |
1.8 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
104 |
|
|
%now illustrate the smoothing filter |
105 |
gforget |
1.11 |
if myenv.verbose>0; |
106 |
|
|
gcmfaces_msg('* entering example_smooth : apply smoother to gridded data'); |
107 |
|
|
end; |
108 |
gforget |
1.8 |
if doSmooth; example_smooth; end; |
109 |
gforget |
1.11 |
if myenv.verbose>0; |
110 |
|
|
gcmfaces_msg('* leaving example_smooth'); |
111 |
|
|
end; |
112 |
|
|
|
113 |
|
|
if myenv.verbose>0; |
114 |
|
|
gcmfaces_msg('*** leaving example_bin_average'); |
115 |
|
|
gcmfaces_msg('==============================================='); |
116 |
|
|
end; |
117 |
|
|
|
118 |
|
|
|
119 |
gforget |
1.1 |
|
120 |
|
|
|