Ejemplo n.º 1
0
 def test_enable_restart_makes_copy(self):
     config = DEFAULT_CONFIG.copy()
     restart_config = enable_restart(config, "initial_conditions")
     self.assertEqual(config, DEFAULT_CONFIG)
     restart_config["diag_table"] = "changed item"
     restart_config["namelist"]["fv_core_nml"]["npx"] = 0
     self.assertEqual(config, DEFAULT_CONFIG)
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 setup_final_run(workdir, firsthalf_config, remove_phy_data=False):
    """Set up run directory for second two-hour run. This must be done after
    the first two-hour run has been performed so that the initial conditions
    are linked appropriately"""
    secondhalf_config = deepcopy(firsthalf_config)
    secondhalf_config['initial_conditions'] = os.path.abspath(
        join(workdir, 'firsthalf', 'RESTART')
    )
    secondhalf_config = fv3config.enable_restart(secondhalf_config)
    fv3config.write_run_directory(secondhalf_config, join(workdir, 'secondhalf'))
    if remove_phy_data:
        for tile in range(1, 7):
            os.remove(join(workdir, 'secondhalf', 'INPUT', f'phy_data.tile{tile}.nc'))
    shutil.copy(RUN_SCRIPT_FILENAME, join(workdir, 'secondhalf', RUN_SCRIPT_FILENAME))
    return secondhalf_config
Ejemplo n.º 4
0
def append_segment_to_run_url(run_url):
    """Append an segment to an initialized segmented run

    Either runs the first segment, or additional ones
    """
    with tempfile.TemporaryDirectory() as dir_:
        print(f"Iteration run={run_url} working_directory={dir_}",
              file=sys.stderr)

        config = read_run_config(run_url)
        last_segment = read_last_segment(run_url)

        if last_segment is not None:
            print("Continuing from segment", last_segment)
            config = fv3config.enable_restart(
                config, os.path.join(last_segment, "RESTART"))
        else:
            print(f"First segment in {run_url}")

        rundir = os.path.join(dir_, "rundir")
        post_processed_out = os.path.join(dir_, "post_processed")

        exit_code = run_segment(config, rundir)
        if exit_code != 0:
            warnings.warn(
                UserWarning(
                    f"FV3 exited with a nonzero exit-code: {exit_code}"))
        preexisting_files = os.path.join(rundir, "preexisting_files.txt")
        print("Skipping upload of the following files:")
        with open(preexisting_files) as f:
            print(f.read())

        post_process(
            rundir=rundir,
            destination=post_processed_out,
            skip=preexisting_files,
            chunks=os.path.join(rundir, "chunks.yaml"),
        )

        append_segment(
            rundir=post_processed_out,
            destination=run_url,
            segment_label=None,
            no_copy=True,
        )
        print("Cleaning up working directory")
        return exit_code
Ejemplo n.º 5
0
 def test_enable_restart_initial_conditions(self):
     config = DEFAULT_CONFIG.copy()
     restart_config = enable_restart(config, "new_path")
     self.assertEqual(restart_config["initial_conditions"], "new_path")
Ejemplo n.º 6
0
 def test_enable_restart_from_empty_config(self):
     with self.assertRaises(ConfigError):
         enable_restart(empty_dict, "initial_conditions")
Ejemplo n.º 7
0
 def test_enable_restart_from_empty_namelist(self):
     config = enable_restart(config_with_empty_namelist, "initial_conditions")
     assert config["namelist"]["fv_core_nml"]["warm_start"]
     assert not config["namelist"]["coupler_nml"]["force_date_from_namelist"]
Ejemplo n.º 8
0
 def test_enable_restart_from_default(self):
     config = DEFAULT_CONFIG.copy()
     restart_config = enable_restart(config, "initial_conditions")
     self.assert_dict_in_and_equal(
         restart_namelist_settings, restart_config["namelist"]
     )