Subversion Repositories lagranto.ecmwf

Rev

Rev 35 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35 Rev 36
Line 1... Line 1...
1
#!/usr/bin/env python
1
#!/usr/bin/python
2
# -*- coding:utf-8 -*-
-
 
3
 
2
 
4
# ---------------------------------------------------------------------
3
# =============================================================================
5
# import modules
4
# Quick Viewer for meteorological fields from ECMWF
6
# ---------------------------------------------------------------------
5
# Michael Sprenger, Sebastian Limbach [ based on IWAL], Winter 2012/13  
-
 
6
# =============================================================================
7
 
7
 
-
 
8
#  Imports
8
from __future__ import print_function
9
import os
9
import sys
10
import sys
86
 
243
 
87
    if args.save is None:
-
 
88
        plt.show()
-
 
89
    else:
244
else:
90
        plt.savefig(args.save, bbox_inches='tight')
245
    sys.exit('Unsupported input file ' + inpfile);
91
 
246
 
-
 
247
# Check whether the input file is available
-
 
248
if os.path.exists(inpfile_folder+inpfile_filename):
-
 
249
    print 'input file found: ' + inpfile_folder + inpfile_filename
-
 
250
else:
-
 
251
    sys.exit( 'input file is missing : ' + inpfile_folder + inpfile_filename )
-
 
252
    
-
 
253
# Check whether field is available on input file
-
 
254
cmd        = 'getvars ' + inpfile_folder + '/' + inpfile_filename
-
 
255
proc       = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
-
 
256
(out, err) = proc.communicate()  
-
 
257
ok         = any( (elem.strip() == field_fieldname) for elem in out.split('\n') ) 
-
 
258
 
-
 
259
# If not available, try to calculate it with p2s
-
 
260
if ( ok == False ):
-
 
261
    print 'Try to calculate '+field_fieldname+' with p2s'
-
 
262
    cmd = 'p2s ' + inpfile_folder + '/' + inpfile_filename
-
 
263
    print 'NOT YET IMPLEMTED'
-
 
264
 
-
 
265
if ok == False:
-
 
266
    sys.exit('variable '+field_fieldname+' missing on '+inpfile_filename);
-
 
267
 
-
 
268
# ----------------------------------------------------------------------------
-
 
269
# Set the color table
-
 
270
# ----------------------------------------------------------------------------
-
 
271
 
-
 
272
color_split = options.color.split(',')
-
 
273
 
-
 
274
if len(color_split) == 5:
-
 
275
    color_cmin = color_split[0]
-
 
276
    color_cmax = color_split[1]
-
 
277
    color_mode = color_split[2]
-
 
278
    color_ncol = color_split[3]
-
 
279
    color_name = color_split[4]
-
 
280
 
-
 
281
elif len(color_split) == 4:
-
 
282
    color_cmin = color_split[0]
-
 
283
    color_cmax = color_split[1]
-
 
284
    color_mode = color_split[2]
-
 
285
    color_ncol = color_split[3]
-
 
286
    color_name = 'adjust'
-
 
287
 
-
 
288
elif len(color_split) == 3:
-
 
289
    color_cmin = color_split[0]
-
 
290
    color_cmax = color_split[1]
-
 
291
    color_mode = color_split[2]
-
 
292
    color_ncol = 18
-
 
293
    color_name = 'hotcold_18lev'
-
 
294
 
-
 
295
elif len(color_split) == 2:
-
 
296
    color_cmin = color_split[0]
-
 
297
    color_cmax = color_split[1]
-
 
298
    color_mode = 'fill'
-
 
299
    color_ncol = '18'
-
 
300
    color_name = 'hotcold_18lev'
-
 
301
 
-
 
302
elif (color_split[0] == 'PV.default') | ( color_split[0] == 'NONE' ) & ( field_fieldname == 'PV' ):
-
 
303
    color_cmin = '-0.5'
-
 
304
    color_cmax = '10.'
-
 
305
    color_mode = 'fill'
-
 
306
    color_ncol = 'adjust'
-
 
307
    color_name = 'PV.default'
-
 
308
 
-
 
309
elif color_split[0] == 'NONE':
-
 
310
    color_cmin = 'p95'
-
 
311
    color_cmax = 'p05'
-
 
312
    color_mode = 'fill'
-
 
313
    color_ncol = '18'
-
 
314
    color_name = 'hotcold_18lev'
-
 
315
 
-
 
316
# ----------------------------------------------------------------------------
-
 
317
# Set the horizontal domain
-
 
318
# ----------------------------------------------------------------------------
-
 
319
 
-
 
320
# Set the geographical projection 
-
 
321
projection = options.projection
-
 
322
print projection      
-
 
323
 
-
 
324
domain_split = options.domain.split(',')
-
 
325
 
-
 
326
print domain_split
-
 
327
 
-
 
328
if len(domain_split) == 4:
-
 
329
    domain_xmin = domain_split[0]
-
 
330
    domain_xmax = domain_split[1]
-
 
331
    domain_ymin = domain_split[2]
-
 
332
    domain_ymax = domain_split[3]
-
 
333
 
-
 
334
elif ( len(domain_split) == 1 ) & (options.domain == 'europe' ):
-
 
335
    domain_xmin = -20
-
 
336
    domain_xmax = 40
-
 
337
    domain_ymin = 30
-
 
338
    domain_ymax = 75
-
 
339
 
-
 
340
elif ( len(domain_split) == 1 ) & (options.domain == 'natlantic' ):
-
 
341
    domain_xmin = -100
-
 
342
    domain_xmax = 10
-
 
343
    domain_ymin = 10
-
 
344
    domain_ymax = 75
-
 
345
 
-
 
346
elif ( len(domain_split) == 1 ) & (options.domain == 'global' ):
-
 
347
    domain_xmin = -180
-
 
348
    domain_xmax = 180
-
 
349
    domain_ymin = -90
-
 
350
    domain_ymax = 90
-
 
351
 
-
 
352
elif ( len(domain_split) == 1 ) & (options.domain == 'nhem' ):
-
 
353
    domain_xmin = -180
-
 
354
    domain_xmax = 180
-
 
355
    domain_ymin = 0
-
 
356
    domain_ymax = 90
-
 
357
 
-
 
358
elif ( len(domain_split) == 1 ) & (options.domain == 'shem' ):
-
 
359
    domain_xmin = -180
-
 
360
    domain_xmax = 180
-
 
361
    domain_ymin = -90
-
 
362
    domain_ymax = 0
-
 
363
    
-
 
364
elif ( len(domain_split) == 2 ):
-
 
365
    domain_xmin = -180
-
 
366
    domain_xmax = 180
-
 
367
    domain_ymin = domain_split[0]
-
 
368
    domain_ymax = domain_split[1]
-
 
369
 
-
 
370
elif ( projection == 'np' ):
-
 
371
    domain_xmin = -180
-
 
372
    domain_xmax = 180
-
 
373
    domain_ymin = 30
-
 
374
    domain_ymax = 90
-
 
375
 
-
 
376
elif ( projection == 'sp' ):
-
 
377
    domain_xmin = -180
-
 
378
    domain_xmax = 180
-
 
379
    domain_ymin = -90
-
 
380
    domain_ymax = -30
92
 
381
    
-
 
382
else:
-
 
383
    domain_xmin = 'adjust'
-
 
384
    domain_xmax = 'adjust'
-
 
385
    domain_ymin = 'adjust'
-
 
386
    domain_ymax = 'adjust'
-
 
387
 
-
 
388
# Check that the geographical domain is reasonable
-
 
389
if ( domain_xmin != 'adjust' ):
-
 
390
    if (domain_xmin >= domain_xmax) | (domain_ymin >= domain_ymax):
-
 
391
        sys.exit('domain problem:')
-
 
392
 
-
 
393
# ----------------------------------------------------------------------------
-
 
394
# Set the settings for vertical cross section
-
 
395
# ----------------------------------------------------------------------------
-
 
396
 
-
 
397
vertical_split = options.vertical.split(',')
-
 
398
 
-
 
399
if len(vertical_split) == 7:
-
 
400
    vertical_lon1 = vertical_split[0]
-
 
401
    vertical_lat1 = vertical_split[1]
-
 
402
    vertical_lon2 = vertical_split[2]
-
 
403
    vertical_lat2 = vertical_split[3]
-
 
404
    vertical_lev1 = vertical_split[4]
-
 
405
    vertical_lev2 = vertical_split[5]
-
 
406
    vertical_type = vertical_split[6]
-
 
407
 
-
 
408
if len(vertical_split) == 6:
-
 
409
    vertical_lon1 = vertical_split[0]
-
 
410
    vertical_lat1 = vertical_split[1]
-
 
411
    vertical_lon2 = vertical_split[2]
-
 
412
    vertical_lat2 = vertical_split[3]
-
 
413
    vertical_lev1 = vertical_split[4]
-
 
414
    vertical_lev2 = vertical_split[5]
-
 
415
    vertical_type = 'linear'
-
 
416
 
-
 
417
if len(vertical_split) == 4:
-
 
418
    vertical_lon1 = vertical_split[0]
-
 
419
    vertical_lat1 = vertical_split[1]
-
 
420
    vertical_lon2 = vertical_split[2]
-
 
421
    vertical_lat2 = vertical_split[3]
-
 
422
    vertical_lev1 = 1030
-
 
423
    vertical_lev2 = 100
-
 
424
    vertical_type = 'linear'
-
 
425
 
-
 
426
elif ( len(vertical_split) == 1 ) & (options.vertical == 'zurich.ns' ):
-
 
427
    vertical_lon1 = 8.538
-
 
428
    vertical_lat1 = 47.3690 - 7.5
-
 
429
    vertical_lon2 = 8.538
-
 
430
    vertical_lat2 = 47.3690 + 7.5
-
 
431
    vertical_lev1 = 1030
-
 
432
    vertical_lev2 = 100
-
 
433
    vertical_type = 'linear'
-
 
434
 
-
 
435
# ----------------------------------------------------------------------------
-
 
436
# Set the profile settings
-
 
437
# ----------------------------------------------------------------------------
-
 
438
 
-
 
439
profile_split = options.profile.split(',')
-
 
440
 
-
 
441
if len(profile_split) == 4:
-
 
442
    profile_lon  = profile_split[0]
-
 
443
    profile_lat  = profile_split[1]
-
 
444
    profile_lev1 = profile_split[2]
-
 
445
    profile_lev2 = profile_split[3]
-
 
446
 
-
 
447
elif len(profile_split) == 2:
-
 
448
    profile_lon  = profile_split[0]
-
 
449
    profile_lat  = profile_split[1]
-
 
450
    profile_lev1 = 1030
-
 
451
    profile_lev2 = 100
-
 
452
 
-
 
453
# ----------------------------------------------------------------------------
-
 
454
# Horizontal cross section 
-
 
455
# ----------------------------------------------------------------------------
-
 
456
 
-
 
457
if ( mode == 'horizontal' ):
-
 
458
 
-
 
459
    os.system('python ' + SCRIPT_PATH + '/ext_scripts/horizontal.py ' + 
-
 
460
        ' '.join([inpfile_filename, 
-
 
461
                  inpfile_folder, 
-
 
462
                  field_fieldname, 
-
 
463
                  str(field_level),
-
 
464
                  str(domain_xmin),str(domain_xmax),str(domain_ymin),str(domain_ymax), 
-
 
465
                  str(options.npixel), 
-
 
466
                  wsname, 
-
 
467
                  figpath,figname, 
-
 
468
                  str(color_cmin), str(color_ncol), str(color_cmax), color_name, 
-
 
469
                  field_unit,projection,color_mode]))
-
 
470
 
-
 
471
 
-
 
472
 
-
 
473
# ----------------------------------------------------------------------------
-
 
474
# Vertical cross section 
-
 
475
# ----------------------------------------------------------------------------
-
 
476
 
-
 
477
if ( mode == 'vertical' ) :
-
 
478
 
-
 
479
    os.system('python ' + SCRIPT_PATH + '/ext_scripts/vertical.py ' +
-
 
480
          ' '.join([inpfile_filename, 
-
 
481
                    inpfile_folder, 
-
 
482
                    field_fieldname,
-
 
483
                    str(vertical_lon1), str(vertical_lon2), 
-
 
484
                    str(vertical_lat1), str(vertical_lat2), 
-
 
485
                    str(vertical_lev1), str(vertical_lev2),
-
 
486
                    vertical_type, 
-
 
487
                    str(options.npixel), 
-
 
488
                    wsname, 
-
 
489
                    figpath, figname,
-
 
490
                    str(color_cmin), str(color_ncol), str(color_cmax), 
-
 
491
                    color_name,color_mode ]))
-
 
492
 
-
 
493
# ----------------------------------------------------------------------------
-
 
494
# Skew-T/log-P (skewtlogp)
-
 
495
# ----------------------------------------------------------------------------
-
 
496
 
93
if __name__ == '__main__':
497
if ( mode == 'profile' ):
-
 
498
 
-
 
499
    os.system('python ' + SCRIPT_PATH + '/ext_scripts/skewtlogp.py ' +
-
 
500
          ' '.join([inpfile_filename,inpfile_folder,
-
 
501
          str(profile_lon), str(profile_lat), str(profile_lev1), str(profile_lev2),
-
 
502
          str(options.npixel), wsname, figpath, figname ]))
-
 
503
 
-
 
504
 
-
 
505
# ----------------------------------------------------------------------------
-
 
506
# Show the figure if requested
-
 
507
# ----------------------------------------------------------------------------
-
 
508
 
-
 
509
if options.show:
-
 
510
    cmd = 'xv ' + figpath + '/' + figname + '.png'
-
 
511
    subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
-
 
512
 
-
 
513
if options.showremove:
-
 
514
    cmd = 'xv ' + figpath + '/' + figname + '.png; rm ' + figpath + '/' + figname + '.png'
-
 
515
    subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
-
 
516
 
-
 
517
if options.labelbar | ( mode == 'colorbar' ):
-
 
518
 
-
 
519
    figname = 'quickview.color'
-
 
520
    os.system('python ' + SCRIPT_PATH + '/ext_scripts/colorbar.py ' +
-
 
521
          ' '.join([str(options.npixel), wsname, figpath, figname])) 
-
 
522
 
94
    main(sys.argv[1:])
523
    if options.showremove:
-
 
524
        cmd = 'xv ' + figpath + '/quickview.color.png;' + 'rm ' + figpath + '/quickview.color.png'
-
 
525
        subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
-
 
526
    else:
-
 
527
        cmd = 'xv ' + figpath + '/quickview.color.png;'
-
 
528
        subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)