source: trunk/src/amsu2ncdf.pro @ 599

Last change on this file since 599 was 599, checked in by llmlod, 12 years ago

petite modif sur la lecture du nom de fichier

  • Property svn:keywords set to URL
File size: 9.5 KB
Line 
1; docformat = 'rst'
2;+
3; .. _amsu2ncdf.pro:
4;
5; =============
6; amsu2ncdf.pro
7; =============
8;
9; DESCRIPTION
10; ===========
11;
12; +todo+
13;
14;    :param numch: number of the channel
15;    :type numch: string
16;    :raise numch: required
17;
18;    :param yyyy: year
19;    :type yyyy: int
20;    :raise yyyy: required
21;
22;    :param mm: month
23;    :type mm: int
24;    :raise mm: required
25;
26;    :param dd: day
27;    :type dd: int
28;    :raise dd: required
29;
30;    :param lon_min: longitude min, W < 0
31;    :units lon_min: deg
32;    :type lon_min: double
33;    :raise lon_min: required
34;
35;    :param lon_max: longitude max, W < 0
36;    :units lon_max: deg
37;    :type lon_max: double
38;    :raise lon_max: required
39;
40;    :param lat_min: latitude min, N > 0
41;    :units lat_min: deg
42;    :type lat_min: double
43;    :raise lat_min: required
44;
45;    :param lat_max: latitude max, N > 0
46;    :units lat_max: deg
47;    :type lat_max: double
48;    :raise lat_max: required
49;
50; read :file:`${PROJECT_ID}/AMSU/yyyy/mm/dd/amsua[_amsub]_{yyyymmdd}_{geomin}_{geomax}_nadir.dat`
51; produced by :ref:`correct_nadir_amsu.pro`.
52;
53; read :file:`${PROJECT_ID}/MSG/2006/06/01/msg_IR108_20060601.nc` that will
54; be used for regrid.++
55;
56; write :file:`${PROJECT_ID}/AMSU/yyyy/mm/dd/amsua[_amsub]_{yyyymmdd}_{hhmmss}_{geomin}_{geomax}_nadir.nc`.
57;
58; .. only:: man
59;
60;    Figure is visible on PDF and HTML documents only.
61;
62; .. only:: html or latex
63;
64;     .. graphviz::
65;
66;        digraph amsu2ncdf {
67;
68;           amsu_t3 [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/yyyy/mm/amsua_amsub_yyyymmdd_geomin_geomax_nadir.dat"];
69;           amsu_t4 [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/yyyy/mm/amsua_amsub_yyyymmdd_geomin_geomax_nadir.nc"];
70;           msg [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/MSG/2006/06/01/msg_IR108_20060601.nc"];
71;
72;           amsu2ncdf [shape=box,
73;           fontname=Courier,
74;           color=blue,
75;           URL="http://forge.ipsl.jussieu.fr/varamma/browser/trunk/src/amsu2ncdf.pro",
76;           label="${PROJECT}/src/amsu2ncdf.pro"];
77;
78;           {amsu_t3 msg} -> {amsu2ncdf} -> {amsu_t4}
79;
80;          }
81;
82; EXAMPLES
83; ========
84;
85; To produce AMSU netCDF file for 20060801::
86;
87;   numch='a5'
88;   yyyy=2006L
89;   mm=8
90;   dd=01
91;   lon_min=-60.
92;   lon_max=50.
93;   lat_min=-30.
94;   lat_max=45.
95;   amsu2ncdf, use_amsua, yyyy, mm, dd, lon_min, lon_max, lat_min, lat_max
96;
97; or::
98;
99;   numch='a5'
100;   yyyy=2006L
101;   mm=8
102;   dd=01
103;   lon_min=-60.
104;   lon_max=50.
105;   lat_min=-30.
106;   lat_max=45.
107;   amsu2ncdf, use_amsua, yyyy, mm, dd, lon_min, lon_max, lat_min, lat_max
108;
109;
110; SEE ALSO
111; ========
112;
113; :ref:`data_amsu`
114; :ref:`data_msg`
115;
116; Use: :func:`read_regular_grid`, :ref:`create_amsu_netcdf.pro`, :func:`geolocation_to_string_idl`
117;
118; Called by :ref:`traite_amsuab.sh`
119;
120; Previous step : :ref:`extract_amsu.pro`
121;
122; Next step : ... science !
123;
124; TODO
125; ====
126;
127;
128; EVOLUTIONS
129; ==========
130;
131;
132;-
133PRO amsu2ncdf, numch, yyyy, mm, dd, lon_min, lon_max, lat_min, lat_max, resol
134;
135compile_opt idl2, strictarrsubs
136;
137@cm_project
138
139
140testfilename=''
141look = 'filename'
142
143; ne pas utiliser les bornes lon et lat fournies en entree car elles
144; peuvent etre differentes de celle du fichier .dat puisqu'on peut
145; creer un fichier .nc extrait du .dat
146;geomin = geolocation_to_string_idl(lon_min, lat_min, look,1)
147;geomax = geolocation_to_string_idl(lon_max, lat_max, look,1)
148
149file='/homedata/eymard/varamma_d/AMSU/' $
150   + string(yyyy,format='(I4.4)') + '/' $
151   + string(mm,format='(I2.2)')   + '/' $
152   + numch + '_' + string(yyyy,format='(I4.4)') $
153   + string(mm,format='(I2.2)') $
154   + string(dd,format='(I2.2)') + '_' $
155   + '*.dat'
156;   + geomin + '_' + geomax + '.dat'
157
158testfilename=FILE_SEARCH(file)
159
160print, testfilename
161
162result=file_amsu_t2_to_mem( yyyy,mm,dd,numch,lon_min,lon_max,lat_min,lat_max,testfilename)
163         desc=result.data.desc
164         hour=result.data.hour
165         fov=result.data.fov
166         lon=result.data.lon
167         lat=result.data.lat
168         mask=result.data.landseamask
169         tb1=result.data.tb
170         ; decodage du nb de points (nn)
171         nn=n_elements(tb1)
172
173; numero d'orbite
174norb=desc[UNIQ(desc)]
175; nombre d'orbites
176nbo=n_elements(norb)
177
178; grille de sortie xaxis, yaxis :
179; --------------------------------
180xaxis=indgen((lon_max-lon_min)/resol+1)*resol+lon_min
181yaxis=indgen((lat_max-lat_min)/resol+1)*resol+lat_min
182nlon=n_elements(xaxis)
183nlat=n_elements(yaxis)
184
185; calcul seuil pour remplir la nouvelle grille
186; --------------------------------------------
187;seuil latitude = MAX((variation de latitude sur un meme fov)/2)
188;pour une orbite quelconque (on choisie la plus longue)
189;moyenne pour fov sur le bord (=min(fov)) et au milieu (=fix(max(fov)/2))
190torb=LONARR(nbo)
191FOR i=0,nbo-1 DO BEGIN
192    inutile=WHERE(desc EQ norb[i],nb)
193    torb[i]=nb
194ENDFOR
195longorb=norb[WHERE(torb EQ MAX(torb))]
196
197ind_bor=WHERE(fov EQ MIN(fov) AND desc EQ longorb[0])
198dif_bor=ABS(lat[ind_bor[1:N_ELEMENTS(ind_bor)-1]]-lat[ind_bor[0:N_ELEMENTS(ind_bor)-2]])
199; arrondi au 0.1 superieur pour lisser un peu mais pas trop
200seuil_lat=CEIL(MAX([dif_bor])/2*10)/10.
201print, seuil_lat
202
203;seuil longitude = MAX((difference de longitude sur une ligne)/2)
204;pour une orbite quelconque (on choisit la plus longue)
205;pour une ligne quelconque (on choisit la plus longue)
206ind_orb=WHERE(desc EQ longorb[0])
207dif_lon=lon[ind_orb[1:N_ELEMENTS(ind_orb)-1]]-lon[ind_orb[0:N_ELEMENTS(ind_orb)-2]]
208; arrondi au 0.1 superieur pour lisser un peu mais pas trop
209seuil_lon=CEIL(MAX(dif_lon[WHERE(dif_lon LT 1)])/2*10)/10.
210print, seuil_lon
211
212; initialisation
213maskg=fltarr(nlon,nlat)
214tbg=fltarr(nlon,nlat,nbo)
215temp=fltarr(nlon,nlat,nbo)
216iheur=fltarr(nbo)
217
218; valeur erreur -999.
219val_err=-999.
220maskg[*]=val_err
221tbg[*]=val_err
222temp[*]=val_err
223
224;;; pour chaque orbite ;;;
225rT=6371 ; rayon de la Terre
226for k=0,nbo-1 do begin
227; trouve tous les indices de l'orbite
228    ind_orb=WHERE(desc eq norb[k])
229;;; pour chaque latitude ;;;
230    for j=0,nlat-1 do begin
231;;; pour chaque longitude ;;;
232        for i=0,nlon-1 do begin
233            ind_pt=WHERE(ABS(yaxis[j]-lat[ind_orb]) LT seuil_lat AND ABS(xaxis[i]-lon[ind_orb]) LT seuil_lon)
234            IF ind_pt[0] NE -1 THEN BEGIN
235;;;cherhce le plus proche en km;;;
236; lon/lat en radian
237                lat_rad=lat[ind_orb[ind_pt]]*!Pi/180.
238                lon_rad=lon[ind_orb[ind_pt]]*!Pi/180.
239                y_rad=yaxis[j]*!Pi/180.
240                x_rad=xaxis[i]*!Pi/180.
241; calcul distance
242                dist = 2*rT*ASIN(SQRT((SIN((y_rad-lat_rad)/2.)*SIN((y_rad-lat_rad)/2.))+(COS(x_rad)*COS(lon_rad)*SIN((x_rad-lon_rad)/2.)*SIN((x_rad-lon_rad)/2.))))
243; selectionne le plus proche
244                dist_min=WHERE(dist EQ MIN(dist))
245; attribut le point le plus proche
246                tbg[i,j,k]=tb1[ind_orb[ind_pt[dist_min]]]
247                temp[i,j,k]=hour[ind_orb[ind_pt[dist_min]]]
248                maskg[i,j]=mask[ind_orb[ind_pt[dist_min]]]
249            ENDIF
250        ENDFOR
251    ENDFOR
252    tps=temp[*,*,k]
253    ind = WHERE(tps eq val_err)
254    tps[ind]=!VALUES.F_NAN
255    iheur[k]=MEAN(tps,/NaN)
256;print, 'orbite '+string(norb[k])+' finie'
257endfor
258
259; decomposition de l'heure de l'orbite en heure, minute, seconde
260h_orb=fix(iheur)
261m_orb=fix((iheur-h_orb)*60)
262s_orb=fix((iheur-h_orb-m_orb/60.)*3600)
263
264  ;
265  ; Creation du fichier NetCDF :
266  ; ----------------------------
267
268geomin = geolocation_to_string_idl(lon_min, lat_min, look,1)
269geomax = geolocation_to_string_idl(lon_max, lat_max, look,1)
270
271 file_ncdf=project_id_env+ 'AMSU/' $
272   + numch + '_' $
273   + string(yyyy,format='(I4.4)') $
274   + string(mm,format='(I2.2)') $
275   + string(dd,format='(I2.2)') + '_' $
276   + geomin + '_' $
277   + geomax + '_' $
278   + 'nadir.nc'
279
280create_amsu_netcdf, file_ncdf, yyyy, mm, dd, h_orb, m_orb, s_orb $
281  ,xaxis,yaxis, tbg, maskg, val_err, numch 
282
283  ; comment the next line to produce an image
284;  goto, ret0
285  ;
286  ; Visualisation :
287  ; ---------------
288minlon=min(xaxis)
289maxlon=max(xaxis)
290minlat=min(yaxis)
291maxlat=max(yaxis)
292  window, 0
293  loadct, 39
294  map_set, limit=[minlat,minlon,maxlat,maxlon]
295
296  tabcolor = MAP_IMAGE(tbg[*,*,1],Startx,Starty, COMPRESS=1, $
297    LATMIN=minlat, LONMIN=minlon, $
298    LATMAX=maxlat, LONMAX=maxlon, $
299    max_value=280., min_value=235., missing=val_err)
300
301  lewh=where(tabcolor ne val_err, cnt, complement=lewhcmpl)
302  if (cnt ne n_elements(tabcolor)) then begin
303    tabcolor[lewhcmpl]=255
304    tabcolor[lewh]=bytscl(tabcolor[lewh], top=254)
305  endif else begin
306    tabcolor=bytscl(tabcolor, top=254)
307  endelse
308
309  ; Display the warped image on the map at the proper position:
310  TV, tabcolor, Startx, Starty
311
312  ; Draw gridlines over the map and image:
313  MAP_GRID, latdel=10, londel=10, /LABEL, /HORIZON  , color=0
314
315  ; Draw continent outlines:
316  MAP_CONTINENTS, /coasts, color=0
317
318;saveimage, 'test_b3_05.png', PNG=PNG
319;saveimage, '20060802_ficdat_orb2_sajust.png', PNG=PNG
320
321   window, 3
322   loadct, 39
323   map_set, limit=[minlat,minlon,maxlat,maxlon]
324
325   tabcolor = MAP_IMAGE(maskg,Startx,Starty, COMPRESS=1, $
326     LATMIN=minlat, LONMIN=minlon, $
327     LATMAX=maxlat, LONMAX=maxlon, $
328     max_value=2., min_value=-1., missing=val_err)
329
330   lewh=where(tabcolor ne val_err, cnt, complement=lewhcmpl)
331   if (cnt ne n_elements(tabcolor)) then begin
332     tabcolor[lewhcmpl]=255
333     tabcolor[lewh]=bytscl(tabcolor[lewh], top=254)
334   endif else begin
335     tabcolor=bytscl(tabcolor, top=254)
336   endelse
337
338;   ; Display the warped image on the map at the proper position:
339   TV, tabcolor, Startx, Starty
340
341;   ; Draw gridlines over the map and image:
342   MAP_GRID, latdel=10, londel=10, /LABEL, /HORIZON  , color=0
343
344;   ; Draw continent outlines:
345   MAP_CONTINENTS, /coasts, color=0
346
347;saveimage, 'essai_mask.png', PNG=PNG
348;saveimage, '20060802_mask_orb2_sajust.png', PNG=PNG
349
350  ret0:
351
352end
353
Note: See TracBrowser for help on using the repository browser.