Changeset 8209738 in flex_extract.git for Source/Python/Mods/tools.py


Ignore:
Timestamp:
May 7, 2020, 3:32:03 PM (4 years ago)
Author:
anphi <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
b936fd3
Parents:
05e9362
Message:

language corrections in comment sections and print commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Source/Python/Mods/tools.py

    rd1bfa24 r8209738  
    1818#        - added documentation
    1919#        - moved all non class methods from former file Flexparttools in here
    20 #        - seperated args and control interpretation
     20#        - separated args and control interpretation
    2121#        - added functions get_list_as_string, read_ecenv, send_mail, make_dir,
    2222#          put_file_to_ecserver, submit_job_to_ecserver, get_informations,
     
    118118
    119119def none_or_str(value):
    120     '''Converts the input string into pythons None-type if the string
    121     contains string "None".
     120    '''Converts the input string into Pythons None type if it
     121    contains the string "None".
    122122
    123123    Parameters
     
    130130    None or value:
    131131        Return depends on the content of the input value. If it was "None",
    132         then the python type None is returned. Otherwise the string itself.
     132        then the Python type None is returned, otherwise the string itself.
    133133    '''
    134134    if value == 'None':
     
    137137
    138138def none_or_int(value):
    139     '''Converts the input string into pythons None-type if the string
    140     contains string "None". Otherwise it is converted to an integer value.
     139    '''Converts the input string into Pythons None-type if it
     140    contains string "None"; otherwise it is converted to an integer value.
    141141
    142142    Parameters
     
    158158def get_cmdline_args():
    159159    '''Decomposes the command line arguments and assigns them to variables.
    160     Apply default values for non mentioned arguments.
     160    Apply default values for arguments not present.
    161161
    162162    Parameters
     
    166166    ------
    167167    args : Namespace
    168         Contains the commandline arguments from script/program call.
     168        Contains the command line arguments from the script / program call.
    169169    '''
    170170
     
    191191    parser.add_argument("--basetime", dest="basetime",
    192192                        type=none_or_int, default=None,
    193                         help="base such as 0 or 12 (for half day retrievals)")
     193                        help="base time such as 0 or 12 (for half day retrievals)")
    194194    parser.add_argument("--step", dest="step",
    195195                        type=none_or_str, default=None,
     
    200200    parser.add_argument("--area", dest="area",
    201201                        type=none_or_str, default=None,
    202                         help="area defined as north/west/south/east")
     202                        help="area, defined by north/west/south/east")
    203203
    204204    # some switches
    205205    parser.add_argument("--debug", dest="debug",
    206206                        type=none_or_int, default=None,
    207                         help="debug mode - leave temporary files intact")
     207                        help="debug mode - temporary files will be conserved")
    208208    parser.add_argument("--oper", dest="oper",
    209209                        type=none_or_int, default=None,
    210                         help='operational mode - prepares dates with '
     210                        help='operational mode - prepares dates from '
    211211                        'environment variables')
    212212    parser.add_argument("--request", dest="request",
    213213                        type=none_or_int, default=None,
    214                         help="list all mars requests in file mars_requests.dat")
     214                        help="list all MARS requests in file mars_requests.dat")
    215215    parser.add_argument("--public", dest="public",
    216216                        type=none_or_int, default=None,
    217                         help="public mode - retrieves the public datasets")
     217                        help="public mode - retrieves public datasets")
    218218    parser.add_argument("--rrint", dest="rrint",
    219219                        type=none_or_int, default=None,
    220                         help='Selection of old or new precipitation '
    221                         'interpolation:\n'
     220                        help='Selection of old or new '
     221                        'interpolation method for precipitation:\n'
    222222                        '     0 - old method\n'
    223223                        '     1 - new method (additional subgrid points)')
     
    226226    parser.add_argument("--inputdir", dest="inputdir",
    227227                        type=none_or_str, default=None,
    228                         help='Path to the temporary directory for the '
    229                         'retrieval grib files and other processing files.')
     228                        help='Path to temporary directory for '
     229                        'retrieved grib files and other processing files.')
    230230    parser.add_argument("--outputdir", dest="outputdir",
    231231                        type=none_or_str, default=None,
    232                         help='Path to the final directory where the final '
    233                         'FLEXPART ready input files are stored.')
     232                        help='Path to final directory where '
     233                        'FLEXPART input files will be stored.')
    234234
    235235    # this is only used by prepare_flexpart.py to rerun a postprocessing step
    236236    parser.add_argument("--ppid", dest="ppid",
    237237                        type=none_or_str, default=None,
    238                         help='This is the specify parent process id of a '
     238                        help='This is the specify the parent process id of a '
    239239                        'single flex_extract run to identify the files. '
    240240                        'It is the second number in the GRIB files.')
     
    243243    parser.add_argument("--job_template", dest='job_template',
    244244                        type=none_or_str, default="job.temp",
    245                         help='The job template file which are adapted to be '
    246                         'submitted to the batch system on ECMWF server.')
     245                        help='Job template file. Will be used for submission '
     246                        'to the batch system on the ECMWF server after '
     247                        'modification.')
    247248    parser.add_argument("--queue", dest="queue",
    248249                        type=none_or_str, default=None,
    249                         help='The ECMWF server name for submission of the '
    250                         'job script to the batch system '
     250                        help='The name of the ECMWF server name where the'
     251                        'job script is to be submitted '
    251252                        '(e.g. ecgate | cca | ccb)')
    252253
     
    289290
    290291    It keeps the final FLEXPART input files if program runs without
    291     ECMWF Api and keywords "ectrans" or "ecstorage" are set to "1".
     292    ECMWF API and keywords "ectrans" or "ecstorage" are set to "1".
    292293
    293294    Parameters
     
    410411
    411412    This method combines the single characters of the passed arguments
    412     with each other. So that each character of each argument value
     413    with each other in a way that each character of each argument value
    413414    will be combined with each character of the other arguments as a tuple.
    414415
     
    519520    pars : str
    520521        Addpar argument from CONTROL file in the format of
    521         parameter names instead of ids. The parameter short
    522         names are sepearted with "/" and they are passed as
    523         one single string.
     522        parameter names instead of IDs. The parameter short
     523        names are separated by "/" and passed as one single string.
    524524
    525525    table : dict
     
    555555
    556556def to_param_id_with_tablenumber(pars, table):
    557     '''Transform parameter names to parameter ids and add table id.
     557    '''Transform parameter names to parameter IDs and add table ID.
    558558
    559559    Conversion with ECMWF grib table 128.
     
    563563    pars : str
    564564        Addpar argument from CONTROL file in the format of
    565         parameter names instead of ids. The parameter short
    566         names are sepearted with "/" and they are passed as
    567         one single string.
     565        parameter names instead of ID. The parameter short
     566        names are separated by "/" and passed as one single string.
    568567
    569568    table : dict
     
    576575    spar : str
    577576        List of addpar parameters from CONTROL file transformed to
    578         parameter ids in the format of integer.
     577        parameter IDs in the format of integer.
    579578    '''
    580579    if not pars:
     
    598597
    599598def get_list_as_string(list_obj, concatenate_sign=', '):
    600     '''Converts a list of arbitrary content into a single string.
     599    '''Converts a list of arbitrary content into a single string using a given
     600    concatenation character.
    601601
    602602    Parameters
     
    624624    '''Creates a directory.
    625625
    626     It gives a warning if the directory already exists and skips process.
    627     The program stops only if there is another problem.
     626    If the directory already exists, an information is printed and the creation
     627    skipped. The program stops only if there is another problem.
    628628
    629629    Parameters
     
    641641        # errno.EEXIST = directory already exists
    642642        if e.errno == errno.EEXIST:
    643             print('WARNING: Directory {0} already exists!'.format(directory))
     643            print('INFORMATION: Directory {0} already exists!'.format(directory))
    644644        else:
    645645            raise # re-raise exception if a different error occured
     
    720720    ------
    721721    job_id : int
    722         The id number of the job as a reference at the ecmwf server.
     722        The id number of the job as a reference at the ECMWF server.
    723723    '''
    724724
     
    732732
    733733        print('\n... Do you have a valid ecaccess certification key?')
    734         sys.exit('... ECACCESS-JOB-SUBMIT FAILED!')
     734        sys.exit('... ecaccess-job-submit FAILED!')
    735735    except OSError as e:
    736736        print('... ERROR CODE: ' + str(e.errno))
     
    738738
    739739        print('\n... Most likely the ECACCESS library is not available!')
    740         sys.exit('... ECACCESS-JOB-SUBMIT FAILED!')
     740        sys.exit('... ecaccess-job-submit FAILED!')
    741741
    742742    return job_id.decode()
     
    744744
    745745def get_informations(filename):
    746     '''Gets basic information from an example grib file.
    747 
    748     These information are important for later use and the
    749     initialization of numpy arrays for data storing.
     746    '''Extracts basic information from a sample grib file.
     747
     748    This information is needed for later use and the
     749    initialization of numpy arrays where data are stored.
    750750
    751751    Parameters
     
    768768
    769769    # --- open file ---
    770     print("Opening file for getting information data --- %s" % filename)
     770    print("Opening grib file for extraction of information --- %s" % filename)
    771771    with open(filename, 'rb') as f:
    772772        # load first message from file
     
    785785               ]
    786786
    787         print('\nInformations are: ')
     787        print('\nInformation extracted: ')
    788788        for key in keys:
    789789            # Get the value of the key in a grib message.
     
    798798
    799799def get_dimensions(info, purefc, dtime, index_vals, start_date, end_date):
    800     '''This function specifies the correct dimensions for x, y and t.
     800    '''This function specifies the correct dimensions for x, y, and t.
    801801
    802802    Parameters
     
    817817    index_vals : list of list of str
    818818        Contains the values from the keys used for a distinct selection
    819         of grib messages in processing the grib files.
     819        of GRIB messages in processing the grib files.
    820820        Content looks like e.g.:
    821821        index_vals[0]: ('20171106', '20171107', '20171108') ; date
     
    849849
    850850def execute_subprocess(cmd_list, error_msg='SUBPROCESS FAILED!'):
    851     '''Executes a command line instruction via a subprocess.
     851    '''Executes a command via a subprocess.
    852852
    853853    Error handling is done if an error occures.
     
    856856    ----------
    857857    cmd_list : list of str
    858         A list of the components for the command line execution. Each
    859         list entry is a single part of the command which is seperated from
    860         the rest by a blank space.
    861         E.g. ['mv', file1, file2]
     858        A list of the components for the command line execution.
     859        They will be concatenated with blank space for the command
     860        to be submitted, like ['mv', file1, file2] for mv file1 file2.
    862861
    863862    Return
    864863    ------
    865864    error_msg : str, optional
    866         The possible error message if the subprocess failed.
    867         By default it will just tell "SUBPROCESS FAILED!".
     865        Error message if the subprocess fails.
     866        By default it will just say "SUBPROCESS FAILED!".
    868867    '''
    869868
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG