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