Ejemplo n.º 1
0
def regrid_2d_prepare(environ, **kwargs):
    input_file = StringIO()
    get(fmt('{regrid_2d_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(
            environ['regrid_2d_namelist']['vars'].keys()) & set(data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = (set(environ['regrid_2d_namelist']['vars'][k].keys())
                    & set(data[k].keys()))
            data[k].update([(ke, environ['regrid_2d_namelist']['vars'][k][ke])
                            for ke in keys])

    src_file = data['regrid_2d_nml']['src_file']
    run(fmt('cp %s {regrid_2d_workdir}/src_file.nc' % src_file, environ))
    data['regrid_2d_nml']['src_file'] = 'src_file.nc'
    output.write(yaml2nml(data))

    put(output, fmt('{regrid_2d_workdir}/input.nml', environ))
    output.close()
Ejemplo n.º 2
0
def regrid_2d_prepare(environ, **kwargs):
    input_file = StringIO()
    get(fmt('{regrid_2d_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(
            environ['regrid_2d_namelist']['vars'].keys()) & set(data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = (set(environ['regrid_2d_namelist']['vars'][k].keys())
                    & set(data[k].keys()))
            data[k].update([(ke, environ['regrid_2d_namelist']['vars'][k][ke])
                            for ke in keys])

    src_file = data['regrid_2d_nml']['src_file']
    run(fmt('cp %s {regrid_2d_workdir}/src_file.nc' % src_file, environ))
    data['regrid_2d_nml']['src_file'] = 'src_file.nc'
    output.write(yaml2nml(data))

    put(output, fmt('{regrid_2d_workdir}/input.nml', environ))
    output.close()
Ejemplo n.º 3
0
def prepare_namelist(environ, **kwargs):
    ''' Read atmos namelist and update variables from environ as needed

    Used vars:
      name
      atmos_namelist
      TRC
      LV
      dt_atmos
      start
      restart
      finish
      rootexp
      workdir

    Depends on:
      None
    '''
    input_file = StringIO()
    get(fmt('{agcm_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(
            environ['atmos_namelist']['vars'].keys()) & set(data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = set(environ['atmos_namelist']['vars'][k]
                       .keys()) & set(data[k].keys())
            data[k].update([(
                ke, environ['atmos_namelist']['vars'][k][ke]) for ke in keys])

    trunc = "%04d" % environ['TRC']
    lev = "%03d" % environ['LV']

    data['MODEL_RES']['trunc'] = "%04d" % environ['TRC']
    data['MODEL_RES']['vert'] = environ['LV']
    data['MODEL_RES']['dt'] = environ['dt_atmos']
    data['MODEL_RES']['IDATEI'] = format_atmos_date(environ['start'])
    data['MODEL_RES']['IDATEW'] = format_atmos_date(environ['restart'])
    data['MODEL_RES']['IDATEF'] = format_atmos_date(environ['finish'])
    data['MODEL_RES']['DHEXT'] = environ.get('DHEXT', 0)
    if environ.get('DHEXT', 0) != 0:
        begin = datetime.strptime(environ['restart'], "%Y%m%d%H")
        end = datetime.strptime(environ['finish'], "%Y%m%d%H")
        nhext = total_seconds(end - begin) / 3600
    else:
        nhext = 0
    data['MODEL_RES']['NHEXT'] = nhext

    # TODO: is this environ['agcm_model_inputs'] ?
    data['MODEL_RES']['path_in'] = fmt(
        '{rootexp}/AGCM-1.0/model/datain', environ)

    data['MODEL_RES']['dirfNameOutput'] = (
        fmt('{workdir}/model/dataout/TQ%sL%s' % (trunc, lev), environ))

    output.write(yaml2nml(data,
                          key_order=['MODEL_RES', 'MODEL_IN', 'PHYSPROC',
                                     'PHYSCS', 'COMCON']))

    # HACK: sigh, this is needed to run atmos post processing, even if we
    # don't use these forecasts.
    output.write("""
 17
   6.0 12.0  18.0  24.0
  30.0 36.0  42.0  48.0
  54.0 60.0  66.0  72.0
  84.0 96.0 120.0 144.0
 168.0
""")

    put(output, fmt('{workdir}/MODELIN', environ))
    output.close()
Ejemplo n.º 4
0
def prepare_namelist(environ, **kwargs):
    ''' Read ocean namelist and update variables from environ as needed

    Used vars:
      name
      ocean_namelist
      npes
      dt_ocean
      dt_atmos
      dt_cpld
      days
      workdir

    Depends on:
      None
    '''
    input_file = StringIO()
    get(fmt('{ocean_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(
            environ['ocean_namelist']['vars'].keys()) & set(data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = (set(environ['ocean_namelist']['vars'][k].keys())
                    & set(data[k].keys()))
            data[k].update([(ke, environ['ocean_namelist']['vars'][k][ke])
                            for ke in keys])

    if ('coupler_nml' in data) and \
            data['coupler_nml'].get('concurrent', False):
        data['ocean_model_nml']['layout'] = ("%d,%d"
                                             % layout(data['coupler_nml']['ocean_npes']))
    else:
        data['ocean_model_nml']['layout'] = ("%d,%d"
                                             % layout(int(environ['npes'])))

    data['ocean_model_nml']['dt_ocean'] = environ['dt_ocean']

    if environ['type'] != 'MOM_solo':
        data['coupler_nml']['dt_atmos'] = environ['dt_atmos']
        data['coupler_nml']['dt_cpld'] = environ['dt_cpld']

    if environ['type'] == 'MOM_solo':
        timing_ctrl_nml = 'ocean_solo_nml'
    else:
        timing_ctrl_nml = 'coupler_nml'

    if 'days' in data[timing_ctrl_nml]:
        data[timing_ctrl_nml].pop('days')
    if 'months' in data[timing_ctrl_nml]:
        data[timing_ctrl_nml].pop('months')

    if ('days' in environ) & ('months' not in environ):
        data[timing_ctrl_nml]['days'] = environ['days']
    elif ('days' not in environ) & ('months' in environ):
        data[timing_ctrl_nml]['months'] = environ['months']
    else:
        print "Error, one should use days or months, not both or none"

    if environ['mode'] == 'warm':
        start = datetime.strptime(str(environ['restart']), "%Y%m%d%H")
    else:
        start = datetime.strptime(str(environ['start']), "%Y%m%d%H")

    # Gui 20131101. MOM_solo do not recognize the current_date,
    #   but needs to use date_init instead.
    if environ['type'] == 'MOM_solo':
        data[timing_ctrl_nml]['date_init'] = \
                "%01d, %01d, %01d, %01d, 0, 0" % \
                (start.year, start.month, start.day, start.hour)
    else:
        data[timing_ctrl_nml]['current_date'] = \
                "%01d, %01d, %01d, %01d, 0, 0" % \
                (start.year, start.month, start.day, start.hour)

    if 'ocean_drifters_nml' in data.keys():
        if data['ocean_drifters_nml']['use_this_module']:
            environ['run_drifters_pos'] = True

    output.write(yaml2nml(data))

    put(output, fmt('{workdir}/input.nml', environ))
    output.close()
Ejemplo n.º 5
0
def prepare_namelist(environ, **kwargs):
    ''' Read ocean namelist and update variables from environ as needed

    Used vars:
      name
      ocean_namelist
      npes
      dt_ocean
      dt_atmos
      dt_cpld
      days
      workdir

    Depends on:
      None
    '''
    input_file = StringIO()
    get(fmt('{ocean_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(
            environ['ocean_namelist']['vars'].keys()) & set(data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = (set(environ['ocean_namelist']['vars'][k].keys())
                    & set(data[k].keys()))
            data[k].update([(ke, environ['ocean_namelist']['vars'][k][ke])
                            for ke in keys])

    if data['coupler_nml'].get('concurrent', False):
        data['ocean_model_nml']['layout'] = ("%d,%d"
                                             % layout(data['coupler_nml']['ocean_npes']))
        data['ice_model_nml']['layout'] = ("0,0")
    else:
        data['ocean_model_nml']['layout'] = ("%d,%d"
                                             % layout(int(environ['npes'])))
        data['ice_model_nml']['layout'] = ("%d,%d"
                                             % layout(int(environ['npes'])))

    data['ocean_model_nml']['dt_ocean'] = environ['dt_ocean']
    data['coupler_nml']['dt_atmos'] = environ['dt_atmos']
    data['coupler_nml']['dt_cpld'] = environ['dt_cpld']

    if 'days' in data['coupler_nml']:
        data['coupler_nml'].pop('days')
    if 'months' in data['coupler_nml']:
        data['coupler_nml'].pop('months')

    if ('days' in environ) & ('months' not in environ):
        data['coupler_nml']['days'] = environ['days']
    elif ('days' not in environ) & ('months' in environ):
        data['coupler_nml']['months'] = environ['months']
    else:
        print "Error, one should use days or months, not both or none"

    if environ['mode'] == 'warm':
        start = datetime.strptime(str(environ['restart']), "%Y%m%d%H")
    else:
        start = datetime.strptime(str(environ['start']), "%Y%m%d%H")
    data['coupler_nml']['current_date'] = start.strftime(
        "%Y, %m, %d, %H, 0, 0")

    if 'ocean_drifters_nml' in data.keys():
        if data['ocean_drifters_nml']['use_this_module']:
            environ['run_drifters_pos'] = True

    output.write(yaml2nml(data))

    put(output, fmt('{workdir}/input.nml', environ))
    output.close()
Ejemplo n.º 6
0
def prepare_namelist(environ, **kwargs):
    ''' Read atmos namelist and update variables from environ as needed

    Used vars:
      name
      atmos_namelist
      TRC
      LV
      dt_atmos
      start
      restart
      finish
      rootexp
      workdir

    Depends on:
      None
    '''
    input_file = StringIO()
    get(fmt('{agcm_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(environ['atmos_namelist']['vars'].keys()) & set(
            data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = set(environ['atmos_namelist']['vars'][k].keys()) & set(
                data[k].keys())
            data[k].update([(ke, environ['atmos_namelist']['vars'][k][ke])
                            for ke in keys])

    trunc = "%04d" % environ['TRC']
    lev = "%03d" % environ['LV']

    data['MODEL_RES']['trunc'] = "%04d" % environ['TRC']
    data['MODEL_RES']['vert'] = environ['LV']
    data['MODEL_RES']['dt'] = environ['dt_atmos']
    data['MODEL_RES']['IDATEI'] = format_atmos_date(environ['start'])
    data['MODEL_RES']['IDATEW'] = format_atmos_date(environ['restart'])
    data['MODEL_RES']['IDATEF'] = format_atmos_date(environ['finish'])
    data['MODEL_RES']['DHEXT'] = environ.get('DHEXT', 0)
    if environ.get('DHEXT', 0) != 0:
        begin = datetime.strptime(environ['restart'], "%Y%m%d%H")
        end = datetime.strptime(environ['finish'], "%Y%m%d%H")
        nhext = total_seconds(end - begin) / 3600
    else:
        nhext = 0
    data['MODEL_RES']['NHEXT'] = nhext

    # TODO: is this environ['agcm_model_inputs'] ?
    data['MODEL_RES']['path_in'] = fmt('{rootexp}/AGCM-1.0/model/datain',
                                       environ)

    data['MODEL_RES']['dirfNameOutput'] = (fmt(
        '{workdir}/model/dataout/TQ%sL%s' % (trunc, lev), environ))

    output.write(
        yaml2nml(data,
                 key_order=[
                     'MODEL_RES', 'MODEL_IN', 'PHYSPROC', 'PHYSCS', 'COMCON'
                 ]))

    # HACK: sigh, this is needed to run atmos post processing, even if we
    # don't use these forecasts.
    output.write("""
 17
   6.0 12.0  18.0  24.0
  30.0 36.0  42.0  48.0
  54.0 60.0  66.0  72.0
  84.0 96.0 120.0 144.0
 168.0
""")

    put(output, fmt('{workdir}/MODELIN', environ))
    output.close()
Ejemplo n.º 7
0
def prepare_namelist(environ, **kwargs):
    ''' Read ocean namelist and update variables from environ as needed

    Used vars:
      name
      ocean_namelist
      npes
      dt_ocean
      dt_atmos
      dt_cpld
      days
      workdir

    Depends on:
      None
    '''
    input_file = StringIO()
    get(fmt('{ocean_namelist[file]}', environ), input_file)
    data = nml_decode(input_file.getvalue())
    input_file.close()
    output = StringIO()

    try:
        tkeys = set(environ['ocean_namelist']['vars'].keys()) & set(
            data.keys())
    except KeyError:
        pass
    else:
        for k in tkeys:
            keys = (set(environ['ocean_namelist']['vars'][k].keys())
                    & set(data[k].keys()))
            data[k].update([(ke, environ['ocean_namelist']['vars'][k][ke])
                            for ke in keys])

    if data['coupler_nml'].get('concurrent', False):
        data['ocean_model_nml']['layout'] = (
            "%d,%d" % layout(data['coupler_nml']['ocean_npes']))
        data['ice_model_nml']['layout'] = ("0,0")
    else:
        data['ocean_model_nml']['layout'] = ("%d,%d" %
                                             layout(int(environ['npes'])))
        data['ice_model_nml']['layout'] = ("%d,%d" %
                                           layout(int(environ['npes'])))

    data['ocean_model_nml']['dt_ocean'] = environ['dt_ocean']
    data['coupler_nml']['dt_atmos'] = environ['dt_atmos']
    data['coupler_nml']['dt_cpld'] = environ['dt_cpld']

    if 'days' in data['coupler_nml']:
        data['coupler_nml'].pop('days')
    if 'months' in data['coupler_nml']:
        data['coupler_nml'].pop('months')

    if ('days' in environ) & ('months' not in environ):
        data['coupler_nml']['days'] = environ['days']
    elif ('days' not in environ) & ('months' in environ):
        data['coupler_nml']['months'] = environ['months']
    else:
        print "Error, one should use days or months, not both or none"

    if environ['mode'] == 'warm':
        start = datetime.strptime(str(environ['restart']), "%Y%m%d%H")
    else:
        start = datetime.strptime(str(environ['start']), "%Y%m%d%H")
    data['coupler_nml']['current_date'] = start.strftime(
        "%Y, %m, %d, %H, 0, 0")

    if 'ocean_drifters_nml' in data.keys():
        if data['ocean_drifters_nml']['use_this_module']:
            environ['run_drifters_pos'] = True

    output.write(yaml2nml(data))

    put(output, fmt('{workdir}/input.nml', environ))
    output.close()