Skip to content

Fix external file paths dependency on OS #106 #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions mfsetup/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,12 @@ def setup_external_filepaths(model, package, variable_name,

model.get_package(package)
# intermediate data
filename_format = os.path.split(filename_format)[-1]
if not relative_external_paths:
intermediate_files = [os.path.normpath(os.path.join(model.tmpdir,
filename_format).format(i)) for i in file_numbers]
else:
intermediate_files = [os.path.join(model.tmpdir,
filename_format).format(i) for i in file_numbers]
filename_format = Path(filename_format).name #os.path.split(filename_format)[-1]
# if not relative_external_paths:
intermediate_files = [(model.tmpdir / filename_format.format(i)).as_posix() for i in file_numbers]
# else:
# intermediate_files = [os.path.join(model.tmpdir,
# filename_format).format(i) for i in file_numbers]

if variable_name in transient2D_variables or variable_name in transient_tabular_variables:
model.cfg['intermediate_data'][variable_name] = {per: f for per, f in
Expand All @@ -503,14 +502,13 @@ def setup_external_filepaths(model, package, variable_name,

# external array(s) read by MODFLOW
# (set to reflect expected locations where flopy will save them)
if not relative_external_paths:
external_files = [os.path.normpath(os.path.join(model.model_ws,
model.external_path,
filename_format.format(i))) for i in file_numbers]
else:
external_files = [os.path.join(model.model_ws,
model.external_path,
filename_format.format(i)) for i in file_numbers]
# if not relative_external_paths:
external_files = [(model.model_ws / model.external_path / filename_format.format(i)).as_posix()
for i in file_numbers]
# else:
# external_files = [os.path.join(model.model_ws,
# model.external_path,
# filename_format.format(i)) for i in file_numbers]

if variable_name in transient2D_variables or variable_name in transient_tabular_variables:
model.cfg['external_files'][variable_name] = {per: f for per, f in
Expand Down
2 changes: 1 addition & 1 deletion mfsetup/mfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def external_path(self):
ext_path = os.path.relpath(abspath)
else:
ext_path = os.path.normpath(abspath)
return ext_path
return Path(ext_path)

@external_path.setter
def external_path(self, x):
Expand Down
14 changes: 5 additions & 9 deletions mfsetup/tests/test_mf6_shellmound.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,15 @@ def test_package_external_file_path_setup(shellmound_model_with_grid,
assert not os.path.isabs(path)

assert m.cfg['intermediate_data']['top'] == \
[os.path.normpath(os.path.join(m.tmpdir, os.path.split(top_filename)[-1]))]
[(m.tmpdir / Path(top_filename).name).as_posix()]
assert m.cfg['intermediate_data']['botm'] == \
[os.path.normpath(os.path.join(m.tmpdir, botm_file_fmt).format(i))
for i in range(m.nlay)]
[(m.tmpdir / botm_file_fmt.format(i)).as_posix() for i in range(m.nlay)]
if not relative_external_paths:
assert m.cfg['dis']['griddata']['top'] == \
[{'filename': os.path.normpath(os.path.join(m.model_ws,
m.external_path,
os.path.split(top_filename)[-1]))}]
[{'filename': (m.model_ws / m.external_path / Path(top_filename).name).as_posix()}]
assert m.cfg['dis']['griddata']['botm'] == \
[{'filename': os.path.normpath(os.path.join(m.model_ws,
m.external_path,
botm_file_fmt.format(i)))} for i in range(m.nlay)]
[{'filename': (m.model_ws / m.external_path / botm_file_fmt.format(i)).as_posix()}
for i in range(m.nlay)]


def test_set_lakarr(shellmound_model_with_dis):
Expand Down