Changeset 991df6a in flex_extract.git for python/plot_retrieved.py


Ignore:
Timestamp:
May 14, 2018, 10:11:29 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
812283d
Parents:
efdb01a
Message:

finished documentation (except plot_retrieved)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/plot_retrieved.py

    refdb01a r991df6a  
    11#!/usr/bin/env python
    2 # 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 #
    5 # Functionality provided: Simple tool for creating maps and time series of retrieved fields.
    6 #
    7 # Requirements:
    8 # in addition to a standard python 2.6 or 2.7 installation the following packages need to be installed
    9 # ECMWF WebMARS, gribAPI with python enabled, emoslib, ecaccess web toolkit, all available from https://software.ecmwf.int/
    10 # dateutils
    11 # matplotlib (optional, for debugging)
    12 
     2# -*- coding: utf-8 -*-
     3#************************************************************************
     4# TODO AP
     5# - documentation der Funktionen
     6# - docu der progam functionality
     7# - apply pep8
     8#************************************************************************
     9#*******************************************************************************
     10# @Author: Leopold Haimberger (University of Vienna)
     11#
     12# @Date: November 2015
     13#
     14# @Change History:
     15#
     16#    February 2018 - Anne Philipp (University of Vienna):
     17#        - applied PEP8 style guide
     18#        - added documentation
     19#        - created function main and moved the two function calls for
     20#          arguments and plotting into it
     21#
     22# @License:
     23#    (C) Copyright 2015-2018.
     24#
     25#    This software is licensed under the terms of the Apache Licence Version 2.0
     26#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
     27#
     28# @Program Functionality:
     29#    Simple tool for creating maps and time series of retrieved fields.
     30#
     31# @Program Content:
     32#    - plot_retrieved
     33#    - plottimeseries
     34#    - plotmap
     35#    - interpret_plotargs
     36#
     37#*******************************************************************************
     38
     39# ------------------------------------------------------------------------------
     40# MODULES
     41# ------------------------------------------------------------------------------
    1342import datetime
    1443import time
    15 import os,inspect,sys,glob
    16 import socket
    17 # add path to submit.py to pythonpath so that python finds its buddies
    18 localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    19 if localpythonpath not in sys.path:
    20     sys.path.append(localpythonpath)
     44import os
     45import inspect
     46import sys
     47import glob
     48from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    2149
    2250from matplotlib.pylab import *
    2351import matplotlib.patches as mpatches
    24 from mpl_toolkits.basemap import Basemap,addcyclic
     52from mpl_toolkits.basemap import Basemap, addcyclic
    2553import matplotlib.colors as mcolors
    2654from matplotlib.font_manager import FontProperties
     
    2856import matplotlib.cm as cmx
    2957import matplotlib.colors as colors
    30 from argparse import ArgumentParser,ArgumentDefaultsHelpFormatter
    31 
    32 from Tools import interpret_args_and_control, silentremove, product
    33 from Control import Control
     58#from rasotools.utils import stats
     59from gribapi import *
     60
     61# add path to pythonpath so that python finds its buddies
     62localpythonpath = os.path.dirname(os.path.abspath(
     63    inspect.getfile(inspect.currentframe())))
     64if localpythonpath not in sys.path:
     65    sys.path.append(localpythonpath)
     66
     67# software specific classes and modules from flex_extract
     68from Tools import silentremove, product
     69from ControlFile import ControlFile
    3470from GribTools import GribTools
    35 from gribapi import *
    36 from rasotools.utils import stats
    37 
    38 def plot_retrieved(args,c):
    39 
    40     start = datetime.datetime.strptime(c.start_date,'%Y%m%d%H')
    41     end = datetime.datetime.strptime(c.end_date,'%Y%m%d%H')
    42 
    43     c.paramIds=asarray(c.paramIds,dtype='int')
    44     c.levels=asarray(c.levels,dtype='int')
    45     c.area=asarray(c.area)
    46 
    47     index_keys=["date","time","step"]
    48     indexfile=c.inputdir+"/date_time_stepRange.idx"
     71
     72# ------------------------------------------------------------------------------
     73# FUNCTION
     74# ------------------------------------------------------------------------------
     75def main():
     76    '''
     77    @Description:
     78        If plot_retrieved is called from command line, this function controls
     79        the program flow and calls the argumentparser function and
     80        the plot_retrieved function for plotting the retrieved GRIB data.
     81
     82    @Input:
     83        <nothing>
     84
     85    @Return:
     86        <nothing>
     87    '''
     88    args, c = interpret_plotargs()
     89    plot_retrieved(args, c)
     90
     91    return
     92
     93def plot_retrieved(args, c):
     94    '''
     95    @Description:
     96        Reads GRIB data from a specified time period, a list of levels
     97        and a specified list of parameter.
     98
     99    @Input:
     100        args: instance of ArgumentParser
     101            Contains the commandline arguments from script/program call.
     102
     103        c: instance of class ControlFile
     104            Contains all necessary information of a CONTROL file. The parameters
     105            are: DAY1, DAY2, DTIME, MAXSTEP, TYPE, TIME, STEP, CLASS, STREAM,
     106            NUMBER, EXPVER, GRID, LEFT, LOWER, UPPER, RIGHT, LEVEL, LEVELIST,
     107            RESOL, GAUSS, ACCURACY, OMEGA, OMEGADIFF, ETA, ETADIFF, DPDETA,
     108            SMOOTH, FORMAT, ADDPAR, WRF, CWC, PREFIX, ECSTORAGE, ECTRANS,
     109            ECFSDIR, MAILOPS, MAILFAIL, GRIB2FLEXPART, DEBUG, INPUTDIR,
     110            OUTPUTDIR, FLEXPART_ROOT_SCRIPTS
     111            For more information about format and content of the parameter see
     112            documentation.
     113
     114    @Return:
     115        <nothing>
     116    '''
     117    start = datetime.datetime.strptime(c.start_date, '%Y%m%d%H')
     118    end = datetime.datetime.strptime(c.end_date, '%Y%m%d%H')
     119
     120    c.paramIds = asarray(c.paramIds, dtype='int')
     121    c.levels = asarray(c.levels, dtype='int')
     122    c.area = asarray(c.area)
     123
     124    index_keys = ["date", "time", "step"]
     125    indexfile = c.inputdir + "/date_time_stepRange.idx"
    49126    silentremove(indexfile)
    50     files=glob.glob(c.inputdir+'/'+c.prefix+'*')
    51     grib=GribTools(files)
    52     iid=grib.index(index_keys=index_keys, index_file = indexfile)
    53 
    54     gdict=dict(Ni = 360, Nj = 181,  iScansNegatively = 0,  jScansPositively = 0,
    55                jPointsAreConsecutive = 0,  alternativeRowScanning = 0,
    56                latitudeOfFirstGridPointInDegrees = 90,
    57                longitudeOfFirstGridPointInDegrees = 181,
    58                latitudeOfLastGridPointInDegrees = -90,
    59                longitudeOfLastGridPointInDegrees = 180,
    60                iDirectionIncrementInDegrees = 1,
    61                jDirectionIncrementInDegrees = 1
    62                )
     127    files = glob.glob(c.inputdir + '/' + c.prefix + '*')
     128    grib = GribTools(files)
     129    iid = grib.index(index_keys=index_keys, index_file = indexfile)
     130
     131    gdict = dict(Ni = 360, Nj = 181,
     132                iScansNegatively = 0,  jScansPositively = 0,
     133                jPointsAreConsecutive = 0,  alternativeRowScanning = 0,
     134                latitudeOfFirstGridPointInDegrees = 90,
     135                longitudeOfFirstGridPointInDegrees = 181,
     136                latitudeOfLastGridPointInDegrees = -90,
     137                longitudeOfLastGridPointInDegrees = 180,
     138                iDirectionIncrementInDegrees = 1,
     139                jDirectionIncrementInDegrees = 1
     140                )
    63141
    64142    index_vals = []
    65143    for key in index_keys:
    66         key_vals = grib_index_get(iid,key)
     144        key_vals = grib_index_get(iid, key)
    67145        print key_vals
    68146
    69147        index_vals.append(key_vals)
    70148
    71     fdict=dict()
    72     fmeta=dict()
    73     fstamp=dict()
     149    fdict = dict()
     150    fmeta = dict()
     151    fstamp = dict()
    74152    for p in c.paramIds:
    75153        for l in c.levels:
    76             key='{:0>3}_{:0>3}'.format(p,l)
    77             fdict[key]=[]
    78             fmeta[key]=[]
    79             fstamp[key]=[]
     154            key = '{:0>3}_{:0>3}'.format(p, l)
     155            fdict[key] = []
     156            fmeta[key] = []
     157            fstamp[key] = []
    80158    for prod in product(*index_vals):
    81159        for i in range(len(index_keys)):
    82             grib_index_select(iid,index_keys[i],prod[i])
     160            grib_index_select(iid, index_keys[i], prod[i])
    83161
    84162        gid = grib_new_from_index(iid)
    85 #        if gid is not None:
    86163
    87164        while(gid is not None):
    88165            date = grib_get(gid, 'date')
    89             fdate= datetime.datetime(date/10000,mod(date,10000)/100,mod(date,100))
     166            fdate = datetime.datetime(date/10000, mod(date,10000)/100,
     167                                      mod(date,100))
    90168            gtime = grib_get(gid, 'time')
    91169            step = grib_get(gid, 'step')
    92             fdatetime=fdate+datetime.timedelta(hours=gtime/100)
    93 #            if fdatetime<start or fdatetime>end:
    94 #                break
     170            fdatetime = fdate + datetime.timedelta(hours=gtime/100)
    95171            gtype = grib_get(gid, 'type')
    96172            paramId = grib_get(gid, 'paramId')
    97173            parameterName = grib_get(gid, 'parameterName')
    98             level=grib_get(gid,'level')
    99             if step>=c.start_step and step <=c.end_step and fdatetime>=start and fdatetime<=end and paramId in c.paramIds and level in c.levels:
    100                 key='{:0>3}_{:0>3}'.format(paramId,level)
     174            level = grib_get(gid, 'level')
     175            if step >= c.start_step and step <= c.end_step and \
     176               fdatetime >= start and fdatetime <= end and \
     177               paramId in c.paramIds and level in c.levels:
     178                key = '{:0>3}_{:0>3}'.format(paramId, level)
    101179                print key
    102                 fdatetimestep=fdatetime+datetime.timedelta(hours=step)
    103                 if len(fstamp)==0:
     180                fdatetimestep = fdatetime + datetime.timedelta(hours=step)
     181                if len(fstamp) == 0:
    104182                    fstamp[key].append(fdatetimestamp)
    105                     fmeta[key].append((paramId,parameterName,gtype,fdatetime,gtime,step,level))
    106                     fdict[key].append(flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']])))
     183                    fmeta[key].append((paramId, parameterName, gtype,
     184                                       fdatetime, gtime, step, level))
     185                    fdict[key].append(flipud(reshape(
     186                            grib_get_values(gid), [gdict['Nj'], gdict['Ni']])))
    107187                else:
    108                     i=0
    109                     inserted=False
     188                    i = 0
     189                    inserted = False
    110190                    for i in range(len(fstamp[key])):
    111                         if fdatetimestep<fstamp[key][i]:
    112                             fstamp[key][i:i]=[fdatetimestep]
    113                             fmeta[key][i:i]=[(paramId,parameterName,gtype,fdatetime,gtime,step,level)]
    114                             fdict[key][i:i]=[flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']]))]
    115                             inserted=True
     191                        if fdatetimestep < fstamp[key][i]:
     192                            fstamp[key][i:i] = [fdatetimestep]
     193                            fmeta[key][i:i] = [(paramId, parameterName, gtype,
     194                                                fdatetime, gtime, step, level)]
     195                            fdict[key][i:i] = [flipud(reshape(
     196                                                grib_get_values(gid),
     197                                                [gdict['Nj'], gdict['Ni']]))]
     198                            inserted = True
    116199                            break
    117200                    if not inserted:
    118201                        fstamp[key].append(fdatetimestep)
    119                         fmeta[key].append((paramId,parameterName,gtype,fdatetime,gtime,step,level))
    120                         fdict[key].append(flipud(reshape(grib_get_values(gid),[gdict['Nj'],gdict['Ni']])))
    121 
     202                        fmeta[key].append((paramId, parameterName, gtype,
     203                                           fdatetime, gtime, step, level))
     204                        fdict[key].append(flipud(reshape(
     205                            grib_get_values(gid), [gdict['Nj'], gdict['Ni']])))
    122206
    123207            grib_release(gid)
     
    125209
    126210    for k in fdict.keys():
    127         fml=fmeta[k]
    128         fdl=fdict[k]
    129 
    130         for fd,fm in zip(fdl,fml):
    131             ftitle=fm[1]+' {} '.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+' '+stats(fd)
    132             pname='_'.join(fm[1].split())+'_{}_'.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+'.{:0>3}'.format(fm[5])
    133             plotmap(fd, fm,gdict,ftitle,pname+'.eps')
     211        fml = fmeta[k]
     212        fdl = fdict[k]
     213
     214        for fd, fm in zip(fdl, fml):
     215            ftitle = fm[1] + ' {} '.format(fm[-1]) + \
     216                datetime.datetime.strftime(fm[3], '%Y%m%d%H') #+ ' ' + stats(fd)
     217            pname = '_'.join(fm[1].split()) + '_{}_'.format(fm[-1]) + \
     218                datetime.datetime.strftime(fm[3], '%Y%m%d%H') + \
     219                '.{:0>3}'.format(fm[5])
     220            plotmap(fd, fm, gdict, ftitle, pname + '.eps')
    134221
    135222    for k in fdict.keys():
    136         fml=fmeta[k]
    137         fdl=fdict[k]
    138         fsl=fstamp[k]
     223        fml = fmeta[k]
     224        fdl = fdict[k]
     225        fsl = fstamp[k]
    139226        if fdl:
    140             fm=fml[0]
    141             fd=fdl[0]
    142             ftitle=fm[1]+' {} '.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+' '+stats(fd)
    143             pname='_'.join(fm[1].split())+'_{}_'.format(fm[-1])+datetime.datetime.strftime(fm[3],'%Y%m%d%H')+'.{:0>3}'.format(fm[5])
    144             lat=-20
    145             lon=20
    146             plottimeseries(fdl,fml,fsl,lat,lon, gdict, ftitle, pname+'.eps')
    147 
    148 def plottimeseries(flist,fmetalist,ftimestamps,lat,lon,gdict,ftitle,filename):
    149     t1=time.time()
    150     latindex=(lat+90)*180/(gdict['Nj']-1)
    151     lonindex=(lon+179)*360/gdict['Ni']
    152     farr=asarray(flist)
    153     ts=farr[:,latindex,lonindex]
    154     f=plt.figure(figsize=(12,6.7))
    155     plt.plot(ftimestamps,ts)
     227            fm = fml[0]
     228            fd = fdl[0]
     229            ftitle = fm[1] + ' {} '.format(fm[-1]) + \
     230                datetime.datetime.strftime(fm[3], '%Y%m%d%H') #+ ' ' + stats(fd)
     231            pname = '_'.join(fm[1].split()) + '_{}_'.format(fm[-1]) + \
     232                datetime.datetime.strftime(fm[3], '%Y%m%d%H') + \
     233                '.{:0>3}'.format(fm[5])
     234            lat = -20
     235            lon = 20
     236            plottimeseries(fdl, fml, fsl, lat, lon,
     237                           gdict, ftitle, pname + '.eps')
     238
     239    return
     240
     241def plottimeseries(flist, fmetalist, ftimestamps, lat, lon,
     242                   gdict, ftitle, filename):
     243    '''
     244    @Description:
     245
     246    @Input:
     247        flist:
     248            The actual data values to be plotted from the grib messages.
     249
     250        fmetalist: list of strings
     251            Contains some meta date for the data field to be plotted:
     252            parameter id, parameter Name, grid type, date and time,
     253            time, forecast step, level
     254
     255        ftimestamps: list of datetime
     256            Contains the time stamps in a datetime format, e.g.
     257
     258        lat:
     259
     260        lon:
     261
     262        gdict:
     263
     264        ftitle: string
     265            The title of the timeseries.
     266
     267        filename: string
     268            The time series is stored in a file with this name.
     269
     270    @Return:
     271        <nothing>
     272    '''
     273    t1 = time.time()
     274    latindex = (lat + 90) * 180 / (gdict['Nj'] - 1)
     275    lonindex = (lon + 179) * 360 / gdict['Ni']
     276    farr = asarray(flist)
     277    ts = farr[:, latindex, lonindex]
     278    f = plt.figure(figsize=(12,6.7))
     279    plt.plot(ftimestamps, ts)
    156280    plt.title(ftitle)
    157     savefig(c.outputdir+'/'+filename)
    158     print 'created ',c.outputdir+'/'+filename
     281    savefig(c.outputdir + '/' + filename)
     282    print 'created ', c.outputdir + '/' + filename
    159283    plt.close(f)
    160     print time.time()-t1,'s'
    161 
    162 def plotmap(flist,fmetalist,gdict,ftitle,filename):
    163     t1=time.time()
    164     f=plt.figure(figsize=(12,6.7))
     284    print time.time() - t1, 's'
     285
     286    return
     287
     288def plotmap(flist, fmetalist, gdict, ftitle, filename):
     289    '''
     290    @Description:
     291
     292    @Input:
     293        flist
     294        fmetalist
     295        gdict
     296        ftitle
     297        filename
     298
     299    @Return:
     300        <nothing>
     301    '''
     302    t1 = time.time()
     303    f = plt.figure(figsize=(12, 6.7))
    165304    mbaxes = f.add_axes([0.05, 0.15, 0.8, 0.7])
    166     m =Basemap(llcrnrlon=-180.,llcrnrlat=-90.,urcrnrlon=180,urcrnrlat=90.)
     305    m = Basemap(llcrnrlon=-180., llcrnrlat=-90., urcrnrlon=180, urcrnrlat=90.)
    167306    #if bw==0 :
    168307        #fill_color=rgb(0.6,0.8,1)
     
    170309        #fill_color=rgb(0.85,0.85,0.85)
    171310
    172     lw=0.3
     311    lw = 0.3
    173312    m.drawmapboundary()
    174     parallels = arange(-90.,91,90.)
    175     # labels = [left,right,top,bottom]
    176     m.drawparallels(parallels,labels=[True,True,True,True],linewidth=lw)
    177     meridians = arange(-180.,181.,60.)
    178     m.drawmeridians(meridians,labels=[True,True,True,True],linewidth=lw)
     313    parallels = arange(-90., 91, 90.)
     314    # labels = [left, right, top, bottom]
     315    m.drawparallels(parallels, labels=[True, True, True, True], linewidth=lw)
     316    meridians = arange(-180., 181., 60.)
     317    m.drawmeridians(meridians, labels=[True, True, True, True], linewidth=lw)
    179318    m.drawcoastlines(linewidth=lw)
    180     xleft=gdict['longitudeOfFirstGridPointInDegrees']
    181     if xleft>180.0:
    182         xleft-=360.
    183     x=linspace(xleft,gdict['longitudeOfLastGridPointInDegrees'],gdict['Ni'])
    184     y=linspace(gdict['latitudeOfLastGridPointInDegrees'],gdict['latitudeOfFirstGridPointInDegrees'],gdict['Nj'])
    185     xx, yy = m(*meshgrid(x,y))
    186 
    187     s=m.contourf(xx,yy, flist)
    188     title(ftitle,y=1.1)
     319    xleft = gdict['longitudeOfFirstGridPointInDegrees']
     320    if xleft > 180.0:
     321        xleft -= 360.
     322    x = linspace(xleft, gdict['longitudeOfLastGridPointInDegrees'], gdict['Ni'])
     323    y = linspace(gdict['latitudeOfLastGridPointInDegrees'],
     324                 gdict['latitudeOfFirstGridPointInDegrees'], gdict['Nj'])
     325    xx, yy = m(*meshgrid(x, y))
     326
     327    s = m.contourf(xx, yy, flist)
     328    title(ftitle, y=1.1)
    189329    cbaxes = f.add_axes([0.9, 0.2, 0.04, 0.6])
    190     cb=colorbar(cax=cbaxes)
    191 
    192     savefig(c.outputdir+'/'+filename)
    193     print 'created ',c.outputdir+'/'+filename
     330    cb = colorbar(cax=cbaxes)
     331
     332    savefig(c.outputdir + '/' + filename)
     333    print 'created ', c.outputdir + '/' + filename
    194334    plt.close(f)
    195     print time.time()-t1,'s'
    196 
    197 
    198 def interpret_plotargs(*args,**kwargs):
    199 
    200     parser = ArgumentParser(description='Retrieve FLEXPART input from ECMWF MARS archive',
     335    print time.time() - t1, 's'
     336
     337    return
     338
     339def interpret_plotargs():
     340    '''
     341    @Description:
     342        Assigns the command line arguments and reads CONTROL file
     343        content. Apply default values for non mentioned arguments.
     344
     345    @Input:
     346        <nothing>
     347
     348    @Return:
     349        args: instance of ArgumentParser
     350            Contains the commandline arguments from script/program call.
     351
     352        c: instance of class ControlFile
     353            Contains all necessary information of a CONTROL file. The parameters
     354            are: DAY1, DAY2, DTIME, MAXSTEP, TYPE, TIME, STEP, CLASS, STREAM,
     355            NUMBER, EXPVER, GRID, LEFT, LOWER, UPPER, RIGHT, LEVEL, LEVELIST,
     356            RESOL, GAUSS, ACCURACY, OMEGA, OMEGADIFF, ETA, ETADIFF, DPDETA,
     357            SMOOTH, FORMAT, ADDPAR, WRF, CWC, PREFIX, ECSTORAGE, ECTRANS,
     358            ECFSDIR, MAILOPS, MAILFAIL, GRIB2FLEXPART, DEBUG, INPUTDIR,
     359            OUTPUTDIR, FLEXPART_ROOT_SCRIPTS
     360            For more information about format and content of the parameter see
     361            documentation.
     362    '''
     363    parser = ArgumentParser(description='Retrieve FLEXPART input from ' + \
     364                            'ECMWF MARS archive',
    201365                            formatter_class=ArgumentDefaultsHelpFormatter)
    202366
     
    212376                         help="end_step in hours")
    213377
    214 # some arguments that override the default in the control file
    215     parser.add_argument("--levelist", dest="levelist",help="Vertical levels to be retrieved, e.g. 30/to/60")
    216     parser.add_argument("--area", dest="area", help="area defined as north/west/south/east")
    217     parser.add_argument("--paramIds", dest="paramIds", help="parameter IDs")
    218     parser.add_argument("--prefix", dest="prefix",default='EN', help="output file name prefix")
     378# some arguments that override the default in the CONTROL file
     379    parser.add_argument("--levelist", dest="levelist",
     380                        help="Vertical levels to be retrieved, e.g. 30/to/60")
     381    parser.add_argument("--area", dest="area",
     382                        help="area defined as north/west/south/east")
     383    parser.add_argument("--paramIds", dest="paramIds",
     384                        help="parameter IDs")
     385    parser.add_argument("--prefix", dest="prefix", default='EN',
     386                        help="output file name prefix")
    219387
    220388# set the working directories
    221     parser.add_argument("--inputdir", dest="inputdir",default=None,
     389    parser.add_argument("--inputdir", dest="inputdir", default=None,
    222390                        help="root directory for storing intermediate files")
    223     parser.add_argument("--outputdir", dest="outputdir",default=None,
     391    parser.add_argument("--outputdir", dest="outputdir", default=None,
    224392                        help="root directory for storing output files")
    225393    parser.add_argument("--flexpart_root_scripts", dest="flexpart_root_scripts",
    226                         help="FLEXPART root directory (to find grib2flexpart and COMMAND file)\n\
    227                               Normally ECMWFDATA resides in the scripts directory of the FLEXPART distribution")
    228 
    229     parser.add_argument("--controlfile", dest="controlfile",default='CONTROL.temp',
    230                         help="file with control parameters")
     394                        help="FLEXPART root directory (to find \
     395                        'grib2flexpart and COMMAND file)\n \
     396                        Normally ECMWFDATA resides in the scripts directory \
     397                        of the FLEXPART distribution")
     398
     399    parser.add_argument("--controlfile", dest="controlfile",
     400                        default='CONTROL.temp', help="file with CONTROL parameters")
    231401    args = parser.parse_args()
    232402
    233403    try:
    234         c=Control(args.controlfile)
     404        c = ControlFile(args.controlfile)
    235405    except IOError:
    236406        try:
    237             c=Control(localpythonpath+args.controlfile)
     407            c = ControlFile(localpythonpath + args.controlfile)
    238408
    239409        except:
    240             print 'Could not read control file "'+args.controlfile+'"'
     410            print 'Could not read CONTROL file "' + args.controlfile + '"'
    241411            print 'Either it does not exist or its syntax is wrong.'
    242             print 'Try "'+sys.argv[0].split('/')[-1]+' -h" to print usage information'
     412            print 'Try "' + sys.argv[0].split('/')[-1] + \
     413                  ' -h" to print usage information'
    243414            exit(1)
    244415
    245416    if args.levelist:
    246         c.levels=args.levelist.split('/')
     417        c.levels = args.levelist.split('/')
    247418    else:
    248         c.levels=[0]
     419        c.levels = [0]
    249420    if args.area:
    250         c.area=args.area.split('/')
     421        c.area = args.area.split('/')
    251422    else:
    252         c.area='[0,0]'
    253 
    254     c.paramIds=args.paramIds.split('/')
     423        c.area = '[0,0]'
     424
     425    c.paramIds = args.paramIds.split('/')
    255426    if args.start_step:
    256         c.start_step=int(args.start_step)
     427        c.start_step = int(args.start_step)
    257428    else:
    258         c.start_step=0
     429        c.start_step = 0
    259430    if args.end_step:
    260         c.end_step=int(args.end_step)
     431        c.end_step = int(args.end_step)
    261432    else:
    262         c.end_step=0
    263 
    264     c.start_date=args.start_date
    265     c.end_date=args.end_date
    266     c.prefix=args.prefix
    267     c.inputdir=args.inputdir
     433        c.end_step = 0
     434
     435    c.start_date = args.start_date
     436    c.end_date = args.end_date
     437    c.prefix = args.prefix
     438    c.inputdir = args.inputdir
    268439    if args.outputdir:
    269         c.outputdir=args.outputdir
     440        c.outputdir = args.outputdir
    270441    else:
    271         c.outputdir=c.inputdir
    272 
    273         return args,c
     442        c.outputdir = c.inputdir
     443
     444    return args, c
    274445
    275446if __name__ == "__main__":
    276 
    277     args,c=interpret_plotargs()
    278     plot_retrieved(args,c)
     447    main()
     448
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG