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