source: trunk/src/evolution_msg.m @ 287

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

add lonmin, lonmax, latmin, latmax parameter

  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1function [times_f,totpix]=evolution_msg(yyyymmddb, yyyymmdde, lonmin,lonmax,latmin,latmax,tseuil)
2
3%EVOLUTION_MSG evolution de la mousson
4
5%+
6%
7% ===============
8% evolution_msg.m
9% ===============
10%
11% .. function:: evolution_msg(yyyymmddb, yyyymmdde, lonmin,lonmax,latmin,latmax,tseuil)
12%
13% DESCRIPTION
14% ===========
15%
16%   :param yyyymmddb: beginning date yyyymmdd
17%   :type yyyymmddb: double
18%   :raise  yyyymmddb: required
19%
20%   :param yyyymmdde: end date yyyymmdd
21%   :type yyyymmdde: double
22%   :raise yyyymmdde: required
23%
24%   :param lonmin: longitude min, W < 0
25%   :units lonmin: deg
26%   :type lonmin: double
27%   :raise lonmin: required
28%
29%   :param lonmax: longitude max, W < 0
30%   :units lonmax: deg
31%   :type lonmax: double
32%   :raise lonmax: required
33%
34%   :param latmin: latitude min, N > 0
35%   :units latmin: deg
36%   :type latmin: double
37%   :raise latmin: required
38%
39%   :param latmax: latitude max, N > 0
40%   :units latmax: deg
41%   :type latmax: double
42%   :raise latmax: required
43%
44%   :param tseuil: seuil de température de brillance
45%   :units tseuil: K
46%   :type tseuil: double
47%   :raise tseuil: required
48%
49% read all MSG filee :file:`${PROJECT_ID}/MSG/{yyyy}/{mm}/msg-tb108_{yyyy}-{mm}-{dd}_15min.nc` from **yyyymmddb** include to **yyyymmdde** excluded. 
50%
51% recherche les pixels dont la valeur de température de brillance < tseuil
52% (pixel froids) pour trouver un systeme convectif
53%
54% dessine l'evolution temporelle du nb de pixels froids
55%
56% EXAMPLES
57% ========
58%
59% see demo 1
60%
61% La figure d'évolution s'affiche (tip : si les labels sont tassés, on peut
62% en cliquant sur la figure dilater l'axe des X)
63%
64% SEE ALSO
65% ========
66%
67% :ref:`guide data MSG <data_msg>`
68%
69% :ref:`varamma_startup.m`
70%
71% Previous step : :ref:`traite_msg-prod.sh`
72%
73% Use : :func:`split_yyyymmdd`
74%
75% TODO
76% ====
77%
78% status de retour
79%
80% split reading (see :func:`MSGread`) and calculate and plot
81%
82% filtrage, lissage
83%
84% check argument
85%
86% missing value
87%
88% ascii output
89%
90% hard coded timestep max per file = 96
91%
92% EVOLUTIONS
93% ==========
94%
95% $Id$
96%
97% - pinsard 2011-05-04T09:18:25Z loholt1.ipsl.polytechnique.fr (Linux)
98%
99%   * replace VARAMMA by PROJECT
100%   * make it run on loholt1
101%   * add yyyymmddb and yyyymmdde parameters
102%
103% - fplod 20110228T150040Z aedon.locean-ipsl.upmc.fr (Darwin)
104%
105%   * example moved to demo
106%   * add missing end
107%
108% - fplod 20110121T131304Z aedon.locean-ipsl.upmc.fr (Darwin)
109%
110%   * complement on header
111%
112% - fplod 20100726T160540Z aedon.locean-ipsl.upmc.fr (Darwin)
113%
114%   * suppress usage of netcdf.open (might be used on climserv
115%     but side effect on zeus running matlab)
116%
117% - fplod 20100726T124715Z aedon.locean-ipsl.upmc.fr (Darwin)
118%
119%   *  files must be in ${PROJECT_ID}/MSG/yyyy/mm/
120%
121% - fplod 20100608T115822Z aedon.locean-ipsl.upmc.fr (Darwin)
122%
123%   * no more datetick if running octave 3.0.2 on zeus
124%
125%   * correction of output name detected by matlab
126%      ::
127%
128%      ??? Output argument "t" (and maybe others) not assigned during call to "/.autofs/home/fplod/incas/varamma/varamma_ws/src/evolution_msg.m (evolution_msg)".
129% - fplod 20100604T083004Z aedon.locean-ipsl.upmc.fr (Darwin)
130%
131%   * add usage of varamma_startup : no more chemin parameter, PROJECT_ID value
132%     used instead
133%
134% - fplod 20100525T142706Z aedon.locean-ipsl.upmc.fr (Darwin)
135%
136%   * revision examples
137%
138% - lelod 20100521
139%
140%   * creation
141%-
142%
143global application;
144global application_version;
145%
146global PROJECT_ID;
147global PROJECT_OD;
148%
149global netcdf_open_available
150%
151h1=1;
152% nb de quarts d'heure/fichier
153h2=96;
154
155% ++ parameters
156lonmin=-15;
157lonmax=-10;
158latmin=15;
159latmax=20;
160tseuil=239;
161
162%
163arg_info=whos('yyyymmddb');
164if ~strcmp(arg_info.class,'double')
165   disp(['Incorrect type of arg yyyymmddb ' arg_info.class]);
166   whos yyyymmddb
167   error(usage);
168end
169clear arg_info
170%
171arg_info=whos('yyyymmdde');
172if ~strcmp(arg_info.class,'double')
173   disp(['Incorrect type of arg yyyymmdde ' arg_info.class]);
174   whos yyyymmddb
175   error(usage);
176end
177clear arg_info
178%
179[yyyyb, mmb, ddb] = split_yyyymmdd(yyyymmddb);
180[yyyye, mme, dde] = split_yyyymmdd(yyyymmdde);
181datenum_current=datenum(yyyyb,mmb,ddb);
182datenum_end=datenum(yyyye,mme,dde);
183addtodate_f='day';
184addtodate_q=1;
185ficlist=[];
186% liste des fichiers sur période choisie - toute la periode si possible +todo+
187while datenum_current < datenum_end
188    disp(['iii : looking for ', datestr(datenum_current,'yyyymmdd')]);
189    yyyy_s=datestr(datenum_current,'yyyy');
190    mm_s=datestr(datenum_current,'mm');
191    dd_s=datestr(datenum_current,'dd');
192    filename=['msg-tb108_' yyyy_s '-' mm_s '-' dd_s '_15min.nc'];
193    fullfilename=[PROJECT_ID 'MSG/' yyyy_s '/' mm_s '/' filename];
194    if (exist(fullfilename))
195       ficlist=[ficlist fullfilename];
196       disp(['iii : data found in ', fullfilename]);
197    else
198       disp(['iii : no fullfilename ', fullfilename]);
199    end
200    % next step
201    datenum_current=addtodate(datenum_current,addtodate_q, addtodate_f);
202    clear yyyy_s
203    clear mm_s
204    clear dd_s
205    clear filename
206    clear fullfilename
207end
208clear datenum_current
209clear datenum_end
210%
211% test if at least one file
212nbfic=size(ficlist,1);
213if (nbfic == 0)
214   error(['eee : no files found during [' num2str(yyyymmddb,'%6.6d') ',' num2str(yyyymmdde,'%6.6d') '[']);
215end
216%
217totpix=[];
218times_f=[];
219for ijour=1:nbfic
220   fullfilename=ficlist(ijour,:);
221   % Ouverture du fichier
222   if netcdf_open_available
223      ncid = netcdf.open(fullfilename, 'NC_NOWRITE');
224   else
225      ncid = netcdf(fullfilename, 'nowrite');
226   end
227   disp(['iii : ouverture de ', fullfilename]);
228   clear fullfilename;
229   if ijour == 1
230      % Si 1er fichier lu,
231      %  - lecture des longitudes et latitudes
232      %  - détermination des indices correspondants à la boite
233      % nb : on procéde ainsi pour limiter le nb de données à lire
234      % mais cela suppose bien sûr que tous les fichers ont les mêmes
235      % caractéristiques (ce qui n'est pas vérifié ici)
236
237      % Récupération des variables.
238      if netcdf_open_available
239         lon=netcdf.getVar(ncid,1);
240         lat=netcdf.getVar(ncid,2);
241      else
242         lon=file{'LONGITUDE'}(:);
243         lat=file{'LATITUDE'}(:);
244      end
245      indicelat1=find(abs(lat-latmin) == min(abs(lat-latmin)),1);
246      indicelat2=find(abs(lat-latmax) == min(abs(lat-latmax)),1);
247      clear lat;
248      indicelon1=find(abs(lon-lonmin) == min(abs(lon-lonmin)),1);
249      indicelon2=find(abs(lon-lonmax) == min(abs(lon-lonmax)),1);
250      clear lon;
251   end
252   if netcdf_open_available
253      data=netcdf.getVar(ncid,0);
254      % apply scale_factor and add_offset
255      data = double(data) * netcdf.getAtt(ncid,0,'scale_factor') + netcdf.getAtt(ncid,0,'add_offset');
256      % permute array to have
257      % dimension 1 : temps, dimension 2 : lat,  dimension 3 : lon
258      data = permute(data,[3 2 1]);
259   else
260      % Set missing value to NaN
261      data(data==file{'DATA'}.missing_value)=NaN;
262      % apply scale_factor and add_offset
263      data=file{'DATA'}.scale_factor(:)*data+file{'DATA'}.add_offset(:);
264   end
265   % reduce lat-lon domain
266   data=data(:,indicelat1:indicelat2,indicelon1:indicelon2);
267   % lecture du temps
268   if netcdf_open_available
269    hours_since19600101=netcdf.getVar(ncid,3);
270   else
271    hours_since19600101=file{'TIME'}(:);
272   end
273   hfin=size(hours_since19600101,1);
274   % close NetCDF file
275   if netcdf_open_available
276      netcdf.close(ncid);
277   else
278      ncclose(ncid);
279   end
280   clear ncid
281   %
282   % conversion du temps lu (HOURS since 1960-01-01 00:00:00) en date
283   times_f=[times_f; hours_since19600101/24.+datenum(1960,01,01)];
284   clear hours_since19600101;
285   %
286   tbmsg=data;
287   clear data;
288   % n pixels froid dans chaque image de chaque jour
289   npix=zeros(hfin,1);
290   for iheure=h1:hfin
291   %   disp(['iii : recherche des pixels froids pour le pas de temps ',num2str(iheure), ' du jour ', num2str(ijour)]);
292      % IDL pixfroid=where(tbmsg(iheure) > tseuil,nb);
293      pixfroid=find(tbmsg(iheure,:,:) < tseuil);
294      nb=size(pixfroid,1);
295      clear pixfroid;
296 %     nbtot=size(tbmsg(iheure,:,:),2) * size(tbmsg(iheure,:,:),3);
297 %     disp(['iii : ', num2str(nb), ' pixels froids parmi ', num2str(nbtot)]);
298%++      if nb ~= 0
299         % tableau du jour
300         npix(iheure)=nb;
301%++      end
302   end
303   clear tbmsg;
304   % concatenation
305   totpix=[totpix;npix];
306end
307clear indicelat1;
308clear indicelat2;
309clear indicelon1;
310clear indicelon2;
311clear h1;
312clear h2;
313clear latmin;
314clear latmax;
315clear lonmin;
316clear lonmax;
317%
318% Create xdata to correspond to the number of points between the start and
319% end dates:
320nbp=nbfic*96;
321times_str=datestr(times_f,6);
322%xdata = linspace(times_f(1),times_f(size(times_f,1)),nbp);
323%
324% sauvegarde des infos en ascii
325%PROJECT_OD='./';
326%fullfilename=[PROJECT_OD, mfilename, '_', times_str(1,:), '_', times_str(size(times_str,1),:),'.txt'];
327%disp(['iii : creation de ', fullfilename]);
328%fid=fopen(fullfilename,'w');
329% écriture en tête
330%fprintf(fid,'# %s\n',fullfilename);
331%fprintf(fid,'# temps nb_froid\n');
332%fprintf(fid,'!!!!!! ATTENTION CE FICHIER EST INCORRECT !!!!! \n');
333%fprintf(fid,'!!!!!! mise au point en cours !!!!! \n');
334%fprintf(fid,'%f %5.5d\n',times_f,totpix);
335%++ pas ok pb écriture string fprintf(fid,'%s %5.5d\n',times_str(1),totpix);
336%fclose(fid);
337%clear fullfilename;
338%
339
340% plot de nb points froids au cours du temps
341
342figure(1);
343clf;
344plot(times_f,totpix)
345
346% Set the number of XTicks to the number of points in xdata
347%set(gca,'XTick',xdata)
348
349% conversion des données temps en chaine mmdd
350%xlabel=datestr(xdata,6);
351switch application
352  case {'matlab'}
353     datetick('x',6);
354  case {'octave'}
355     switch application_version
356        case {'3.0.2'}
357           disp(['no datetick available using ', application , ' ', application_version]);
358        otherwise
359           error(['unknown application version running ', application , ' ' ,application_version]);
360     end
361  otherwise
362     error('unknown application running');
363end
364%set (gca, 'xticklabel', xlabel);
365%get (gca, 'xticklabelmode');
366xlabel('date','fontsize',8)
367ylabel('nb pixels froids');
368title(['evolution du nb de pixels froids dans les donnees MSG entre ', times_str(1,:), ' et ', times_str(size(times_str,1),:)]);
369
370% sauvegarde de la figure
371%printer='ps';
372%print_printer=['-d', printer];
373%fullfilename=[PROJECT_OD, mfilename, '_', times_str(1,:), '_', times_str(size(times_str,1),:),'.', printer];
374%clear printer;
375%print(print_printer,fullfilename);
376%disp(['iii : creation de ', fullfilename]);
377%clear print_printer;
378%clear fullfilename;
379%
380
381end
382
383%!demo
384%! clear all
385%! varamma_startup
386%! more off
387%! yyyymmddb=20060801;
388%! yyyymmdde=20060802;
389%! lonmin=-15;
390%! lonmax=-10;
391%! latmin=15;
392%! latmax=20;
393%! tseuil=239;
394%! [times_f,totpix]=evolution_msg(yyyymmddb, yyyymmdde, lonmin,lonmax,latmin,latmax,tseuil);
Note: See TracBrowser for help on using the repository browser.