HWRF  trunk@4391
exhwrf_init.py
1 #! /usr/bin/env python
2 
3 ##@namespace scripts.exhwrf_init
4 # Runs the spectral, initial and boundary processing and generates
5 # WRF input files for use by other scripts. Which work is done is
6 # selected by several environment variables:
7 #
8 # * $INIT_MODEL=GFS --- analysis time initialization, which does NOT
9 # have to be from the GFS model.
10 # * $INIT_MODEL=GDAS1 --- initialize from prior cycle of a global model,
11 # which does NOT have to be from the GDAS model.
12 # * $INIT_FHR=N --- for an integer N, the forecast hour of the prior
13 # GDAS cycle. This is generally a number from 3 to 9.
14 # * $INIT_PARTS=ANL --- only run what is needed for the initial time of
15 # the forecast, when relocation and GSI are disabled
16 # * $INIT_PARTS=3DVAR --- all inputs needed for the relocation and GSI
17 # * $INIT_PARTS=BDY --- boundary conditions only
18 # * $INIT_PARTS=ALL --- run all parts of the initialization
19 #
20 # @note Models other than GDAS and GFS can be used as initial, boundary
21 # and previous cycle forecast conditions by modifying the hwrf config
22 # files. However, the $INIT_MODEL variable must still be set to GFS or
23 # GDAS. For example, the GEFS-based HWRF ensemble runs a 20 member
24 # forecast ensemble using the GEFS 20 member forecast, but it still sets
25 # $INIT_MODEL=GFS when running its exhwrf_init scripts with GEFS data.
26 
27 import os, sys, produtil.log, produtil.setup
28 from produtil.log import jlogger
29 
30 def fail(msg):
31  """!Log a message to produtil.log.jlogger and exit with status 0
32  @param msg the error message"""
33  jlogger.error(msg)
34  sys.exit(2)
35 
36 def main():
37  """!Run the selected parts of the initialization."""
38  ENV=os.environ
39  init_model=ENV['INIT_MODEL'].lower()
40  init_fhr=int(ENV.get('INIT_FHR','0'))
41  init_parts=ENV['INIT_PARTS'].lower()
42  if init_model!='gfs' and init_model!='gdas1':
43  fail('Aborting: init_model="%s" must be "gfs" or "gdas1"'%(init_model,))
44  if init_model=='gdas1' and init_fhr<1:
45  fail('Aborting: when init_model=gdas1, init_fhr must be > 1 (init_fhr=%d)'%(init_fhr,))
46  if init_model=='gfs': init_fhr=0
47 
48  import hwrf_expt
50  os.chdir(hwrf_expt.conf.getdir('WORKhwrf'))
51  if init_model=='gfs':
52  init=hwrf_expt.gfs_init
53  elif not hwrf_expt.conf.getbool('config','run_gsi'):
54  jlogger.info('GSI is disabled. This job need not be run.')
55  sys.exit(0)
56  else:
57  init=None
58  logger=hwrf_expt.fgat_init.log()
59  logger.info('search for fgat hour %d'%(init_fhr,))
60  for fhr,init in hwrf_expt.fgat_init.fhr_and_init():
61  if abs(fhr-init_fhr)<0.01:
62  logger.info('fhr %d is init_fhr %d'%(fhr,init_fhr))
63  #init.run()
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 init_parts == 'parent':
70  init.run_through_anl()
71  elif init_parts == '3dvar':
72  init.run_through_anl()
73  init.run_init_after_anl()
74  elif init_parts == 'bdy':
75  init.run_real_bdy()
76  elif init_parts == 'all':
77  init.run_through_anl()
78  init.run_init_after_anl()
79  init.run_real_bdy()
80  else:
81  fail('Aborting: invalid value of INIT_PARTS: "%s" (must be "parent," "3dvar" or "bdy")'%(init_parts,))
82 
83 if __name__=='__main__':
84  try:
86  main()
87  except Exception as e:
88  jlogger.critical('HWRF init is aborting: '+str(e),exc_info=True)
89  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 fail(msg)
Log a message to produtil.log.jlogger and exit with status 0.
Definition: exhwrf_init.py:30
Configures logging.
Definition: log.py:1
def main()
Run the selected parts of the initialization.
Definition: exhwrf_init.py:36