Skip to content
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

Relative paths not working in newly initialized FMModel #532

Open
veenstrajelmer opened this issue Apr 13, 2023 · 1 comment
Open

Relative paths not working in newly initialized FMModel #532

veenstrajelmer opened this issue Apr 13, 2023 · 1 comment
Labels
priority: high type: bug Something isn't working type: enhancement Improvements to existing functionality

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Apr 13, 2023

Describe the bug
When initializing an FMModel and providing input (network, fixedweirfile, extfile, etc), one has to provide absolute paths of the files. When relative paths are used (the files are e.g. located in the folder where the mdu will also be saved), the files are not found. This might have to do with the mdu file not (yet) being saved, but even when doing that first, relative paths do not work.

To Reproduce

import os
import hydrolib.core.dflowfm as hcdfm

dir_output = r'c:\test_model_folder'
    
#create dummy file
if not os.path.exists(dir_output):
    os.mkdir(dir_output)
file_pli = os.path.join(dir_output,'test_model.pli')
with open(file_pli,'w') as f:
    f.write("""name
                2    2
                1.0    2.0
                3.0    4.0
                """)

## input
mdu_file = os.path.join(dir_output, 'test_model.mdu')
mdu = hcdfm.FMModel()

#absolute paths works
mdu.geometry.fixedweirfile = file_pli

#relative path does not work
mdu.geometry.fixedweirfile = os.path.basename(file_pli)

mdu.save(mdu_file)

Expected behavior
Being able to provide relative paths to the mdu keywords.
EDIT: It does work when setting os.chdir(dir_output), but changing the working directory is not always desireable. It might get a bit messy when using a nested model tree.

Version info (please complete the following information):

  • OS: Windows
  • Version main branch
@veenstrajelmer
Copy link
Collaborator Author

veenstrajelmer commented Apr 14, 2023

A sort of workaround is to set os.chdir(dir_output) at the top of the script. However, this does not make the paths to the bc-files relative (not included in the minimal example above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high type: bug Something isn't working type: enhancement Improvements to existing functionality
Projects
Status: To do
Development

No branches or pull requests

3 participants