コード例 #1
0
ファイル: run_member.py プロジェクト: sreeds82/cm1_dart
def cm1_prep(mem, start, end, restart_name='cm1out_rst_000001.nc'):
    """ Function to write new namelist.input and check to be
        sure files are in order 

    """
    # If this is a restart, be sure we have the right file
    if start != 0:
        # Try loading the restart file with the correct name
        if not os.path.exists(restart_name):
            error_handler(
                'unable to find file {:s} in member {:d} directory'.format(
                    restart_name, mem), 'cm1_prep')
        # Make sure that the restart file is indeed at the correct time
        rstnc = Dataset(restart_name, 'r')
        time_sec = int(rstnc.variables['time'][0])
        rstnc.close()
        if time_sec != start:
            error_handler(
                'restart file {:s} for member {:d} does not match current cycle time: {:d} min.'
                .format(restart_name, mem, start), 'cm1_prep')

    # Find out how long the run should be
    dtime = int(end - start)

    # Write the namelist
    if not os.path.exists('namelist.input'):
        os.system('cp {:s}/namelist.input .'.format(dir_dom))
    nmld = read_namelist('namelist.input')
    if start != 0:
        irst = 1
        nmld['param2']['irst'] = 1
        nmld['param2']['rstnum'] = 1
        nmld['param1']['run_time'] = dtime
        nmld['param1']['rstfrq'] = cycle_len
        write_namelist(nmld, 'namelist.input')
        #os.system('./write_cm1_namelist.py -r {:s} -l {:d}'.format(restart_name, dtime))
    else:
        nmld['param1']['run_time'] = dtime
        nmld['param1']['rstfrq'] = cycle_len
        write_namelist(nmld, 'namelist.input')
        #os.system('./write_cm1_namelist.py -l {:d}'.format(dtime))
    if not os.path.exists('namelist.input'):
        error_handler('Unable to find namelist.input', 'wrf_prep')
コード例 #2
0
ファイル: run_member.py プロジェクト: huangynj/cm1_dart
def cm1_prep(mem,start,end,restart_name='cm1out_rst_000001.nc'):
    """ Function to write new namelist.input and check to be
        sure files are in order 

    """
    # If this is a restart, be sure we have the right file
    if start != 0:
        # Try loading the restart file with the correct name
        if not os.path.exists(restart_name):
            error_handler('unable to find file {:s} in member {:d} directory'.format(restart_name, mem), 'cm1_prep')
        # Make sure that the restart file is indeed at the correct time
        rstnc = Dataset(restart_name, 'r')
        time_sec = int(rstnc.variables['time'][0])
        rstnc.close()
        if time_sec != start:
            error_handler('restart file {:s} for member {:d} does not match current cycle time: {:d} min.'.format(restart_name, mem, start), 'cm1_prep')
    

    # Find out how long the run should be 
    dtime = int(end-start)

    # Write the namelist
    if not os.path.exists('namelist.input'):
        os.system('cp {:s}/namelist.input .'.format(dir_dom))
    nmld = read_namelist('namelist.input')
    if start != 0:
        irst = 1
        nmld['param2']['irst'] = 1
        nmld['param2']['rstnum'] = 1
        nmld['param1']['run_time'] = dtime
        nmld['param1']['rstfrq'] = cycle_len
        write_namelist(nmld, 'namelist.input')
        #os.system('./write_cm1_namelist.py -r {:s} -l {:d}'.format(restart_name, dtime))
    else:
        nmld['param1']['run_time'] = dtime
        nmld['param1']['rstfrq'] = cycle_len
        write_namelist(nmld, 'namelist.input')
        #os.system('./write_cm1_namelist.py -l {:d}'.format(dtime))
    if not os.path.exists('namelist.input'):
        error_handler('Unable to find namelist.input','wrf_prep')
コード例 #3
0
# Change the name of the template file
dartnml['model_nml']['cm1_template_file'] = restart_filename

# Set the right obs sequence name
dartnml['filter_nml']['obs_sequence_in_name'] = 'obs_seq.prior'

# Set the number of ensemble members
dartnml['filter_nml']['ens_size'] = ens_size

# Set some interesting observation types to assimilate
dartnml['obs_kind_nml']['assimilate_these_obs_types'] = ['TEMPERATURE_2M']
#>@todo TJH test the rest of the observation types in the obs file
#dartnml['obs_kind_nml']['evaluate_these_obs_types'] = ['TEMPERATURE_2M']

# Write this modified namelist out
write_namelist(dartnml, 'input.nml')

# filter will read the contents of input_filelist.txt for the names
# of the CM1 restart files. After each model advance these same
# filenames will be queried for the new model state.
# So, the actual file associated with this name must be updated.
# Ensemble advances are handled by running advance_ensemble.py
# Each model advance is performed in a unique model directory that
# has an instance or ensemble member number in the directory name.

os.system('{remove} input_filelist.txt'.format(**locals()))
os.system('touch input_filelist.txt')

for instance in range(1, ens_size + 1):

    # filter will read the contents of input_filelist.txt for
コード例 #4
0
    format(**locals()))
os.system(
    '{copy} {truthdir}/namelist.input       {dirname}/namelist.input.template || exit 2'
    .format(**locals()))

# Enforce certain assumptions.
# 1) we are always starting from a netCDF file ... irst == 1
# 2) restart always be named cm1_out_rst_000001.nc ... rstnum == 1
# 3) the run_time value will be a dummy string
# Python version --use namelist utilities
nmld = read_namelist(os.path.join(dirname, 'namelist.input.template'))
nmld['param2']['irst'] = 1
nmld['param2']['rstnum'] = 1
nmld['param1']['run_time'] = cm1_forecast_length
nmld['param1']['rstfrq'] = cm1_forecast_length
write_namelist(nmld, os.path.join(dirname, 'namelist.input.template'))

os.system('{remove} input_filelist.txt'.format(**locals()))

# Python -- write to input_filelist.txt in with
# statement.  This will automatically close
# the file when we are out of the block
with open('input_filelist.txt', 'w') as outfile:
    outfile.write(os.path.join(dirname, filename) + '\n')

# When perfect_model_obs starts, it needs to read the grid information.
# The DART/CM1 interface specifies the file for the grid information by
# the input.nml:&model_nml:cm1_template_file  variable, which defaults
# to cm1out_rst_000001.nc
#
# Consequently, we can get simply link to the true model state.
コード例 #5
0
ファイル: make_ensemble.py プロジェクト: sreeds82/cm1_dart
def main():
    DOMDIR = dir_dom
    os.chdir(DOMDIR)
    """
    if os.path.isdir(DOMDIR+'/mems'):
        remove = raw_input('Remove contents of current ensemble directory (0 or 1)?')
        if remove:
            os.system('rm -rf {:s}/mems/*'.format(DOMDIR))
        else:
            exit(1)
    else:
        os.system('mkdir mems')  
    """
    print "############### MAKING ENSEMBLE ###############"
    print "############## NUMBER OF MEMS: %d #############" % Ne
    # Now populate the ensemble directory
    print "Populating ensemble directory (mems)"
    os.chdir(DOMDIR + '/mems')

    # Check our initialization method to see what we need for
    # each ensemble member
    if cm1nml['param2']['isnd'] == 7:
        # Will need an input sounding file.  Check for this
        if not os.path.exists('{:s}/input_sounding'.format(DOMDIR)):
            print(
                "ERROR: CM1 namelist has isnd=7, but no input_sounding file found in {:s}"
                .format(DOMDIR))
            exit(1)

    # Loop through each member
    print "######################################"
    print "Making ensemble member sub-directories"
    print "######################################"
    print ""
    for k in range(Ne):
        #for k in [0]:
        k = k + 1  # Don't start at 0
        print "***** MEMBER {:d} *****".format(k)
        os.chdir(DOMDIR)
        # Run script to generate the namelist
        write_namelist(cm1nml, 'namelist.input')
        # That will be written as namelist.input
        # hold onto that while making a directory for it
        os.chdir('{:s}/mems'.format(DOMDIR))
        os.system('mkdir {:s}/mems/m{:d}'.format(DOMDIR, k))
        os.chdir('{:s}/mems/m{:d}'.format(DOMDIR, k))
        # Copy in the namelist
        os.system('cp {:s}/namelist.input namelist.input'.format(DOMDIR))
        # See if we need an input sounding file
        if cm1nml['param2']['isnd'] == 7:
            os.system('cp {:s}/input_sounding .'.format(DOMDIR))

        # Link in executable
        os.system('ln -sf {:s}/LANDUSE.TBL .'.format(dir_src_model))
        os.system('ln -sf {:s}/cm1.exe .'.format(dir_src_model))

        # Go back up a directory to start the next one
        os.chdir('%s/mems' % DOMDIR)

    print "### DONE MAKING DIRECTORIES ###"
    print ""

    os.chdir(DOMDIR)
コード例 #6
0
# Python version --use namelist utilities
# read the namelist
nmld = read_namelist('namelist.input')

# Check for environment variable that
# contains the current forecast length
# Otherwise leave as is
if os.environ.get('CM1_FORECAST_LENGTH') not in [None, '']:
    cm1_forecast_length = float(os.envion.get('CM1_FORECAST_LENGTH'))
    nmld['param1']['run_time'] = cm1_forecast_length
    nmld['param1']['rstfrq'] = cm1_forecast_length

# Set the other namelist requirements and write
nmld['param2']['irst'] = 1
nmld['param2']['rstnum'] = 1
write_namelist(nmld, 'namelist.input')

# Python -- write to input_filelist.txt in with
# statement.  This will automatically close
# the file when we are out of the block
# Only have one ens member to worry about here, so link directly
os.system('{remove} input_filelist.txt'.format(**locals()))
with open('input_filelist.txt', 'w') as outfile:
    outfile.write('dir_model_001/cm1out_rst_000001.nc\n')

# While we're here, make a copy of the restart file for
# advance model with the time of the current restart
# file attached to it
# Read the simulation start (base time) from the namelist
nmldtime = nmld['param11']
startdt = datetime(nmldtime['year'], nmldtime['month'], nmldtime['day'],\
コード例 #7
0
ファイル: make_ensemble.py プロジェクト: huangynj/cm1_dart
def main():
    DOMDIR = dir_dom
    os.chdir(DOMDIR)
    """
    if os.path.isdir(DOMDIR+'/mems'):
        remove = raw_input('Remove contents of current ensemble directory (0 or 1)?')
        if remove:
            os.system('rm -rf {:s}/mems/*'.format(DOMDIR))
        else:
            exit(1)
    else:
        os.system('mkdir mems')  
    """
    print "############### MAKING ENSEMBLE ###############"
    print "############## NUMBER OF MEMS: %d #############" % Ne
    # Now populate the ensemble directory
    print "Populating ensemble directory (mems)"
    os.chdir(DOMDIR+'/mems')

    # Check our initialization method to see what we need for
    # each ensemble member
    if cm1nml['param2']['isnd'] == 7:
        # Will need an input sounding file.  Check for this
        if not os.path.exists('{:s}/input_sounding'.format(DOMDIR)):
            print("ERROR: CM1 namelist has isnd=7, but no input_sounding file found in {:s}".format(DOMDIR))
            exit(1)


    # Loop through each member
    print "######################################"
    print "Making ensemble member sub-directories"
    print "######################################"
    print ""
    for k in range(Ne):
    #for k in [0]:
        k = k+1 # Don't start at 0
        print "***** MEMBER {:d} *****".format(k)
        os.chdir(DOMDIR)
        # Run script to generate the namelist
        write_namelist(cm1nml, 'namelist.input')
        # That will be written as namelist.input
        # hold onto that while making a directory for it
        os.chdir('{:s}/mems'.format(DOMDIR))
        os.system('mkdir {:s}/mems/m{:d}'.format(DOMDIR,k))
        os.chdir('{:s}/mems/m{:d}'.format(DOMDIR,k))
        # Copy in the namelist
        os.system('cp {:s}/namelist.input namelist.input'.format(DOMDIR))
        # See if we need an input sounding file
        if cm1nml['param2']['isnd'] == 7:
            os.system('cp {:s}/input_sounding .'.format(DOMDIR))
            

        # Link in executable
        os.system('ln -sf {:s}/LANDUSE.TBL .'.format(dir_src_model))
        os.system('ln -sf {:s}/cm1.exe .'.format(dir_src_model))

        # Go back up a directory to start the next one
        os.chdir('%s/mems' % DOMDIR)

    print "### DONE MAKING DIRECTORIES ###"
    print ""

    os.chdir(DOMDIR)