Exemplo n.º 1
0
def metgrid(**kwargs):
    logging.info('Running metgrid...')

    wrf_config = get_wrf_config(**kwargs)
    wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))

    utils.run_subprocess('./metgrid.exe', cwd=wps_dir)
Exemplo n.º 2
0
    def process(self, *args, **kwargs):
        logging.info('Running metgrid...')
        wrf_config = self.get_config(**kwargs)
        logging.info('wrf conifg: ' + wrf_config.to_json_string())

        wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))

        utils.run_subprocess('./metgrid.exe', cwd=wps_dir)
Exemplo n.º 3
0
    def process(self, *args, **kwargs):
        logging.info('Running geogrid...')

        wrf_config = self.get_config(**kwargs)
        wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))

        if not executor.check_geogrid_output(wps_dir):
            logging.info('Running Geogrid.exe')
            utils.run_subprocess('./geogrid.exe', cwd=wps_dir)
        else:
            logging.info('Geogrid output already available')
Exemplo n.º 4
0
def replace_namelist_wps(wrf_config, start_date=None, end_date=None):
    logging.info('Replacing namelist.wps...')
    if os.path.exists(wrf_config.get('namelist_wps')):
        f = wrf_config.get('namelist_wps')
    else:
        f = res_mgr.get_resource_path(
            os.path.join('execution', constants.DEFAULT_NAMELIST_WPS_TEMPLATE))

    dest = os.path.join(utils.get_wps_dir(wrf_config.get('wrf_home')),
                        'namelist.wps')
    replace_file_with_values(wrf_config, f, dest, 'namelist_wps_dict',
                             start_date, end_date)
Exemplo n.º 5
0
    def post_process(self, *args, **kwargs):
        # make a sym link in the nfs dir
        wrf_config = self.get_config(**kwargs)
        wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))

        nfs_metgrid_dir = os.path.join(wrf_config.get('nfs_dir'), 'metgrid')

        utils.create_dir_if_not_exists(nfs_metgrid_dir)
        # utils.delete_files_with_prefix(nfs_metgrid_dir, 'met_em.d*')
        # utils.create_symlink_with_prefix(wps_dir, 'met_em.d*', nfs_metgrid_dir)

        utils.create_zip_with_prefix(wps_dir, 'met_em.d*',
                                     os.path.join(wps_dir, 'metgrid.zip'))

        utils.delete_files_with_prefix(nfs_metgrid_dir, 'met_em.d*')
        utils.move_files_with_prefix(wps_dir, 'metgrid.zip', nfs_metgrid_dir)
Exemplo n.º 6
0
def run_wps(wrf_config):
    logging.info('Downloading GFS data')
    executor.download_gfs_data(wrf_config)

    logging.info('Replacing the namelist wps file')
    executor.replace_namelist_wps(wrf_config)

    logging.info('Running WPS...')
    executor.run_wps(wrf_config)

    logging.info('Cleaning up wps dir...')
    wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))
    shutil.rmtree(wrf_config.get('gfs_dir'))
    utils.delete_files_with_prefix(wps_dir, 'FILE:*')
    utils.delete_files_with_prefix(wps_dir, 'PFILE:*')
    utils.delete_files_with_prefix(wps_dir, 'geo_em.*')
Exemplo n.º 7
0
def ungrib(**kwargs):
    logging.info('Running ungrib...')

    wrf_config = get_wrf_config(**kwargs)
    wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))

    # Running link_grib.csh
    logging.info('Running link_grib.csh')
    gfs_date, gfs_cycle, start = utils.get_appropriate_gfs_inventory(
        wrf_config)
    dest = \
        utils.get_gfs_data_url_dest_tuple(wrf_config.get('gfs_url'), wrf_config.get('gfs_inv'), gfs_date, gfs_cycle, '',
                                          wrf_config.get('gfs_res'), '')[1]  # use get_gfs_data_url_dest_tuple to get
    utils.run_subprocess('csh link_grib.csh %s/%s' %
                         (wrf_config.get('gfs_dir'), dest),
                         cwd=wps_dir)

    utils.run_subprocess('./ungrib.exe', cwd=wps_dir)
Exemplo n.º 8
0
def pre_ungrib(**kwargs):
    logging.info('Running preprocessing for ungrib...')

    wrf_config = get_wrf_config(**kwargs)

    wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))
    logging.info('WPS dir: %s' % wps_dir)

    logging.info('Cleaning up files')
    utils.delete_files_with_prefix(wps_dir, 'FILE:*')
    utils.delete_files_with_prefix(wps_dir, 'PFILE:*')

    # Linking VTable
    if not os.path.exists(os.path.join(wps_dir, 'Vtable')):
        logging.info('Creating Vtable symlink')
        os.symlink(os.path.join(wps_dir, 'ungrib/Variable_Tables/Vtable.NAM'),
                   os.path.join(wps_dir, 'Vtable'))
    pass
Exemplo n.º 9
0
    def process(self, *args, **kwargs):
        logging.info('Running ungrib...')

        wrf_config = self.get_config(**kwargs)
        logging.info('wrf conifg: ' + wrf_config.to_json_string())

        wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))

        # Running link_grib.csh
        logging.info('Running link_grib.csh')
        gfs_date, gfs_cycle, start = utils.get_appropriate_gfs_inventory(
            wrf_config)
        # use get_gfs_data_url_dest_tuple to get
        dest = \
            utils.get_gfs_data_url_dest_tuple(wrf_config.get('gfs_url'), wrf_config.get('gfs_inv'), gfs_date, gfs_cycle,
                                              '', wrf_config.get('gfs_res'), '')[1]

        utils.run_subprocess('csh link_grib.csh %s/%s' %
                             (wrf_config.get('gfs_dir'), dest),
                             cwd=wps_dir)

        utils.run_subprocess('./ungrib.exe', cwd=wps_dir)
Exemplo n.º 10
0
def run_wps(wrf_config):
    logging.info('Running WPS: START')
    wrf_home = wrf_config.get('wrf_home')
    wps_dir = utils.get_wps_dir(wrf_home)
    output_dir = utils.create_dir_if_not_exists(
        os.path.join(wrf_config.get('nfs_dir'), 'results',
                     wrf_config.get('run_id'), 'wps'))

    logging.info('Backup the output dir')
    utils.backup_dir(output_dir)

    logs_dir = utils.create_dir_if_not_exists(os.path.join(output_dir, 'logs'))

    logging.info('Cleaning up files')
    utils.delete_files_with_prefix(wps_dir, 'FILE:*')
    utils.delete_files_with_prefix(wps_dir, 'PFILE:*')
    utils.delete_files_with_prefix(wps_dir, 'met_em*')

    # Linking VTable
    if not os.path.exists(os.path.join(wps_dir, 'Vtable')):
        logging.info('Creating Vtable symlink')
    os.symlink(os.path.join(wps_dir, 'ungrib/Variable_Tables/Vtable.NAM'),
               os.path.join(wps_dir, 'Vtable'))

    # Running link_grib.csh
    gfs_date, gfs_cycle, start = utils.get_appropriate_gfs_inventory(
        wrf_config)
    dest = utils.get_gfs_data_url_dest_tuple(wrf_config.get('gfs_url'),
                                             wrf_config.get('gfs_inv'),
                                             gfs_date, gfs_cycle, '',
                                             wrf_config.get('gfs_res'),
                                             '')[1].replace('.grb2', '')
    utils.run_subprocess('csh link_grib.csh %s/%s' %
                         (wrf_config.get('gfs_dir'), dest),
                         cwd=wps_dir)

    try:
        # Starting ungrib.exe
        try:
            utils.run_subprocess('./ungrib.exe', cwd=wps_dir)
        finally:
            utils.move_files_with_prefix(wps_dir, 'ungrib.log', logs_dir)

        # Starting geogrid.exe'
        if not check_geogrid_output(wps_dir):
            logging.info('Geogrid output not available')
            try:
                utils.run_subprocess('./geogrid.exe', cwd=wps_dir)
            finally:
                utils.move_files_with_prefix(wps_dir, 'geogrid.log', logs_dir)

        # Starting metgrid.exe'
        try:
            utils.run_subprocess('./metgrid.exe', cwd=wps_dir)
        finally:
            utils.move_files_with_prefix(wps_dir, 'metgrid.log', logs_dir)
    finally:
        logging.info('Moving namelist wps file')
        utils.move_files_with_prefix(wps_dir, 'namelist.wps', output_dir)

    logging.info('Running WPS: DONE')

    logging.info('Zipping metgrid data')
    metgrid_zip = os.path.join(wps_dir,
                               wrf_config.get('run_id') + '_metgrid.zip')
    utils.create_zip_with_prefix(wps_dir, 'met_em.d*', metgrid_zip)

    logging.info('Moving metgrid data')
    dest_dir = os.path.join(wrf_config.get('nfs_dir'), 'metgrid')
    utils.move_files_with_prefix(wps_dir, metgrid_zip, dest_dir)
Exemplo n.º 11
0
    def pre_process(self, *args, **kwargs):
        logging.info('Running pre-processing for metgrid...')

        wrf_config = self.get_config(**kwargs)
        wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))
        utils.delete_files_with_prefix(wps_dir, 'met_em*')
Exemplo n.º 12
0
def pre_metgrid(**kwargs):
    logging.info('Running preporcessing for geogrid...')

    wrf_config = get_wrf_config(**kwargs)
    wps_dir = utils.get_wps_dir(wrf_config.get('wrf_home'))
    utils.delete_files_with_prefix(wps_dir, 'met_em*')