HWRF  trunk@4391
exhwrf_input.py
1 #! /usr/bin/env python
2 
3 ##@namespace scripts.exhwrf_input
4 # Pulls input data from tape or over the network.
5 #
6 # This script will examine the selected HWRF configuration to figure out
7 # what data is needed to run it. This is done by calling
8 # hwrf_expt.inputiter(). The result is sent to an
9 # hwrf.input.InputSource for processing. The InputSource object will
10 # pull data from multiple sources in priority order, as defined in the
11 # hwrf configuration files (typically parm/hwrf_input.conf)
12 
13 import logging, os, sys
15 from produtil.log import jlogger
16 from produtil.run import batchexe
17 import hwrf.input
18 
19 def main(args):
20  """!Uses an hwrf.input.InputSource to get data requested by the
21  HWRF configuration (hwrf_expt.inputiter()). Will exit with status
22  1 if any mandatory data is missing."""
23  import hwrf_expt
24  hwrf_expt.init_module(make_ensemble_da=True)
25 
26  conf=hwrf_expt.conf
27  cycle=hwrf_expt.conf.cycle
28  input_catalog=conf.get('config','input_catalog')
29  input_sources=conf.get('config','input_sources')
30  logger=conf.log('exhwrf_input')
31  WORKhwrf=conf.getdir('WORKhwrf')
32 
33  if input_catalog!='hwrfdata':
34  jlogger.info("Input catalog is %s, not \"hwrfdata\" so data should "
35  "be staged on disk already. I have nothing to do, so "
36  "I'll just exit. This is not an error.")
37  sys.exit(0)
38 
39  # Make sure we're in the cycle's work directory, otherwise we might
40  # pull archives and other big things to $HOME.
41  produtil.fileop.chdir(WORKhwrf,logger=logger)
42 
43  # Figure out how to run htar:
44  htar=batchexe(conf.getexe('htar'))
45 
46  # Figure out how to run hsi:
47  hsi=batchexe(conf.getexe('hsi'))
48 
49  # Get the list of data to pull:
50  indata=list(d for d in hwrf_expt.inputiter())
51 
52  nostage=True
53  skipme=set()
54  onlyme=set()
55  for arg in args:
56  if arg[0:5]=='skip:':
57  logger.info('%s: skip dataset %s'%(arg,arg[5:]))
58  skipme.add(arg[5:])
59  elif arg[0:5]=='only:':
60  logger.info('%s: only pull dataset %s'%(arg,arg[5:]))
61  onlyme.add(arg[5:])
62  elif arg == '--stage':
63  logger.info('--stage: enable -Hnostage')
64  nostage=False
65  elif arg=='-Hnostage' or arg=='--nostage' or arg=='--no-stage':
66  logger.info('%s: do not use -Hnostage'%(arg,))
67  nostage=True
68  else:
69  logger.warning('Ignoring unrecognized argument %s'%(repr(arg),))
70 
71  # Make the final list:
72  data=list()
73  for d in indata:
74  ds=d['dataset']
75  if ds in skipme or (onlyme and (ds not in onlyme)):
76  pass #logger.info('SKIP: %s'%(repr(d),))
77  else:
78  #logger.info('FIND: %s'%(repr(d),))
79  data.append(d)
80 
81  # Decide where to put the data:
82  cat=hwrf.input.DataCatalog(conf,"hwrfdata",cycle)
83 
84  if nostage:
85  jlogger.info('Enabling htar -Hnostage option.')
86  htar=htar['-Hnostage']
87  else:
88  jlogger.info('Not using htar -Hnostage option.')
89 
90  # Now pull the data:
91  getem=hwrf.input.InputSource(conf,input_sources,conf.cycle,
92  htar=htar,hsi=hsi,logger=logger)
93  bad=not getem.get(data,cat)
94  if bad:
95  jlogger.error('Missing data in exhwrf_input. Workflow may fail.')
96  sys.exit(1)
97 
98 if __name__=='__main__':
99  try:
100  produtil.setup.setup(thread_logger=True,eloglevel=logging.INFO)
101  jlogger.info("HWRF input job starting")
102  main(sys.argv[1:])
103  jlogger.info("HWRF input job completed")
104  except Exception as e:
105  jlogger.critical('HWRF input is aborting: '+str(e),exc_info=True)
106  sys.exit(2)
This module provides a set of utility functions to do filesystem operations.
Definition: fileop.py:1
Contains setup(), which initializes the produtil package.
Definition: setup.py:1
def init_module
Initializes the HWRF object structure.
Definition: hwrf_expt.py:384
A shell-like syntax for running serial, MPI and OpenMP programs.
Definition: run.py:1
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 inputiter()
Iterates over all inputs required by this configuration.
Definition: hwrf_expt.py:148
Obtains input data needed by various subclasses of hwrf.hwrftask.HWRFTask.
Definition: input.py:1
def main(args)
Uses an hwrf.input.InputSource to get data requested by the HWRF configuration (hwrf_expt.inputiter()).
Definition: exhwrf_input.py:19
Fetch data from multiple sources.
Definition: input.py:301
Configures logging.
Definition: log.py:1
Provides the location of a file in an archive, on disk or on a remote server via sftp or ftp...
Definition: input.py:109
def chdir
Changes to the specified directory.
Definition: fileop.py:145