From e771e6a7538074e5904e84c25590140614909e54 Mon Sep 17 00:00:00 2001 From: aleaf Date: Wed, 3 Jun 2020 10:06:20 -0500 Subject: [PATCH] fix(mfnwtmodel.py; mf6model.py): listing file paths in name file reflect the paths entered in the configuration file, relative to the model_ws or sim_ws; resolves #2 --- docs/source/config-file.rst | 1 - mfsetup/mf6_defaults.yml | 1 + mfsetup/mf6model.py | 3 +-- mfsetup/mfnwt_defaults.yml | 2 ++ mfsetup/mfnwtmodel.py | 3 +++ mfsetup/tests/data/pfl_nwt_test.yml | 2 ++ mfsetup/tests/test_lgr.py | 2 +- mfsetup/tests/test_mf6_shellmound.py | 12 ++++++++++++ mfsetup/tests/test_pfl_mfnwt_inset.py | 12 ++++++++++++ 9 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/source/config-file.rst b/docs/source/config-file.rst index a8c535e7..a3c47606 100644 --- a/docs/source/config-file.rst +++ b/docs/source/config-file.rst @@ -15,7 +15,6 @@ Modflow-setup uses the `pyyaml`_ package to parse the configuration file into th Configuration file structure Configuration defaults - Description of source datatypes Some additional notes on YAML diff --git a/mfsetup/mf6_defaults.yml b/mfsetup/mf6_defaults.yml index 4fa43994..3119d766 100644 --- a/mfsetup/mf6_defaults.yml +++ b/mfsetup/mf6_defaults.yml @@ -8,6 +8,7 @@ simulation: model: modelname: 'model' version: 'mf6' + # list file format is relative to the model workspace list_filename_fmt: '{}.list' options: print_input: True diff --git a/mfsetup/mf6model.py b/mfsetup/mf6model.py index 3f470b79..c33c58bd 100644 --- a/mfsetup/mf6model.py +++ b/mfsetup/mf6model.py @@ -962,8 +962,7 @@ def _parse_model_kwargs(cfg): raise TypeError('unrecognized configuration input for simulation.') # listing file - cfg['model']['list'] = os.path.join(sim_ws, - cfg['model']['list_filename_fmt'] + cfg['model']['list'] = os.path.join(cfg['model']['list_filename_fmt'] .format(cfg['model']['modelname'])) # newton options diff --git a/mfsetup/mfnwt_defaults.yml b/mfsetup/mfnwt_defaults.yml index 9d2aa003..c13c4179 100644 --- a/mfsetup/mfnwt_defaults.yml +++ b/mfsetup/mfnwt_defaults.yml @@ -8,6 +8,8 @@ model: exe_name: 'mfnwt' version: 'mfnwt' external_path: 'external/' + # list file format is relative to the model workspace + list_filename_fmt: '{}.list' relative_external_filepaths: True hiKlakes_value: 1.e4 default_lake_depth: 2 # m; default depth to assume when setting up lak package or high-k lakes (layer 1 bottom is adjusted to achieve this thickness) diff --git a/mfsetup/mfnwtmodel.py b/mfsetup/mfnwtmodel.py index 2a377edf..1a0aa45c 100644 --- a/mfsetup/mfnwtmodel.py +++ b/mfsetup/mfnwtmodel.py @@ -46,6 +46,9 @@ def __init__(self, parent=None, cfg=None, self._set_cfg(cfg) # set up the model configuration dictionary self.relative_external_paths = self.cfg.get('model', {}).get('relative_external_paths', True) self.model_ws = self._get_model_ws() + + # set the list file path + self.lst.file_name = [self.cfg['model']['list_filename_fmt'].format(self.name)] # property arrays self._ibound = None diff --git a/mfsetup/tests/data/pfl_nwt_test.yml b/mfsetup/tests/data/pfl_nwt_test.yml index b25a8c11..53fbf5b3 100644 --- a/mfsetup/tests/data/pfl_nwt_test.yml +++ b/mfsetup/tests/data/pfl_nwt_test.yml @@ -4,6 +4,8 @@ model: exe_name: 'mfnwt' external_path: 'external/' perimeter_boundary_type: 'specified head' + # list file path is relative to model_ws + list_filename_fmt: 'external/{}.list' packages: ['dis', 'bas6', 'oc', diff --git a/mfsetup/tests/test_lgr.py b/mfsetup/tests/test_lgr.py index 01dcebd7..b7975526 100644 --- a/mfsetup/tests/test_lgr.py +++ b/mfsetup/tests/test_lgr.py @@ -181,7 +181,7 @@ def test_lgr_model_setup(pleasant_lgr_setup_from_yaml): specified_options = {'list', 'print_input', 'save_flows', 'newton'} assert not any(specified_options.difference(name_options.keys())) path, fname = os.path.split(name_options['list'][0]) - assert os.path.abspath(m.model_ws).lower() == path.lower() + assert os.path.abspath(m.model_ws).lower() == os.path.abspath(path).lower() assert name_options['newton'][0] == 'under_relaxation' # check that the model names were included in the external files diff --git a/mfsetup/tests/test_mf6_shellmound.py b/mfsetup/tests/test_mf6_shellmound.py index d3b15266..da31dec7 100644 --- a/mfsetup/tests/test_mf6_shellmound.py +++ b/mfsetup/tests/test_mf6_shellmound.py @@ -162,6 +162,18 @@ def test_model(shellmound_model): os.path.normpath(os.path.join(os.path.abspath(model.model_ws), model.external_path)) +def test_namefile(shellmound_model_with_dis): + model = shellmound_model_with_dis + model.write_input() + + # check that listing file was written correctly + expected_listfile_name = model.cfg['model']['list_filename_fmt'].format(model.name) + with open(model.namefile) as src: + for line in src: + if 'LIST' in line: + assert line.strip().split()[-1] == expected_listfile_name + + def test_snap_to_NHG(shellmound_cfg, shellmound_simulation): cfg = deepcopy(shellmound_cfg) #simulation = deepcopy(simulation) diff --git a/mfsetup/tests/test_pfl_mfnwt_inset.py b/mfsetup/tests/test_pfl_mfnwt_inset.py index dbb06f02..3867c94a 100644 --- a/mfsetup/tests/test_pfl_mfnwt_inset.py +++ b/mfsetup/tests/test_pfl_mfnwt_inset.py @@ -72,6 +72,18 @@ def test_pfl_nwt_with_grid(pfl_nwt_with_grid): assert pfl_nwt_with_grid.modelgrid is not None +def test_namefile(pfl_nwt_with_dis): + model = pfl_nwt_with_dis + model.write_input() + + # check that listing file was written correctly + expected_listfile_name = model.cfg['model']['list_filename_fmt'].format(model.name) + with open(model.namefile) as src: + for line in src: + if 'LIST' in line: + assert line.strip().split()[-1] == expected_listfile_name + + def test_perioddata(pfl_nwt): model = pfl_nwt assert np.array_equal(model.perioddata.steady, [True, False])