/[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.15 - (hide annotations) (download)
Fri Mar 20 23:20:31 2015 UTC (10 years, 4 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.14: +0 -4 lines
- example_bin_average.m : remove old comment
- added : example_remap.m and prep_remap.m

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

  ViewVC Help
Powered by ViewVC 1.1.22