Changeset 991df6a in flex_extract.git for python/Tools.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/Tools.py

    refdb01a r991df6a  
    33#************************************************************************
    44# TODO AP
    5 #AP
    6 # -
     5# - check myerror
     6# - check normalexit
     7# - check getListAsString
     8# - seperate args and control interpretation
    79#************************************************************************
    8 """
    9 
    10 """
     10#*******************************************************************************
     11# @Author: Anne Philipp (University of Vienna)
     12#
     13# @Date: May 2018
     14#
     15# @Change History:
     16#    October 2014 - Anne Fouilloux (University of Oslo)
     17#        - created functions silentremove and product (taken from ECMWF)
     18#
     19#    November 2015 - Leopold Haimberger (University of Vienna)
     20#        - created functions: interpret_args_and_control, cleanup
     21#          myerror, normalexit, init128, toparamId
     22#
     23#    April 2018 - Anne Philipp (University of Vienna):
     24#        - applied PEP8 style guide
     25#        - added documentation
     26#        - moved all functions from file FlexpartTools to this file Tools
     27#        - added function getListAsString
     28#
     29# @License:
     30#    (C) Copyright 2014-2018.
     31#
     32#    This software is licensed under the terms of the Apache Licence Version 2.0
     33#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
     34#
     35# @Modul Description:
     36#    This module contains a couple of helpful functions which are
     37#    used in different places in flex_extract.
     38#
     39# @Module Content:
     40#    - interpret_args_and_control
     41#    - cleanup
     42#    - myerror
     43#    - normalexit
     44#    - product
     45#    - silentremove
     46#    - init128
     47#    - toparamId
     48#    - getListAsString
     49#
     50#*******************************************************************************
     51
    1152# ------------------------------------------------------------------------------
    1253# MODULES
    1354# ------------------------------------------------------------------------------
    14 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    1555import os
    1656import errno
    1757import sys
    1858import glob
     59import traceback
    1960from numpy import *
    2061from gribapi import *
    21 import Control
     62from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
     63
     64# software specific class from flex_extract
     65from ControlFile import ControlFile
    2266
    2367# ------------------------------------------------------------------------------
     
    2872    '''
    2973    @Description:
    30         Assigns the command line arguments and reads control file
     74        Assigns the command line arguments and reads CONTROL file
    3175        content. Apply default values for non mentioned arguments.
    3276
     
    3882            Contains the commandline arguments from script/program call.
    3983
    40         c: instance of class Control
    41             Contains all necessary information of a control file. The parameters
     84        c: instance of class ControlFile
     85            Contains all necessary information of a CONTROL file. The parameters
    4286            are: DAY1, DAY2, DTIME, MAXSTEP, TYPE, TIME, STEP, CLASS, STREAM,
    4387            NUMBER, EXPVER, GRID, LEFT, LOWER, UPPER, RIGHT, LEVEL, LEVELIST,
     
    62106                        help="# of days to be retrieved at once")
    63107
    64     # some arguments that override the default in the control file
     108    # some arguments that override the default in the CONTROL file
    65109    parser.add_argument("--basetime", dest="basetime",
    66110                        help="base such as 00/12 (for half day retrievals)")
     
    96140    parser.add_argument("--controlfile", dest="controlfile",
    97141                        default='CONTROL.temp',
    98                         help="file with control parameters")
     142                        help="file with CONTROL parameters")
    99143    parser.add_argument("--debug", dest="debug", default=0,
    100144                        help="Debug mode - leave temporary files intact")
     
    102146    args = parser.parse_args()
    103147
    104     # create instance of Control for specified controlfile
     148    # create instance of ControlFile for specified controlfile
    105149    # and assign the parameters (and default values if necessary)
    106150    try:
    107         c = Control.Control(args.controlfile)
     151        c = ControlFile(args.controlfile)
    108152    except IOError:
    109153        try:
    110             c = Control.Control(localpythonpath + args.controlfile)
     154            c = ControlFile(localpythonpath + args.controlfile)
    111155        except:
    112             print('Could not read control file "' + args.controlfile + '"')
     156            print('Could not read CONTROL file "' + args.controlfile + '"')
    113157            print('Either it does not exist or its syntax is wrong.')
    114158            print('Try "' + sys.argv[0].split('/')[-1] +
     
    119163    if  args.start_date is None and getattr(c, 'start_date') is None:
    120164        print('start_date specified neither in command line nor \
    121                in control file ' + args.controlfile)
     165               in CONTROL file ' + args.controlfile)
    122166        print('Try "' + sys.argv[0].split('/')[-1] +
    123167              ' -h" to print usage information')
    124168        exit(1)
    125169
    126     # save all existing command line parameter to the Control instance
     170    # save all existing command line parameter to the ControlFile instance
    127171    # if parameter is not specified through the command line or CONTROL file
    128172    # set default values
     
    199243    @Description:
    200244        Remove all files from intermediate directory
    201         (inputdir from control file).
    202 
    203     @Input:
    204         c: instance of class Control
    205             Contains all the parameters of control files, which are e.g.:
     245        (inputdir from CONTROL file).
     246
     247    @Input:
     248        c: instance of class ControlFile
     249            Contains all the parameters of CONTROL file, which are e.g.:
    206250            DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
    207251            STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
     
    240284
    241285    @Input:
    242         c: instance of class Control
    243             Contains all the parameters of control files, which are e.g.:
     286        c: instance of class ControlFile
     287            Contains all the parameters of CONTROL file, which are e.g.:
    244288            DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
    245289            STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
     
    290334
    291335    @Input:
    292         c: instance of class Control
    293             Contains all the parameters of control files, which are e.g.:
     336        c: instance of class ControlFile
     337            Contains all the parameters of CONTROL file, which are e.g.:
    294338            DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
    295339            STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
     
    357401            See example in description above.
    358402    '''
    359 
    360403    pools = map(tuple, args) * kwds.get('repeat', 1)
    361404    result = [[]]
     
    371414    '''
    372415    @Description:
    373         Removes the file which name is passed to the function if
    374         it exists. The function does not fail if the file does not
    375         exist.
     416        If "filename" exists , it is removed.
     417        The function does not fail if the file does not exist.
    376418
    377419    @Input:
     
    426468    @Input:
    427469        pars: string
    428             Addpar argument from control file in the format of
     470            Addpar argument from CONTROL file in the format of
    429471            parameter names instead of ids. The parameter short
    430472            names are sepearted with "/" and they are passed as
     
    438480    @Return:
    439481        ipar: list of integer
    440             List of addpar parameters from control file transformed to
     482            List of addpar parameters from CONTROL file transformed to
    441483            parameter ids in the format of integer.
    442484    '''
     
    455497    return ipar
    456498
    457 def getListAsString(listobj):
    458     '''
    459     @Description:
    460     '''
    461     return ", ".join( str(l) for l in listobj)
     499def getListAsString(listObj):
     500    '''
     501    @Description:
     502        Converts a list of arbitrary content into a single string.
     503
     504    @Input:
     505        listObj: list
     506            A list with arbitrary content.
     507
     508    @Return:
     509        strOfList: string
     510            The content of the list as a single string.
     511    '''
     512
     513    strOfList = ", ".join( str(l) for l in listObj)
     514
     515    return strOfList
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG