source: trunk/src/essailai.m @ 325

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

rehab MSG, EPSAT tools (to be cont.)

  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
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%
134global application;
135global application_version;
136global PROJECT_OD;
137%
138% default yyyy
139yyyy=int16(2001);
140yyyy_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
149lonmax=15.929;
150lonmin=15.921;
151latmax=-13.402;
152latmin=-10.455;
153% ++ forcage au domaine initial
154lonmax=max(lon_value);
155lonmin=min(lon_value);
156latmax=max(lat_value);
157latmin=min(lat_value);
158%
159% initialisation du nb de pas en latitude et longitude
160lonres=10;
161latres=10;
162%
163% Define the range and spacing of the x- and y-coordinates,
164% and then fit them into X and Y
165xv = linspace(lonmin, lonmax, lonres);
166yv = linspace(latmin, latmax, lonres);
167[xinterp,yinterp] = meshgrid(xv,yv);
168clear xv
169clear 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%
176nb_datestr=size(datestr_value,1);
177%
178ifigure=0;
179%
180switch 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');
229end
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
233som=zeros(nb_datestr,1);
234som(:)=NaN;
235moy=zeros(nb_datestr,1);
236moy(:)=NaN;
237ecartyp=zeros(nb_datestr,1);
238ecartyp(:)=NaN;
239%
240for 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))]);
245end
246
247% initialise les jours (les valeurs de x, les valeurs de y étant les sommes, les moyennes,
248% les ecart type calculées
249startdate=datenum(yyyy_d,1,1);
250enddate=datenum(yyyy_d,12,eomday(yyyy_d,12));
251xdata=zeros(nb_datestr,1);
252xdata(:)=NaN;
253for index_datestr=1:nb_datestr
254    xdata(index_datestr)=datenum(datestr_value(index_datestr,:),'yyyymmdd');
255end
256xticklabel=datestr(xdata,'yyyymmdd');
257
258% dessin de l'évolution de la somme des LAI
259ifigure=ifigure+1;
260figure(ifigure);
261plot(xdata,som,'o');
262set(gca,'XTickLabel',xticklabel)
263xlabel('date')
264ylabel('sum LAI 8d');
265title(['sum LAI 8d of the year ', num2str(yyyy)]);
266%
267% save figure
268printer='ps';
269print_printer=['-d', printer];
270fullfilename=[PROJECT_OD, mfilename, '_sum.', printer];
271clear printer;
272print(print_printer,fullfilename);
273clear print_printer;
274clear fullfilename;
275%
276% dessin de l'évolution de la moyenne des LAI
277ifigure=ifigure+1;
278figure(ifigure);
279plot(xdata,moy,'o');
280set(gca,'XTick',xdata)
281set(gca,'XTickLabel',xticklabel)
282xlabel('date')
283ylabel('mean LAI 8d');
284title(['mean LAI 8d of the year ', num2str(yyyy)]);
285%
286% save figure
287printer='ps';
288print_printer=['-d', printer];
289fullfilename=[PROJECT_OD, mfilename, '_mean.', printer];
290clear printer;
291print(print_printer,fullfilename);
292clear print_printer;
293clear fullfilename;
294%
295% dessin de l'évolution des écart-types des LAI
296ifigure=ifigure+1;
297figure(ifigure);
298plot(xdata,ecartyp,'o');
299set(gca,'XTick',xdata)
300set(gca,'XTickLabel',xticklabel)
301xlabel('date')
302ylabel('std LAI 8d');
303title(['std LAI 8d of the year ', num2str(yyyy)]);
304% save figure
305printer='ps';
306print_printer=['-d', printer];
307fullfilename=[PROJECT_OD, mfilename, '_stddev.', printer];
308clear printer;
309print(print_printer,fullfilename);
310clear print_printer;
311clear fullfilename;
312%
313
314% sauvegarde des infos en ASCII
315fullfilename=[PROJECT_OD, mfilename, '.txt'];
316disp(['iii : ', mfilename ' : ','creation of ', fullfilename]);
317fid=fopen(fullfilename,'w');
318% écriture en tête
319fprintf(fid,'# %s\n',fullfilename);
320clear fullfilename;
321% écriture data
322fprintf(fid,'# yyyymmdd mean sum stddev\n');
323for 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));
325end
326fclose(fid);
327whos
Note: See TracBrowser for help on using the repository browser.