/[MITgcm]/MITgcm_contrib/gael/matlab_class/sample_processing/example_bin_average.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/sample_processing/example_bin_average.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.14 - (hide annotations) (download)
Fri Mar 20 15:41:43 2015 UTC (10 years, 4 months ago) by gforget
Branch: MAIN
Changes since 1.13: +5 -14 lines
- remove deprecated choiceGrid (or choiceV3orV4) switches and arguments

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

  ViewVC Help
Powered by ViewVC 1.1.22