def metplus_config():
    """! Create a METplus configuration object that can be
    manipulated/modified to
         reflect different paths, directories, values, etc. for individual
         tests.
    """
    # Read in the configuration object CONFIG
    config = config_metplus.setup(util.baseinputconfs)
    util.get_logger(config)
    return config
 def __init__(self, p, logger):
     #pylint:disable=redefined-outer-name
     super(CyclonePlotterWrapper, self).__init__(p, logger)
     if logger is None:
         self.logger = util.get_logger(self.p)
     else:
         self.logger = logger
     self.app_path = os.path.join(p.getdir('MET_INSTALL_DIR'),
                                  'bin/tc_pairs')
     self.app_name = os.path.basename(self.app_path)
     self.input_data = p.getdir('CYCLONE_INPUT_DIR')
     self.output_dir = p.getdir('CYCLONE_OUT_DIR')
     self.init_date = p.getstr('config', 'CYCLONE_INIT_DATE')
     self.init_hr = p.getstr('config', 'CYCLONE_INIT_HR')
     self.projection = p.getstr('config', 'CYCLONE_PROJECTION')
     self.model = p.getstr('config', 'CYCLONE_MODEL')
     self.title = p.getstr('config', 'CYCLONE_PLOT_TITLE')
     self.gen_ascii = p.getbool('config', 'GENERATE_TRACK_ASCII')
     # Create a set to keep track of unique storm_ids for each track file.
     self.unique_storm_id = set()
     # Data structure to separate data based on storm id.
     self.storm_id_dict = {}
     # Data/info which we want to retrieve from the track files.
     self.columns_of_interest = [
         'AMODEL', 'STORM_ID', 'BASIN', 'INIT', 'LEAD', 'VALID', 'ALAT',
         'ALON', 'BLAT', 'BLON', 'AMSLP', 'BMSLP'
     ]
     self.llcrnrlat = p.getfloat('config', 'CYCLONE_LLCRNRLAT')
     self.llcrnrlon = p.getfloat('config', 'CYCLONE_LLCRNRLON')
     self.urcrnrlat = p.getfloat('config', 'CYCLONE_URCRNRLAT')
     self.urcrnrlon = p.getfloat('config', 'CYCLONE_URCRNRLON')
     self.resolution = p.getstr('config', 'CYCLONE_RESOLUTION')
     self.circle_marker = p.getint('config', 'CIRCLE_MARKER_SIZE')
     self.cross_marker = p.getint('config', 'CROSS_MARKER_SIZE')
示例#3
0
def metplus_config():
    """! Create a METplus configuration object that can be
    manipulated/modified to
         reflect different paths, directories, values, etc. for individual
         tests.
    """
    try:
        if 'JLOGFILE' in os.environ:
            produtil.setup.setup(send_dbn=False,
                                 jobname='MTDWrapper',
                                 jlogfile=os.environ['JLOGFILE'])
        else:
            produtil.setup.setup(send_dbn=False, jobname='MTDWrapper')
        produtil.log.postmsg('mtd_wrapper  is starting')

        # Read in the configuration object CONFIG
        config = config_metplus.setup()
        logger = util.get_logger(config)
        config = ConfigWrapper(config, logger)
        return config

    except Exception as e:
        produtil.log.jlogger.critical('mtd_wrapper failed: %s' % (str(e), ),
                                      exc_info=True)
        sys.exit(2)
示例#4
0
 def __init__(self, p):
     met_build_base = p.getdir('MET_BUILD_BASE')
     self.tc_exe = os.path.join(met_build_base, 'bin/tc_stat')
     #        self.init_date_beg = p.getstr('config', 'INIT_DATE_BEG')
     #        self.init_date_end = p.getstr('config', 'INIT_DATE_END')
     #        self.init_hour_inc = p.getint('config', 'INIT_HOUR_INC')
     self.logger = util.get_logger(p)
     self.config = p
示例#5
0
 def __init__(self, config, logger=None):
     """!Class for Creating and Running External Programs.
         It was intended to handle the MET executables but
         can be used by other executables."""
     self.config = config
     self.logger = logger
     if self.logger == None:
         self.logger = util.get_logger(self.config,sublog='CommandRunner')
     self.verbose = self.config.getstr('config', 'LOG_MET_VERBOSITY', '2')
示例#6
0
 def __init__(self, p, logger):
     super(TcPairsWrapper, self).__init__(p, logger)
     self.config = self.p
     self.app_path = os.path.join(p.getdir('MET_INSTALL_DIR'), 'bin/tc_pairs')
     self.app_name = os.path.basename(self.app_path)
     if self.logger is None:
         self.logger = util.get_logger(self.p,sublog='TcPairs')
     self.cmd = ''
     self.logger.info("Initialized TcPairsWrapper")
    def __init__(self, p, logger):
        """!Constructor for TCMPRPlotterWrapper
            Args:
            @param p:  The configuration instance, contains
                            the conf file information.
            @param logger:  A logger, can be None
        """

        # pylint:disable=too-many-instance-attributes
        # All these instance attributes are needed to support the
        # plot_tcmpr.R functionality.
        super(TCMPRPlotterWrapper, self).__init__(p, logger)
        self.config = p

        if self.logger is None:
            self.logger = util.get_logger(self.p)

        self._init_tcmpr_script()

        # The only required argument for plot_tcmpr.R, the name of
        # the tcst file to plot.
        self.input_data = p.getstr('config', 'TCMPR_DATA')

        # Optional arguments
        self.plot_config_file = p.getstr('config', 'CONFIG_FILE')
        self.output_base_dir = p.getdir('TCMPR_PLOT_OUT_DIR')
        self.prefix = p.getstr('config', 'PREFIX')
        self.title = p.getstr('config', 'TITLE')
        self.subtitle = p.getstr('config', 'SUBTITLE')
        self.xlab = p.getstr('config', 'XLAB')
        self.ylab = p.getstr('config', 'YLAB')
        self.xlim = p.getstr('config', 'XLIM')
        self.ylim = p.getstr('config', 'YLIM')
        self.filter = p.getstr('config', 'FILTER')
        self.filtered_tcst_data = p.getstr('config', 'FILTERED_TCST_DATA_FILE')
        self.dep_vars = p.getstr('config', 'DEP_VARS')
        self.scatter_x = p.getstr('config', 'SCATTER_X')
        self.scatter_y = p.getstr('config', 'SCATTER_Y')
        self.skill_ref = p.getstr('config', 'SKILL_REF')
        self.series = p.getstr('config', 'SERIES')
        self.series_ci = p.getstr('config', 'SERIES_CI')
        self.legend = p.getstr('config', 'LEGEND')
        self.lead = p.getstr('config', 'LEAD')
        self.plot_types = p.getstr('config', 'PLOT_TYPES')
        self.rp_diff = p.getstr('config', 'RP_DIFF')
        self.demo_year = p.getstr('config', 'DEMO_YR')
        self.hfip_baseline = p.getstr('config', 'HFIP_BASELINE')
        self.footnote_flag = p.getstr('config', 'FOOTNOTE_FLAG')
        self.plot_config_options = p.getstr('config', 'PLOT_CONFIG_OPTS')
        self.save_data = p.getstr('config', 'SAVE_DATA')

        # Optional flags, by default these will be set to False in the
        # produtil config files.
        self.no_ee = p.getbool('config', 'NO_EE')
        self.no_log = p.getbool('config', 'NO_LOG')
        self.save = p.getbool('config', 'SAVE')
 def test_create_tile_grid_string(self):
     # Test that the tile grid string is what was
     # expected.
     p = P.Params()
     p.init(__doc__)
     logger = util.get_logger(p)
     lat = -14.1
     lon = 64.2
     expected_string = 'latlon 49.0:60:0.5 -29.0:60:0.5'
     actual_string = str(et.create_tile_grid_string(lat, lon, logger, p))
     self.assertEqual(actual_string, expected_string)
示例#9
0
 def setUp(self):
     """ Run run_tc_pairs.py based on the metplus.conf file in the
         $METPLUS_BASE/parm directory, then base all unit tests on
         the output from that run.
     """
     self.p = self.get_config()
     self.logger = util.get_logger(self.p)
     self.init_list = util.gen_init_list(
         self.p.getstr('config', 'INIT_DATE_BEG'),
         self.p.getstr('config', 'INIT_DATE_END'),
         self.p.getint('config', 'INIT_HOUR_INC'),
         self.p.getstr('config', 'INIT_HOUR_END'))
     # just run the first time
     self.request_time = self.init_list[0]
示例#10
0
    def __init__(self, p, logger):
        super(PB2NCWrapper, self).__init__(p, logger)
        self.p = p
        if logger is None:
            self.logger = util.get_logger(p)
        self.pb_dict = self.create_pb_dict()

        self.app_path = self.pb_dict['APP_PATH']
        self.app_name = self.pb_dict['APP_NAME']
        self.args = []

        # Conversion of hours to seconds
        # pylint:disable=invalid-name
        # Need to set constant value, most Pythonic way according to
        # Stack-Overflow is to set attribute.
        self.HOURS_TO_SECONDS = 3600
示例#11
0
 def __init__(self, p, logger):
     super(ExtractTilesWrapper, self).__init__(p, logger)
     met_build_base = p.getdir('MET_BUILD_BASE')
     self.app_path = os.path.join(p.getdir('MET_BUILD_BASE'), 'bin/tc_pairs')
     self.app_name = os.path.basename(self.app_path)
     self.tc_pairs_dir = self.p.getdir('TC_PAIRS_DIR')
     self.overwrite_flag = self.p.getbool('config',
                                          'OVERWRITE_TRACK')
     self.addl_filter_opts = \
         self.p.getstr('config', 'EXTRACT_TILES_FILTER_OPTS')
     self.filtered_out_dir = self.p.getdir('EXTRACT_OUT_DIR')
     self.tc_stat_exe = os.path.join(met_build_base, 'bin/tc_stat')
     self.init_beg = self.p.getstr('config', 'INIT_BEG')[0:8]
     self.init_end = self.p.getstr('config', 'INIT_END')[0:8]
     self.init_hour_inc = int(self.p.getint('config', 'INIT_INC') / 3600)
     self.init_hour_end = self.p.getint('config', 'INIT_HOUR_END')
     if self.logger is None:
         self.logger = util.get_logger(self.p)
     self.config = self.p
示例#12
0
    def __init__(self, p, logger):
        super(PointStatWrapper, self).__init__(p, logger)
        if logger is None:
            self.logger = util.get_logger(p)

        self.p = p
        self.ps_dict = self.create_point_stat_dict()

        # For building the argument string via
        # CommandBuilder:
        self.app_path = self.ps_dict['APP_PATH']
        self.app_name = self.ps_dict['APP_NAME']
        self.app_name = os.path.basename(self.app_path)
        self.outdir = ""
        self.outfile = ""
        self.args = []
        self.input_dir = ""
        self.param = ""
        # Conversion factor for hours to seconds
        self.HOURS_TO_SECONDS = 3600
def metplus_config():
    try:
        if 'JLOGFILE' in os.environ:
            produtil.setup.setup(send_dbn=False,
                                 jobname='TCPairsWrapper ',
                                 jlogfile=os.environ['JLOGFILE'])
        else:
            produtil.setup.setup(send_dbn=False, jobname='TCPairsWrapper ')
        produtil.log.postmsg('tc_pairs_wrapper  is starting')

        # Read in the configuration object CONFIG
        config = config_metplus.setup(util.baseinputconfs)
        logger = util.get_logger(config)
        return config

    except Exception as e:
        produtil.log.jlogger.critical('tc_pairs_wrapper failed: %s' %
                                      (str(e), ),
                                      exc_info=True)
        sys.exit(2)
示例#14
0
    def __init__(self, p, logger):
        super(TcStatWrapper, self).__init__(p, logger)
        self.app_name = 'tc_stat'
        self.config = self.p
        self.logger = logger
        if self.logger is None:
            self.logger = util.get_logger(self.p, sublog='TcStat')

        self.app_path = os.path.join(self.p.getdir('MET_INSTALL_DIR'),
                                     'bin/tc_stat')
        self.app_name = os.path.basename(self.app_path)
        self.tc_exe = self.app_path

        # TODO after testing, remove lines below that have ###
        ###met_install_dir = self.p.getdir('MET_INSTALL_DIR')
        ###self.tc_exe = os.path.join(met_install_dir, 'bin/tc_stat')
        #        self.init_date_beg = p.getstr('config', 'INIT_DATE_BEG')
        #        self.init_date_end = p.getstr('config', 'INIT_DATE_END')
        #        self.init_hour_inc = p.getint('config', 'INIT_HOUR_INC')
        ###self.logger = util.get_logger(p)
        ###self.config = p

        self.logger.info("Initialized TcStatWrapper")
示例#15
0
def main():
    """!Main program.

    Master MET+ script that invokes the necessary Python scripts
    to perform various activities, such as series analysis."""

    # Job Logger
    produtil.log.jlogger.info('Top of master_metplus')

    # Used for logging and usage statment
    cur_filename = sys._getframe().f_code.co_filename
    cur_function = sys._getframe().f_code.co_name

    # Setup Task logger, Until Conf object is created, Task logger is
    # only logging to tty, not a file.
    logger = logging.getLogger('master_metplus')
    logger.info('logger Top of master_metplus.')

    # Parse arguments, options and return a config instance.
    p = config_metplus.setup(filename=cur_filename)

    # NOW we have a conf object p, we can now get the logger
    # and set the handler to write to the LOG_METPLUS
    # TODO: Frimel setting up logger file handler.
    # Setting up handler i.e util.get_logger should be moved to
    # the setup wrapper and encapsulated in the config object.
    # than you would get it this way logger=p.log(). The config
    # object has-a logger we want.
    logger = util.get_logger(p)
    #logger.info('Top of master_metplus after conf file setup.')

    # This is available in each subprocess from os.system BUT
    # we also set it in each process since they may be called stand alone.
    os.environ['MET_BASE'] = p.getdir('MET_BASE')

    # Use config object to get the list of processes to call
    process_list = util.getlist(p.getstr('config', 'PROCESS_LIST'))

    # Keep this comment.
    # When running commands in the process_list, reprocess the
    # original command line using (item))[sys.argv[1:]].
    #
    # You could call each task (ie. run_tc_pairs.py) without any args since
    # the final METPLUS_CONF file was just created from config_metplus.setup,
    # and each task, also calls setup, which use an existing final conf
    # file over command line args.
    #
    # both work ...
    # Note: Using (item))sys.argv[1:], is preferable since
    # it doesn't depend on the conf file existing.       
    processes = []
    for item in process_list:
      try:
        logger = p.log(item)
        command_builder = getattr(sys.modules[__name__], item+"Wrapper")(p, logger)
      except AttributeError:
        raise NameError("Process %s doesn't exist" % item)
        exit()

      processes.append(command_builder)

    if p.getstr('config', 'LOOP_METHOD') == "processes":
        for process in processes:
            # referencing using repr(process.app_name) in log since it may be None,
            # if not set in the command builder subclass' contsructor, and no need to
            # generate an exception because of that.
            produtil.log.postmsg('master_metplus Calling run_all_times '
                                 'in: %s wrapper.' % repr(process.app_name))
            process.run_all_times()

    elif p.getstr('config', 'LOOP_METHOD') == "times":
        use_init = p.getbool('config', 'LOOP_BY_INIT', True)
        if use_init:
            time_format = p.getstr('config', 'INIT_TIME_FMT')
            start_t = p.getstr('config', 'INIT_BEG')
            end_t = p.getstr('config', 'INIT_END')
            time_interval = p.getint('config', 'INIT_INC')
        else:
            time_format = p.getstr('config', 'VALID_TIME_FMT')
            start_t = p.getstr('config', 'VALID_BEG')
            end_t = p.getstr('config', 'VALID_END')
            time_interval = p.getint('config', 'VALID_INC')
                        
        if time_interval < 60:
            print("ERROR: time_interval parameter must be greater than 60 seconds")
            exit(1)
        
        loop_time = calendar.timegm(time.strptime(start_t, time_format))
        end_time = calendar.timegm(time.strptime(end_t, time_format))
        while loop_time <= end_time:
            run_time = time.strftime("%Y%m%d%H%M", time.gmtime(loop_time))
            logger.info("****************************************")
            logger.info("* RUNNING MET+")
            if use_init:
                logger.info("*  at init time: " + run_time)
            else:
                logger.info("*  at valid time: " + run_time)
            logger.info("****************************************")            
            for process in processes:
                # Set valid time to -1 if using init and vice versa
                if use_init:
                    process.run_at_time(run_time, -1)
                else:
                    process.run_at_time(-1, run_time)
                process.clear()

            loop_time += time_interval

    else:
        print("ERROR: Invalid LOOP_METHOD defined. " + \
              "Options are processes, times")
        exit()
    exit()
示例#16
0
            # at this point,
            # explicitly remove them (and any resulting empty directories)
            #  so they don't cause any problems with further processing
            # steps.
            util.prune_empty(fcst_anly_ascii_dir, self.logger)


if __name__ == "__main__":
    try:
        if 'JLOGFILE' in os.environ:
            produtil.setup.setup(send_dbn=False,
                                 jobname='SeriesByInit',
                                 jlogfile=os.environ['JLOGFILE'])
        else:
            produtil.setup.setup(send_dbn=False, jobname='SeriesByInit')
        produtil.log.postmsg('series_by_init is starting')

        # Read in the configuration object CONFIG
        CONFIG = config_metplus.setup()
        LOG = util.get_logger(CONFIG)
        if 'MET_BASE' not in os.environ:
            os.environ['MET_BASE'] = CONFIG.getdir('MET_BASE')

        SBI = SeriesByInitWrapper(CONFIG, LOG)
        SBI.run_all_times()
        produtil.log.postmsg('series_by_init completed')
    except Exception as e:
        produtil.log.jlogger.critical('series_by_init failed: %s' % (str(e), ),
                                      exc_info=True)
        sys.exit(2)
示例#17
0
 def setUp(self):
     self.p = self.get_config()
     self.logger = util.get_logger(self.p)
     self.sbi = SeriesByInit(self.p, self.logger)
示例#18
0
def main():
    """!Main program.

    Master METplus script that invokes the necessary Python scripts
    to perform various activities, such as series analysis."""
    # Setup Task logger, Until Conf object is created, Task logger is
    # only logging to tty, not a file.
    logger = logging.getLogger('master_metplus')
    logger.info('Starting METplus v%s', util.get_version_number())

    # Parse arguments, options and return a config instance.
    conf = config_metplus.setup(filename='master_metplus.py')

    # NOW we have a conf object p, we can now get the logger
    # and set the handler to write to the LOG_METPLUS
    # TODO: Frimel setting up logger file handler.
    # Setting up handler i.e util.get_logger should be moved to
    # the setup wrapper and encapsulated in the config object.
    # than you would get it this way logger=p.log(). The config
    # object has-a logger we want.
    logger = util.get_logger(conf)

    logger.info('Running METplus v%s called with command: %s',
                util.get_version_number(), ' '.join(sys.argv))

    # check for deprecated config items and warn user to remove/replace them
    util.check_for_deprecated_config(conf, logger)

    config = ConfigWrapper(conf, logger)

    # set staging dir to OUTPUT_BASE/stage if not set
    if not config.has_option('dir', 'STAGING_DIR'):
        config.set('dir', 'STAGING_DIR',
                   os.path.join(config.getdir('OUTPUT_BASE'), "stage"))

    # handle dir to write temporary files
    util.handle_tmp_dir(config)

    # This is available in each subprocess from os.system BUT
    # we also set it in each process since they may be called stand alone.
    os.environ['MET_BASE'] = config.getdir('MET_BASE')

    config.env = os.environ.copy()

    # Use config object to get the list of processes to call
    process_list = util.getlist(config.getstr('config', 'PROCESS_LIST'))

    # Keep this comment.
    # When running commands in the process_list, reprocess the
    # original command line using (item))[sys.argv[1:]].
    #
    # You could call each task (ie. run_tc_pairs.py) without any args since
    # the final METPLUS_CONF file was just created from config_metplus.setup,
    # and each task, also calls setup, which use an existing final conf
    # file over command line args.
    #
    # both work ...
    # Note: Using (item))sys.argv[1:], is preferable since
    # it doesn't depend on the conf file existing.
    processes = []
    for item in process_list:
        try:
            logger = config.log(item)
            command_builder = \
                getattr(sys.modules[__name__],
                        item + "Wrapper")(config, logger)
            # if Usage specified in PROCESS_LIST, print usage and exit
            if item == 'Usage':
                command_builder.run_all_times()
                exit(1)
        except AttributeError:
            raise NameError("Process %s doesn't exist" % item)

        processes.append(command_builder)

    loop_order = config.getstr('config', 'LOOP_ORDER', '')
    if loop_order == '':
        loop_order = config.getstr('config', 'LOOP_METHOD')

    if loop_order == "processes":
        for process in processes:
            # referencing using repr(process.app_name) in
            # log since it may be None,
            # if not set in the command builder subclass' contsructor,
            # and no need to generate an exception because of that.
            produtil.log.postmsg('master_metplus Calling run_all_times '
                                 'in: %s wrapper.' % repr(process.app_name))
            process.run_all_times()

    elif loop_order == "times":
        util.loop_over_times_and_call(config, processes)

    else:
        logger.error("Invalid LOOP_METHOD defined. " + \
              "Options are processes, times")
        exit()

    # scrub staging directory if requested
    if config.getbool('config', 'SCRUB_STAGING_DIR', False) and\
       os.path.exists(config.getdir('STAGING_DIR')):
        staging_dir = config.getdir('STAGING_DIR')
        logger.info("Scrubbing staging dir: %s", staging_dir)
        shutil.rmtree(staging_dir)

    # rewrite final conf so it contains all of the default values used
    util.write_final_conf(conf, logger)

    logger.info('METplus has successfully finished running.')

    exit()
示例#19
0
def main():
    logger = logging.getLogger('run_example')
    init_time = 0
    start_time = 0
    end_time = 0
    time_interval = 1
    short_opts = "c:r:h"
    long_opts = ["config=", "help", "runtime="]
    # All command line input, get options and arguments
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], short_opts, long_opts)
    except getopt.GetoptError as err:
        print(str(err))
        usage('SCRIPT IS EXITING DUE TO UNRECOGNIZED COMMAND LINE OPTION')
    for k, v in opts:
        if k in ('-c', '--config'):
            # adds the conf file to the list of arguments.
            args.append(config_launcher.set_conf_file_path(v))
        elif k in ('-h', '--help'):
            usage()
            exit()
        elif k in ('-r', '--runtime'):
            start_time = v
            end_time = v
        else:
            assert False, "UNHANDLED OPTION"
    if not args:
        args = None
    (parm, infiles,
     moreopt) = config_launcher.parse_launch_args(args, usage, None, logger)
    p = config_launcher.launch(infiles, moreopt)
    logger = util.get_logger(p)
    logger.setLevel(logging.DEBUG)

    if start_time == 0:
        start_time = p.getstr('config', 'START_TIME')
        end_time = p.getstr('config', 'END_TIME')
        time_interval = p.getstr('config', 'TIME_INTERVAL')

    # Get the list of processes to call
    process_list = util.getlist(p.getstr('config', 'PROCESS_LIST'))

    model_type = p.getstr('config', 'MODEL_TYPE')
    fcst_vars = util.getlist(p.getstr('config', 'FCST_VARS'))
    lead_seq = util.getlistint(p.getstr('config', 'LEAD_SEQ'))

    init_time = start_time
    while init_time <= end_time:
        print("")
        print("****************************************")
        print("* RUNNING MET+")
        print("* EVALUATING " + model_type + " at init time: " + init_time)
        print("****************************************")
        logger.info("****************************************")
        logger.info("* RUNNING MET+")
        logger.info("* EVALUATING " + model_type + " at init time: " +
                    init_time)
        logger.info("****************************************")

        for lead in lead_seq:
            for fcst_var in fcst_vars:
                # loop over models to compare
                accums = util.getlist(p.getstr('config', fcst_var + "_ACCUM"))
                ob_types = util.getlist(
                    p.getstr('config', fcst_var + "_OBTYPE"))
                for accum in accums:
                    for ob_type in ob_types:
                        if lead < int(accum):
                            continue

                        obs_var = p.getstr('config', ob_type + "_VAR")
                        logger.info("")
                        logger.info("")
                        logger.info("For " + init_time + " F" + str(lead) +
                                    ", processing " + model_type + "_" +
                                    fcst_var + "_" + accum + " vs " + ob_type +
                                    " " + obs_var + "_" + accum)

                        valid_time = util.shift_time(init_time, lead)
                        data_interval = p.getint('config',
                                                 ob_type + '_DATA_INTERVAL')
                        if int(valid_time[8:10]) % data_interval != 0:

                            logger.warning("No observation for valid time: " +
                                           valid_time + ". Skipping...")
                            continue

                        for process in process_list:
                            if process == "pcp_combine":
                                run_pcp = CG_pcp_combine(p, logger)
                                run_pcp.run_at_time(valid_time, accum, ob_type,
                                                    fcst_var)
                            elif process == "regrid_data_plane":
                                run_regrid = CG_regrid_data_plane(p, logger)
                                run_regrid.run_at_time(valid_time, accum,
                                                       ob_type)
                            elif process == "grid_stat":
                                run_grid_stat = CG_grid_stat(p, logger)
                                run_grid_stat.run_at_time(
                                    init_time, lead, accum, ob_type, fcst_var)
                            else:
                                print("ERROR: Invalid process in process list")
                                exit(1)

        init_time = util.shift_time(init_time, int(time_interval))

    (logger).info("END OF EXECUTION")
示例#20
0
def get_test_logger():
    # Create a logger object based on the logging_test.conf
    config_instance = get_test_config()
    fixture_logger = util.get_logger(config_instance)
    return fixture_logger
示例#21
0
def main():
    """!Main program.

    Master MET+ script that invokes the necessary Python scripts
    to perform various activities, such as series analysis."""

    # Job Logger
    produtil.log.jlogger.info('Top of master_metplus')

    # Setup Task logger, Until Conf object is created, Task logger is
    # only logging to tty, not a file.
    logger = logging.getLogger('master_metplus')
    logger.info('logger Top of master_metplus.')

    # Used for logging and usage statment
    cur_filename = sys._getframe().f_code.co_filename
    cur_function = sys._getframe().f_code.co_name

    short_opts = "c:r:h"
    long_opts = ["config=", "help", "runtime="]
    # All command line input, get options and arguments
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], short_opts, long_opts)
    except getopt.GetoptError as err:
        print(str(err))
        usage('SCRIPT IS EXITING DUE TO UNRECOGNIZED COMMAND LINE OPTION')
    for k, v in opts:
        if k in ('-c', '--config'):
            # adds the conf file to the list of arguments.
            print("ADDED CONF FILE: " + v)
            args.append(config_launcher.set_conf_file_path(v))
        elif k in ('-h', '--help'):
            usage()
            exit()
        elif k in ('-r', '--runtime'):
            start_time = v
            end_time = v
        else:
            assert False, "UNHANDLED OPTION"
    if not args:
        args = None
    (parm, infiles,
     moreopt) = config_launcher.parse_launch_args(args, usage, None, logger)
    p = config_launcher.launch(infiles, moreopt)

    # NOW I have a conf object p, I can now setup the handler
    # to write to the LOG_FILENAME.
    logger = util.get_logger(p)

    # This is available in each subprocess from os.system BUT
    # we also set it in each process since they may be called stand alone.
    os.environ['MET_BASE'] = p.getdir('MET_BASE')

    # Use config object to get the list of processes to call
    process_list = util.getlist(p.getstr('config', 'PROCESS_LIST'))

    # Keep this comment.
    # When running commands in the process_list, reprocess the
    # original command line using (item))[sys.argv[1:]].
    #
    # You could call each task (ie. run_tc_pairs.py) without any args since
    # the final METPLUS_CONF file was just created from config_metplus.setup,
    # and each task, also calls setup, which use an existing final conf
    # file over command line args.
    #
    # both work ...
    # Note: Using (item))sys.argv[1:], is preferable since
    # it doesn't depend on the conf file existing.
    processes = []
    for item in process_list:
        try:
            command_builder = getattr(sys.modules[__name__],
                                      item + "Wrapper")(p, logger)
        except AttributeError:
            raise NameError("Process %s doesn't exist" % item)
            exit()

        processes.append(command_builder)

    if p.getstr('config', 'LOOP_METHOD') == "processes":
        for process in processes:
            process.run_all_times()

    elif p.getstr('config', 'LOOP_METHOD') == "times":
        time_format = p.getstr('config', 'INIT_TIME_FMT')
        start_t = p.getstr('config', 'INIT_BEG')
        end_t = p.getstr('config', 'INIT_END')
        time_interval = p.getint('config', 'INIT_INC')
        if time_interval < 60:
            print(
                "ERROR: time_interval parameter must be greater than 60 seconds"
            )
            exit(1)

        init_time = calendar.timegm(time.strptime(start_t, time_format))
        end_time = calendar.timegm(time.strptime(end_t, time_format))
        while init_time <= end_time:
            run_time = time.strftime("%Y%m%d%H%M", time.gmtime(init_time))
            print("")
            print("****************************************")
            print("* RUNNING MET+")
            print("* at init time: " + run_time)
            print("****************************************")
            logger.info("****************************************")
            logger.info("* RUNNING MET+")
            logger.info("*  at init time: " + run_time)
            logger.info("****************************************")
            for process in processes:
                process.run_at_time(run_time)
                process.clear()

            init_time += time_interval

    else:
        print("ERROR: Invalid LOOP_METHOD defined. " + \
              "Options are processes, times")
        exit()
    exit()
    for item in process_list:

        cmd_shell = cmd.to_shell()
        logger.info("INFO | [" + cur_filename + ":" + cur_function + "] | " +
                    "Running: " + cmd_shell)
        ret = run(cmd)
        if ret != 0:
            logger.error("ERROR | [" + cur_filename + ":" + cur_function +
                         "] | " + "Problem executing: " + cmd_shell)
            exit(0)
示例#22
0
 def __init__(self, p, logger):
     super(TcPairsWrapper, self).__init__(p, logger)
     self.config = self.p
     if self.logger is None:
         self.logger = util.get_logger(self.p)