def pleasant_lgr_stand_alone_parent(pleasant_lgr_test_cfg_path, tmpdir): """Stand-alone version of lgr parent model for comparing with LGR results. """ # Edit the configuration file before the file paths within it are converted to absolute # (model.load_cfg converts the file paths) cfg = load(pleasant_lgr_test_cfg_path) del cfg['setup_grid']['lgr'] cfg['simulation']['sim_ws'] = os.path.join(tmpdir, 'pleasant_lgr_just_parent') # save out the edited configuration file path, fname = os.path.split(pleasant_lgr_test_cfg_path) new_file = os.path.join(path, 'pleasant_lgr_just_parent.yml') dump(new_file, cfg) # load in the edited configuration file, converting the paths to absolute cfg = MF6model.load_cfg(new_file) # add some stuff just for the tests cfg['gisdir'] = os.path.join(cfg['simulation']['sim_ws'], 'gis') m = MF6model.setup_from_cfg(cfg) m.write_input() #if hasattr(m, 'sfr'): # sfr_package_filename = os.path.join(m.model_ws, m.sfr.filename) # m.sfrdata.write_package(sfr_package_filename, # version='mf6' # ) return m
def shellmound_model(shellmound_cfg, shellmound_simulation): cfg = shellmound_cfg.copy() cfg['model']['simulation'] = shellmound_simulation cfg = MF6model._parse_model_kwargs(cfg) kwargs = get_input_arguments(cfg['model'], mf6.ModflowGwf, exclude='packages') m = MF6model(cfg=cfg, **kwargs) return m
def test_rotated_grid(shellmound_cfg, shellmound_simulation): cfg = deepcopy(shellmound_cfg) #simulation = deepcopy(simulation) cfg['model']['simulation'] = shellmound_simulation cfg['setup_grid']['snap_to_NHG'] = False cfg['setup_grid']['rotation'] = 18. cfg['setup_grid']['xoff'] += 8000 cfg['dis']['dimensions']['nrow'] = 20 cfg['dis']['dimensions']['ncol'] = 25 cfg = MF6model._parse_model_kwargs(cfg) kwargs = get_input_arguments(cfg['model'], mf6.ModflowGwf, exclude='packages') m = MF6model(cfg=cfg, **kwargs) m.setup_grid() assert m.modelgrid.angrot == 18. assert m.modelgrid.xoffset == cfg['setup_grid']['xoff'] assert m.modelgrid.yoffset == cfg['setup_grid']['yoff'] m.setup_dis() #m.setup_tdis() #m.setup_solver() #m.setup_packages(reset_existing=False) #m.write_input() j = 2
def test_setup_from_yaml_issue(project_root_path, remake_top): cfg = MF6model.load_cfg( Path(project_root_path) / 'examples/pleasant_lgr_parent.yml') lgr_test_path = Path(project_root_path) / 'examples/pleasant_lgr' shutil.rmtree(lgr_test_path, ignore_errors=True) keep_keys = { 'simulation', 'model', 'parent', 'setup_grid', 'dis', 'tdis', 'intermediate_data', 'postprocessing', 'filename' } new_cfg = {k: v for k, v in cfg.items() if k in keep_keys} new_cfg['model']['packages'] = ['dis'] new_cfg['dis']['remake_top'] = remake_top del new_cfg['setup_grid']['lgr'] MF6model.setup_from_cfg(new_cfg)
def get_pleasant_mf6(pleasant_mf6_cfg, pleasant_simulation): print('creating Pleasant Lake MF6model instance from cfgfile...') cfg = copy.deepcopy(pleasant_mf6_cfg) cfg['model']['simulation'] = pleasant_simulation kwargs = get_input_arguments(cfg['model'], mf6.ModflowGwf, exclude='packages') m = MF6model(cfg=cfg, **kwargs) return m
def test_lgr_load(pleasant_lgr_setup_from_yaml, pleasant_lgr_test_cfg_path): m = pleasant_lgr_setup_from_yaml #deepcopy(pfl_nwt_setup_from_yaml) m2 = MF6model.load(pleasant_lgr_test_cfg_path) assert m2.inset['plsnt_lgr_inset'].simulation is m2.simulation assert set(m2.get_package_list()).difference(m.get_package_list()) == {'SFR_OBS'}
def pleasant_lgr_setup_from_yaml(pleasant_lgr_cfg): m = MF6model.setup_from_cfg(pleasant_lgr_cfg) m.write_input() for model in m, m.inset['plsnt_lgr_inset']: if hasattr(model, 'sfr'): sfr_package_filename = os.path.join(model.model_ws, model.sfr.filename) model.sfrdata.write_package(sfr_package_filename, version='mf6' ) return m
def test_solver_defaults(test_data_path, tmpdir): """Verify that default values aren't applied to solver packages if the simplified settings options are used (e.g. simple/moderate/complex)""" # modflow-6 IMS package mf6_model_config = test_data_path / 'pleasant_mf6_test.yml' cfg = MF6model.load_cfg(mf6_model_config) keep_keys = { 'simulation', 'model', 'parent', 'setup_grid', 'dis', 'tdis', 'intermediate_data', 'postprocessing' } new_cfg = {k: v for k, v in cfg.items() if k in keep_keys} new_cfg['model']['packages'] = ['dis'] new_cfg['ims'] = {'options': {'complexity': 'moderate'}} temp_yaml = Path(tmpdir) / 'junk.yml' dump(temp_yaml, new_cfg) m = MF6model.setup_from_yaml(temp_yaml) assert 'nonlinear' not in m.cfg['ims'] assert 'linear' not in m.cfg['ims'] # modflow-nwt NWT package mfnwt_model_config = test_data_path / 'pleasant_nwt_test.yml' cfg = MFnwtModel.load_cfg(mfnwt_model_config) keep_keys = { 'simulation', 'model', 'parent', 'setup_grid', 'dis', 'bas6', 'intermediate_data', 'postprocessing' } new_cfg = {k: v for k, v in cfg.items() if k in keep_keys} new_cfg['model']['packages'] = ['dis', 'bas6'] new_cfg['nwt'] = {'options': 'moderate'} temp_yaml = Path(tmpdir) / 'junk.yml' dump(temp_yaml, new_cfg) m = MFnwtModel.setup_from_yaml(temp_yaml) expected_keys = { 'headtol', 'fluxtol', 'maxiterout', 'thickfact', 'linmeth', 'iprnwt', 'ibotav', 'Continue', 'use_existing_file', 'options' } assert not set(m.cfg['nwt'].keys()).difference(expected_keys) assert m.cfg['nwt']['options'] == 'moderate'
def pleasant_lgr_setup_from_yaml(pleasant_lgr_cfg): m = MF6model.setup_from_cfg(pleasant_lgr_cfg) m.write_input() #for model in m, m.inset['plsnt_lgr_inset']: # if hasattr(model, 'sfr'): # sfr_package_filename = os.path.join(model.model_ws, model.sfr.filename) # model.sfrdata.write_package(sfr_package_filename, # version='mf6', # options=['save_flows', # 'BUDGET FILEOUT {}.sfr.cbc'.format(model.name), # 'STAGE FILEOUT {}.sfr.stage.bin'.format(model.name), # 'mover' # ] # ) return m
def shellmound_tmr_model_setup(shellmound_tmr_cfg_path): m = MF6model.setup_from_yaml(shellmound_tmr_cfg_path) m.write_input() #if hasattr(m, 'sfr'): # sfr_package_filename = os.path.join(m.model_ws, m.sfr.filename) # m.sfrdata.write_package(sfr_package_filename, # version='mf6', # options=['save_flows', # 'BUDGET FILEOUT {}.sfr.cbc'.format(m.name), # 'STAGE FILEOUT {}.sfr.stage.bin'.format(m.name), # # 'OBS6 FILEIN {}'.format(sfr_obs_filename) # # location of obs6 file relative to sfr package file (same folder) # ] # ) return m
def pleasant_mf6_setup_from_yaml(pleasant_mf6_test_cfg_path): m = MF6model.setup_from_yaml(pleasant_mf6_test_cfg_path) m.write_input() if hasattr(m, 'sfr'): sfr_package_filename = os.path.join(m.model_ws, m.sfr.filename) m.sfrdata.write_package( sfr_package_filename, version='mf6', idomain=m.idomain, options=[ 'save_flows', 'BUDGET FILEOUT shellmound.sfr.cbc', 'STAGE FILEOUT shellmound.sfr.stage.bin', # 'OBS6 FILEIN {}'.format(sfr_obs_filename) # location of obs6 file relative to sfr package file (same folder) ]) return m
def pleasant_lgr_setup_from_yaml(pleasant_lgr_cfg): m = MF6model.setup_from_cfg(pleasant_lgr_cfg) m.write_input() return m