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

Construct correctly-cased path in case of path_style="unix" #698

Open
veenstrajelmer opened this issue Aug 21, 2024 · 1 comment
Open

Construct correctly-cased path in case of path_style="unix" #698

veenstrajelmer opened this issue Aug 21, 2024 · 1 comment

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Aug 21, 2024

Is your feature request related to a problem? Please describe.
When generating a dummy ext file like so:

import os
import hydrolib.core.dflowfm as hcdfm

# input
model_name = 'abc'
dir_base = r'P:\archivedprojects\11209231-003-bes-modellering\hydrodynamica\hackathon\preprocessing\ModelBuilderOutput_JV2\Bonaire.pli'
dir_output = os.path.expanduser(r"~\Downloads\test_pdrive_bug")
path_style = 'unix' # windows / unix, making relative paths only works when path_style is equal to os

# make dirs
os.makedirs(dir_output, exist_ok=True)

file_pli = os.path.join(dir_base, 'Maracaibo_bnd.pli')

ext_new = hcdfm.ExtModel()

ForcingModel_object = hcdfm.ForcingModel()
file_bc = os.path.join(dir_output, f'{model_name}.bc')
ForcingModel_object.save(filepath=file_bc)

# generate hydrolib-core Boundary object to be appended to the ext file
boundary_object = hcdfm.Boundary(quantity='waterlevelbnd', #the FM quantity for tide is also waterlevelbnd
                                  locationfile=file_pli,
                                  forcingfile=ForcingModel_object)
ext_new.boundary.append(boundary_object)

#save new ext file
ext_file_new = os.path.join(dir_output, f'{model_name}_new.ext')
ext_new.save(filepath=ext_file_new,path_style=path_style)

This results in an ext file with:

[Boundary]
quantity     = waterlevelbnd
locationFile = /P/archivedprojects/11209231-003-bes-modellering/hydrodynamica/hackathon/preprocessing/ModelBuilderOutput_JV2/Bonaire.pli/Maracaibo_bnd.pli
forcingFile  = /C/Users/veenstra/Downloads/test_pdrive_bug/abc.bc

This is a bit inconvenient since the P drive does not exist on unix, it is lowercase p instead. Of course, the C-path will also not be found on unix, but this can be ignored since it is just a dummy for this testcase.

Describe the solution you'd like
Do uppercase drive letters exist in unix at all? If not, we might make them lowercase automatically. However, I realize the entire path is case-sensitive in unix, so it has to also be provided case-sensitive. It seems it is possible to convert these automatically, but it might be cumbersome to implement. Furthermore, it does not correct the drive letter.

Describe alternatives you've considered
Alternatively, the user would supply the correctly-cased path, which of course is error-prone.

@veenstrajelmer veenstrajelmer changed the title Lowercase drive letters in case of path_style="unix" Construct correctly-cased path in case of path_style="unix" Aug 21, 2024
@priscavdsluis
Copy link
Contributor

We have the option in hydrolib-core to fix the casing of model file paths during an import, such that they match with the file paths that are actually on the file system:
https://deltares.github.io/HYDROLIB-core/0.5.2/tutorials/loading_and_saving_a_model/#loading-models-on-case-sensitive-systems

We could take that into account for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants