Changeset 64cf353 in flex_extract.git for python/plot_retrieved.py


Ignore:
Timestamp:
Feb 8, 2018, 9:54:05 PM (6 years ago)
Author:
Anne Philipp <bscannephilipp@…>
Branches:
master, ctbto, dev
Children:
02c8c50
Parents:
6180177
Message:

pep8 changes + documentation added + minor code style changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/plot_retrieved.py

    rd69b677 r64cf353  
    11#!/usr/bin/env python
    22# This software is licensed under the terms of the Apache Licence Version 2.0
    3 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 
    4 # 
     3# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
     4#
    55# Functionality provided: Simple tool for creating maps and time series of retrieved fields.
    6 # 
    7 # Requirements: 
     6#
     7# Requirements:
    88# in addition to a standard python 2.6 or 2.7 installation the following packages need to be installed
    99# ECMWF WebMARS, gribAPI with python enabled, emoslib, ecaccess web toolkit, all available from https://software.ecmwf.int/
     
    1919if localpythonpath not in sys.path:
    2020    sys.path.append(localpythonpath)
    21    
     21
    2222from matplotlib.pylab import *
    2323import matplotlib.patches as mpatches
     
    4343    c.levels=asarray(c.levels,dtype='int')
    4444    c.area=asarray(c.area)
    45    
     45
    4646    index_keys=["date","time","step"]
    4747    indexfile=c.inputdir+"/date_time_stepRange.idx"
     
    6767
    6868        index_vals.append(key_vals)
    69    
     69
    7070    fdict=dict()
    7171    fmeta=dict()
     
    101101                fdatetimestep=fdatetime+datetime.timedelta(hours=step)
    102102                if len(fstamp)==0:
    103                     fstamp[key].append(fdatetimestamp)   
     103                    fstamp[key].append(fdatetimestamp)
    104104                    fmeta[key].append((paramId,parameterName,gtype,fdatetime,gtime,step,level))
    105105                    fdict[key].append(flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']])))
     
    118118                        fmeta[key].append((paramId,parameterName,gtype,fdatetime,gtime,step,level))
    119119                        fdict[key].append(flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']])))
    120                    
     120
    121121
    122122            grib_release(gid)
    123123            gid = grib_new_from_index(iid)
    124            
     124
    125125    for k in fdict.keys():
    126126        fml=fmeta[k]
    127127        fdl=fdict[k]
    128        
     128
    129129        for fd,fm in zip(fdl,fml):
    130130            ftitle=fm[1]+' {} '.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+' '+stats(fd)
    131131            pname='_'.join(fm[1].split())+'_{}_'.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+'.{:0>3}'.format(fm[5])
    132132            plotmap(fd, fm,gdict,ftitle,pname+'.eps')
    133        
     133
    134134    for k in fdict.keys():
    135135        fml=fmeta[k]
     
    143143            lat=-20
    144144            lon=20
    145             plottimeseries(fdl,fml,fsl,lat,lon, gdict, ftitle, pname+'.eps')   
    146    
     145            plottimeseries(fdl,fml,fsl,lat,lon, gdict, ftitle, pname+'.eps')
     146
    147147def plottimeseries(flist,fmetalist,ftimestamps,lat,lon,gdict,ftitle,filename):
    148148    t1=time.time()
     
    158158    plt.close(f)
    159159    print time.time()-t1,'s'
    160    
     160
    161161def plotmap(flist,fmetalist,gdict,ftitle,filename):
    162162    t1=time.time()
    163163    f=plt.figure(figsize=(12,6.7))
    164     mbaxes = f.add_axes([0.05, 0.15, 0.8, 0.7]) 
     164    mbaxes = f.add_axes([0.05, 0.15, 0.8, 0.7])
    165165    m =Basemap(llcrnrlon=-180.,llcrnrlat=-90.,urcrnrlon=180,urcrnrlat=90.)
    166166    #if bw==0 :
     
    168168    #else:
    169169        #fill_color=rgb(0.85,0.85,0.85)
    170    
     170
    171171    lw=0.3
    172172    m.drawmapboundary()
     
    179179    xleft=gdict['longitudeOfFirstGridPointInDegrees']
    180180    if xleft>180.0:
    181         xleft-=360. 
     181        xleft-=360.
    182182    x=linspace(xleft,gdict['longitudeOfLastGridPointInDegrees'],gdict['Ni'])
    183183    y=linspace(gdict['latitudeOfLastGridPointInDegrees'],gdict['latitudeOfFirstGridPointInDegrees'],gdict['Nj'])
     
    186186    s=m.contourf(xx,yy, flist)
    187187    title(ftitle,y=1.1)
    188     cbaxes = f.add_axes([0.9, 0.2, 0.04, 0.6]) 
     188    cbaxes = f.add_axes([0.9, 0.2, 0.04, 0.6])
    189189    cb=colorbar(cax=cbaxes)
    190    
     190
    191191    savefig(c.outputdir+'/'+filename)
    192192    print 'created ',c.outputdir+'/'+filename
     
    200200                            formatter_class=ArgumentDefaultsHelpFormatter)
    201201
    202 # the most important arguments 
     202# the most important arguments
    203203    parser.add_argument("--start_date", dest="start_date",
    204204                        help="start date YYYYMMDD")
     
    241241            print 'Try "'+sys.argv[0].split('/')[-1]+' -h" to print usage information'
    242242            exit(1)
    243    
    244     if args.levelist:       
     243
     244    if args.levelist:
    245245        c.levels=args.levelist.split('/')
    246246    else:
     
    250250    else:
    251251        c.area='[0,0]'
    252    
     252
    253253    c.paramIds=args.paramIds.split('/')
    254254    if args.start_step:
     
    269269    else:
    270270        c.outputdir=c.inputdir
    271    
     271
    272272        return args,c
    273273
    274274if __name__ == "__main__":
    275    
     275
    276276    args,c=interpret_plotargs()
    277277    plot_retrieved(args,c)
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG