Ejemplo n.º 1
0
def gen_cmcards_file(output_path, params = DEFAULT_SIM_PARAMS):
  cmcards_template = CMS_TEMPLATES.get_template('FLOW.cmcards')
  cmcards_config = CMSConfig(params['sim_name']).load_sim_config()

  cmcards_config['sim_start_date'] = params['sim_starttime'].strftime('%y%j')
  cmcards_config['sim_start_hour'] = params['sim_starttime'].strftime('%H')

  # Godawful, ugly code coming up---avert your eyes!
  sim_output_times = [0.0, 0.0, 0.0]
  n_tstep = 1
  sim_endtime = params['sim_starttime'] + timedelta(hours = params['sim_runtime'])
  time_step = params['sim_timestep']
  while (params['sim_starttime'] + timedelta(hours = time_step)) <= sim_endtime:
    sim_output_times.append(time_step)
    sim_output_times.append(time_step)
    sim_output_times.append(0.0)

    time_step += params['sim_timestep']
    n_tstep += 1

  sim_output_times.insert(0, n_tstep)
  sim_output_times = ' '.join(str(x) for x in sim_output_times)

  cmcards_config['sim_output_times'] = sim_output_times
  cmcards_config.update(params)

  with open(output_path, 'w') as cmcards_output:
    cmcards_output.writelines(cmcards_template.render(**cmcards_config))

  return None
Ejemplo n.º 2
0
def gen_sim_file(output_path, params = DEFAULT_SIM_PARAMS):
  sim_template = CMS_TEMPLATES.get_template('WAVE.sim')
  sim_config = CMSConfig(params['sim_name']).load_sim_config()

  sim_config.update(params)

  with open(output_path, 'w') as sim_output:
    sim_output.writelines(sim_template.render(**sim_config))

  return None
Ejemplo n.º 3
0
def gen_std_file(output_path, sim_name, params=STD_DEFAULT_PARAMS):
    std_template = CMS_TEMPLATES.get_template('WAVE.std')

    model_config = CMSConfig(sim_name).load_sim_config()

    # Set up a grid for observation cells.  This could probably live in the
    # gridfiles module.
    nx = int(model_config['nx'])
    ny = int(model_config['ny'])
    grid = meshgrid(xrange(1, nx + 1), xrange(1, ny + 1))

    params['kout'] = nx * ny
    params['observation_cells'] = zip(grid[0].flatten('F'),
                                      grid[1].flatten('F'))

    with open(output_path, 'w') as std_output:
        std_output.writelines(std_template.render(**params))

    return None