source: CDB/trunk/driver/diag_driver_comp.py @ 31

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CDB/trunk/driver/diag_driver_comp.py@31
Revision 31, 22.8 KB checked in by lalibert, 7 years ago (diff)

Fixed parallel dimension bug

Line 
1"""
2This script sets up a diagnostic for a model run.
3
4REQUIRES: python 2.7 with
5netcdf4-python
6optparse
7os
8
9Created scripts require:
10NCO 4.0.8 w/ OPeNDAP, netCDF4/HDF5
11CDO 1.5.1 w/ OPeNDAP, netCDF4/HDF5
12gnu-parallel
13
14Frederic Laliberte 12/2011
15"""
16
17cdb_environment_variables={'path':['cdo','nco','python'],'dir':['temp','diag','script','in','source','data','out']}
18
19class Open_With_Indent:
20
21    def __init__(self,file_name,read_method):
22        self.open = open(file_name,read_method)
23        self._current_indent=0
24   
25    def writei(self,write_string):
26        self.open.write(write_string.rjust(len(write_string)+self._current_indent))
27
28    def inc_indent(self):
29        self._current_indent+=3
30
31    def dec_indent(self):
32        if self._current_indent > 3:
33            self._current_indent-=3
34        else:
35            self._current_indent=0
36
37class Experiment_Setup:
38    """ Sets an experiment for the CMIP5 archive """
39
40    def __init__(self,options):
41        for opt in dir(options):
42            if opt[0] != '_' and opt not in ['ensure_value','read_file','read_module']:
43                setattr(self,opt,getattr(options,opt))
44        if 'years' in dir(self):
45            self.years=self.years.split(',')
46
47    def prepare_scripts(self):
48        """ Prepares the scripts for bash launch """
49        parallel_dimension_number=0
50   
51        out=Open_With_Indent(self.output_file,'w')
52
53        out.writei('#!/bin/bash\n')
54        if self.pbs_expt:
55            if self.queue != None: out.writei('#PBS -q {0}\n'.format(self.queue))
56            #out.writei('#PBS -l nodes=1:ppn={0},walltime={1}\n'.format(max(self.dim_async,self.y_async),self.walltime))
57            out.writei('#PBS -l nodes=1:ppn={0}\n'.format(max(self.dim_async,self.y_async)))
58            out.writei('#PBS -N {0}_{1}_{2}_{3}_{4}\n'.format(self.years[0],self.years[1],self.model,self.run_id,self.experiment))
59            out.writei('#PBS -o {5}/pbs_out/{0}_{1}_{2}_{3}_{4}\n'.format(self.years[0],self.years[1],self.model,self.run_id,self.experiment,self.source_dir))
60            out.writei('#PBS -e {5}/pbs_err/{0}_{1}_{2}_{3}_{4}\n'.format(self.years[0],self.years[1],self.model,self.run_id,self.experiment,self.source_dir))
61
62        out.writei('\n')
63        out.writei('#The next variable should be empty. If your script completed and some\n')
64        out.writei('#years did not process properly (usually due to a timeout on large\n')
65        out.writei('#storage systems), you can list the years (space separated)\n')
66        out.writei('#to recompute these years. Simply rerun or resubmit the scripts\n')
67        out.writei('CDB_YEARS_FIX_LIST=""\n'.format(self.years[0],self.years[1]))
68        out.writei('\n')
69        out.writei('CDB_YEARS={0},{1}\n'.format(self.years[0],self.years[1]))
70        out.writei('CDB_MODEL={0}\n'.format(self.model))
71        out.writei('CDB_RUN_ID={0}\n'.format(self.run_id))
72        out.writei('CDB_EXPT={0}\n'.format(self.experiment))
73        out.writei('CDB_DIAG_NAME={0}\n'.format(self.diagnostic))
74        out.writei('export CDB_MODEL_NAME=`echo $CDB_MODEL | tr \',\' \' \' | awk -F\' \' \'{ print $2}\'`\n')
75        out.writei('export CDB_OUT_FILE=${CDB_DIAG_NAME}_${CDB_MODEL_NAME}_${CDB_EXPT}_$(echo $CDB_YEARS | tr \',\' \'_\')_${CDB_RUN_ID}\n')
76        out.writei('\n')
77        out.writei('#SETUP THE ENVIRONMENT\n')
78        out.writei('CDB_SOURCE_DIR={0}\n'.format(self.source_dir))
79        out.writei('source ${CDB_SOURCE_DIR}/cdb_header\n')
80        out.writei('#SET THE OUTPUT DIRECTORY\n')
81        out.writei('CDB_OUT_DIR="${CDB_OUT_DIR}/${CDB_DIAG_NAME}"\n')
82        out.writei('mkdir -p ${CDB_OUT_DIR}\n')
83        out.writei('\n')
84        out.writei('#SET THE TEMP DIRECTORY\n')
85        out.writei('if [ -z "${PBS_JOBID}" ]; then\n')
86        out.writei('CDB_TEMP_DIR=${CDB_TEMP_DIR}.${$}\n')
87        out.writei('else\n')
88        out.writei('CDB_TEMP_DIR=${CDB_TEMP_DIR}.${PBS_JOBID}\n')
89        out.writei('fi\n')
90        out.writei('mkdir -p ${CDB_TEMP_DIR}\n')
91        out.writei('\n')
92
93       
94        #LOAD SCRIPT FILE AND CONVERT PARALLEL INSTANCES
95        script_file=open(self.diag_dir+'/'+self.diagnostic+'.sh','r')
96
97        parallel_dimension=None
98        for line in script_file:
99            if line.lstrip()[:17].upper() == '#!START YEAR LOOP':
100                out.writei('function yearly_processing()\n')
101                out.writei('{\n')
102                out.writei('cat > $2 <<EndOfScriptHeader\n')
103                out.writei('#!/bin/bash\n')
104                out.writei('#This file launches a yearly diagnostic\n')
105                out.writei('CDB_YEAR=$1\n')
106                out.writei('\n')
107                out.writei('CDB_YEAR_START=${CDB_YEAR_START}\n')
108                out.writei('CDB_YEAR_END=${CDB_YEAR_END}\n')
109                out.writei('CDB_MODEL=${CDB_MODEL}\n')
110                out.writei('CDB_RUN_ID=${CDB_RUN_ID}\n')
111                out.writei('CDB_EXPT=${CDB_EXPT}\n')
112                out.writei('CDB_DIAG_NAME=${CDB_DIAG_NAME}\n')
113                out.writei('CDB_MODEL_NAME=${CDB_MODEL_NAME}\n')
114                out.writei('CDB_OUT_FILE=${CDB_OUT_FILE}\n')
115                for type_var in cdb_environment_variables.keys():
116                    for name_var in cdb_environment_variables[type_var]:
117                        out.writei('export CDB_{0}_{1}=$CDB_{0}_{1}\n'.format(name_var.upper(),type_var.upper()))
118                out.writei('\n')
119                out.writei('CDB_VAR_LIST="${CDB_VAR_LIST}"\n')
120
121                out.open.write('EndOfScriptHeader\n')
122                out.writei('\n')
123                out.writei('cat >> $2 <<\'EndOfScriptMain\'\n')
124                if not self.no_retrieval:
125                    if self.debug:
126                        #out.writei('trap "rm -rf ${CDB_TEMP_DIR}; kill -s TERM $PPID" TERM\n')
127                        out.writei('bash $CDB_SOURCE_DIR/retrieval_script.sh -d ${CDB_DIAG_NAME} -v ${CDB_VAR_LIST} -m ${CDB_MODEL} -e ${CDB_EXPT} -r ${CDB_RUN_ID} -y ${CDB_YEAR}\n')
128                    out.writei('CDB_VAR_ATTRIBUTION=`bash $CDB_SOURCE_DIR/retrieval_script.sh -d ${CDB_DIAG_NAME} -v ${CDB_VAR_LIST} -m ${CDB_MODEL} -e ${CDB_EXPT} -r ${CDB_RUN_ID} -y ${CDB_YEAR}`\n')
129                    out.writei('for CDB_VAR in ${CDB_VAR_ATTRIBUTION}; do eval ${CDB_VAR}; done\n')
130                    if self.time_diff:
131                        out.writei('#Previous year\n')
132                        out.writei('let "CDB_YEAR-=1"\n')
133                        out.writei('CDB_VAR_ATTRIBUTION=`bash $CDB_SOURCE_DIR/retrieval_script.sh -d ${CDB_DIAG_NAME} -v ${CDB_VAR_LIST} -m ${CDB_MODEL} -e ${CDB_EXPT} -r ${CDB_RUN_ID} -y ${CDB_YEAR}`\n')
134                        out.writei('for CDB_VAR in ${CDB_VAR_ATTRIBUTION}; do eval PREV_${CDB_VAR}; done\n')
135                        out.writei('#Next year\n')
136                        out.writei('let "CDB_YEAR+=2"\n')
137                        out.writei('CDB_VAR_ATTRIBUTION=`bash $CDB_SOURCE_DIR/retrieval_script.sh -d ${CDB_DIAG_NAME} -v ${CDB_VAR_LIST} -m ${CDB_MODEL} -e ${CDB_EXPT} -r ${CDB_RUN_ID} -y ${CDB_YEAR}`\n')
138                        out.writei('for CDB_VAR in ${CDB_VAR_ATTRIBUTION}; do eval NEXT_${CDB_VAR}; done\n')
139                        out.writei('let "CDB_YEAR-=1"\n')
140            elif line.lstrip()[:15].upper() == '#!END YEAR LOOP':
141                out.open.write('EndOfScriptMain\n')
142                out.writei('}\n')
143
144                #YEARS LOOP --- SHOULD ALLOW A PBS IMPLEMENTATION
145                out.writei('\n')
146                out.writei('\n')
147                out.writei('CDB_YEAR_START=$(echo $CDB_YEARS | awk -F\',\' \'{print $1}\')\n')
148                out.writei('CDB_YEAR_END=$(echo $CDB_YEARS | awk -F\',\' \'{print $2}\')\n')
149                out.writei('CDB_YEAR=${CDB_YEAR_START}\n')
150                #Create yearly_scripts
151                out.writei('if [ -z "$CDB_YEARS_FIX_LIST" ];then\n')
152                out.inc_indent()
153                out.writei('while [ "$CDB_YEAR" -le "$CDB_YEAR_END" ]; do\n')
154                out.inc_indent()
155                out.writei('yearly_processing $CDB_YEAR ${CDB_TEMP_DIR}/script_${CDB_YEAR}.sh\n')
156                out.writei('let "CDB_YEAR += 1"\n')
157                out.dec_indent()
158                out.writei('done #CDB_YEAR\n')
159                out.dec_indent()
160                out.writei('else\n')
161                out.inc_indent()
162                out.writei('#The user has specified a subset of years to be computed.\n')
163                out.writei('for CDB_YEAR in $CDB_YEARS_FIX_LIST; do\n')
164                out.inc_indent()
165                out.writei('yearly_processing $CDB_YEAR ${CDB_TEMP_DIR}/script_${CDB_YEAR}.sh\n')
166                out.dec_indent()
167                out.writei('done #CDB_YEAR\n')
168                out.dec_indent()
169                out.writei('fi\n')
170
171                #Process the yearly_scripts
172                if self.debug:
173                    out.writei('for SCRIPT in `ls ${CDB_TEMP_DIR}/script_????.sh`; do bash $SCRIPT; rm $SCRIPT; done\n')
174                elif self.y_async == 1:
175                    out.writei('for SCRIPT in `ls ${CDB_TEMP_DIR}/script_????.sh`; do bash $SCRIPT > ${CDB_OUT_DIR}/${CDB_OUT_FILE}.out 2>&1; rm $SCRIPT; done\n')
176                else:
177                    out.writei('ls ${CDB_TEMP_DIR}/script_????.sh | parallel --tmpdir ${CDB_OUT_DIR} -k -j'+str(self.y_async)+' "bash {}" > ${CDB_OUT_DIR}/${CDB_OUT_FILE}.out 2>&1 &\n')
178                    out.writei('pid=${!}\n')
179                    out.writei('${CDB_SOURCE_DIR}/parallel_ramdisk.sh $pid ${CDB_TEMP_DIR}\n')
180                    out.writei('rm ${CDB_TEMP_DIR}/script_????.sh\n')
181
182            elif line.lstrip()[:10].upper() == '#!PARALLEL' and self.dim_async > 1:
183                if parallel_dimension != None:
184                    raise IOError('Attempting to parallelize a dimension without having closed the previous parallel instance')
185                else:
186                    parallel_dimension = line.lstrip()[10:].rstrip('\n').strip()
187                    out.writei('#Creating a parallel loop over dimension '+parallel_dimension+' with '+str(self.dim_async)+' processors:\n')
188                    out.writei('#########################################################################\n')
189                    out.writei('#Identify the files to transfer\n')
190                    out.writei('LIST_TEMP_FILE=`ls ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}*`\n')
191                    out.writei('export LIST_FILE_ID=`for FILE in ${LIST_TEMP_FILE}; do echo ${FILE#${CDB_TEMP_DIR}/${CDB_TEMP_FILE}}; done`\n')
192                    out.writei('export CDB_TEMP_FILE="${CDB_TEMP_FILE}"\n')
193
194                    out.writei('\n')
195                    out.writei('#Define splitting function:\n')
196                    out.writei('function parallel_dimension_'+parallel_dimension+str(parallel_dimension_number)+'() {\n')
197
198                    out.inc_indent()
199                    out.writei('cat > $1 <<\'EndOfFunction\'\n')
200                    out.writei('NUM_DIM=`echo $1 | tr \',\' \' \' | awk -F\' \' \'{ print $1 }\'`\n')
201                    out.writei('LAST_NUM=`echo $1 | tr \',\' \' \' | awk -F\' \' \'{ print $2 }\'`\n')
202                    out.writei('NUM_ID=$(printf "%03d" ${NUM_DIM})\n')
203                    out.writei('for FILE_ID in $LIST_FILE_ID; do\n')
204
205                    out.inc_indent()
206                    out.writei('DIM_LENGTH=`ncks -H -v '+parallel_dimension+' ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID} | wc -l`\n')
207                    out.writei('let "DIM_LENGTH-=1"\n')
208                    out.writei('if [ "$DIM_LENGTH" -gt "1" ]; then\n')
209
210                    out.inc_indent()
211                    out.writei('ncks -d '+parallel_dimension+',${NUM_DIM},${LAST_NUM} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'${NUM_ID}${FILE_ID}\n')
212                    out.dec_indent()
213                    out.writei('else\n')
214                    out.inc_indent()
215                    out.writei('cp ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'${NUM_ID}${FILE_ID}\n')
216                    out.dec_indent()
217                    out.writei('fi\n')
218
219                    out.dec_indent()
220                    out.writei('done\n')
221                    out.writei('if [ -e "${CDB_TEMP_DIR}/${CDB_TEMP_FILE}" ]; then\n')
222                    out.writei('ncks -d '+parallel_dimension+',${NUM_DIM},${LAST_NUM} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'${NUM_ID}\n')
223                    out.writei('fi\n')
224                    out.writei('CDB_TEMP_FILE="${CDB_TEMP_FILE}.'+parallel_dimension+'${NUM_ID}"\n')
225                    out.writei('#########################################################################\n')
226                    out.inc_indent()
227                    out.inc_indent()
228            elif line.lstrip()[:14].upper() == '#!END PARALLEL' and self.dim_async > 1:
229                if line.lstrip()[14:].rstrip('\n').strip() != parallel_dimension:
230                    raise IOError('Attempting to close a different parallel instance')
231                else:
232                    out.dec_indent()
233                    out.dec_indent()
234                    out.writei('#########################################################################\n')
235                    out.writei('for FILE_ID in $LIST_FILE_ID; do rm -f ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}; done\n')
236                    out.writei('if [ -e "${CDB_TEMP_DIR}/${CDB_TEMP_FILE}" ]; then\n')
237                    out.writei('rm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}\n')
238                    out.writei('fi\n')
239                    out.writei('\n')
240                    if parallel_dimension != 'time':
241                         out.writei('LIST_LOCAL_FILE=`ls ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}*`\n')
242                         out.writei('export LIST_LOCAL_FILE_ID=`for FILE in ${LIST_LOCAL_FILE}; do echo ${FILE#${CDB_TEMP_DIR}/${CDB_TEMP_FILE}}; done`\n')
243                         out.writei('for FILE_ID in $LIST_LOCAL_FILE_ID; do\n')
244                         out.inc_indent()
245                         out.writei('ncpdq -a '+parallel_dimension+',time ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}_perm\n')
246                         out.writei('mv ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}_perm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}\n')
247                         out.dec_indent()
248                         out.writei('done\n')
249
250
251                    out.dec_indent()
252                    out.open.write('EndOfFunction\n')
253                    out.dec_indent()
254                    out.writei('}\n')
255                    out.writei('parallel_dimension_'+parallel_dimension+str(parallel_dimension_number)+' ${CDB_TEMP_DIR}/'+parallel_dimension+'_function'+str(parallel_dimension_number)+'.sh\n')
256                    out.writei('#Performing parallel computation\n')
257                    out.writei('DIM_LENGTHS=`for FILE in $LIST_TEMP_FILE; do ncks -H -v '+parallel_dimension+' ${FILE} | wc -l; done`\n')
258                    out.writei('DIM_LENGTH=`for DIM in ${DIM_LENGTHS}; do echo $DIM; done | awk \'{if(min==""){min=max=$1}; if($1>max) {max=$1}; if($1<min) {min=$1}} END {print max}\'`\n')
259                    out.writei('let "DIM_LENGTH -= 2"\n')
260                    if line.lstrip()[:14].upper() == '#!END PARAFULL':
261                        out.writei('STRIDE=1\n')
262                    else:
263                        out.writei('STRIDE=`expr $DIM_LENGTH / '+str(self.dim_async)+' + 1`\n')
264                    out.writei('NUM_DIM=0\n')
265                    out.writei('while [ "$NUM_DIM" -le "$DIM_LENGTH" ]; do if [ "$((${NUM_DIM} + ${STRIDE} - 1))" -ge "$DIM_LENGTH" ]; then \\\n')
266                    out.writei('echo ${NUM_DIM},${DIM_LENGTH}; else echo ${NUM_DIM},$((${NUM_DIM} + ${STRIDE} - 1)); fi; \\\n')
267                    out.writei('let "NUM_DIM += ${STRIDE}"; done |\\\n')
268                    out.writei('parallel -j'+str(self.dim_async)+' -k "bash ${CDB_TEMP_DIR}/'+parallel_dimension+'_function'+str(parallel_dimension_number)+'.sh {}"\n')
269                    out.writei('rm ${CDB_TEMP_DIR}/'+parallel_dimension+'_function'+str(parallel_dimension_number)+'.sh\n')
270                    out.writei('\n')
271                    out.writei('#Delete files that were deleted in the parallel process\n')
272                    out.writei('for FILE_ID in $LIST_FILE_ID; do\n')
273                    out.inc_indent()
274                    out.writei('if [ ! -f ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'000${FILE_ID} ]; then rm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}; fi\n')
275                    out.dec_indent()
276                    out.writei('done\n')
277
278                    out.writei('#Recombine output files\n')
279                    out.writei('LIST_PARALLEL_FILE=`ls ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'000*`\n')
280                    out.writei('LIST_PARALLEL_FILE_ID=`for FILE in ${LIST_PARALLEL_FILE}; do echo ${FILE#${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'000}; done`\n')
281
282                    out.writei('for FILE_ID in $LIST_PARALLEL_FILE_ID; do\n')
283                    out.inc_indent()
284                    out.writei('if [ ! -f ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID} ]; then\n')
285                    out.inc_indent()
286                    out.writei('ncrcat ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'???${FILE_ID} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}\n')
287                    out.writei('rm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'???${FILE_ID}\n')
288                    if parallel_dimension != 'time':
289                        out.writei('ncpdq -a time,'+parallel_dimension+' ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID} ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}_perm\n')
290                        out.writei('mv ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}_perm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}${FILE_ID}\n')
291                    out.dec_indent()
292                    out.writei('else\n')
293                    out.inc_indent()
294                    out.writei('rm ${CDB_TEMP_DIR}/${CDB_TEMP_FILE}.'+parallel_dimension+'???${FILE_ID}\n')
295                    out.dec_indent()
296                    out.writei('fi\n')
297                    out.dec_indent()
298                    out.writei('done\n')
299                    out.writei('#########################################################################\n')
300                    parallel_dimension=None
301                    parallel_dimension_number+=1
302            else:
303                out.writei(line)
304        #Finally, introduce the code to structure the output as in an ESG archive:
305        out.writei('if [ ! -z "$CDB_CMIP5_COMP_LIST" ]; then\n')
306        out.inc_indent()
307        out.writei('for FILE_DESC in $CDB_CMIP5_COMP_LIST; do\n')
308        out.inc_indent()
309        out.writei('FILE=$(echo $FILE_DESC | awk -F\';\' \'{print $1}\')\n')
310        out.writei('REALM_FREQ_INFO=$(echo $FILE_DESC | awk -F\';\' \'{print $2}\')\n')
311        out.writei('bash $CDB_SOURCE_DIR/structure_out_as_in.sh -d ${CDB_DIAG_NAME} -m ${CDB_MODEL} -e ${CDB_EXPT} -r ${CDB_RUN_ID} -y ${CDB_YEARS} -f ${REALM_FREQ_INFO} $FILE\n')
312        out.dec_indent()
313        out.writei('done\n')
314        out.dec_indent()
315        out.writei('fi\n')
316        #if self.pbs_expt:
317        out.writei('rm -rf ${CDB_TEMP_DIR}\n')
318        out.open.close()
319
320if __name__ == "__main__":
321    import sys
322    #from netCDF4 import Dataset
323    from optparse import OptionParser, OptionGroup
324    import os
325    import shutil
326
327    #import numpy as np
328    #from mpl_toolkits.basemap import Basemap
329
330    #Option parser
331    parser = OptionParser()
332
333    #Setup options
334    setup_group=OptionGroup(parser, "Setup","These options must be set when using this script")
335    setup_group.add_option("-m","--model",dest="model",
336                      default="CanESM2",
337                      help="Model to diagnose")
338    setup_group.add_option("-r","--run_id",dest="run_id",
339                      default="r1i1p1",
340                      help="Run ID")
341    setup_group.add_option("-e","--experiment",dest="experiment",
342                      default="rcp45",
343                      help="Experiment name")
344    setup_group.add_option("-d","--diagnostic",dest="diagnostic",
345                      default="zonal_tas",
346                      help="The diagnostic to compute")
347    setup_group.add_option("-D","--diag_dir",dest="diag_dir",
348                      default=".",
349                      help="Diagnostic directory")
350    setup_group.add_option("-y","--years",dest="years",
351                      default="2050,2099",
352                      help="Comma-separated begining and end years")
353    setup_group.add_option("-o","--output_file",dest="output_file",
354                      default="script",
355                      help="Script output file")
356    setup_group.add_option("-s","--source_dir",dest="source_dir",
357                      default=".",
358                      help="CDB_SOURCE_DIR, necessary for -P option")
359
360    parser.add_option_group(setup_group)
361    #Processing Options
362    proc_group=OptionGroup(parser, "Processing","Use these options to set parallelized options. BEWARE! Asynchronous options are largely untested!")
363    proc_group.add_option("-P","--pbs_expt",dest="pbs_expt",
364                      default=False, action="store_true",
365                      help="Prepare a pbs header for each model/run_id/experiment")
366    proc_group.add_option("-w","--walltime",dest="walltime",
367                      default="1:00:00",
368                      help="pbs job walltime. Inactive for now: Determined by queue")
369    proc_group.add_option("-q","--queue",dest="queue",
370                      default=None,
371                      help="PBS queue")
372    proc_group.add_option("--y_async",dest="y_async",
373                      default=1,
374                      help="Uses the specified # of processors for the asynchronous processing of years. Cannot be used with --dim_async.")
375    proc_group.add_option("--dim_async",dest="dim_async",
376                      default=1,
377                      help="Uses the specified # of processors in dimension splitting. Cannot be used with --y_async")
378    proc_group.add_option("--debug",dest="debug",
379                      default=False, action="store_true",
380                      help="Debug flag. Disables options --y_async and --dim_async.")
381    proc_group.add_option("--no_retrieval",dest="no_retrieval",
382                      default=False, action="store_true",
383                      help="Do not put retrieval commands inside the script. For IPCC data there should not be any reason to use this feature.")
384    setup_group.add_option("--time_diff",dest="time_diff",
385                      default=False, action="store_true",
386                      help="Request the year before and the year after: allows to take a time derivative. If the years before and after are unavailable, the script terminates.")
387    parser.add_option_group(proc_group)
388
389    (options, args) = parser.parse_args()
390
391    #Disable asynchronous computing if debugging
392    if options.debug:
393        options.y_async=1
394        options.dim_async=1
395
396    if options.y_async>1 and options.dim_async>1:
397        raise IOError('Only Y_ASYNC>1 or --DIM_ASYNC>1, but not both.')
398
399    experiment = Experiment_Setup(options)
400
401    #PREPARE SCRIPTS
402    experiment.prepare_scripts()
Note: See TracBrowser for help on using the repository browser.