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