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

Annotation of /MITgcm_contrib/gael/matlab_class/sample_analysis/plot_one_field.m

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


Revision 1.16 - (hide annotations) (download)
Fri Mar 20 15:41:27 2015 UTC (11 years, 7 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.15: +24 -27 lines
- remove deprecated choiceGrid (or choiceV3orV4) switches and arguments

1 gforget 1.16 function []=plot_one_field(plotMethod);
2 gforget 1.9 %object: illustrate several methods to plot fields within gcmfaces.
3 gforget 1.16 %inputs: plotMethod selects the plotting method
4 gforget 1.9 % 0) all, one after the other
5     % 1) plot a gcmfaces object face by face
6     % 2) use convert2array then plot in array coordinates.
7     % 3) use convert2pcol then plot in lat-lon coordinates.
8 gforget 1.16 % 4) use m_map_gcmfaces front end to m_map.
9     % 5) use gcmfaces_sphere.
10     % 6) use stretched vertical coordinate.
11 gforget 1.9
12     input_list_check('plot_one_field',nargin);
13 gforget 1.1
14 gforget 1.16 if isempty(whos('plotMethod')); plotMethod=0; end;
15    
16 gforget 1.13 gcmfaces_global;
17     if myenv.verbose>0;
18     gcmfaces_msg('===============================================');
19 gforget 1.16 gcmfaces_msg(['*** entering plot_one_field that displays ' ...
20     'a gridded field of ocean depth, first ' ...
21 gforget 1.13 'in gcmfaces and array formats. Then in geographic coordinates ' ...
22     'using pcolor and in various projections using m_map (if avail. in path). '],'');
23     end;
24    
25 gforget 1.1 %%%%%%%%%%%%%%%%%
26     %load parameters:
27     %%%%%%%%%%%%%%%%%
28 gforget 1.14
29     gcmfaces_global;
30 gforget 1.15 myenv.nctiles=1;
31 gforget 1.16
32     %load grid:
33     nF=5;
34     fileFormat='compact';
35     dirGrid=fullfile([myenv.gcmfaces_dir '../']);
36     dirGrid=fullfile(dirGrid,'GRID/');
37 gforget 1.14
38     mygrid=[]; grid_load(dirGrid,nF,fileFormat,1);
39 gforget 1.1
40     %%%%%%%%%%%
41     %get field:
42     %%%%%%%%%%%
43 gforget 1.14
44     fld=mygrid.Depth; fld(fld==0)=NaN;
45     cc=[[0:0.05:0.5] [0.6 0.75 1 1.25]]*1e4; myCmap='gray';
46 gforget 1.9
47 gforget 1.1 %%%%%%%%%%%%
48     %plot field:
49     %%%%%%%%%%%%
50 gforget 1.9
51     if plotMethod==0|plotMethod==1;
52 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* gcmfaces format display -- face by face.'); end;
53 gforget 1.9 if nF==1;
54 gforget 1.15 figureL; imagescnan(fld{1}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
55 gforget 1.9 elseif nF==5;
56 gforget 1.15 figureL;
57 gforget 1.12 subplot(3,3,7); imagescnan(fld{1}','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,'1','FontSize',32,'Color','r','Rotation',0);
59     subplot(3,3,8); imagescnan(fld{2}','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,'2','FontSize',32,'Color','r','Rotation',0);
61     subplot(3,3,5); imagescnan(fld{3}','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,'3','FontSize',32,'Color','r','Rotation',0);
63     subplot(3,3,6); imagescnan(fld{4}','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,'4','FontSize',32,'Color','r','Rotation',0);
65     subplot(3,3,3); imagescnan(fld{5}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
66     tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'5','FontSize',32,'Color','r','Rotation',0);
67 gforget 1.9 elseif nF==6;
68     error('face by face plot for cude : not yet implemented');
69     end;
70     end;
71    
72     if plotMethod==0|plotMethod==2;
73 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* array format display -- all faces concatenated somehow.'); end;
74 gforget 1.15 figureL;
75 gforget 1.9 FLD=convert2array(fld);
76 gforget 1.16 imagescnan(FLD','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); %delete(cb);
77     for ff=1:mygrid.nFaces;
78 gforget 1.12 tmp0=0*mygrid.XC;
79 gforget 1.16 tmp1=round(size(tmp0{ff})/2);
80     tmp0{ff}(tmp1(1),tmp1(2))=1;
81 gforget 1.12 tmp0=convert2array(tmp0); [ii,jj]=find(tmp0==1);
82     if ff==3; ang=90; elseif ff>3; ang=-90; else; ang=0; end;
83     hold on; text(ii,jj,num2str(ff),'FontSize',32,'Color','r','Rotation',ang);
84     end;
85 gforget 1.9 end;
86    
87     if plotMethod==0|plotMethod==3;
88 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* geographical display -- using pcolor.'); end;
89 gforget 1.15 figureL;
90 gforget 1.9 [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld); pcolor(X,Y,FLD);
91     if ~isempty(find(X>359)); axis([0 360 -90 90]); else; axis([-180 180 -90 90]); end;
92 gforget 1.12 shading flat; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb); xlabel('longitude'); ylabel('latitude');
93 gforget 1.2 end;
94 gforget 1.1
95 gforget 1.9 if plotMethod==0|plotMethod==4;
96 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* geographical display -- using m_map.'); end;
97 gforget 1.9 if ~isempty(which('m_proj'));
98 gforget 1.15 figureL; m_map_gcmfaces(fld,0,{'myCaxis',cc},{'myCmap',myCmap});
99 gforget 1.12 elseif myenv.verbose;
100 gforget 1.9 fprintf('if you want to use m_map_gcmfaces, you will need to have m_map in your path\n');
101     end;
102     end;
103    
104 gforget 1.14 if plotMethod==0|plotMethod==5;
105     if myenv.verbose>0; gcmfaces_msg('* geographical display -- on a sphere.'); end;
106     gcmfaces_sphere(fld,cc,[],'N',3);
107     end;
108    
109 gforget 1.11 %test case for depthStretchPlot:
110 gforget 1.14 if plotMethod==0|plotMethod==6;
111 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* section display -- using strecthed vertical coord.'); end;
112 gforget 1.12 x=ones(length(mygrid.RC),1)*[1:200]; z=mygrid.RC*ones(1,200); c=sin(z/2000*pi).*cos(x/50*pi);
113 gforget 1.16 figureL;
114     subplot(1,2,1); set(gca,'FontSize',16);
115     pcolor(x,z,c); shading flat; title('standard depth display');
116     subplot(1,2,2); set(gca,'FontSize',16);
117     depthStretchPlot('pcolor',{x,z,c}); shading flat; title('stretched depth display');
118 gforget 1.11 end;
119    
120 gforget 1.13 if myenv.verbose>0;
121     gcmfaces_msg('*** leaving plot_one_field');
122     gcmfaces_msg('===============================================');
123     end;
124 gforget 1.9

  ViewVC Help
Powered by ViewVC 1.1.22