HWRF  trunk@4391
exhwrf_relocate.py
1 #! /usr/bin/env python
2 
3 ##@namespace scripts.exhwrf_relocate
4 # Relocates, resizes and otherwise modifies the vortex from the
5 # parent model and prior HWRF cycle's forecast.
6 #
7 # * $INIT_MODEL=GFS --- analysis time initialization, which does NOT
8 # have to be from the GFS model.
9 # * $INIT_MODEL=GDAS1 --- initialize from prior cycle of a global model,
10 # which does NOT have to be from the GDAS model.
11 # * $INIT_FHR=N --- for an integer N, the forecast hour of the prior
12 # GDAS cycle. This is generally a number from 3 to 9.
13 #
14 # @note Models other than GDAS and GFS can be used as initial, boundary
15 # and previous cycle forecast conditions by modifying the hwrf config
16 # files. However, the $INIT_MODEL variable must still be set to GFS or
17 # GDAS. For example, the GEFS-based HWRF ensemble runs a 20 member
18 # forecast ensemble using the GEFS 20 member forecast, but it still sets
19 # $INIT_MODEL=GFS when running its exhwrf_init scripts with GEFS data.
20 
21 import os, sys, produtil.log, produtil.setup
22 from produtil.log import jlogger
23 
24 def fail(msg):
25  """!Log a message to produtil.log.jlogger and exit with status 0
26  @param msg the error message"""
27  jlogger.error(msg)
28  sys.exit(2)
29 
30 def main():
31  """!Runs the hwrf.init.HWRFInit.run_relocate() for the selected initialization:
32 
33  * INIT_MODEL=GFS --- hwrf_expt.gfs_init.run_relocate()
34  * INIT_MODEL=GDAS --- the run_relocate() is called for the appropriate
35  member of hwrf_expt.fgat_init"""
36  ENV=os.environ
37  init_model=ENV['INIT_MODEL'].lower()
38  init_fhr=int(ENV.get('INIT_FHR','0'))
39  if init_model!='gfs' and init_model!='gdas1':
40  fail('Aborting: init_model="%s" must be "gfs" or "gdas1"'%(init_model,))
41  if init_model=='gdas1' and init_fhr<1:
42  fail('Aborting: when init_model=gdas1, init_fhr must be >= 1 (init_fhr=%d)'%(init_fhr,))
43  if init_model=='gfs': init_fhr=0
44 
45  import hwrf_expt
47  if init_model=='gfs':
48  jlogger.info('HWRF relocation for GFS fhr starting')
49  init=hwrf_expt.gfs_init.run_relocate()
50  jlogger.info('HWRF relocation for GFS fhr completed')
51  elif not hwrf_expt.conf.getbool('config','run_gsi'):
52  jlogger.info('GSI is disabled. This job need not be run.')
53  sys.exit(0)
54  else:
55  init=None
56  logger=hwrf_expt.fgat_init.log()
57  logger.info('search for fgat hour %d'%(init_fhr,))
58  for fhr,init in hwrf_expt.fgat_init.fhr_and_init():
59  if abs(fhr-init_fhr)<0.01:
60  logger.info('fhr %d is init_fhr %d'%(fhr,init_fhr))
61  jlogger.info('HWRF relocation for GDAS1 fhr %d starting'%fhr)
62  init.run_relocate()
63  jlogger.info('HWRF relocation for GDAS1 fhr %d completed'%fhr)
64  break
65  else:
66  logger.info('fhr %d is not init_fhr %d'%(fhr,init_fhr))
67  assert(init is not None)
68 
69 if __name__=='__main__':
70  try:
72  main()
73  except Exception as e:
74  jlogger.critical('HWRF relocation is aborting: '+str(e),exc_info=True)
75  sys.exit(2)
Contains setup(), which initializes the produtil package.
Definition: setup.py:1
def init_module
Initializes the HWRF object structure.
Definition: hwrf_expt.py:384
def setup(ignore_hup=False, dbnalert_logger=None, jobname=None, cluster=None, send_dbn=None, thread_logger=False, thread_stack=2 **24, kwargs)
Initializes the produtil package.
Definition: setup.py:15
def main()
Runs the hwrf.init.HWRFInit.run_relocate() for the selected initialization:
Configures logging.
Definition: log.py:1
def fail(msg)
Log a message to produtil.log.jlogger and exit with status 0.