|
28 | 28 | load_config(config)
|
29 | 29 | from fun_gen import *
|
30 | 30 |
|
| 31 | +# Try to read date as parameters |
| 32 | +# ------------------------------ |
| 33 | +try : |
| 34 | + arg_ini = sys.argv[2] |
| 35 | + arg_end = sys.argv[3] |
| 36 | + |
| 37 | + # Define parameters |
| 38 | + # ----------------- |
| 39 | + mdini = dt.datetime.strptime(arg_ini,'%Y-%m-%d').toordinal() |
| 40 | + mdend = dt.datetime.strptime(arg_end,'%Y-%m-%d').toordinal() |
| 41 | + |
| 42 | +except : |
| 43 | + print('No date arguments given') |
| 44 | + print('=> Saving all in one file\n') |
| 45 | + |
| 46 | + # Define parameters |
| 47 | + # ----------------- |
| 48 | + mdini = dt.datetime.strptime(meteo_ini,'%Y-%m-%d').toordinal() |
| 49 | + mdend = dt.datetime.strptime(meteo_end,'%Y-%m-%d').toordinal() |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
31 | 54 | print('NB /!\: 3-h fields hard coded ...\n')
|
32 | 55 |
|
33 | 56 |
|
|
52 | 75 | LAT,LON = np.meshgrid(lat,lon)
|
53 | 76 |
|
54 | 77 |
|
55 |
| -# Define parameters |
56 |
| -# ----------------- |
57 |
| -mdini = dt.datetime.strptime(meteo_ini,'%Y-%m-%d').toordinal() |
58 |
| -mdend = dt.datetime.strptime(meteo_end,'%Y-%m-%d').toordinal() |
59 | 78 | name = 'reanalysis-cerra-single-levels'
|
60 | 79 |
|
61 | 80 |
|
|
114 | 133 |
|
115 | 134 | full_data = []
|
116 | 135 |
|
| 136 | + # Tag for file name |
| 137 | + tag_ini = dt.datetime.fromordinal(mdini) |
| 138 | + tag_ini = tag_ini.strftime('%Y%m%d') |
| 139 | + |
| 140 | + tag_end = dt.datetime.fromordinal(mdend) |
| 141 | + tag_end = tag_end.strftime('%Y%m%d') |
| 142 | + |
117 | 143 |
|
118 | 144 | # Loop on days
|
119 | 145 | # ------------
|
120 |
| - for jd in range(mdini,mdend+1): |
| 146 | + for jd in range(mdini,mdend+2): |
121 | 147 |
|
122 | 148 | date = dt.datetime.fromordinal(jd)
|
123 | 149 | print(date.strftime('%Y-%m-%d'),end='\r')
|
|
194 | 220 |
|
195 | 221 | # Write variable to NetCDF
|
196 | 222 | # ------------------------
|
197 |
| - oname = name +'_'+ftag+ '_'+ meteo_ini +'_'\ |
198 |
| - + meteo_end +'.nc' |
199 |
| - write_nc_meteo(ncdir+'/'+oname,lon,lat,var,full_data,long_name,units) |
| 223 | + oname = name +'_'+ftag+ '_'+ tag_ini +'_'\ |
| 224 | + + tag_end +'.nc' |
| 225 | + write_nc_meteo(ncdir+'/'+oname,mdini,mdend,lon,lat,var,full_data,long_name,units) |
200 | 226 |
|
201 | 227 | # TEST !!!!!!!
|
202 | 228 | #if ftag == '2m_temperature':
|
203 | 229 | # full_data = full_data[0:2,:,:]
|
204 | 230 |
|
205 | 231 | # Write to binary file
|
206 | 232 | # --------------------
|
207 |
| - full_data.tofile(bindir+'/BC_'+otag+'_'+meteo_ini+'_'+meteo_end,format='float32') |
208 |
| - print('[FILE SAVED] '+bindir+'/BC_'+otag+'_'+meteo_ini+'_'+meteo_end+'\n') |
| 233 | + full_data.tofile(bindir+'/BC_'+otag+'_'+tag_ini+'_'+tag_end,format='float32') |
| 234 | + print('[FILE SAVED] '+bindir+'/BC_'+otag+'_'+tag_ini+'_'+tag_end+'\n') |
209 | 235 |
|
210 | 236 | '''
|
211 | 237 | data = np.fromfile(bindir+'/BC_'+otag+'_'+meteo_ini+'_'+meteo_end,dtype='float32')
|
|
228 | 254 |
|
229 | 255 | print('Processing wind variables :\n')
|
230 | 256 | print('---------------------------\n')
|
231 |
| -for jd in range(mdini,mdend+1): |
| 257 | +for jd in range(mdini,mdend+2): |
232 | 258 |
|
233 | 259 | date = dt.datetime.fromordinal(jd)
|
234 | 260 | print(date.strftime('%Y-%m-%d'),end='\r')
|
|
278 | 304 | oname = name +'_uwind_'+ meteo_ini +'_'\
|
279 | 305 | + meteo_end +'.nc'
|
280 | 306 |
|
281 |
| -write_nc_meteo(ncdir+'/'+oname,lon,lat,'u10',ufull_data,long_name,units) |
| 307 | +write_nc_meteo(ncdir+'/'+oname,mdini,mdend,lon,lat,'u10',ufull_data,long_name,units) |
282 | 308 |
|
283 | 309 | # V10
|
284 | 310 | long_name = '10 meter V wind component'
|
285 | 311 | oname = name +'_vwind_'+ meteo_ini +'_'\
|
286 | 312 | + meteo_end +'.nc'
|
287 | 313 |
|
288 |
| -write_nc_meteo(ncdir+'/'+oname,lon,lat,'v10',vfull_data,long_name,units) |
| 314 | +write_nc_meteo(ncdir+'/'+oname,mdini,mdend,lon,lat,'v10',vfull_data,long_name,units) |
289 | 315 |
|
290 | 316 |
|
291 | 317 | # Write to binary file
|
292 | 318 | # --------------------
|
293 |
| -ufull_data.tofile(bindir+'/BC_uwind_'+meteo_ini+'_'+meteo_end,format='float32') |
294 |
| -print('[FILE SAVED] '+bindir+'/BC_uwind_'+meteo_ini+'_'+meteo_end) |
295 |
| - |
296 |
| -vfull_data.tofile(bindir+'/BC_vwind_'+meteo_ini+'_'+meteo_end,format='float32') |
297 |
| -print('[FILE SAVED] '+bindir+'/BC_vwind_'+meteo_ini+'_'+meteo_end) |
298 |
| - |
| 319 | +ufull_data.tofile(bindir+'/BC_uwind_'+tag_ini+'_'+tag_end,format='float32') |
| 320 | +print('[FILE SAVED] '+bindir+'/BC_uwind_'+tag_ini+'_'+tag_end) |
299 | 321 |
|
| 322 | +vfull_data.tofile(bindir+'/BC_vwind_'+tag_ini+'_'+meteo_end,format='float32') |
| 323 | +print('[FILE SAVED] '+bindir+'/BC_vwind_'+tag_ini+'_'+tag_end) |
0 commit comments