Skip to content

Commit

Permalink
fix(mfnwtmodel.py; mf6model.py): listing file paths in name file refl…
Browse files Browse the repository at this point in the history
…ect the paths entered in the configuration file, relative to the model_ws or sim_ws; resolves #2
  • Loading branch information
aleaf committed Jun 3, 2020
1 parent 1f66706 commit e771e6a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 4 deletions.
1 change: 0 additions & 1 deletion docs/source/config-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Modflow-setup uses the `pyyaml`_ package to parse the configuration file into th

Configuration file structure <config-file-structure>
Configuration defaults <config-file-defaults>
Description of source datatypes <source-data>


Some additional notes on YAML
Expand Down
1 change: 1 addition & 0 deletions mfsetup/mf6_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions mfsetup/mf6model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mfsetup/mfnwt_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions mfsetup/mfnwtmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mfsetup/tests/data/pfl_nwt_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion mfsetup/tests/test_lgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions mfsetup/tests/test_mf6_shellmound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions mfsetup/tests/test_pfl_mfnwt_inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit e771e6a

Please sign in to comment.