1 | %+ |
---|
2 | % .. _essailai.m: |
---|
3 | % |
---|
4 | % ========== |
---|
5 | % essailai.m |
---|
6 | % ========== |
---|
7 | % |
---|
8 | % DESCRIPTION |
---|
9 | % =========== |
---|
10 | % |
---|
11 | % read LAI file :file:`${PROJECT_ID}/LAI/laisen{yyyy}_float.txt`. |
---|
12 | % |
---|
13 | % plot maps of LAI for every dates on figures (4 days/page) if matlab is |
---|
14 | % running (sorry for octave users : griddata is not ok either in 3.0.2 or |
---|
15 | % 3.3.52) |
---|
16 | % |
---|
17 | % compute sum, std, moy |
---|
18 | % |
---|
19 | % plot sum, std, moy |
---|
20 | % Figures are saved in :file:`${PROJECT_OD}/essailai_sum.ps`, |
---|
21 | % :file:`${PROJECT_OD}/essailai_mean.ps` and |
---|
22 | % :file:`${PROJECT_OD}/essailai_stddev.ps`. |
---|
23 | % |
---|
24 | % save sum, std, moy for each date in file :file:`${PROJECT_OD}/essailai.txt` |
---|
25 | % |
---|
26 | % EXAMPLES |
---|
27 | % ======== |
---|
28 | % |
---|
29 | % :: |
---|
30 | % |
---|
31 | % $ octave |
---|
32 | % octave> varamma_startup |
---|
33 | % octave> more off |
---|
34 | % octave> essailai |
---|
35 | % |
---|
36 | % |
---|
37 | % CAUTIONS |
---|
38 | % ======== |
---|
39 | % |
---|
40 | % If matlab is running, Statistical Toolbox is needed because of |
---|
41 | % usage of :func:`nanmean`, :func:`nansum` and :func:`nanstd`. |
---|
42 | % |
---|
43 | % SEE ALSO |
---|
44 | % ======== |
---|
45 | % |
---|
46 | % :ref:`guide data LAI <data_lai>` |
---|
47 | % |
---|
48 | % :func:`varamma_startup` |
---|
49 | % |
---|
50 | % :func:`read_lai_2d` |
---|
51 | % :func:`showgrid` |
---|
52 | % |
---|
53 | % :func:`nanmean` |
---|
54 | % :func:`nanstd` |
---|
55 | % :func:`nansum` |
---|
56 | % |
---|
57 | % TODO |
---|
58 | % ==== |
---|
59 | % |
---|
60 | % transform into a function with yyyy as parameter |
---|
61 | % |
---|
62 | % fixer les bornes lat, long (axes) et lai (z) pour pouvoir comparer |
---|
63 | % les images de lai=f(lat,long) dans le temps |
---|
64 | % |
---|
65 | % utilisation de datetick avec octave > 3.0.2 et matlab |
---|
66 | % |
---|
67 | % compute sum, mean and std within box |
---|
68 | % |
---|
69 | % evaluation of interpolation quality of griddata |
---|
70 | % may be usage of other method than linear |
---|
71 | % |
---|
72 | % IO error |
---|
73 | % |
---|
74 | % EVOLUTIONS |
---|
75 | % ========== |
---|
76 | % |
---|
77 | % $Id$ |
---|
78 | % |
---|
79 | % $URL$ |
---|
80 | % |
---|
81 | % - fplod 20101213T114841Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
82 | % |
---|
83 | % * save data (sum, mean, stddev) in ASCII format |
---|
84 | % * save figures |
---|
85 | % * add year in titles |
---|
86 | % |
---|
87 | % - fplod 20101208T095815Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
88 | % |
---|
89 | % * restruction because of griddata problem running octave |
---|
90 | % |
---|
91 | % * 4 plots/page |
---|
92 | % |
---|
93 | % * explicit types |
---|
94 | % |
---|
95 | % * usage of :func:`griddata` |
---|
96 | % thanks to "Using MESHGRID and GRIDDATA to Fit Vector Data and Plot |
---|
97 | % Unevenly Spaced Data" |
---|
98 | % http://www.mathworks.com/support/tech-notes/1200/1212.html |
---|
99 | % |
---|
100 | % * add info of Matlab Statiscal tool box (see |
---|
101 | % |
---|
102 | % - fplod 20101206T112730Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
103 | % |
---|
104 | % * usage of read_lai_2d |
---|
105 | % |
---|
106 | % - fplod 20100923T144224Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
107 | % |
---|
108 | % * replace simul_lai by simul_lai_2d |
---|
109 | % * replace read_lai by read_lai_2d |
---|
110 | % * add call to showgrid_lai |
---|
111 | % |
---|
112 | % - fplod 20100830T160653Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
113 | % |
---|
114 | % * add argument to simul_lai call |
---|
115 | % * replace nb_date with nb_datestr |
---|
116 | % |
---|
117 | % - fplod 20100824T143715Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
118 | % |
---|
119 | % * add header |
---|
120 | % * correction for reading LAI ASCII files |
---|
121 | % Aim is to have arrays doy(nb_doys), lat(nb_lat), lon(nb_lon) lai(nb_doy,nb_lat,nb_lon) |
---|
122 | % thanks to http://web.cecs.pdx.edu/~gerry/MATLAB/plotting/examples/readColData.m |
---|
123 | % and http://enacit1.epfl.ch/cours_matlab/mfiles.html#entrees_sorties |
---|
124 | % |
---|
125 | % * make work running matlab : change ! operator to ~, replace " by ', endwhile by while |
---|
126 | % |
---|
127 | % * improve indentation (including comments) |
---|
128 | % |
---|
129 | % - soclod 20100822 |
---|
130 | % |
---|
131 | % * draft |
---|
132 | %- |
---|
133 | % |
---|
134 | global application; |
---|
135 | global application_version; |
---|
136 | global PROJECT_OD; |
---|
137 | % |
---|
138 | % default yyyy |
---|
139 | yyyy=int16(2001); |
---|
140 | yyyy_d=double(yyyy); |
---|
141 | % |
---|
142 | [lon_value, lat_value, datestr_value, lai_value]=read_lai_2d(yyyy); |
---|
143 | % |
---|
144 | % uncommment following lines to use simulated data |
---|
145 | %index_simulation=int8(1); |
---|
146 | %[lon_value, lat_value, datestr_value, lai_value]=simul_lai_2d(index_simulation); |
---|
147 | % |
---|
148 | % initialise les longitudes et les latitudes |
---|
149 | lonmax=15.929; |
---|
150 | lonmin=15.921; |
---|
151 | latmax=-13.402; |
---|
152 | latmin=-10.455; |
---|
153 | % ++ forcage au domaine initial |
---|
154 | lonmax=max(lon_value); |
---|
155 | lonmin=min(lon_value); |
---|
156 | latmax=max(lat_value); |
---|
157 | latmin=min(lat_value); |
---|
158 | % |
---|
159 | % initialisation du nb de pas en latitude et longitude |
---|
160 | lonres=10; |
---|
161 | latres=10; |
---|
162 | % |
---|
163 | % Define the range and spacing of the x- and y-coordinates, |
---|
164 | % and then fit them into X and Y |
---|
165 | xv = linspace(lonmin, lonmax, lonres); |
---|
166 | yv = linspace(latmin, latmax, lonres); |
---|
167 | [xinterp,yinterp] = meshgrid(xv,yv); |
---|
168 | clear xv |
---|
169 | clear yv |
---|
170 | % |
---|
171 | % initialise le tableau LAI et des tableau associés |
---|
172 | % tracé de la grille lat-lon |
---|
173 | % mode='line' |
---|
174 | % ++ ok result=showgrid_lai(lon_value, lat_value, mode); |
---|
175 | % |
---|
176 | nb_datestr=size(datestr_value,1); |
---|
177 | % |
---|
178 | ifigure=0; |
---|
179 | % |
---|
180 | switch application |
---|
181 | case {'matlab'} |
---|
182 | % plot lai_value=f(lat,long) for each day of year |
---|
183 | % definition du nb de subplots par page |
---|
184 | nb_column_page=2; |
---|
185 | nb_line_page=2; |
---|
186 | nb_subplot=nb_column_page * nb_line_page; |
---|
187 | % |
---|
188 | % loop on every date |
---|
189 | index_subplot=1; |
---|
190 | for index_datestr=1:nb_datestr |
---|
191 | z=squeeze(lai_value(:,index_datestr)); |
---|
192 | % test if not only NaN for this day of year |
---|
193 | if ( isnan(z) ) |
---|
194 | disp(['no data for ' datestr_value(index_datestr,:) ]); |
---|
195 | else |
---|
196 | disp(['data for ' datestr_value(index_datestr,:) ]); |
---|
197 | % début de figure si index_subplot = 1 |
---|
198 | if (index_subplot == 1) |
---|
199 | ifigure=ifigure+1; |
---|
200 | figure(ifigure); |
---|
201 | end |
---|
202 | subplot(nb_line_page,nb_column_page,index_subplot); |
---|
203 | % Calculate Z in the X-Y interpolation space, which is an |
---|
204 | % evenly spaced grid: |
---|
205 | method='linear'; |
---|
206 | zinterp = griddata(lon_value, lat_value, z, xinterp, yinterp, method); |
---|
207 | %mesh(xinterp,yinterp,zinterp) |
---|
208 | contourf(xinterp,yinterp,zinterp) |
---|
209 | xlabel('longitude'); |
---|
210 | ylabel('latitude'); |
---|
211 | title(['LAI ' datestr_value(index_datestr,:)]); |
---|
212 | %++colormap(cool(8)) |
---|
213 | colorbar('WestOutside'); |
---|
214 | % préparation subplot suivant : si index_subplot = nb_subplot, |
---|
215 | % remise à 1 de compteur de subplots |
---|
216 | if (index_subplot == nb_subplot ) |
---|
217 | index_subplot=1; |
---|
218 | else |
---|
219 | index_subplot=index_subplot+1; |
---|
220 | end |
---|
221 | end |
---|
222 | % clear z |
---|
223 | % clear zinterp |
---|
224 | end |
---|
225 | case {'octave'} |
---|
226 | disp([mfilename ' pb with griddata with octave < 3.3.52']); |
---|
227 | otherwise |
---|
228 | error('unknown application running'); |
---|
229 | end |
---|
230 | % |
---|
231 | % calcul de la somme, de la moyenne et de l'écart-type des LAI |
---|
232 | % pour chaque date sur toute la zone géographique |
---|
233 | som=zeros(nb_datestr,1); |
---|
234 | som(:)=NaN; |
---|
235 | moy=zeros(nb_datestr,1); |
---|
236 | moy(:)=NaN; |
---|
237 | ecartyp=zeros(nb_datestr,1); |
---|
238 | ecartyp(:)=NaN; |
---|
239 | % |
---|
240 | for index_datestr=1:nb_datestr |
---|
241 | som(index_datestr)=nansum(nansum(lai_value(:,index_datestr))); |
---|
242 | moy(index_datestr)=nanmean(nanmean(lai_value(:,index_datestr))); |
---|
243 | ecartyp(index_datestr)=nanstd(nanstd(lai_value(:,index_datestr))); |
---|
244 | disp(['index_datestr som moy std ', num2str(index_datestr), ' ', num2str(som(index_datestr)), ' ', num2str(moy(index_datestr)), ' ', num2str(ecartyp(index_datestr))]); |
---|
245 | end |
---|
246 | |
---|
247 | % initialise les jours (les valeurs de x, les valeurs de y étant les sommes, les moyennes, |
---|
248 | % les ecart type calculées |
---|
249 | startdate=datenum(yyyy_d,1,1); |
---|
250 | enddate=datenum(yyyy_d,12,eomday(yyyy_d,12)); |
---|
251 | xdata=zeros(nb_datestr,1); |
---|
252 | xdata(:)=NaN; |
---|
253 | for index_datestr=1:nb_datestr |
---|
254 | xdata(index_datestr)=datenum(datestr_value(index_datestr,:),'yyyymmdd'); |
---|
255 | end |
---|
256 | xticklabel=datestr(xdata,'yyyymmdd'); |
---|
257 | |
---|
258 | % dessin de l'évolution de la somme des LAI |
---|
259 | ifigure=ifigure+1; |
---|
260 | figure(ifigure); |
---|
261 | plot(xdata,som,'o'); |
---|
262 | set(gca,'XTickLabel',xticklabel) |
---|
263 | xlabel('date') |
---|
264 | ylabel('sum LAI 8d'); |
---|
265 | title(['sum LAI 8d of the year ', num2str(yyyy)]); |
---|
266 | % |
---|
267 | % save figure |
---|
268 | printer='ps'; |
---|
269 | print_printer=['-d', printer]; |
---|
270 | fullfilename=[PROJECT_OD, mfilename, '_sum.', printer]; |
---|
271 | clear printer; |
---|
272 | print(print_printer,fullfilename); |
---|
273 | clear print_printer; |
---|
274 | clear fullfilename; |
---|
275 | % |
---|
276 | % dessin de l'évolution de la moyenne des LAI |
---|
277 | ifigure=ifigure+1; |
---|
278 | figure(ifigure); |
---|
279 | plot(xdata,moy,'o'); |
---|
280 | set(gca,'XTick',xdata) |
---|
281 | set(gca,'XTickLabel',xticklabel) |
---|
282 | xlabel('date') |
---|
283 | ylabel('mean LAI 8d'); |
---|
284 | title(['mean LAI 8d of the year ', num2str(yyyy)]); |
---|
285 | % |
---|
286 | % save figure |
---|
287 | printer='ps'; |
---|
288 | print_printer=['-d', printer]; |
---|
289 | fullfilename=[PROJECT_OD, mfilename, '_mean.', printer]; |
---|
290 | clear printer; |
---|
291 | print(print_printer,fullfilename); |
---|
292 | clear print_printer; |
---|
293 | clear fullfilename; |
---|
294 | % |
---|
295 | % dessin de l'évolution des écart-types des LAI |
---|
296 | ifigure=ifigure+1; |
---|
297 | figure(ifigure); |
---|
298 | plot(xdata,ecartyp,'o'); |
---|
299 | set(gca,'XTick',xdata) |
---|
300 | set(gca,'XTickLabel',xticklabel) |
---|
301 | xlabel('date') |
---|
302 | ylabel('std LAI 8d'); |
---|
303 | title(['std LAI 8d of the year ', num2str(yyyy)]); |
---|
304 | % save figure |
---|
305 | printer='ps'; |
---|
306 | print_printer=['-d', printer]; |
---|
307 | fullfilename=[PROJECT_OD, mfilename, '_stddev.', printer]; |
---|
308 | clear printer; |
---|
309 | print(print_printer,fullfilename); |
---|
310 | clear print_printer; |
---|
311 | clear fullfilename; |
---|
312 | % |
---|
313 | |
---|
314 | % sauvegarde des infos en ASCII |
---|
315 | fullfilename=[PROJECT_OD, mfilename, '.txt']; |
---|
316 | disp(['iii : ', mfilename ' : ','creation of ', fullfilename]); |
---|
317 | fid=fopen(fullfilename,'w'); |
---|
318 | % écriture en tête |
---|
319 | fprintf(fid,'# %s\n',fullfilename); |
---|
320 | clear fullfilename; |
---|
321 | % écriture data |
---|
322 | fprintf(fid,'# yyyymmdd mean sum stddev\n'); |
---|
323 | for index_datestr=1:nb_datestr |
---|
324 | fprintf(fid,'%s %f %f %f\n', datestr_value(index_datestr,:), moy(index_datestr), som(index_datestr), ecartyp(index_datestr)); |
---|
325 | end |
---|
326 | fclose(fid); |
---|
327 | whos |
---|