Changeset efdb01a in flex_extract.git for python/prepareFLEXPART.py


Ignore:
Timestamp:
May 9, 2018, 12:15:00 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
991df6a
Parents:
02c8c50
Message:

whole bunch of modifications due to new structure of ECMWFDATA, added basics of documentation, minor programming corrections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/prepareFLEXPART.py

    • Property mode changed from 100644 to 100755
    r02c8c50 refdb01a  
    3030        - added documentation
    3131        - 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!
    3234
    3335@License:
    34     (C) Copyright 2014.
     36    (C) Copyright 2014-2018.
    3537
    3638    This software is licensed under the terms of the Apache Licence Version 2.0
     
    4042    - A standard python 2.6 or 2.7 installation
    4143    - dateutils
    42     - matplotlib (optional, for debugging)
    4344    - ECMWF specific packages, all available from https://software.ecmwf.int/
    4445        ECMWF WebMARS, gribAPI with python enabled, emoslib and
     
    5253        surface fields for FLEXPART runs
    5354"""
    54 
     55# ------------------------------------------------------------------------------
     56# MODULES
     57# ------------------------------------------------------------------------------
    5558import calendar
    5659import shutil
    5760import datetime
    5861import time
    59 import os,inspect,sys
     62import os
     63import inspect
     64import sys
    6065import socket
    6166from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    62 # add path to submit.py to pythonpath so that python finds its buddies
    63 localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    64 if localpythonpath not in sys.path:
    65     sys.path.append(localpythonpath)
    66 from UIOTools import UIOFiles
    67 #from string import strip
    68 from GribTools import GribTools
    69 from FlexpartTools import ECFlexpart, Control, interpret_args_and_control, cleanup
     67import UIOFiles
     68import Control
     69import Tools
     70import ECFlexpart
    7071
    71 hostname=socket.gethostname()
    72 ecapi= 'ecmwf' not in hostname
    73 
     72hostname = socket.gethostname()
     73ecapi = 'ecmwf' not in hostname
    7474try:
    7575    if ecapi:
     
    7878    ecapi = False
    7979
    80 
     80# add path to submit.py to pythonpath so that python finds its buddies
     81localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
     82if localpythonpath not in sys.path:
     83    sys.path.append(localpythonpath)
     84# ------------------------------------------------------------------------------
     85# FUNCTION
     86# ------------------------------------------------------------------------------
    8187def prepareFLEXPART(args, c):
    8288    '''
     
    121127                        day=int(c.end_date[6:]))
    122128
    123     # to deaccumulated the fluxes correctly
     129    # to deaccumulate the fluxes correctly
    124130    # one day ahead of the start date and
    125131    # one day after the end date is needed
     
    128134
    129135    # get all files with flux data to be deaccumulated
    130     inputfiles = UIOFiles(['.grib', '.grb', '.grib1',
     136    inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
    131137                           '.grib2', '.grb1', '.grb2'])
    132138
     
    138144
    139145    # deaccumulate the flux data
    140     flexpart = ECFlexpart(c, fluxes=True)
     146    flexpart = ECFlexpart.ECFlexpart(c, fluxes=True)
    141147    flexpart.write_namelist(c, 'fort.4')
    142148    flexpart.deacc_fluxes(inputfiles, c)
     
    146152
    147153    # get a list of all files from the root inputdir
    148     inputfiles = UIOFiles(['.grib', '.grb', '.grib1',
     154    inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
    149155                           '.grib2', '.grb1', '.grb2'])
    150156
     
    157163        start = startm1
    158164
    159     flexpart = ECFlexpart(c, fluxes=False)
     165    flexpart = ECFlexpart.ECFlexpart(c, fluxes=False)
    160166    flexpart.create(inputfiles, c)
    161167    flexpart.process_output(c)
    162168
    163169    # check if in debugging mode, then store all files
     170    # otherwise delete temporary files
    164171    if int(c.debug) != 0:
    165172        print('Temporary files left intact')
    166173    else:
    167         cleanup(c)
     174        Tools.cleanup(c)
    168175
    169176    return
    170177
    171178if __name__ == "__main__":
    172     args, c = interpret_args_and_control()
     179    args, c = Tools.interpret_args_and_control()
    173180    prepareFLEXPART(args, c)
    174     cleanup(c)
    175 
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG