source: flex_extract.git/python/submit.py @ b780393

ctbtodev
Last change on this file since b780393 was d69b677, checked in by Anne Philipp <bscannephilipp@…>, 6 years ago

original ECMWFDATA v7.0.2 from flexpart.eu

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#!/usr/bin/env python
2#             
3# This software is licensed under the terms of the Apache Licence Version 2.0
4# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5#
6# Functionality provided: Prepare input 3D-wind fields in hybrid coordinates + surface fields for FLEXPART runs
7#
8# Creation: October  2014 - Anne Fouilloux - University of Oslo
9# Extension November 2015 - Leopold Haimberger - University of Vienna for:
10# - using the WebAPI also for general MARS retrievals
11# - job submission on ecgate and cca
12# - job templates suitable for twice daily operational dissemination
13# - dividing retrievals of longer periods into digestable chunks
14# - retrieve also longer term forecasts, not only analyses and short term forecast data
15# - conversion into GRIB2
16# - conversion into .fp format for faster execution of FLEXPART
17#
18# Further documentation may be obtained from www.flexpart.eu
19#
20# Requirements:
21# in addition to a standard python 2.6 or 2.7 installation the following packages need to be installed
22# ECMWF WebMARS, gribAPI with python enabled, emoslib, ecaccess web toolkit, all available from https://software.ecmwf.int/
23# dateutils
24# matplotlib (optional, for debugging)
25#
26#
27import calendar
28import shutil
29import datetime
30import time
31import os,sys,glob
32import subprocess
33import inspect
34# add path to submit.py to pythonpath so that python finds its buddies
35localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
36sys.path.append(localpythonpath)
37from UIOTools import UIOFiles
38from string import strip
39from argparse import ArgumentParser,ArgumentDefaultsHelpFormatter
40from GribTools import GribTools
41from FlexpartTools import EIFlexpart, Control, interpret_args_and_control, normalexit,myerror
42from getMARSdata import getMARSdata
43from prepareFLEXPART import prepareFLEXPART
44
45
46
47def main():
48
49    calledfromdir=os.getcwd()
50#    os.chdir(localpythonpath)
51    args,c=interpret_args_and_control()
52    if args.queue==None:
53        if c.inputdir[0]!='/':
54            c.inputdir=os.path.join(calledfromdir,c.inputdir)
55        if c.outputdir[0]!='/':
56            c.outputdir=os.path.join(calledfromdir,c.outputdir)
57        getMARSdata(args,c)
58        prepareFLEXPART(args,c)
59        normalexit(c)
60    else:
61        submit(args.job_template,c,args.queue)
62       
63       
64def submit(jtemplate,c,queue):
65   
66    f=open(jtemplate)
67    lftext=f.read().split('\n')
68    insert_point=lftext.index('EOF')
69    f.close()
70   
71    clist=c.tolist()
72    colist=[]
73    mt=0
74    for elem in clist:
75        if 'maxstep' in elem:
76            mt=int(elem.split(' ')[1])
77           
78    for elem in clist:
79        if 'start_date' in elem:
80            elem='start_date '+'${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}'
81        if 'end_date' in elem:
82            elem='start_date '+'${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}'
83        if 'base_time' in elem:
84            elem='base_time '+'${MSJ_BASETIME}'
85        if 'time' in elem and mt>24:
86            elem='time '+'${MSJ_BASETIME} {MSJ_BASETIME}'
87        colist.append(elem)
88       
89    lftextondemand=lftext[:insert_point]+clist+lftext[insert_point+2:]
90    lftextoper=lftext[:insert_point]+colist+lftext[insert_point+2:]
91   
92    h=open('job.ksh','w')
93    h.write('\n'.join(lftextondemand)) 
94    h.close()
95   
96    h=open('joboper.ksh','w')
97    h.write('\n'.join(lftextoper)) 
98    h.close()
99   
100    try:   
101        p=subprocess.check_call(['ecaccess-job-submit','-queueName',queue,'job.ksh'])
102    except:
103        print 'ecaccess-job-submit failed, probably eccert has expired'
104        exit(1)
105    #pout=p.communicate(input=s)[0]
106    print 'You should get an email with subject flex.hostname.pid'
107
108
109
110           
111if __name__ == "__main__":
112    main()
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG