Ejemplo n.º 1
0
def test_dump_load(c12_config, diag_table):
    config = copy.deepcopy(c12_config)
    config["diag_table"] = diag_table
    f = io.StringIO()
    fv3config.dump(config, f)
    f.seek(0)
    loaded = fv3config.load(f)
    assert config == loaded
Ejemplo n.º 2
0
def enable_restart():
    args = _parse_enable_restart_args()

    with fsspec.open(args.config) as f:
        config = fv3config.load(f)

    restart_config = fv3config.enable_restart(config, args.initial_conditions)

    with fsspec.open(args.config, mode="w") as f:
        fv3config.dump(restart_config, f)
Ejemplo n.º 3
0
def prepare_config(args):
    # Get model config with prognostic run updates
    with open(args.user_config, "r") as f:
        dict_ = yaml.safe_load(f)

    final = to_fv3config(
        dict_,
        model_url=args.model_url,
        diagnostic_ml=args.diagnostic_ml,
    )
    fv3config.dump(final, sys.stdout)
Ejemplo n.º 4
0
def enable_nudging():
    args = _parse_enable_nudging_args()

    with fsspec.open(args.config) as f:
        config = fv3config.load(f)

    # only update config if nudging is turned on
    if config["namelist"]["fv_core_nml"].get("nudge", False):
        updated_config = fv3config.enable_nudging(config)

        with fsspec.open(args.config, mode="w") as f:
            fv3config.dump(updated_config, f)
Ejemplo n.º 5
0
def create(url: str, fv3config_dict: dict):
    """Initialize a segmented run at ``url`` from a fv3config dictionary"""
    logger.info(f"Setting up segmented run at {url}")
    fs = vcm.cloud.get_fs(url)
    if fs.exists(url):
        raise FileExistsError(
            f"The given url '{url}' contains an object. Delete "
            "everything under output url and resubmit.")
    validate_chunks(fv3config_dict)
    fs.makedirs(url, exist_ok=True)
    with fs.open(os.path.join(url, "fv3config.yml"), "w") as f:
        fv3config.dump(fv3config_dict, f)
Ejemplo n.º 6
0
def subprocess_run(config_dict, outdir):
    with tempfile.NamedTemporaryFile(mode="w") as config_file:
        fv3config.dump(config_dict, config_file)
        config_file.flush()
        subprocess.check_call([
            "fv3run",
            config_file.name,
            outdir,
            "--runfile",
            MOCK_RUNSCRIPT,
            "--capture-output",
        ])
Ejemplo n.º 7
0
def docker_run(config_dict, outdir):
    with tempfile.NamedTemporaryFile(mode="w") as config_file:
        fv3config.dump(config_dict, config_file)
        config_file.flush()
        try:
            subprocess.check_call([
                "fv3run",
                config_file.name,
                outdir,
                "--runfile",
                MOCK_RUNSCRIPT,
                "--dockerimage",
                DOCKER_IMAGE_NAME,
            ])
        except subprocess.CalledProcessError as err:
            if os.path.isfile(os.path.join(outdir, "stdout.log")):
                with open(os.path.join(outdir, "stdout.log")) as stdout:
                    print(f"STDOUT: {stdout.read()}")
            if os.path.isfile(os.path.join(outdir, "stderr.log")):
                with open(os.path.join(outdir, "stderr.log")) as stderr:
                    print(f"STDERR: {stderr.read()}")
            raise err
import fv3config
import argparse
import os

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Create a run directory for FV3.")
    parser.add_argument("configfile", type=str, help="yaml configuration path")
    parser.add_argument("outdir", type=str, help="output directory")
    args = parser.parse_args()

    with open(args.configfile, "r") as f:
        config = fv3config.load(f)
    fv3config.write_run_directory(config, args.outdir)

    with open(os.path.join(args.outdir, "fv3config.yml"), "w") as f:
        fv3config.dump(config, f)
Ejemplo n.º 9
0
def config_dict_filename_run(config_dict, outdir):
    with tempfile.NamedTemporaryFile(mode="w") as config_file:
        fv3config.dump(config_dict, config_file)
        config_file.flush()
        fv3config.run_native(config_file.name, outdir, runfile=MOCK_RUNSCRIPT)