Changeset ff99eae in flex_extract.git for python/get_mars_data.py
- Timestamp:
- Jun 1, 2018, 8:34:59 PM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- e1228f3
- Parents:
- ccab809
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
python/get_mars_data.py
r991df6a rff99eae 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 #************************************************************************4 # TODO AP5 # - add function docstrings!!!!6 #************************************************************************7 3 #******************************************************************************* 8 4 # @Author: Anne Fouilloux (University of Oslo) … … 13 9 # 14 10 # November 2015 - Leopold Haimberger (University of Vienna): 15 # - moved the getEIdata program into a function "get MARSdata"11 # - moved the getEIdata program into a function "get_mars_data" 16 12 # - moved the AgurmentParser into a seperate function 17 13 # - adatpted the function for the use in flex_extract 18 # - renamed file to get MARSdata14 # - renamed file to get_mars_data 19 15 # 20 16 # February 2018 - Anne Philipp (University of Vienna): … … 42 38 # @Program Content: 43 39 # - main 44 # - get MARSdata40 # - get_mars_data 45 41 # 46 42 #******************************************************************************* … … 54 50 import inspect 55 51 try: 56 ecapi =True52 ecapi = True 57 53 import ecmwfapi 58 54 except ImportError: 59 ecapi=False 55 ecapi = False 56 57 # software specific classes and modules from flex_extract 58 from tools import my_error, normal_exit, interpret_args_and_control 59 from EcFlexpart import EcFlexpart 60 from UioFiles import UioFiles 60 61 61 62 # add path to pythonpath so that python finds its buddies 62 localpythonpath= os.path.dirname(os.path.abspath(63 LOCAL_PYTHON_PATH = os.path.dirname(os.path.abspath( 63 64 inspect.getfile(inspect.currentframe()))) 64 if localpythonpath not in sys.path: 65 sys.path.append(localpythonpath) 66 67 # software specific classes and modules from flex_extract 68 from ControlFile import ControlFile 69 from Tools import myerror, normalexit, \ 70 interpret_args_and_control 71 from ECFlexpart import ECFlexpart 72 from UIOFiles import UIOFiles 65 if LOCAL_PYTHON_PATH not in sys.path: 66 sys.path.append(LOCAL_PYTHON_PATH) 73 67 74 68 # ------------------------------------------------------------------------------ … … 78 72 ''' 79 73 @Description: 80 If get MARSdata is called from command line, this function controls74 If get_mars_data is called from command line, this function controls 81 75 the program flow and calls the argumentparser function and 82 the get MARSdata function for retrieving EC data.76 the get_mars_data function for retrieving EC data. 83 77 84 78 @Input: … … 89 83 ''' 90 84 args, c = interpret_args_and_control() 91 get MARSdata(args,c)92 normal exit(c)85 get_mars_data(c) 86 normal_exit(c) 93 87 94 88 return 95 89 96 def get MARSdata(args,c):90 def get_mars_data(c): 97 91 ''' 98 92 @Description: … … 103 97 104 98 @Input: 105 args: instance of ArgumentParser106 Contains the commandline arguments from script/program call.107 108 99 c: instance of class ControlFile 109 100 Contains all the parameters of CONTROL file, which are e.g.: … … 126 117 os.makedirs(c.inputdir) 127 118 128 print ("Retrieving EC data!")129 print ("start date %s " % (c.start_date))130 print ("end date %s " % (c.end_date))119 print "Retrieving EC data!" 120 print "start date %s " % (c.start_date) 121 print "end date %s " % (c.end_date) 131 122 132 123 if ecapi: … … 160 151 # -------------- flux data ------------------------------------------------ 161 152 print 'removing old flux content of ' + c.inputdir 162 tobecleaned = U IOFiles('*_acc_*.' + str(os.getppid()) + '.*.grb')163 tobecleaned.list Files(c.inputdir)164 tobecleaned.delete Files()153 tobecleaned = UioFiles('*_acc_*.' + str(os.getppid()) + '.*.grb') 154 tobecleaned.list_files(c.inputdir) 155 tobecleaned.delete_files() 165 156 166 157 # if forecast for maximum one day (upto 23h) are to be retrieved, … … 172 163 while day < endp1: 173 164 # retrieve MARS data for the whole period 174 flexpart = E CFlexpart(c, fluxes=True)165 flexpart = EcFlexpart(c, fluxes=True) 175 166 tmpday = day + datechunk - datetime.timedelta(days=1) 176 167 if tmpday < endp1: … … 186 177 flexpart.retrieve(server, dates, c.inputdir) 187 178 except IOError: 188 my error(c, 'MARS request failed')179 my_error(c, 'MARS request failed') 189 180 190 181 day += datechunk … … 199 190 while day <= end: 200 191 # retrieve MARS data for the whole period 201 flexpart = E CFlexpart(c, fluxes=True)192 flexpart = EcFlexpart(c, fluxes=True) 202 193 tmpday = day + datechunk - datetime.timedelta(days=1) 203 194 if tmpday < end: … … 213 204 flexpart.retrieve(server, dates, c.inputdir) 214 205 except IOError: 215 my error(c, 'MARS request failed')206 my_error(c, 'MARS request failed') 216 207 217 208 day += datechunk … … 219 210 # -------------- non flux data -------------------------------------------- 220 211 print 'removing old non flux content of ' + c.inputdir 221 tobecleaned = U IOFiles('*__*.' + str(os.getppid()) + '.*.grb')222 tobecleaned.list Files(c.inputdir)223 tobecleaned.delete Files()212 tobecleaned = UioFiles('*__*.' + str(os.getppid()) + '.*.grb') 213 tobecleaned.list_files(c.inputdir) 214 tobecleaned.delete_files() 224 215 225 216 day = start 226 217 while day <= end: 227 228 flexpart = ECFlexpart(c, fluxes=False)229 230 231 232 233 234 235 236 237 238 239 240 241 242 myerror(c, 'MARS request failed')243 244 218 # retrieve all non flux MARS data for the whole period 219 flexpart = EcFlexpart(c, fluxes=False) 220 tmpday = day + datechunk - datetime.timedelta(days=1) 221 if tmpday < end: 222 dates = day.strftime("%Y%m%d") + "/to/" + \ 223 tmpday.strftime("%Y%m%d") 224 else: 225 dates = day.strftime("%Y%m%d") + "/to/" + \ 226 end.strftime("%Y%m%d") 227 228 print "retrieve " + dates + " in dir " + c.inputdir 229 230 try: 231 flexpart.retrieve(server, dates, c.inputdir) 232 except IOError: 233 my_error(c, 'MARS request failed') 234 235 day += datechunk 245 236 246 237 return … … 248 239 if __name__ == "__main__": 249 240 main() 250
Note: See TracChangeset
for help on using the changeset viewer.