HWRF  trunk@4391
prelaunch.py
1 """!Functions called automatically before a cycle is launched.
2 
3 This module contains utility functions for the hwrf.launcher.launch()
4 prelaunch argument. These functions edit the configuration of an
5 individual cycle before the cycle starts."""
6 
7 import os
8 import hwrf.numerics
9 import produtil.fileop
10 
11 ##@var __all__
12 # Symbols exported by "from hwrf.prelaunch import *"
13 __all__=['prelaunch_ungrib','prelaunch_rsmc','prelaunch_basin']
14 
15 def prelaunch_ensid(conf,logger):
16  """!Changes the ungrib item and item2 based on the ensemble ID.
17  This is used to ensure ensemble member 0 uses the GEFS control,
18  which has a different item in the hwrf.input.DataCatalog."""
19  ens_overrides=conf.getbool('prelaunch','ensid_overrides')
20  if not ens_overrides:
21  logger.info('Ensemble ID overrides are disabled.')
22  return
23  ens=conf.getint('config','ENS',99)
24  item=conf.get('ungrib','item_E%02d'%ens,'')
25  item2=conf.get('ungrib','item2_E%02d'%ens,'')
26  if item:
27  logger.info('Overriding [ungrib] item=item_E%02d=%s'%(ens,item))
28  conf.set('ungrib','item',item)
29  if item2:
30  logger.info('Overriding [ungrib] item2=item2_E%02d=%s'%(ens,item2))
31  conf.set('ungrib','item2',item2)
32 
33 def prelaunch_ungrib(conf,logger,cycle):
34  """!Change the ungrib table based on the year.
35 
36  Modifies the tbl entry in the [ungrib] section based on the year
37  if a tbl$YEAR is available for the year of the cycle being run.
38  @param conf the hwrf.config.HWRFConfig to modify
39  @param logger the logging.Logger for log messages
40  @param cycle the cycle being run."""
41  ungrib_overrides=conf.getbool('prelaunch','ungrib_overrides')
42  if not ungrib_overrides:
43  logger.info('Ungrib overrides are disabled.')
44  return
45 
46  # We're in an exhwrf_launch job, not in run_hwrf.py
47  cyc=hwrf.numerics.to_datetime(cycle) # the cycle as a datetime
48 
49  # Replace [ungrib] tbl with per-year data
50  tblYEARname=cyc.strftime("tbl%Y") # ie.: tbl2011 for 2011090418
51  tblYEARvalue=conf.get("ungrib",tblYEARname,'')
52  if tblYEARvalue:
53  conf.set("ungrib",'tbl',tblYEARvalue)
54 
55 def prelaunch_rsmc(conf,logger,cycle):
56  """!Modifies the configuration for the RSMC (JTWC, NHC, etc.)
57 
58  Modifies the configuration to work differently for JTWC and NHC
59  storms. Searches for the rsmc_conf option in the [prelaunch]
60  section for the name of a configuration file to read, and reads it
61  if it exists.
62  @param conf the hwrf.config.HWRFConfig to modify
63  @param logger the logging.Logger for log messages
64  @param cycle the cycle being run."""
65  rsmc_overrides=conf.getbool('prelaunch','rsmc_overrides')
66  if not rsmc_overrides:
67  logger.info('RSMC overrides are disabled.')
68  return
69 
70  vit=conf.syndat
71  rsmc=str(vit.center).upper()
72  rfile=conf.strinterp('prelaunch','{rsmc_conf}',RSMC=rsmc)
73  if not produtil.fileop.isnonempty(rfile):
74  logger.warning('%s: RSMC override file is empty or non-existent'
75  %(rfile,))
76  conf.read(rfile)
77 
78 def prelaunch_basin(conf,logger,cycle):
79  """!Modifies the configuration for the basin.
80 
81  @anchor prelaunch_basin_main
82  Modifies the configuration to work differently for each basin.
83  Searches for the basin_conf option in the [prelaunch] section for
84  the name of a configuration file to read, and reads it if it
85  exists. If it does not exist, searches for the no_basin_conf
86  section in [prelaunch] and runs that instead, if it exists.
87  @param conf the hwrf.config.HWRFConfig to modify
88  @param logger the logging.Logger for log messages
89  @param cycle the cycle being run."""
90  basin_overrides=conf.getbool('prelaunch','basin_overrides')
91  if not basin_overrides:
92  logger.info('Basin overrides are disabled.')
93  return
94 
95  vit=conf.syndat
96  if vit is None:
97  logger.warning('Cannot use basin overrides - conf.syndat is None')
98  return
99  bfile=conf.strinterp('prelaunch','{basin_conf}',vit=vit)
100  nfile=conf.strinterp('prelaunch','{no_basin_conf}',vit=vit)
101 
102  if os.path.exists(bfile):
103  logger.warning('%s: reading basin override file'%(bfile,))
104  conf.read(bfile)
105  elif os.path.exists(nfile):
106  logger.warning('%s: basin override enabled, but file is '
107  'missing or empty; will read %s instead.'
108  %(bfile,nfile))
109  conf.read(nfile)
110  else:
111  logger.warning('%s: basin override enabled, and no "no_basin_file"'
112  'is available at %s; will not override defaults.'
113  %(bfile,nfile))
114 
This module provides a set of utility functions to do filesystem operations.
Definition: fileop.py:1
def prelaunch_basin(conf, logger, cycle)
Modifies the configuration for the basin.
Definition: prelaunch.py:78
def prelaunch_ensid(conf, logger)
Changes the ungrib item and item2 based on the ensemble ID.
Definition: prelaunch.py:15
def isnonempty(filename)
Returns True if the filename refers to an existent file that is non-empty, and False otherwise...
Definition: fileop.py:333
def to_datetime(d)
Converts the argument to a datetime.
Definition: numerics.py:346
Time manipulation and other numerical routines.
Definition: numerics.py:1
def prelaunch_ungrib(conf, logger, cycle)
Change the ungrib table based on the year.
Definition: prelaunch.py:33
def prelaunch_rsmc(conf, logger, cycle)
Modifies the configuration for the RSMC (JTWC, NHC, etc.)
Definition: prelaunch.py:55