Changeset 54a8a01 in flex_extract.git for python/prepare_flexpart.py
- Timestamp:
- Aug 31, 2018, 7:50:37 AM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 597d4d1
- Parents:
- e1228f3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/prepare_flexpart.py
rff99eae r54a8a01 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 #************************************************************************4 # ToDo AP5 # - wieso start=startm1 wenn basetime = 0 ? wenn die fluxes nicht mehr6 # relevant sind? verstehe ich nicht7 #************************************************************************8 3 #******************************************************************************* 9 4 # @Author: Anne Fouilloux (University of Oslo) … … 62 57 import sys 63 58 import socket 59 import _config 64 60 65 61 # software specific classes and modules from flex_extract 66 62 from UioFiles import UioFiles 67 from tools import interpret_args_and_control, clean_up63 from tools import clean_up, get_cmdline_arguments, read_ecenv 68 64 from EcFlexpart import EcFlexpart 69 65 … … 81 77 sys.path.append(LOCAL_PYTHON_PATH) 82 78 79 83 80 # ------------------------------------------------------------------------------ 84 81 # FUNCTION … … 97 94 <nothing> 98 95 ''' 99 args, c = interpret_args_and_control() 100 prepare_flexpart(args, c) 96 97 args = get_cmdline_arguments() 98 99 try: 100 c = ControlFile(args.controlfile) 101 except IOError: 102 try: 103 c = ControlFile(LOCAL_PYTHON_PATH + args.controlfile) 104 except IOError: 105 print 'Could not read CONTROL file "' + args.controlfile + '"' 106 print 'Either it does not exist or its syntax is wrong.' 107 print 'Try "' + sys.argv[0].split('/')[-1] + \ 108 ' -h" to print usage information' 109 sys.exit(1) 110 111 env_parameter = read_ecenv(c.ecmwfdatadir + 'python/ECMWF_ENV') 112 c.assign_args_to_control(args, env_parameter) 113 c.assign_envs_to_control(env_parameter) 114 c.check_conditions() 115 prepare_flexpart(args.ppid, c) 101 116 102 117 return 103 118 104 def prepare_flexpart( args, c):119 def prepare_flexpart(ppid, c): 105 120 ''' 106 121 @Description: … … 112 127 113 128 @Input: 114 args: instance of ArgumentParser 115 Contains the commandline arguments from script/program call. 129 ppid: int 130 Contains the ppid number of the current ECMWF job. If it is called 131 from this script, it is "None". 116 132 117 133 c: instance of class ControlFile … … 132 148 ''' 133 149 134 if not args.ppid:150 if not ppid: 135 151 c.ppid = str(os.getppid()) 136 152 else: 137 c.ppid = args.ppid153 c.ppid = ppid 138 154 139 155 c.ecapi = ecapi … … 148 164 day=int(c.end_date[6:])) 149 165 150 # to deaccumulate the fluxes correctly 151 # one day ahead of the start date and 152 # one day after the end date is needed 153 startm1 = start - datetime.timedelta(days=1) 154 # endp1 = end + datetime.timedelta(days=1) 155 156 # get all files with flux data to be deaccumulated 157 inputfiles = UioFiles('*OG_acc_SL*.' + c.ppid + '.*') 158 inputfiles.list_files(c.inputdir) 166 # assign starting date minus 1 day 167 # since for basetime 00 we need the 12 hours upfront 168 # (the day before from 12 UTC to current day 00 UTC) 169 if c.basetime == '00': 170 start = start - datetime.timedelta(days=1) 171 172 print 'Prepare ' + start.strftime("%Y%m%d") + \ 173 "/to/" + end.strftime("%Y%m%d") 159 174 160 175 # create output dir if necessary 161 176 if not os.path.exists(c.outputdir): 162 177 os.makedirs(c.outputdir) 178 179 # get all files with flux data to be deaccumulated 180 inputfiles = UioFiles(c.inputdir, '*OG_acc_SL*.' + c.ppid + '.*') 163 181 164 182 # deaccumulate the flux data … … 167 185 flexpart.deacc_fluxes(inputfiles, c) 168 186 169 print 'Prepare ' + start.strftime("%Y%m%d") + \170 "/to/" + end.strftime("%Y%m%d")171 172 187 # get a list of all files from the root inputdir 173 inputfiles = UioFiles('????__??.*' + c.ppid + '.*') 174 inputfiles.list_files(c.inputdir) 175 176 # produce FLEXPART-ready GRIB files and 177 # process GRIB files - 188 inputfiles = UioFiles(c.inputdir, '????__??.*' + c.ppid + '.*') 189 190 # produce FLEXPART-ready GRIB files and process them - 178 191 # copy/transfer/interpolate them or make them GRIB2 179 if c.basetime == '00':180 start = startm1181 182 192 flexpart = EcFlexpart(c, fluxes=False) 183 193 flexpart.create(inputfiles, c) … … 187 197 # otherwise delete temporary files 188 198 if int(c.debug) != 0: 189 print ' Temporary files left intact'199 print '\nTemporary files left intact' 190 200 else: 191 201 clean_up(c)
Note: See TracChangeset
for help on using the changeset viewer.