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

    refdb01a r991df6a  
    33#************************************************************************
    44# TODO AP
    5 #AP
    6 # - Change History ist nicht angepasst ans File! Original geben lassen
    75# - wieso cleanup in main wenn es in prepareflexpart bereits abgefragt wurde?
    86#   doppelt gemoppelt?
     
    108#   relevant sind? verstehe ich nicht
    119#************************************************************************
    12 """
    13 @Author: Anne Fouilloux (University of Oslo)
    14 
    15 @Date: October 2014
    16 
    17 @ChangeHistory:
    18     November 2015 - Leopold Haimberger (University of Vienna):
    19         - using the WebAPI also for general MARS retrievals
    20         - job submission on ecgate and cca
    21         - job templates suitable for twice daily operational dissemination
    22         - dividing retrievals of longer periods into digestable chunks
    23         - retrieve also longer term forecasts, not only analyses and
    24           short term forecast data
    25         - conversion into GRIB2
    26         - conversion into .fp format for faster execution of FLEXPART
    27 
    28     February 2018 - Anne Philipp (University of Vienna):
    29         - applied PEP8 style guide
    30         - added documentation
    31         - minor changes in programming style for consistence
    32         - BUG: removed call of cleanup-Function after call of prepareFlexpart
    33                 since it is already called in prepareFlexpart at the end!
    34 
    35 @License:
    36     (C) Copyright 2014-2018.
    37 
    38     This software is licensed under the terms of the Apache Licence Version 2.0
    39     which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
    40 
    41 @Requirements:
    42     - A standard python 2.6 or 2.7 installation
    43     - dateutils
    44     - ECMWF specific packages, all available from https://software.ecmwf.int/
    45         ECMWF WebMARS, gribAPI with python enabled, emoslib and
    46         ecaccess web toolkit
    47 
    48 @Description:
    49     Further documentation may be obtained from www.flexpart.eu.
    50 
    51     Functionality provided:
    52         Prepare input 3D-wind fields in hybrid coordinates +
    53         surface fields for FLEXPART runs
    54 """
     10#*******************************************************************************
     11# @Author: Anne Fouilloux (University of Oslo)
     12#
     13# @Date: October 2014
     14#
     15# @Change History:
     16#
     17#    November 2015 - Leopold Haimberger (University of Vienna):
     18#        - using the WebAPI also for general MARS retrievals
     19#        - job submission on ecgate and cca
     20#        - job templates suitable for twice daily operational dissemination
     21#        - dividing retrievals of longer periods into digestable chunks
     22#        - retrieve also longer term forecasts, not only analyses and
     23#          short term forecast data
     24#        - conversion into GRIB2
     25#        - conversion into .fp format for faster execution of FLEXPART
     26#
     27#    February 2018 - Anne Philipp (University of Vienna):
     28#        - applied PEP8 style guide
     29#        - added documentation
     30#        - minor changes in programming style for consistence
     31#        - BUG: removed call of cleanup-Function after call of
     32#               prepareFlexpart in main since it is already called in
     33#               prepareFlexpart at the end!
     34#        - created function main and moved the two function calls for
     35#          arguments and prepareFLEXPART into it
     36#
     37# @License:
     38#    (C) Copyright 2014-2018.
     39#
     40#    This software is licensed under the terms of the Apache Licence Version 2.0
     41#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
     42#
     43# @Program Functionality:
     44#    This program prepares the final version of the grib files which are
     45#    then used by FLEXPART. It converts the bunch of grib files extracted
     46#    via getMARSdata by doing for example the necessary conversion to get
     47#    consistent grids or the disaggregation of flux data. Finally, the
     48#    program combines the data fields in files per available hour with the
     49#    naming convention xxYYMMDDHH, where xx should be 2 arbitrary letters
     50#    (mostly xx is chosen to be "EN").
     51#
     52# @Program Content:
     53#    - main
     54#    - prepareFLEXPART
     55#
     56#*******************************************************************************
     57
    5558# ------------------------------------------------------------------------------
    5659# MODULES
    5760# ------------------------------------------------------------------------------
    58 import calendar
    5961import shutil
    6062import datetime
    61 import time
     63#import time
    6264import os
    6365import inspect
     
    6567import socket
    6668from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    67 import UIOFiles
    68 import Control
    69 import Tools
    70 import ECFlexpart
    7169
    7270hostname = socket.gethostname()
     
    7876    ecapi = False
    7977
    80 # add path to submit.py to pythonpath so that python finds its buddies
    81 localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
     78# add path to pythonpath so that python finds its buddies
     79localpythonpath = os.path.dirname(os.path.abspath(
     80    inspect.getfile(inspect.currentframe())))
    8281if localpythonpath not in sys.path:
    8382    sys.path.append(localpythonpath)
     83
     84# software specific classes and modules from flex_extract
     85from UIOFiles import UIOFiles
     86from Tools import interpret_args_and_control, cleanup
     87from ECFlexpart import ECFlexpart
    8488# ------------------------------------------------------------------------------
    8589# FUNCTION
    8690# ------------------------------------------------------------------------------
     91def main():
     92    '''
     93    @Description:
     94        If prepareFLEXPART is called from command line, this function controls
     95        the program flow and calls the argumentparser function and
     96        the prepareFLEXPART function for preparation of GRIB data for FLEXPART.
     97
     98    @Input:
     99        <nothing>
     100
     101    @Return:
     102        <nothing>
     103    '''
     104    args, c = interpret_args_and_control()
     105    prepareFLEXPART(args, c)
     106
     107    return
     108
    87109def prepareFLEXPART(args, c):
    88110    '''
    89111    @Description:
    90 
     112        Lists all grib files retrieved from MARS with getMARSdata and
     113        uses prepares data for the use in FLEXPART. Specific data fields
     114        are converted to a different grid and the flux data are going to be
     115        disaggregated. The data fields are collected by hour and stored in
     116        a file with a specific FLEXPART relevant naming convention.
    91117
    92118    @Input:
     
    94120            Contains the commandline arguments from script/program call.
    95121
    96         c: instance of class Control
    97             Contains all the parameters of control files, which are e.g.:
     122        c: instance of class ControlFile
     123            Contains all the parameters of CONTROL file, which are e.g.:
    98124            DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
    99125            STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
     
    134160
    135161    # get all files with flux data to be deaccumulated
    136     inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
    137                            '.grib2', '.grb1', '.grb2'])
    138 
    139     inputfiles.listFiles(c.inputdir, '*OG_acc_SL*.' + c.ppid + '.*')
     162    inputfiles = UIOFiles('*OG_acc_SL*.' + c.ppid + '.*')
     163    inputfiles.listFiles(c.inputdir)
    140164
    141165    # create output dir if necessary
     
    144168
    145169    # deaccumulate the flux data
    146     flexpart = ECFlexpart.ECFlexpart(c, fluxes=True)
     170    flexpart = ECFlexpart(c, fluxes=True)
    147171    flexpart.write_namelist(c, 'fort.4')
    148172    flexpart.deacc_fluxes(inputfiles, c)
     
    152176
    153177    # get a list of all files from the root inputdir
    154     inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
    155                            '.grib2', '.grb1', '.grb2'])
    156 
    157     inputfiles.listFiles(c.inputdir, '????__??.*' + c.ppid + '.*')
     178    inputfiles = UIOFiles('????__??.*' + c.ppid + '.*')
     179    inputfiles.listFiles(c.inputdir)
    158180
    159181    # produce FLEXPART-ready GRIB files and
     
    163185        start = startm1
    164186
    165     flexpart = ECFlexpart.ECFlexpart(c, fluxes=False)
     187    flexpart = ECFlexpart(c, fluxes=False)
    166188    flexpart.create(inputfiles, c)
    167189    flexpart.process_output(c)
     
    172194        print('Temporary files left intact')
    173195    else:
    174         Tools.cleanup(c)
     196        cleanup(c)
    175197
    176198    return
    177199
    178200if __name__ == "__main__":
    179     args, c = Tools.interpret_args_and_control()
    180     prepareFLEXPART(args, c)
     201    main()
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG