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