Changeset ff99eae in flex_extract.git for python/prepare_flexpart.py


Ignore:
Timestamp:
Jun 1, 2018, 8:34:59 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
e1228f3
Parents:
ccab809
Message:

completed application of pep8 style guide and pylint investigations. added documentation almost everywhere

File:
1 moved

Legend:

Unmodified
Added
Removed
  • python/prepare_flexpart.py

    r991df6a rff99eae  
    22# -*- coding: utf-8 -*-
    33#************************************************************************
    4 # TODO AP
    5 # - wieso cleanup in main wenn es in prepareflexpart bereits abgefragt wurde?
    6 #   doppelt gemoppelt?
     4# ToDo AP
    75# - wieso start=startm1 wenn basetime = 0 ?  wenn die fluxes nicht mehr
    86#   relevant sind? verstehe ich nicht
     
    2927#        - added documentation
    3028#        - minor changes in programming style for consistence
    31 #        - BUG: removed call of cleanup-Function after call of
     29#        - BUG: removed call of clean_up-Function after call of
    3230#               prepareFlexpart in main since it is already called in
    3331#               prepareFlexpart at the end!
    3432#        - created function main and moved the two function calls for
    35 #          arguments and prepareFLEXPART into it
     33#          arguments and prepare_flexpart into it
    3634#
    3735# @License:
     
    4442#    This program prepares the final version of the grib files which are
    4543#    then used by FLEXPART. It converts the bunch of grib files extracted
    46 #    via getMARSdata by doing for example the necessary conversion to get
     44#    via get_mars_data by doing for example the necessary conversion to get
    4745#    consistent grids or the disaggregation of flux data. Finally, the
    4846#    program combines the data fields in files per available hour with the
     
    5250# @Program Content:
    5351#    - main
    54 #    - prepareFLEXPART
     52#    - prepare_flexpart
    5553#
    5654#*******************************************************************************
     
    5957# MODULES
    6058# ------------------------------------------------------------------------------
    61 import shutil
    6259import datetime
    63 #import time
    6460import os
    6561import inspect
    6662import sys
    6763import socket
    68 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    6964
    70 hostname = socket.gethostname()
    71 ecapi = 'ecmwf' not in hostname
     65# software specific classes and modules from flex_extract
     66from UioFiles import UioFiles
     67from tools import interpret_args_and_control, clean_up
     68from EcFlexpart import EcFlexpart
     69
     70ecapi = 'ecmwf' not in socket.gethostname()
    7271try:
    7372    if ecapi:
     
    7776
    7877# add path to pythonpath so that python finds its buddies
    79 localpythonpath = os.path.dirname(os.path.abspath(
     78LOCAL_PYTHON_PATH = os.path.dirname(os.path.abspath(
    8079    inspect.getfile(inspect.currentframe())))
    81 if localpythonpath not in sys.path:
    82     sys.path.append(localpythonpath)
     80if LOCAL_PYTHON_PATH not in sys.path:
     81    sys.path.append(LOCAL_PYTHON_PATH)
    8382
    84 # software specific classes and modules from flex_extract
    85 from UIOFiles import UIOFiles
    86 from Tools import interpret_args_and_control, cleanup
    87 from ECFlexpart import ECFlexpart
    8883# ------------------------------------------------------------------------------
    8984# FUNCTION
     
    9287    '''
    9388    @Description:
    94         If prepareFLEXPART is called from command line, this function controls
     89        If prepare_flexpart is called from command line, this function controls
    9590        the program flow and calls the argumentparser function and
    96         the prepareFLEXPART function for preparation of GRIB data for FLEXPART.
     91        the prepare_flexpart function for preparation of GRIB data for FLEXPART.
    9792
    9893    @Input:
     
    10398    '''
    10499    args, c = interpret_args_and_control()
    105     prepareFLEXPART(args, c)
     100    prepare_flexpart(args, c)
    106101
    107102    return
    108103
    109 def prepareFLEXPART(args, c):
     104def prepare_flexpart(args, c):
    110105    '''
    111106    @Description:
    112         Lists all grib files retrieved from MARS with getMARSdata and
     107        Lists all grib files retrieved from MARS with get_mars_data and
    113108        uses prepares data for the use in FLEXPART. Specific data fields
    114109        are converted to a different grid and the flux data are going to be
     
    157152    # one day after the end date is needed
    158153    startm1 = start - datetime.timedelta(days=1)
    159     endp1 = end + datetime.timedelta(days=1)
     154#    endp1 = end + datetime.timedelta(days=1)
    160155
    161156    # get all files with flux data to be deaccumulated
    162     inputfiles = UIOFiles('*OG_acc_SL*.' + c.ppid + '.*')
    163     inputfiles.listFiles(c.inputdir)
     157    inputfiles = UioFiles('*OG_acc_SL*.' + c.ppid + '.*')
     158    inputfiles.list_files(c.inputdir)
    164159
    165160    # create output dir if necessary
     
    168163
    169164    # deaccumulate the flux data
    170     flexpart = ECFlexpart(c, fluxes=True)
     165    flexpart = EcFlexpart(c, fluxes=True)
    171166    flexpart.write_namelist(c, 'fort.4')
    172167    flexpart.deacc_fluxes(inputfiles, c)
    173168
    174     print('Prepare ' + start.strftime("%Y%m%d") +
    175           "/to/" + end.strftime("%Y%m%d"))
     169    print 'Prepare ' + start.strftime("%Y%m%d") + \
     170          "/to/" + end.strftime("%Y%m%d")
    176171
    177172    # get a list of all files from the root inputdir
    178     inputfiles = UIOFiles('????__??.*' + c.ppid + '.*')
    179     inputfiles.listFiles(c.inputdir)
     173    inputfiles = UioFiles('????__??.*' + c.ppid + '.*')
     174    inputfiles.list_files(c.inputdir)
    180175
    181176    # produce FLEXPART-ready GRIB files and
     
    185180        start = startm1
    186181
    187     flexpart = ECFlexpart(c, fluxes=False)
     182    flexpart = EcFlexpart(c, fluxes=False)
    188183    flexpart.create(inputfiles, c)
    189184    flexpart.process_output(c)
     
    192187    # otherwise delete temporary files
    193188    if int(c.debug) != 0:
    194         print('Temporary files left intact')
     189        print 'Temporary files left intact'
    195190    else:
    196         cleanup(c)
     191        clean_up(c)
    197192
    198193    return
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG