def test_simulation_nwm_public(tmp_data_dir_public,capsys):
    with capsys.disabled():
        print("Question: WrfHydroSim object is constructed properly for NWM public?")

    # Set directory paths
    expected_dir = tmp_data_dir_public / 'data' / 'expected'
    compile_dir = tmp_data_dir_public / 'data' / 'wrf_hydro_nwm_public' / 'compiled'
    domain_top_dir = tmp_data_dir_public / 'data' / 'domain'

    # Load expected objects
    model_objects_expected = pickle.load(open(expected_dir / 'test_model_nwm_public.pkl', "rb"))
    domain_object_expected = pickle.load(open(expected_dir / 'test_domain_nwm_public.pkl', "rb"))
    simulation_object_expected = pickle.load(open(expected_dir / 'test_simulation_nwm_public.pkl',"rb"))

    # Load previous test artifacts
    model_object_postcompile = pickle.load(open(compile_dir / 'WrfHydroModel.pkl','rb'))

    # Setup a simulation
    domain_object = wrfhydropy.WrfHydroDomain(domain_top_dir=domain_top_dir,
                                   domain_config='NWM',
                                   model_version='v1.2.1')
    model_object_postcompile_expected=model_objects_expected['model_object_postcompile']
    simulation_object = wrfhydropy.WrfHydroSim(model_object_postcompile,domain_object)

    # Compare expected to new
    hydro_diffs = deepdiff.DeepDiff(simulation_object_expected.hydro_namelist,
                              simulation_object.hydro_namelist)
    assert hydro_diffs == {}
    hrldas_diffs = deepdiff.DeepDiff(simulation_object_expected.namelist_hrldas,
                              simulation_object.namelist_hrldas)
    assert hrldas_diffs == {}
def test_run_nwm_public(tmp_data_dir_public,capsys,):
    with capsys.disabled():
        print("Question: WrfHydroSim object is able to run NWM public?")

    # Set directory paths
    expected_dir = tmp_data_dir_public / 'data' / 'expected'
    compile_dir = tmp_data_dir_public / 'data' / 'wrf_hydro_nwm_public' / 'compiled'
    domain_top_dir = tmp_data_dir_public / 'data' / 'domain'
    run_dir = tmp_data_dir_public / 'data' / 'wrf_hydro_nwm_public' / 'run'

    # Load expected objects
    simulation_object_expected = pickle.load(open(expected_dir / 'test_simulation_nwm_public.pkl',"rb"))
    run_object_expected = pickle.load(open(expected_dir / 'test_run_nwm_public.pkl',"rb"))

    # Load previous test artifacts
    model_object_postcompile = pickle.load(open(compile_dir / 'WrfHydroModel.pkl','rb'))

    # Setup a simulation
    domain_object = wrfhydropy.WrfHydroDomain(domain_top_dir=domain_top_dir,
                                   domain_config='NWM',
                                   model_version='v1.2.1')

    simulation_object = wrfhydropy.WrfHydroSim(model_object_postcompile,domain_object)

    # Run the sim
    run_object = simulation_object.run(run_dir, mode='w')

    # Compare to the expected simulation to the post-run simulation to make sure nothing in the
    # namelists was altered at run-time
    hydro_diffs = deepdiff.DeepDiff(simulation_object_expected.hydro_namelist,
                              simulation_object.hydro_namelist)
    assert hydro_diffs == {}
    hrldas_diffs = deepdiff.DeepDiff(simulation_object_expected.namelist_hrldas,
                              simulation_object.namelist_hrldas)
    assert hrldas_diffs == {}

    # Check that the model ran successfully
    assert run_object.run_log.returncode == 0

    ## Get names of restart files in expected run and check that names nad orders match
    hydro_restarts_expected=[]
    for restart_file in run_object_expected.restart_hydro:
        hydro_restarts_expected.append(restart_file.name)

    for i in range(len(hydro_restarts_expected)):
        assert run_object.restart_hydro[i].name == hydro_restarts_expected[i]
def test_domain_nwm_public(tmp_data_dir_public,capsys):
    with capsys.disabled():
        print("Question: The WrfHydroDomain class is constructed properly for NWM public?")

    # Set directory paths
    domain_top_dir = tmp_data_dir_public / 'data' / 'domain'
    expected_dir = tmp_data_dir_public / 'data' / 'expected'

    # Load expected object
    domain_object_expected = pickle.load(open(expected_dir / 'test_domain_nwm_public.pkl',"rb"))

    # Generate new objects
    domain_object = wrfhydropy.WrfHydroDomain(domain_top_dir=domain_top_dir,
                                   domain_config='NWM',
                                   model_version='v1.2.1')

    # Compare expected to new
    diffs = deepdiff.DeepDiff(domain_object_expected,domain_object)
    assert diffs == {}
Esempio n. 4
0
def test_setup_nwm(tmp_data_dir, capsys):
    with capsys.disabled():
        print(
            "\nQuestion: WrfHydroSetup object is constructed properly for NWM public? ",
            end=''
        )

    # Set directory paths
    expected_dir = tmp_data_dir / 'data' / 'expected'
    compile_dir = tmp_data_dir / 'data' / 'wrf_hydro_nwm_public' / 'compiled'
    domain_top_dir = tmp_data_dir / 'data' / 'domain'

    # Load expected objects
    # model_objects_expected = pickle.load(open(expected_dir / 'test_model_nwm.pkl', "rb"))
    # domain_object_expected = pickle.load(open(expected_dir / 'test_domain_nwm.pkl', "rb"))
    setup_object_expected = pickle.load(open(expected_dir / 'test_setup_nwm.pkl', "rb"))

    # Load previous test artifacts
    model_object_postcompile = pickle.load(open(compile_dir / 'WrfHydroModel.pkl', 'rb'))

    # Setup a setup object
    domain_object = wrfhydropy.WrfHydroDomain(
        domain_top_dir=domain_top_dir,
        domain_config='NWM',
        model_version='v1.2.1'
    )
    #model_object_postcompile_expected = model_objects_expected['model_object_postcompile']
    setup_object = wrfhydropy.WrfHydroSetup(model_object_postcompile, domain_object)
    setup_object.namelist_hrldas['noahlsm_offline']['restart_frequency_hours'] = 6
    setup_object.hydro_namelist['hydro_nlist']['rst_dt'] = 360

    # Compare expected to new
    hydro_diffs = deepdiff.DeepDiff(
        setup_object_expected.hydro_namelist,
        setup_object.hydro_namelist
    )
    assert hydro_diffs == {}

    hrldas_diffs = deepdiff.DeepDiff(
        setup_object_expected.namelist_hrldas,
        setup_object.namelist_hrldas
    )
    assert hrldas_diffs == {}
Esempio n. 5
0
# ######################################################
# Model Section
# There are implied options here
# What is the argument? Are there more arguments?

#domain_top_path = '/home/docker/domain/croton_NY'
#source_path = '/home/docker/wrf_hydro_nwm/trunk/NDHMS'
USER = os.path.expanduser('~/')
domain_top_path = pathlib.PosixPath(USER + '/Downloads/croton_NY')
source_path = pathlib.PosixPath(USER +
                                '/WRF_Hydro/wrf_hydro_nwm_public/trunk/NDHMS')
#domain_top_path = USER + '/domain/croton_NY'
#source_path = USER + '/wrf_hydro_nwm_public/trunk/NDHMS/'

theDomain = wrfhydropy.WrfHydroDomain(domain_top_dir=domain_top_path,
                                      model_version='v1.2.1',
                                      domain_config='NWM')

theModel = wrfhydropy.WrfHydroModel(source_path, model_config='NWM')

theSetup = wrfhydropy.WrfHydroSetup(theModel, theDomain)

#print('ensemble 0')
#e0=WrfHydroEnsembleSim([])
#print('len(e0): ',len(e0))
#e0.add_members(theSim)
#print('len(e0): ',len(e0))

print('ensemble 1')
e1 = wrfhydropy.WrfHydroEnsembleSetup([theSetup])
print('len(e1): ', len(e1))
Esempio n. 6
0
def test_run_nwm(tmp_data_dir, capsys):
    with capsys.disabled():
        print(
            "\nQuestion: WrfHydroSetup object is able to run NWM public? ",
            end=''
        )

    # Set directory paths
    expected_dir = tmp_data_dir / 'data' / 'expected'
    compile_dir = tmp_data_dir / 'data' / 'wrf_hydro_nwm_public' / 'compiled'
    domain_top_dir = tmp_data_dir / 'data' / 'domain'
    run_dir = tmp_data_dir / 'data' / 'wrf_hydro_nwm_public' / 'run'

    # Load expected objects
    setup_object_expected = pickle.load(open(expected_dir / 'test_setup_nwm.pkl', "rb"))
    run_objects_expected = pickle.load(open(expected_dir / 'test_run_nwm.pkl', "rb"))
    job_list_expected = pickle.load(open(expected_dir / 'test_job_list_nwm.pkl', "rb"))

    # Load previous test artifacts
    model_object_postcompile = pickle.load(open(compile_dir / 'WrfHydroModel.pkl', 'rb'))

    # Setup a setup object
    domain_object = wrfhydropy.WrfHydroDomain(
        domain_top_dir=domain_top_dir,
        domain_config='NWM',
        model_version='v1.2.1'
    )
    # compare the domain object?

    setup_object = wrfhydropy.WrfHydroSetup(model_object_postcompile, domain_object)
    setup_object.namelist_hrldas['noahlsm_offline']['restart_frequency_hours'] = 6
    setup_object.hydro_namelist['hydro_nlist']['rst_dt'] = 360
    #assert setup_object == setup_object_expected
    # TODO JLM: why does this not check?

    job_list = mk_job_list()
    # assert job_list == job_list_expected
    # TODO(JLM): why does this not check?

    # Run the setup
    run_object = wrfhydropy.WrfHydroRun(
        setup_object,
        run_dir=run_dir,
        rm_existing_run_dir=True,
        jobs=job_list
    )

    prerun_diffs = deepdiff.DeepDiff(
        run_objects_expected['run_object_prerun'],
        run_object
    )

    # with capsys.disabled():
    #     #How to check that the diffs are actually allowable
    #     #pprint.pprint(prerun_diffs['values_changed'])
    #     pprint.pprint(prerun_diffs)
    #     #How to get the allowable diffs
    #     #pprint.pprint(prerun_diffs['values_changed'].keys())
    #     pprint.pprint(prerun_diffs.keys())

    allowable_prerun_diffs = set(
        ['root.jobs_pending[0].job_date_id',
         'root.jobs_pending[1].job_submission_time',
         'root.setup.model.compile_log.args[1]',
         'root.setup.model.object_id',
         'root.jobs_pending[1].job_date_id',
         'root.jobs_pending[0].job_submission_time',
         'root.setup.model.compile_log.stdout']
    )

    assert set(prerun_diffs.keys()) == set(['values_changed'])
    assert set(prerun_diffs['values_changed'].keys()) == allowable_prerun_diffs

    run_object.run_jobs()

    postrun_diffs = deepdiff.DeepDiff(
        run_objects_expected['run_object_postrun'],
        run_object
    )

    # with capsys.disabled():
        # How to check that the diffs are actually allowable
        # pprint.pprint(postrun_diffs['values_changed'])
        # How to get the allowable diffs
        # pprint.pprint(postrun_diffs['values_changed'].keys())
        
    allowable_postrun_diffs = set(
        ['root.jobs_completed[0].exe_cmd',
         'root.jobs_completed[0].job_submission_time',
         'root.jobs_completed[0].run_log.args[2]',
         'root.jobs_completed[1].job_submission_time',
         'root.jobs_completed[0].job_end_time',
         'root.object_id',
         'root.jobs_completed[0].job_date_id',
         'root.jobs_completed[0].job_start_time',
         'root.jobs_completed[1].job_date_id',
         'root.jobs_completed[1].job_end_time',
         'root.jobs_completed[1].run_log.args[2]',
         'root.jobs_completed[1].exe_cmd',
         'root.setup.model.compile_log.args[1]',
         'root.setup.model.compile_log.stdout',
         'root.jobs_completed[1].job_start_time',
         'root.setup.model.object_id']
    )

    assert set(postrun_diffs.keys()) == set(['values_changed'])
    assert set(postrun_diffs['values_changed'].keys()) == allowable_postrun_diffs