コード例 #1
0
ファイル: wrfpy.py プロジェクト: rvanharen/wrfpy
  def _header(self):
    '''
    define suite.rc header information
    '''
    start_time = utils.datetime_to_string(
      utils.return_validate(self.config['options_general']['date_start']),
      format='%Y%m%d%H')
    end_time = utils.datetime_to_string(
      utils.return_validate(self.config['options_general']['date_end']),
      format='%Y%m%d%H')
    # define template
    template = """#!Jinja2

{{% set START = "{start_time}" %}}
{{% set STOP  = "{end_time}" %}}

[cylc]
  # set required cylce point format
  cycle point format = %Y%m%d%H

"""
    # context variables in template
    context = {
      "start_time":start_time,
      "end_time":end_time
      }
    return template.format(**context)
コード例 #2
0
ファイル: config.py プロジェクト: rvanharen/wrfpy
 def _check_general(self):
   '''
   check general options in json config file
     - date_start and date_end have a valid format
     - end_date is after start_date
     - boundary_interval is an integer
   '''
   # check if start_date and end_date are in valid format
   start_date = utils.return_validate(
     self.config['options_general']['date_start'])
   end_date = utils.return_validate(
     self.config['options_general']['date_end'])
   # end_date should be after start_date
   if (start_date >= end_date):
     message = ''
     logger.error(message)
     raise IOError(message)
   # boundary interval should be an int number of hours
   assert isinstance(self.config['options_general']['boundary_interval'],
                       int), ('boundary_interval should be given as an '
                              'integer in %s' %self.configfile)
   # boundary interval should not be larger than time between start_date
   # and end_date
   assert ((self.config['options_general']['boundary_interval']*3600) < (
     end_date - start_date).total_seconds()), (
       'boundary interval is larger than time between start_date and '
       'end_date')
コード例 #3
0
ファイル: wrfda.py プロジェクト: rvanharen/wrfpy
  def prepare_wrfda_namelist(self, domain):
    # set domain specific workdir
    wrfda_workdir = os.path.join(self.wrfda_workdir, "d0" + str(domain))
    # read WRFDA namelist
    wrfda_namelist = os.path.join(self.config['filesystem']['wrfda_dir'],
                                  'var/test/tutorial/namelist.input')
    wrfda_nml = f90nml.read(wrfda_namelist)

    # read WRF namelist in WRF work_dir
    wrf_nml = f90nml.read(os.path.join(self.config['filesystem']['wrf_run_dir'],
                                       'namelist.input'))
    ## silent remove file if exists
    ##utils.silentremove(os.path.join(wrfda_workdir, 'fg'))
    ## create symlink of wrfinput_d0${domain}
    ##os.symlink(os.path.join(self.rundir, 'wrfinput_d0' + str(domain)),
    ##          os.path.join(wrfda_workdir, 'fg'))
    # set domain specific information in namelist
    for var in ['e_we', 'e_sn', 'e_vert', 'dx', 'dy']:
      # get variable from ${RUNDIR}/namelist.input
      var_value = wrf_nml['domains'][var]
      # set domain specific variable in WRDFA_WORKDIR/namelist.input
      wrfda_nml['domains'][var] = var_value[domain - 1]
    for var in ['mp_physics', 'ra_lw_physics', 'ra_sw_physics', 'radt',
                'sf_sfclay_physics', 'sf_surface_physics', 'bl_pbl_physics',
                'cu_physics', 'cudt', 'num_soil_layers']:
      # get variable from ${RUNDIR}/namelist.input
      var_value = wrf_nml['physics'][var]
      # set domain specific variable in WRDFA_WORKDIR/namelist.input
      try:
        wrfda_nml['physics'][var] = var_value[domain - 1]
      except TypeError:
        wrfda_nml['physics'][var] = var_value
    obsproc_nml = f90nml.read(os.path.join(self.obs[domain][0], 'namelist.obsproc'))
    # sync wrfda namelist with obsproc namelist
    wrfda_nml['wrfvar18']['analysis_date'] = obsproc_nml['record2']['time_analysis']
    wrfda_nml['wrfvar21']['time_window_min'] = obsproc_nml['record2']['time_window_min']
    wrfda_nml['wrfvar22']['time_window_max'] = obsproc_nml['record2']['time_window_max']
    if check_cv5():
      wrfda_nml['wrfvar7']['cv_options'] =  5
      wrfda_nml['wrfvar6']['max_ext_its'] = 2
      wrfda_nml['wrfvar5']['check_max_iv'] = True
    else:
      wrfda_nml['wrfvar7']['cv_options'] =  3
    tana = utils.return_validate(obsproc_nml['record2']['time_analysis'][:-6])
    wrfda_nml['time_control']['start_year'] = tana.year
    wrfda_nml['time_control']['start_month'] = tana.month
    wrfda_nml['time_control']['start_day'] = tana.day
    wrfda_nml['time_control']['start_hour'] = tana.hour
    wrfda_nml['time_control']['end_year'] = tana.year
    wrfda_nml['time_control']['end_month'] = tana.month
    wrfda_nml['time_control']['end_day'] = tana.day
    wrfda_nml['time_control']['end_hour'] = tana.hour
    # save changes to wrfda_nml
    utils.silentremove(os.path.join(wrfda_workdir, 'namelist.input'))
    wrfda_nml.write(os.path.join(wrfda_workdir, 'namelist.input'))
コード例 #4
0
ファイル: wrfpy.py プロジェクト: rvanharen/wrfpy
  def _scheduling(self):
    '''
    define suite.rc scheduling information
    '''
    # get start_hour and increment time from config.json
    start_hour = str(
      utils.return_validate(
      self.config['options_general']['date_start']).hour).zfill(2)
    incr_hour = self.config['options_general']['run_hours']
    # define template
    template = """[scheduling]
  initial cycle point = {{{{ START }}}}
  final cycle time   = {{{{ STOP }}}}
  [[dependencies]]
    # Initial cycle point
    [[[R1/T{start_hour}]]]
      graph = \"\"\"
        wrf_init => wrf_real => wrfda => wrf_run
        wrf_init => obsproc_init => obsproc_run
        obsproc_run => wrfda
      \"\"\"
    # Repeat every {incr_hour} hours, starting {incr_hour} hours after initial cylce point
    [[[+PT{incr_hour}H/PT{incr_hour}H]]]
      graph = \"\"\"
        wrf_run[-PT2H] => wrf_init => wrf_real => wrfda => copy_urb => wrf_run
        wrf_init => obsproc_init => obsproc_run
        obsproc_run => wrfda
      \"\"\"

"""
    # context variables in template
    context = {
      "start_hour": start_hour,
      "incr_hour": incr_hour
      }
    return template.format(**context)