HWRF  trunk@4391
exhwrf_forecast.py
1 #! /usr/bin/env python
2 
3 ##@namespace scripts.exhwrf_forecast
4 #Runs the HWRF forecast based on provided input data, producing
5 #native output suitable for the HWRF post processing suite. This
6 #script runs either the coupled or uncoupled forecast job. Which is
7 #chosen is based on the ocean status file. If ocean is enabled, and
8 #ocean init succeeded, a coupled run is attempted. Otherwise, an
9 #uncoupled run.
10 
11 import os, sys
13 import hwrf.mpipomtc, hwrf_wcoss
14 
15 def set_vars(coupling,logger,wrf_ranks):
16  """!Sets MPI tuning variables for the local cluster."""
17  if produtil.cluster.name() in ['gyre','tide']:
18  hwrf_wcoss.set_vars_for_coupled_hwrf(logger,wave,ocean,wrf_ranks)
19  else:
20  logger.info('Not on WCOSS, so not setting WCOSS-specific vars.')
21 
22 def doit():
23  """!Main program for this script: runs the forecast."""
25  import hwrf_expt
27  conf=hwrf_expt.conf
28  logger=hwrf_expt.conf.log('exhwrf_forecast')
29 
30  ocean_flag=conf.getbool('config','run_ocean')
31  ocean_model=conf.getstr('config','ocean_model')
32 
33  wave_flag=conf.getbool('config','run_wave')
34  wave_model=conf.getstr('config','wave_model')
35 
36  fallbacks_flag=conf.getbool('config','allow_fallbacks')
37  wrf_ranks=conf.getint('runwrf','wrf_ranks')
38 
39  run_wave=wave_flag
40  run_ocean=ocean_flag
41 
42  if wave_flag:
43  wave_success=hwrf_expt.wvstatus.get(logger)
44 
45  if wave_model=='WW3' and not hwrf_expt.ww3init.is_completed():
46  logger.warning('The ww3init completion flag is off. '
47  'Wave init failed.')
48  wave_success=False
49 
50  if not wave_success:
51  basin1=conf.syndat.basin1
52  if basin1 in hwrf_expt.non_wave_basins:
54  'Cannot run wave in this basin- run uncoupled.')
55  set_vars(False,logger,wrf_ranks)
56  hwrf_expt.runwrf.remove_wave()
57  elif fallbacks_flag:
58  logger.critical(
59  'CRITICAL FAILURE: HWRF wave init failed, but '
60  'fallbacks are enabled. Running uncoupled.')
61  set_vars(False,logger,wrf_ranks)
62  hwrf_expt.runwrf.remove_wave()
63  return
64  else:
65  logger.critical(
66  'CRITICAL FAILURE: HWRF wave init failed, and '
67  'fallbacks are disabled. Aborting.')
68  sys.exit(1)
69  else:
70  produtil.log.postmsg('Wave init succeeded. Running coupled.')
71  #set_vars(True,logger,wrf_ranks)
72  else:
73  produtil.log.postmsg('Wave is disabled. Running uncoupled.')
74  #set_vars(False,logger,wrf_ranks)
75 
76  if ocean_flag:
77  ocean_success=hwrf_expt.ocstatus.get(logger)
78 
79  if ocean_model=='POM' and not hwrf_expt.pominit.is_completed():
80  logger.warning('The pominit completion flag is off. '
81  'Ocean init failed.')
82  ocean_success=False
83 
84  if ocean_model=='HYCOM' and not hwrf_expt.hycominit.is_completed():
85  logger.warning('The hycominit completion flag is off. '
86  'Ocean init failed.')
87  #ocean_success=False
88 
89  if not ocean_success:
90  basin1=conf.syndat.basin1
91  if basin1 in hwrf_expt.non_ocean_basins:
93  'Cannot run ocean in this basin- run uncoupled.')
94  set_vars(False,logger,wrf_ranks)
95  hwrf_expt.runwrf.remove_ocean()
96  elif fallbacks_flag:
97  logger.critical(
98  'CRITICAL FAILURE: HWRF ocean init failed, but '
99  'fallbacks are enabled. Running uncoupled.')
100  set_vars(False,logger,wrf_ranks)
101  hwrf_expt.runwrf.remove_ocean()
102  else:
103  logger.critical(
104  'CRITICAL FAILURE: HWRF ocean init failed, and '
105  'fallbacks are disabled. Aborting.')
106  sys.exit(1)
107  else:
108  produtil.log.postmsg('Ocean init succeeded. Running coupled.')
109  set_vars(True,logger,wrf_ranks)
110  else:
111  produtil.log.postmsg('Ocean is disabled. Running uncoupled.')
112  set_vars(False,logger,wrf_ranks)
113 
114  hwrf_expt.runwrf.run()
115  produtil.log.postmsg('Forecast complete.')
116 
117 # Multistorm
118 # THIS Function IS NOT being USED. - Technically it can be deleted.
119 # This sets the Number of compute nodes since this changes based on the number of storms.
120 def set_total_tasks(conf):
121  num_storms=len(conf.getstr('config','multistorm_sids','nosids').split(','))
122 
123  num_domains=num_storms*2+1
124 
125  nio_g=int(conf.getstr('runwrf','nio_groups'))
126  nio_tpg=conf.getstr('runwrf','nio_tasks_per_group').split(',')
127 
128  npx=int(conf.getstr('runwrf_namelist','dm_task_split.nest_pes_x').split(',')[0])
129  npy=int(conf.getstr('runwrf_namelist','dm_task_split.nest_pes_y').split(',')[0])
130  num_computetasks=npx*npy
131 
132  num_iotasks=0
133  for index in range(num_domains):
134  num_iotasks+=nio_g*int(nio_tpg[index])
135 
136  total_tasks=num_computetasks + num_iotasks
137 
138  os.environ["TOTAL_TASKS"]=str(total_tasks)
139 
140 
141 if __name__=='__main__':
142  doit()
Runs the POM initialization and POM-WRF coupled forecast.
Definition: mpipomtc.py:1
Contains setup(), which initializes the produtil package.
Definition: setup.py:1
def doit()
Main program for this script: runs the forecast.
def init_module
Initializes the HWRF object structure.
Definition: hwrf_expt.py:384
def postmsg(message)
Sends the message to the jlogfile logging stream at level INFO.
Definition: log.py:46
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
Provides information about the cluster on which this job is running.
Definition: cluster.py:1
Configures logging.
Definition: log.py:1
def set_vars_for_coupled_hwrf(logger, wave, ocean, wrf_ranks)
Sets variables that seem to speed up the H15B (2015 pre-baseline) version of HWRF on Phase I WCOSS...
Definition: hwrf_wcoss.py:60
def name()
Synonym for here.name.
Definition: cluster.py:109
def set_vars(coupling, logger, wrf_ranks)
Sets MPI tuning variables for the local cluster.