Changeset 991df6a in flex_extract.git for python/prepareFLEXPART.py
- Timestamp:
- May 14, 2018, 10:11:29 PM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 812283d
- Parents:
- efdb01a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/prepareFLEXPART.py
refdb01a r991df6a 3 3 #************************************************************************ 4 4 # TODO AP 5 #AP6 # - Change History ist nicht angepasst ans File! Original geben lassen7 5 # - wieso cleanup in main wenn es in prepareflexpart bereits abgefragt wurde? 8 6 # doppelt gemoppelt? … … 10 8 # relevant sind? verstehe ich nicht 11 9 #************************************************************************ 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 55 58 # ------------------------------------------------------------------------------ 56 59 # MODULES 57 60 # ------------------------------------------------------------------------------ 58 import calendar59 61 import shutil 60 62 import datetime 61 import time63 #import time 62 64 import os 63 65 import inspect … … 65 67 import socket 66 68 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 67 import UIOFiles68 import Control69 import Tools70 import ECFlexpart71 69 72 70 hostname = socket.gethostname() … … 78 76 ecapi = False 79 77 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 79 localpythonpath = os.path.dirname(os.path.abspath( 80 inspect.getfile(inspect.currentframe()))) 82 81 if localpythonpath not in sys.path: 83 82 sys.path.append(localpythonpath) 83 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 84 88 # ------------------------------------------------------------------------------ 85 89 # FUNCTION 86 90 # ------------------------------------------------------------------------------ 91 def 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 87 109 def prepareFLEXPART(args, c): 88 110 ''' 89 111 @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. 91 117 92 118 @Input: … … 94 120 Contains the commandline arguments from script/program call. 95 121 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.: 98 124 DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME, 99 125 STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT, … … 134 160 135 161 # 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) 140 164 141 165 # create output dir if necessary … … 144 168 145 169 # deaccumulate the flux data 146 flexpart = ECFlexpart .ECFlexpart(c, fluxes=True)170 flexpart = ECFlexpart(c, fluxes=True) 147 171 flexpart.write_namelist(c, 'fort.4') 148 172 flexpart.deacc_fluxes(inputfiles, c) … … 152 176 153 177 # 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) 158 180 159 181 # produce FLEXPART-ready GRIB files and … … 163 185 start = startm1 164 186 165 flexpart = ECFlexpart .ECFlexpart(c, fluxes=False)187 flexpart = ECFlexpart(c, fluxes=False) 166 188 flexpart.create(inputfiles, c) 167 189 flexpart.process_output(c) … … 172 194 print('Temporary files left intact') 173 195 else: 174 Tools.cleanup(c)196 cleanup(c) 175 197 176 198 return 177 199 178 200 if __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.