1 | %+ |
---|
2 | % |
---|
3 | % .. _precipPlot.m: |
---|
4 | % |
---|
5 | % ============ |
---|
6 | % precipPlot.m |
---|
7 | % ============ |
---|
8 | % |
---|
9 | % DESCRIPTION |
---|
10 | % =========== |
---|
11 | % |
---|
12 | % plot precipitation data according to files originaly transmitted to |
---|
13 | % Soukèyé Cisse in :file:`Données climatiques_Soukèye.zip` |
---|
14 | % |
---|
15 | % This zip file contains Excel files. Some have been converted in CSV. |
---|
16 | % |
---|
17 | % +todo+ :ref:`pre_precip.sh` |
---|
18 | % |
---|
19 | % This file in mainly a serie of exercices for Soukèyé Cisse to learn octave. |
---|
20 | % |
---|
21 | % EXAMPLES |
---|
22 | % ======== |
---|
23 | % |
---|
24 | % :: |
---|
25 | % |
---|
26 | % $ octave |
---|
27 | % octave> more off |
---|
28 | % octave> varamma_startup |
---|
29 | % octave> precipPlot |
---|
30 | % |
---|
31 | % TODO |
---|
32 | % ==== |
---|
33 | % |
---|
34 | % - trouver une solution pour visualiser sur zeus et/ou sur le poste de travail lodyn301 |
---|
35 | % les fichiers dans $VARAMMA_OD |
---|
36 | % |
---|
37 | % * sur zeus pas de xv ni de gv !! |
---|
38 | % * sur lodyn301 le /usr/temp/soclod différent de /usr/temp/soclod de zeus !! |
---|
39 | % |
---|
40 | % - embrouille dans les fichiers/données de moyennes mensuelles : pas de figure pour l'année 1995 |
---|
41 | % alors qu'il y a des données |
---|
42 | % |
---|
43 | % - calcul et tracé des cumuls par decades |
---|
44 | % - avec subplot mettre toutes figures sur un meme graphe |
---|
45 | % |
---|
46 | % - last day of mont is not always 31 |
---|
47 | % tip eomday function |
---|
48 | % |
---|
49 | % EVOLUTIONS |
---|
50 | % ========== |
---|
51 | % |
---|
52 | % $Id$ |
---|
53 | % |
---|
54 | % $URL$ |
---|
55 | % |
---|
56 | % - fplod 20100720T165423Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
57 | % |
---|
58 | % * sauvegarde des données des moyennes mensuelles dans |
---|
59 | % $VARAMMA_OD/precipPlot_station_meanmonthly.txt |
---|
60 | % sous forme ASCII (header + 3 colonnes de données) |
---|
61 | % * make it ok running matlab : replace " by ' |
---|
62 | % |
---|
63 | % - soclod+fplod 20100720T16000Z |
---|
64 | % |
---|
65 | % * sauvegarder des figures des moyennes mensuelles dans |
---|
66 | % $VARAMMA_OD/precipPlot_station_meanmonthly_yyyy.ps |
---|
67 | % |
---|
68 | % implique l'utilisation de varamma_startup |
---|
69 | % |
---|
70 | % * ajout de l'exemple dans l'en tête |
---|
71 | % |
---|
72 | % - soclod 20100720T150000Z |
---|
73 | % |
---|
74 | % * changer l'axe des abscisses avec startdate et enddate dans le tracé des moyenne mensuelles |
---|
75 | % |
---|
76 | % - soclod 20100719TT150000Z |
---|
77 | % |
---|
78 | % * calcul de moyennes mensuelles et tracé des moyennes mensuelles des mois de mousson |
---|
79 | % |
---|
80 | % - soclod 20100716TT140000Z |
---|
81 | % |
---|
82 | % * change ian-imonth loops to line loop because of implicit missing values |
---|
83 | % |
---|
84 | % - soclod 20100716TT130000Z |
---|
85 | % |
---|
86 | % * année sur 2 digits sur le graphique precip_journaliere toutes les |
---|
87 | % années |
---|
88 | % |
---|
89 | % - fplod 20100716T080507Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
90 | % |
---|
91 | % * tick one day on 10 on figure with several month |
---|
92 | % |
---|
93 | % - fplod 20100716T073903Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
94 | % |
---|
95 | % * bug fix : replace xdecad by xdata, add figure(ifigure) to move |
---|
96 | % one plot |
---|
97 | % * make it ok running matlab : replace " by ' |
---|
98 | % |
---|
99 | % - soclod 20100715 |
---|
100 | % |
---|
101 | % * dessin precip_journaliere avec label x yyyymmdd |
---|
102 | % * desin precip_journaliere avec subplot |
---|
103 | % |
---|
104 | % - fplod 20100715T075514Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
105 | % |
---|
106 | % * add a figure using datetime label |
---|
107 | % |
---|
108 | % - 20100708 soclod+fplod |
---|
109 | % |
---|
110 | % * ajout precip journaliere |
---|
111 | % |
---|
112 | % - fplod 20100709T072024Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
113 | % * add loop on figure |
---|
114 | % * make it work using matlab 7.4 |
---|
115 | % |
---|
116 | % .. note:: |
---|
117 | % |
---|
118 | % sous octave load('petitecote.xls.csv') charge le tableau petitecote_xls |
---|
119 | % sous matlab load('petitecote.xls.csv') charge le tableau petitecote |
---|
120 | % |
---|
121 | % precipitation journaliere de juin a octobre |
---|
122 | % a partir du fichier Barkedji_pluviom_SP-2008.xls |
---|
123 | % |
---|
124 | % pour faire la conversion Ascii de Barkedji_pluviom_SP-2008.xls en : |
---|
125 | % - ne pas avoir de , entre les cellules |
---|
126 | % - ne pas avoir de ligne vide |
---|
127 | % - ne pas avoir de ligne qui coimmencent par de " |
---|
128 | % |
---|
129 | % |
---|
130 | % :: |
---|
131 | % |
---|
132 | % $ xls2csv -c" " -q1 Barkedji_pluviom_SP-2008.xls | \ |
---|
133 | % sed -e "/^ *$/d" -e "/^\"/d" -e "/^jour/d" | tr -d '\f' \ |
---|
134 | % > $PROJECT/src/Barkedji_pluviom_SP-2008.xls.csv |
---|
135 | % |
---|
136 | % pour faire la conversion Ascii de petite\ côte.xls : |
---|
137 | % ++ pas fini |
---|
138 | % xls2csv -c" " -q1 petite\ côte.xls| sed -e "s/^ 19/\" \" 19/" -e "s/^ janvier/\"station\" \"année\" janvier/" > /usr/home/fplod/incas/varamma/varamma_ws/src/petitecote.xls.csv |
---|
139 | % |
---|
140 | %- |
---|
141 | % |
---|
142 | ifigure=1; |
---|
143 | % |
---|
144 | % Load data from PDXprecip.dat and plot it with symbols |
---|
145 | |
---|
146 | load PDXprecip.dat; % read data into PDXprecip matrix |
---|
147 | month = PDXprecip(:,1); % copy first column of PDXprecip into month |
---|
148 | precip = PDXprecip(:,2); % and second column into precip |
---|
149 | |
---|
150 | plot(month,precip,'o'); % plot precip vs. month with circles |
---|
151 | |
---|
152 | xlabel('month of the year'); % add axis labels and plot title |
---|
153 | ylabel('mean precipitation (mm)'); |
---|
154 | title('Mean monthly precipitation at Portland International Airport'); |
---|
155 | |
---|
156 | % initialize tableau petitecote |
---|
157 | petitecote=load('petitecote.xls.csv'); |
---|
158 | % initialize le tableau month |
---|
159 | month=1:12; |
---|
160 | % start boucle of year |
---|
161 | for ii=1:2; |
---|
162 | % prepare affichage figure after (not delete the figure before) |
---|
163 | ifigure=ifigure + 1; |
---|
164 | figure(ifigure) |
---|
165 | % initialize tableau content precipitation during the courant month |
---|
166 | precip=petitecote(ii,2:13); |
---|
167 | % initialize year |
---|
168 | iyear=petitecote(ii,1); |
---|
169 | % trace courant figure |
---|
170 | plot(month,precip,'o'); |
---|
171 | % define title with courant month and courant year |
---|
172 | xlabel(['month of the year ' num2str(iyear)]); |
---|
173 | % define au title with precipitation in (mm) |
---|
174 | ylabel('precipitation (mm)'); |
---|
175 | % give title of figure |
---|
176 | title('monthly precipitation from file petitecote.xls.csv'); |
---|
177 | % fin de la boucle on year |
---|
178 | end |
---|
179 | clear ii; |
---|
180 | clear month; |
---|
181 | clear precip; |
---|
182 | clear petitecote |
---|
183 | |
---|
184 | % same plot than above using datetime label |
---|
185 | petitecote=load('petitecote.xls.csv'); |
---|
186 | month=1:12; |
---|
187 | for ii=1:2 |
---|
188 | ifigure=ifigure + 1; |
---|
189 | iyear=petitecote(ii,1); |
---|
190 | startdate=datenum(iyear,1,1); |
---|
191 | enddate=datenum(iyear,12,31); |
---|
192 | xdata=linspace(startdate,enddate,size(month,2)); |
---|
193 | precip=petitecote(ii,2:13); |
---|
194 | plot(xdata,precip,'o'); |
---|
195 | set(gca,'XTick',xdata) |
---|
196 | % nb : because of lack of datetick in octave 3.0.2 on zeus |
---|
197 | % we use xticklabel instead of datetick |
---|
198 | xticklabel=datestr(xdata,'yyyy/mm'); |
---|
199 | set(gca,'XTickLabel',xticklabel) |
---|
200 | xlabel(['month of the year ' num2str(iyear)]); |
---|
201 | ylabel('precipitation (mm)'); |
---|
202 | title('monthly precipitation from file petitecote.xls.csv with datetime'); |
---|
203 | end |
---|
204 | clear ii; |
---|
205 | clear month; |
---|
206 | clear precip; |
---|
207 | |
---|
208 | load('precip_journaliere') |
---|
209 | % plot 1 figure / month |
---|
210 | day=1:31; |
---|
211 | for imonth=6:10 |
---|
212 | ifigure=ifigure + 1; |
---|
213 | figure(ifigure); |
---|
214 | precip=precip_journaliere(:,imonth-4); |
---|
215 | plot(day, precip, 'o'); |
---|
216 | xlabel(['day of the month ' num2str(imonth)]); |
---|
217 | ylabel('precipjournaliere (mm)'); |
---|
218 | title('precipitation journaliere'); |
---|
219 | end |
---|
220 | load('precip_journaliere') |
---|
221 | day=1:31; |
---|
222 | year=2008; |
---|
223 | for imonth=6:10 |
---|
224 | ifigure=ifigure+1; |
---|
225 | figure(ifigure); |
---|
226 | startdate=datenum(year,imonth,1); |
---|
227 | enddate=datenum(year,imonth,31); |
---|
228 | xdata=linspace(startdate,enddate,size(day,2)); |
---|
229 | precip=precip_journaliere(:,imonth-4); |
---|
230 | plot(xdata,precip,'o'); |
---|
231 | set(gca,'xtick',xdata); |
---|
232 | xticklabel=datestr(xdata,'dd'); |
---|
233 | set(gca,'xticklabel',xticklabel); |
---|
234 | xlabel(['day of the month ' num2str(imonth) ' ' num2str(year)]); |
---|
235 | ylabel('precipjournaliere (mm)'); |
---|
236 | title('precipitation journaliere'); |
---|
237 | end |
---|
238 | |
---|
239 | load('precip_journaliere') |
---|
240 | day=1:31; |
---|
241 | year=2008; |
---|
242 | ifigure=ifigure+1; |
---|
243 | figure(ifigure); |
---|
244 | nl=2; |
---|
245 | nc=3; |
---|
246 | for imonth=6:10 |
---|
247 | % compute the day number of the 1st date on current month plot |
---|
248 | startdate=datenum(year,imonth,1); |
---|
249 | % compute the day number of the last date on current month plot |
---|
250 | % +todo+ last day of mont is not always 31 |
---|
251 | enddate=datenum(year,imonth,31); |
---|
252 | % set x values where we want a tick : one tick every ten days |
---|
253 | xdata=startdate:10:enddate; |
---|
254 | % set text associated to each x values where we want a tick: format dd |
---|
255 | xticklabel=datestr(xdata,'dd'); |
---|
256 | % fill precip with current month daily precipitation |
---|
257 | precip=precip_journaliere(:,imonth-4); |
---|
258 | % set x to day numbers |
---|
259 | x=day+startdate-1; |
---|
260 | % define position of plot on the figure |
---|
261 | subplot(nl,nc,imonth-5); |
---|
262 | plot(x,precip,'o'); |
---|
263 | % control number of ticks and associated text |
---|
264 | set(gca,'xtick',xdata); |
---|
265 | set(gca,'xticklabel',xticklabel); |
---|
266 | xlabel(['day of the month ' num2str(imonth) ' ' num2str(year)]); |
---|
267 | ylabel('precipjournaliere (mm)'); |
---|
268 | title('precipitation journaliere'); |
---|
269 | end |
---|
270 | |
---|
271 | ifigure=ifigure+1; |
---|
272 | figure(ifigure) |
---|
273 | precip_journaliere=load('velingra_q_1961-2000.xsl.csv'); |
---|
274 | % initialize le tableau of the years |
---|
275 | an=1961:2000; |
---|
276 | % initialize the number d'années |
---|
277 | nban=size(an,2); |
---|
278 | % initialize tableau x sachant que x contienne des numéros de jour |
---|
279 | % ayant comme 1ére valeur le 1er jan 1961 et |
---|
280 | % comme derniére valeur le 31 dec 2000 |
---|
281 | % initialize array month with value of month in one year |
---|
282 | month=1:12; |
---|
283 | x=1+datenum(1961,1,1):nban*size(month,2)*31+datenum(1961,1,1); |
---|
284 | % xdata is an array of nban day numbers yyyy/01/01 where we want ticks |
---|
285 | xdata=datenum(an,1,1); |
---|
286 | % xticklabel is an array of nban strings "yyyy/mm/dd" we want as associated |
---|
287 | % to ticks |
---|
288 | xticklabel=datestr(xdata,'yy'); |
---|
289 | % initialize le tableau content precipitation de tous jours, tous les |
---|
290 | % mois et de toutes les années |
---|
291 | % ++ NaN au lieu de zero |
---|
292 | precip=zeros(1,size(an,2)*size(month,2)*31); |
---|
293 | for iligne=1:size(precip_journaliere,1) |
---|
294 | % get year in 1st column |
---|
295 | ian=precip_journaliere(iligne,1); |
---|
296 | % get month in 2d column |
---|
297 | imonth=precip_journaliere(iligne,2); |
---|
298 | % d = position of 1st current month and current year in precip array |
---|
299 | d=datenum(ian,imonth,1)-datenum(1961,1,1)+1; |
---|
300 | f=d+31-1; |
---|
301 | precip(d:f)=precip_journaliere(iligne,3:33); |
---|
302 | end |
---|
303 | |
---|
304 | % tracer the courant figure |
---|
305 | plot(x,precip,'-'); |
---|
306 | % control number of ticks and associated text |
---|
307 | set(gca,'xtick',xdata); |
---|
308 | set(gca,'xticklabel',xticklabel); |
---|
309 | % definir au title with number of day for courant month and courant year |
---|
310 | xlabel('1st day of the month each year'); |
---|
311 | % definir au title with precipitation in (mm) |
---|
312 | ylabel('precipjournaliere (mm)'); |
---|
313 | % give title of figure |
---|
314 | title('annual velingra precipitation'); |
---|
315 | % |
---|
316 | ifigure=ifigure + 1; |
---|
317 | figure(ifigure); |
---|
318 | % one figure from June 1st to October 30th |
---|
319 | load precip_journaliere |
---|
320 | month=6:10; |
---|
321 | x=1:size(month,2)*31; |
---|
322 | plot(x(1:31),precip_journaliere(:,2),'o', x(31+1:31+31), precip_journaliere(:,3),'-',x(31+31+1:31*3), precip_journaliere(:,4),'+',x(31*3+1:31*4), precip_journaliere(:,5),'x',x(31*4+1:31*5),precip_journaliere(:,6),'*'); |
---|
323 | xlabel('day number (from June 1st to October 30th)'); |
---|
324 | ylabel('precipjournaliere (mm)'); |
---|
325 | title('precipitation journaliere'); |
---|
326 | |
---|
327 | |
---|
328 | ifigure=1; |
---|
329 | %nl=3; |
---|
330 | %nc=3; |
---|
331 | station='velingra'; |
---|
332 | precip_journaliere=load('velingra_q_1961-2000.xsl.csv'); |
---|
333 | % initialise les annee |
---|
334 | domaine_an=1961:2000; |
---|
335 | nban=size(domaine_an,2); |
---|
336 | % initialise le tableau des mois pour chaque annee |
---|
337 | domaine_month=1:12; |
---|
338 | nbmonth=size(domaine_month,2); |
---|
339 | % initialise le tableau contenant les sommes et les moyennes |
---|
340 | % mensuelles de toutes les annee |
---|
341 | summensuelle=zeros(nban,nbmonth); |
---|
342 | meanmensuelle=zeros(nban,nbmonth); |
---|
343 | % boucle sur les annee |
---|
344 | for ian=1:nban; |
---|
345 | % boucle sur les mois |
---|
346 | for imonth=domaine_month; |
---|
347 | % calcul de la ligne contenant les precipitations du mois |
---|
348 | % courant/annee courante |
---|
349 | iligne=imonth+((ian-1)*12); |
---|
350 | if (iligne <= size(precip_journaliere,1)); |
---|
351 | % calcul de la somme mensuelle des precipitations |
---|
352 | summensuelle(ian,imonth)=sum(precip_journaliere(iligne,3:eomday(ian+1961-1,imonth)+2)); |
---|
353 | % calcul de la moyenne mensuelle des precipitations |
---|
354 | meanmensuelle(ian,imonth)=summensuelle(ian,imonth)/eomday(ian+1961-1,imonth); |
---|
355 | else |
---|
356 | summensuelle(ian,imonth)=NaN; |
---|
357 | meanmensuelle(ian,imonth)=NaN; |
---|
358 | end |
---|
359 | end |
---|
360 | end |
---|
361 | % |
---|
362 | % trace des moyennes mensuelles |
---|
363 | domaine_an=1961:2000; |
---|
364 | nban=size(domaine_an,2); |
---|
365 | domaine_month=6:10; |
---|
366 | xdata=zeros(1,size(domaine_month,2)); |
---|
367 | % boucle sur les années à dessiner |
---|
368 | for ian=1:nban; |
---|
369 | startdate=datenum(ian+(1961-1),6,1); |
---|
370 | enddate=datenum(ian+1961-1,10,31); |
---|
371 | % set x values were we want tick:one tick for month |
---|
372 | for imonth=domaine_month |
---|
373 | xdata(imonth-5)=datenum(ian+1961-1,imonth,1); |
---|
374 | end |
---|
375 | xticklabel=datestr(xdata,'yyyy/mm/dd'); |
---|
376 | % ++todo+++ subplot(nl,nc,(ian+1)-1961); |
---|
377 | % dessine les precipitations moyennes mensuelles de chaque mois de |
---|
378 | % l'annee courante |
---|
379 | if (find(meanmensuelle(ian,domaine_month) > 0 )) |
---|
380 | ifigure=ifigure+1; |
---|
381 | figure(ifigure); |
---|
382 | plot(xdata, meanmensuelle(ian,domaine_month),'o'); |
---|
383 | % on impose les bornes x et y des graphiques pour avoir la même echelle |
---|
384 | % sur toutes les figures |
---|
385 | set(gca,'xtick',xdata); |
---|
386 | set(gca,'xticklabel',xticklabel); |
---|
387 | xlabel(['month of the year ' num2str(ian+1961-1)]); |
---|
388 | ylabel('mean monthly of precipitation (mm)'); |
---|
389 | title('mean precipitation velingra'); |
---|
390 | % sauvegarde de la figure de l'année courante |
---|
391 | % dans un fichier POSTSCRIPT ${PROJECT_OD}/precipPlot_velingra_meanmonthly_yyyy.ps |
---|
392 | filename=[PROJECT_OD mfilename '_' station '_meanmonthly_' num2str(ian+1961-1) '.ps']; |
---|
393 | print(filename,'-dps'); |
---|
394 | else |
---|
395 | disp(['no data in year ' num2str(ian+1961-1)]) |
---|
396 | end |
---|
397 | end |
---|
398 | close all |
---|
399 | % save monthly means in an ASCII file |
---|
400 | fullfilename=[PROJECT_OD mfilename '_' station '_meanmonthly.txt']; |
---|
401 | disp(['iii : creation de ', fullfilename]); |
---|
402 | fid=fopen(fullfilename,'w'); |
---|
403 | % write header |
---|
404 | fprintf(fid,'# %s\n',fullfilename); |
---|
405 | fprintf(fid,'# year month mean\n'); |
---|
406 | for iyear=1961:2000 |
---|
407 | for imonth=6:10 |
---|
408 | fprintf(fid,'%4.4d %2.2d %5.1f\n', iyear, imonth, meanmensuelle(iyear-1961+1,imonth-5)); |
---|
409 | end |
---|
410 | end |
---|
411 | fclose(fid); |
---|
412 | clear fullfilename; |
---|