Esempio n. 1
0
def generate_namelist_input_file_template(namelist_input_path, target_dir, config_dict_list):
    """Generates initial namelist input file template for a new experiment

    Parameters
    ----------
    namelist_input_path : str
        Path to original namelist input file
    target_dir : str
        Target directory for the new namelist input file template
    config_dict_list : list of dicts
        List of configuration dictionaries from master_config.py containing the
        namelist parameters that need modified for the new namelist input template file
    """
    namelist_args = {}
    for config_dict in config_dict_list:
        namelist_args.update(config_dict)
    namelist_input_target = os.path.join(target_dir, os.path.basename(namelist_input_path))
    editNamelistFile(namelist_input_path,
                     namelist_input_target,
                     **namelist_args)
Esempio n. 2
0
# Pop some needed values from the arpsintrp_param dictionary imported from the config file
start_time = config.arpsintrp_param.pop('start_time')
end_time = config.arpsintrp_param.pop('end_time')
step_time = config.arpsintrp_param.pop('step_time')

for ens_member_name, t0_interp_input_file_name, lbc_interp_input_file_name, member_path in \
        zip(ens_member_names, t0_interp_input_file_names, lbc_interp_input_file_names,
            member_paths):

    # Initial conditions
    editNamelistFile(arpsintrp_input_template_path, t0_interp_input_file_name,
                     runname=ens_member_name,
                     hdmpfheader=member_path,
                     hdmpfmt=3,
                     exbcdmp=0,
                     tbgn_dmpin=start_time,
                     tend_dmpin=start_time,
                     tintv_dmpin=step_time,
                     **config.arpsintrp_param)

    # Boundary conditions
    editNamelistFile(arpsintrp_input_template_path, lbc_interp_input_file_name,
                     runname=ens_member_name,
                     hdmpfheader=member_path,
                     hdmpfmt=0,
                     exbcdmp=3,
                     tbgn_dmpin=start_time,
                     tend_dmpin=end_time,
                     tintv_dmpin=step_time,
                     **config.arpsintrp_param)
Esempio n. 3
0
                                  config.radarinfo_file)
    if not os.path.exists(radarinfo_link):
        os.symlink(config.radarinfo_path, radarinfo_link)
    # Change directories to the output directory
    os.chdir(config.remapped_radar_dir)

    # Create the namelist files
    initime_stamp = config.initial_datetime.strftime('%Y-%m-%d.%H:%M:00')
    for level2_file_name, level2_path, radremap_input_file_path, radremap_output_file_path in \
            zip(level2_file_names, level2_paths, radremap_input_file_paths,
                radremap_output_file_paths):
        editNamelistFile(radremap_input_template_path,
                         radremap_input_file_path,
                         **config.grid_param,
                         initime=initime_stamp,
                         inifile=config.external_inifile_path,
                         inigbf=config.external_inigbf_path,
                         radname=radname,
                         radfname=level2_path,
                         dirname=config.remapped_radar_dir + '/')

    # Run the radar remapper for each file
    count = 0
    commands = []
    nthreads = config.radremap_param.get('nthreads', 1)
    nfiles = len(level2_file_names)
    for i, level2_file_name, level2_path, radremap_input_file_path, radremap_output_file_path in \
            zip(range(nfiles), level2_file_names, level2_paths,
                radremap_input_file_paths, radremap_output_file_paths):
        radar_time = level2_file_name[4:19]
        radar_time_subdir = os.path.join(config.remapped_radar_dir, radar_time)
Esempio n. 4
0
# Create the arpssfc work directory in icbc scratch directory if it doesn't already exist.
arpssfc_work_dir = os.path.join(config.prep_work_dir, 'arpssfc_work')
if not os.path.exists(arpssfc_work_dir):
    os.makedirs(arpssfc_work_dir)
arpssfc_input_exp_path = os.path.join(
    arpssfc_work_dir, 'arpssfc_{}.input'.format(config.exp_name))
arpssfc_output_exp_path = os.path.join(
    arpssfc_work_dir, 'arpssfc_{}.output'.format(config.exp_name))

# Copy the arpssfc namelist template file to the working directory
# shutil.copy(arpssfc_input_template_path, arpssfc_work_dir)

# Edit the namelist file
editNamelistFile(arpssfc_input_template_path,
                 arpssfc_input_exp_path,
                 runname=config.exp_name,
                 **config.grid_param,
                 **config.arpssfc_param)

# Create the output directory if it doesn't already exist
if not os.path.exists(config.sfcdata_dir):
    os.makedirs(config.sfcdata_dir)

# Run arpssfc
with open(arpssfc_input_exp_path, 'r') as input_file, \
     open(arpssfc_output_exp_path, 'w') as output_file:
    print("Running {} for {}".format(config.arpssfc_exe_path,
                                     arpssfc_input_exp_path))
    subprocess.call(config.arpssfc_exe_path,
                    stdin=input_file,
                    stdout=output_file,
Esempio n. 5
0
    t0_input_file_name = wrf2arps_dict['t0_input_file_name']
    t0_output_file_name = wrf2arps_dict['t0_output_file_name']
    lbc_input_file_name = wrf2arps_dict['lbc_input_file_name']
    lbc_output_file_name = wrf2arps_dict['lbc_output_file_name']
    ens_member_name = wrf2arps_dict['ens_member_name']
    wrf_timestring = wrf2arps_dict['wrf_timestring']
    ens_member = wrf2arps_dict['ens_member']
    dirname = config.wrf2arps_param['dirname']

    # Initial conditions
    editNamelistFile("{}".format(wrf2arps_input_template_path),
                     t0_input_file_name,
                     dir_extd=ens_member_dirs[i],
                     runname=ens_member_name,
                     init_time_str=wrf_timestrings[0],
                     start_time_str=wrf_timestring,
                     end_time_str=wrf_timestring,
                     **config.wrf2arps_param,
                     **config.grid_param)

    # Boundary conditions
    # editNamelistFile("{}".format(wrf2arps_input_template_path),
    #                  lbc_input_file_name,
    #                  dir_extd=ens_member_dirs[ens_member - 1],
    #                  runname=ens_member_name,
    #                  init_time_str=wrf_timestrings[0],
    #                  start_time_str=wrf_timestring,
    #                  end_time_str=wrf_timestring,
    #                  hdmpfmt=0,
    #                  exbcdmp=3,
Esempio n. 6
0
t0_input_file_name = wrf2arps_dict['t0_input_file_name']
t0_output_file_name = wrf2arps_dict['t0_output_file_name']
lbc_input_file_name = wrf2arps_dict['lbc_input_file_name']
lbc_output_file_name = wrf2arps_dict['lbc_output_file_name']
ens_member_name = wrf2arps_dict['ens_member_name']
newse_timestring = wrf2arps_dict['newse_timestring']
ens_member = wrf2arps_dict['ens_member']

# Initial conditions
editNamelistFile("{}".format(template),
                 t0_input_file_name,
                 dir_extd=basedir,
                 runname="%s" % ens_member_name,
                 init_time_str=newse_timestring,
                 start_time_str=newse_timestring,
                 end_time_str=newse_timestring,
                 dirname=outputdir,
                 dmp_out_joined=dmp_out_joined,
                 hdmpfmt=3,
                 exbcdmp=0,
                 nproc_x=nproc_x,
                 nproc_y=nproc_y)

# STOPPED HERE!

# Boundary conditions
editNamelistFile("{}".format(template),
                 lbc_input_file_name,
                 dir_extd=basedir,
                 runname="%s" % ens_member_name,
                 init_time_str=newse_timestring,
Esempio n. 7
0
# Additional parameters for initial condition (t0) run

if run_t0:
    extdfile_t0_args = ext2arps_param.copy()
    new_args = {
        'hdmpopt': 1,
        'exbcdmp': 0,
        'nextdfil': 1
    }
    extdfile_t0_args.update(new_args)

    # Create namelist file for t0 run
    editNamelistFile(ext2arps_input_template_path,
                     ext2arps_input_t0_exp_path,
                     runname=config.exp_name,
                     **config.grid_param,
                     **extdfile_t0_args)

# Additional parameters for lateral boundary condition (lbc) run

if run_lbc:
    extdfile_lbc_args = ext2arps_param.copy()
    new_args = {
        'hdmpfmt': 0
    }
    extdfile_lbc_args.update(new_args)

    # Create namelist file for lbc run
    editNamelistFile(ext2arps_input_template_path,
                     ext2arps_input_lbc_exp_path,