source: trunk/src/affiche_eofpc_3Drev.m @ 327

Last change on this file since 327 was 327, checked in by pinsard, 13 years ago

change svn properties

  • Property svn:keywords set to URL
File size: 5.0 KB
Line 
1function [EOF2D,PC,varargout]=affiche_eofpc_3Drev(mat_3D,date, lon,lat,anomalies,mask,titre_fig,ydir,fac)
2
3%+
4%
5% .. _affiche_eofpc_3Drev.m:
6%
7% =====================
8% affiche_eofpc_3Drev.m
9% =====================
10%
11% matrice 3D de la forme (lon,lat,date)
12% dates de la taille size(mat_3D,3)
13% lon, lat, matrices de la taille [size(mat_3D,1),size(mat_3D,2)]
14% anomalies : booleen a mettre a true si on travaille sur des champs d''anomalies
15% EOF faits sur le temps, PC 2D
16% Affichage sur 1 seule page : mean mat_3D, EOF 1-3 et PC 1-3
17% Output: EOF et PC; Output optionnel: pc_var_exp si spécifié 
18%
19% EVOLUTIONS
20% ==========
21%
22% $Id: affiche_eofpc_3Drev.m 325 2011-08-04 15:30:01Z pinsard $
23%
24% $URL$
25%
26% - fplod 20110124T154434Z aedon.locean-ipsl.upmc.fr (Darwin)
27%
28%   * add minimal rest header
29%
30%-
31
32sx=size(mat_3D,1);
33sy=size(mat_3D,2);
34 
35 if(nargin<3)
36     lon=1:sy;
37end
38 if(nargin<4)
39     lat=1:sx;
40end
41 if(nargin<5)
42  anomalies=false;
43end
44 if(nargin<6)
45     mask=ones(sx,sy);
46end
47 if(nargin<7)
48     titre_fig='';
49end
50 if(nargin<8)
51     ydir='normal';
52end
53 if(nargin<9)
54     fac=[1 1 1];
55 end
56 
57%preparation de la matrice
58for(i=1:size(mat_3D,3))
59     mat_3D(:,:,i)=mat_3D(:,:,i).*mask;
60end
61mat_2D=reshape(mat_3D,sx*sy,size(mat_3D,3));
62
63mat_2D=mat_2D';%'
64
65%elimination des points tq pour tout t mat_2D =NaN
66mean_m2D=meanNaN(mat_2D,1);
67mat_2D_ssnan=mat_2D(:,~isnan(mean_m2D));
68clear mat_2D
69%elimination des dates tq 1er ou dernier element de matrice = NaN
70iidata=find(~isnan(mat_2D_ssnan(:,1)) & ~isnan(mat_2D_ssnan(:,end)));
71mat_2D_ssnan=mat_2D_ssnan(iidata,:);
72date=date(iidata);
73
74%soustraction de la moyenne temporelle
75size(mat_2D_ssnan);
76for(i=1:size(mat_2D_ssnan,2))
77     mat_2D_ssnan(:,i)= mat_2D_ssnan(:,i)-meanNaN(mat_2D_ssnan(:,i));
78end
79
80
81[U,S,V] = svd(mat_2D_ssnan',0); %'
82clear mat_2D_ssnan
83std_u=nstd(U,0,1);
84diag_s=diag(S);
85pc_var_exp=(diag_s.^2/sum(diag_s.^2))*100;
86std_v=nstd(V,0,1);
87
88
89for(i=1: 3)
90              PC(:,i)=  V(:,i)/std_v(i)*fac(i);     
91              EOF(:,i)=U(:,i)*std_v(i)*diag_s(i)*fac(i);
92end
93
94%Plot des EOF
95figure_a4p
96
97              hf=subplot(3,2,1);
98              if(anomalies)
99        mat_3D_moy=squeeze(nstd(mat_3D,1,3));
100      else     
101              mat_3D_moy=squeeze(meanNaN(mat_3D,3));
102              end       
103              if(min(size(lon))==1)
104              imagesc(lon,lat,mat_3D_moy)
105              set(gca,'ydir',ydir)
106              hc=colorbar('WestOutside');
107              else
108              num_cont=contourf_CB(lon,lat,mat_3D_moy);
109              set(gca,'ydir',ydir)
110              CB_discrete(num_cont,'WestOutside');
111
112q =input('Changer l''affichage de la matrice moyenne (o/n) ? ', 's');
113if (q=='o')
114              min_coul=input('valeur min : ');
115              max_coul=input('valeur max : ');
116              stp_coul=input('step : ');
117     hf=subplot(3,2,1);       
118num_cont=contourf_CB(lon,lat,mat_3D_moy,[min_coul:stp_coul: max_coul]);
119              set(gca,'ydir',ydir)
120            CB_discrete([min_coul-stp_coul:stp_coul: max_coul+stp_coul],'WestOutside');
121
122end
123
124              end
125
126
127              if(anomalies)
128              title('std of the field')
129              else     
130              title('mean field')
131              end
132              ajoute_date_fig(gcf,3);
133
134
135             
136              for(i=1:3)
137              subplot(3,2,i+1)
138              EOFnan=NaN(sx*sy,1);
139              EOFnan(~isnan(mean_m2D))=EOF(:,i);
140              EOF2D(:,:,i)=reshape(EOFnan,sx,sy);
141             
142              if(min(size(lon))==1)
143
144              imagesc(lon,lat,EOF2D(:,:,i))
145              set(gca,'ydir','normal')
146              if(rem(i,2)==1)
147              hc=colorbar('EastOutside');
148              else
149              hc=colorbar('WestOutside');
150              end
151              else
152              num_cont=contourf_CB(lon,lat,squeeze(EOF2D(:,:,i)));
153              set(gca,'ydir',ydir)
154              if(rem(i,2)==1)
155              CB_discrete(num_cont,'EastOutside');
156              else
157              CB_discrete(num_cont,'WestOutside');
158              end
159              end
160             
161              eval ([' title(''EOF ',num2str(i),': var exp = ', num2str(pc_var_exp(i),2),'%'')'])
162             
163              end
164
165q =input('Changer les parametres de l''affichage (o/n) ? ', 's');
166if (q=='o')
167              min_coul=input('valeur min : ');
168              max_coul=input('valeur max : ');
169              if(min(size(lon))>1)
170              stp_coul=input('step : ');
171              end
172              for(i=1:3)
173              subplot(3,2,i+1)
174              if(min(size(lon))==1)
175
176              imagesc(lon,lat,EOF2D(:,:,i),[min_coul max_coul])
177              set(gca,'ydir',ydir)
178              caxis([min_coul max_coul])
179              if(rem(i,2)==1)
180              hc=colorbar('EastOutside');
181              else
182              hc=colorbar('WestOutside');
183              end
184              else
185              num_cont=contourf_CB(lon,lat,squeeze(EOF2D(:,:,i)),[min_coul:stp_coul: max_coul]);
186              set(gca,'ydir',ydir)
187              if(rem(i,2)==1)
188              CB_discrete([min_coul-stp_coul:stp_coul: max_coul+stp_coul],'EastOutside');
189              else
190              CB_discrete([min_coul-stp_coul:stp_coul: max_coul+stp_coul],'WestOutside');
191              end
192              end
193  eval ([' title(''EOF ',num2str(i),': var exp = ', num2str(pc_var_exp(i),2),'%'')'])
194end       
195
196end
197
198              subplot(3,2,5:6) 
199              %Plot des PC
200             
201              plot(date, PC(:,1),date, PC(:,2),date, PC(:,3))
202hold on
203              plot(date,zeros(size(date)),'k')
204              datetick('x','yyyy')
205              axis([date(1) date(end) -4 4]);
206             
207              legend('PC1','PC2','PC3')
208              title(titre_fig)
209             
210if(nargout==3)
211  pc_var_exp=pc_var_exp(1:3);
212  varargout={pc_var_exp};
213end
Note: See TracBrowser for help on using the repository browser.