source: flex_extract.git/python/submit.py @ 51f9853

ctbtodev
Last change on this file since 51f9853 was 51f9853, checked in by anphi <anne.philipp@…>, 5 years ago

added request parameter for writing mars requests into csv file

  • Property mode set to 100755
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        if c.request == '0' or c.request == '2':
59            prepareFLEXPART(args,c)
60            normalexit(c)
61        else:
62            normalexit(c)
63    else:
64        submit(args.job_template,c,args.queue)
65
66
67def submit(jtemplate,c,queue):
68
69    f=open(jtemplate)
70    lftext=f.read().split('\n')
71    insert_point=lftext.index('EOF')
72    f.close()
73
74    clist=c.tolist()
75    colist=[]
76    mt=0
77    for elem in clist:
78        if 'maxstep' in elem:
79            mt=int(elem.split(' ')[1])
80
81    for elem in clist:
82        if 'start_date' in elem:
83            elem='start_date '+'${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}'
84        if 'end_date' in elem:
85            elem='start_date '+'${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}'
86        if 'base_time' in elem:
87            elem='base_time '+'${MSJ_BASETIME}'
88        if 'time' in elem and mt>24:
89            elem='time '+'${MSJ_BASETIME} {MSJ_BASETIME}'
90        colist.append(elem)
91
92    lftextondemand=lftext[:insert_point]+clist+lftext[insert_point+2:]
93    lftextoper=lftext[:insert_point]+colist+lftext[insert_point+2:]
94
95    h=open('job.ksh','w')
96    h.write('\n'.join(lftextondemand))
97    h.close()
98
99    h=open('joboper.ksh','w')
100    h.write('\n'.join(lftextoper))
101    h.close()
102
103    try:
104        p=subprocess.check_call(['ecaccess-job-submit','-queueName',queue,'job.ksh'])
105    except:
106        print 'ecaccess-job-submit failed, probably eccert has expired'
107        exit(1)
108    #pout=p.communicate(input=s)[0]
109    print 'You should get an email with subject flex.hostname.pid'
110
111
112
113
114if __name__ == "__main__":
115    main()
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG