/[MITgcm]/MITgcm_contrib/gael/matlab_class/sample_analysis/example_display.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/sample_analysis/example_display.m

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


Revision 1.5 - (show annotations) (download)
Fri Mar 17 17:45:20 2017 UTC (8 years, 4 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint66f, checkpoint66e, checkpoint66o, HEAD
Changes since 1.4: +17 -3 lines
- example_MITprof.m (new): illustrate use of MITprof data sets
- example_display.m: add face by face display for cube sphere

1 function []=example_display(method);
2 % EXAMPLE_DISPLAY(method) illustrate various options to display 2D fields.
3 %
4 % method (optional) selects the plotting method
5 % 1: plot a gcmfaces object face by face (as in Fig. C1) of doi:10.5194/gmd-8-3071-2015).
6 % 2: use convert2array via qwckplot (a quick but crude display option).
7 % 3: use convert2pcol then pcolor (for a display in lat-lon coordinates).
8 % 4: use the m_map_gcmfaces front end to m_map (https://www.eoas.ubc.ca/~rich/map.html).
9 % 5: use gcmfaces_sphere to display fields on a sphere.
10 % 6: use stretched vertical coordinate.
11 % If method is not specified then it is set to [3:5] by default.
12 %
13 % Example: addpath gcmfaces/sample_analysis/; example_display;
14
15 gcmfaces_global;
16
17 input_list_check('example_display',nargin);
18
19 if isempty(whos('method')); method=[1:5]; end;
20
21 if myenv.verbose>0;
22 gcmfaces_msg('===============================================');
23 gcmfaces_msg(['*** entering example_display: displays a gridded ' ...
24 'field of ocean depth (gcmfaces object) in geographic coordinates ' ...
25 'using pcolor, in various projections (if m_map is in Matlab path), ' ...
26 'and on a sphere.'],'');
27 end;
28
29 %%%%%%%%%%%%%%%%%
30 %load grid:
31 %%%%%%%%%%%%%%%%%
32
33 if isempty(mygrid);
34 grid_load;
35 end;
36 nF=mygrid.nFaces;
37
38 %%%%%%%%%%%
39 %get field:
40 %%%%%%%%%%%
41
42 fld=mygrid.Depth; fld(fld==0)=NaN;
43 cc=[[0:0.05:0.5] [0.6 0.75 1 1.25]]*1e4; myCmap='gray';
44
45 %%%%%%%%%%%%
46 %plot field:
47 %%%%%%%%%%%%
48
49 if sum(ismember(method,1));
50 if myenv.verbose>0; gcmfaces_msg('* gcmfaces format display -- face by face.'); end;
51 if nF==1;
52 figureL; imagescnan(fld{1}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
53 elseif nF==5;
54 figureL;
55 subplot(3,3,7); imagescnan(fld{1}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
56 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'1','FontSize',32,'Color','r','Rotation',0);
57 subplot(3,3,8); imagescnan(fld{2}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
58 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'2','FontSize',32,'Color','r','Rotation',0);
59 subplot(3,3,5); imagescnan(fld{3}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
60 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'3','FontSize',32,'Color','r','Rotation',0);
61 subplot(3,3,6); imagescnan(fld{4}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
62 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'4','FontSize',32,'Color','r','Rotation',0);
63 subplot(3,3,3); imagescnan(fld{5}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
64 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'5','FontSize',32,'Color','r','Rotation',0);
65 elseif nF==6;
66 figureL;
67 subplot(3,4,9); imagescnan(fld{1}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
68 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'1','FontSize',32,'Color','r','Rotation',0);
69 subplot(3,4,10); imagescnan(fld{2}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
70 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'2','FontSize',32,'Color','r','Rotation',0);
71 subplot(3,4,6); imagescnan(fld{3}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
72 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'3','FontSize',32,'Color','r','Rotation',0);
73 subplot(3,4,7); imagescnan(fld{4}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
74 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'4','FontSize',32,'Color','r','Rotation',0);
75 subplot(3,4,3); imagescnan(fld{5}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
76 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'5','FontSize',32,'Color','r','Rotation',0);
77 subplot(3,4,4); imagescnan(fld{6}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
78 tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'6','FontSize',32,'Color','r','Rotation',0);
79 else;
80 error('face by face plot not yet implemented for this grid');
81 end;
82 title('display face by face');
83 end;
84
85 if sum(ismember(method,2));
86 if myenv.verbose>0; gcmfaces_msg('* array format display -- all faces concatenated.'); end;
87 figureL; qwckplot(fld); cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); %delete(cb);
88 title('display using qwckplot');
89 for ff=1:mygrid.nFaces;
90 tmp0=0*mygrid.XC;
91 tmp1=round(size(tmp0{ff})/2);
92 tmp0{ff}(tmp1(1),tmp1(2))=1;
93 tmp0=convert2array(tmp0); [ii,jj]=find(tmp0==1);
94 if ff==3; ang=90; elseif ff>3; ang=-90; else; ang=0; end;
95 hold on; text(ii,jj,num2str(ff),'FontSize',32,'Color','r','Rotation',ang);
96 end;
97 end;
98
99 if sum(ismember(method,3));
100 if myenv.verbose>0; gcmfaces_msg('* geographical display -- using pcolor directly.'); end;
101 figureL;
102 [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld); pcolor(X,Y,FLD);
103 if ~isempty(find(X>359)); axis([0 360 -90 90]); else; axis([-180 180 -90 90]); end;
104 shading flat; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
105 xlabel('longitude'); ylabel('latitude');
106 title('display using convert2pcol');
107 end;
108
109 if sum(ismember(method,4));
110 if myenv.verbose>0; gcmfaces_msg('* geographical display -- using m_map_gcmfaces.'); end;
111 if ~isempty(which('m_proj'));
112 figureL; m_map_gcmfaces(fld,0,{'myCaxis',cc},{'myCmap',myCmap});
113 aa=get(gcf,'Children'); axes(aa(4));
114 title('display using m_map_gcmfaces','Interpreter','none');
115 elseif myenv.verbose;
116 fprintf(' > To use m_map_gcmfaces, please add m_map to your Matlab path\n');
117 end;
118 end;
119
120 if sum(ismember(method,5));
121 if myenv.verbose>0; gcmfaces_msg('* geographical display -- on a sphere.'); end;
122 figureL; gcmfaces_sphere(fld,cc,[],'N',3);
123 title('display using gcmfaces_sphere','Interpreter','none');
124 end;
125
126 %test case for depthStretchPlot:
127 if sum(ismember(method,6));
128 if myenv.verbose>0; gcmfaces_msg('* section display -- using strecthed vertical coord.'); end;
129 x=ones(length(mygrid.RC),1)*[1:200]; z=mygrid.RC*ones(1,200); c=sin(z/2000*pi).*cos(x/50*pi);
130 figureL;
131 subplot(1,2,1); set(gca,'FontSize',16);
132 pcolor(x,z,c); shading flat; title('standard depth display');
133 subplot(1,2,2); set(gca,'FontSize',16);
134 depthStretchPlot('pcolor',{x,z,c}); shading flat;
135 title('stretched depth display');
136 end;
137
138 if myenv.verbose>0;
139 gcmfaces_msg('*** leaving example_display');
140 gcmfaces_msg('===============================================');
141 end;
142

  ViewVC Help
Powered by ViewVC 1.1.22