Skip to content

Commit

Permalink
fix: allow empty file paths in the .fnm file
Browse files Browse the repository at this point in the history
issue: #82 #260
  • Loading branch information
priscavdsluis committed Jul 5, 2022
1 parent 087e0e0 commit ed896f9
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 111 deletions.
3 changes: 1 addition & 2 deletions hydrolib/core/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,7 @@ def _load(self, filepath: Path) -> Dict:
if filepath.is_file():
return self._parse(filepath)
else:
warn(f"File: `{filepath}` not found, skipped parsing.")
return {}
raise ValueError(f"File: `{filepath}` not found, skipped parsing.")

def save(self, filepath: Optional[Path] = None, recurse: bool = False) -> None:
"""Save the model to disk.
Expand Down
208 changes: 104 additions & 104 deletions hydrolib/core/io/rr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,67 @@ class RainfallRunoffModel(FileModel):
"""

# Note that order is defined by the .fnm file type and is used for parsing the data.
control_file: Path = Path("delft_3b.ini")
control_file: Optional[Path] = Path("delft_3b.ini")
node_data: Optional[NodeFile]
link_data: Optional[LinkFile]
open_water_data: Path = Path("3brunoff.tp")
paved_area_general: Path = Path("paved.3b")
paved_area_storage: Path = Path("paved.sto")
paved_area_dwa: Path = Path("paved.dwa")
paved_area_sewer_pump_capacity: Path = Path("paved.tbl")
boundaries: Path = Path("pluvius.dwa")
pluvius: Path = Path("pluvius.3b")
pluvius_general: Path = Path("pluvius.alg")
kasklasse: Path = Path("kasklass")
open_water_data: Optional[Path] = Path("3brunoff.tp")
paved_area_general: Optional[Path] = Path("paved.3b")
paved_area_storage: Optional[Path] = Path("paved.sto")
paved_area_dwa: Optional[Path] = Path("paved.dwa")
paved_area_sewer_pump_capacity: Optional[Path] = Path("paved.tbl")
boundaries: Optional[Path] = Path("pluvius.dwa")
pluvius: Optional[Path] = Path("pluvius.3b")
pluvius_general: Optional[Path] = Path("pluvius.alg")
kasklasse: Optional[Path] = Path("kasklass")
bui_file: Optional[BuiModel] = None
verdampings_file: Path = Path("default.evp")
unpaved_area_general: Path = Path("unpaved.3b")
unpaved_area_storage: Path = Path("unpaved.sto")
green_house_area_initialisation: Path = Path("kasinit")
green_house_area_usage_data: Path = Path("kasgebr")
crop_factors: Path = Path("cropfact")
table_bergingscoef: Path = Path("bergcoef")
unpaved_alpha_factor_definitions: Path = Path("unpaved.alf")
run_log_file: Path = Path("sobek_3b.log")
schema_overview: Path = Path("3b_gener.out")
output_results_paved_area: Path = Path("paved.out")
output_results_unpaved_area: Path = Path("unpaved.out")
output_results_green_houses: Path = Path("grnhous.out")
output_results_open_water: Path = Path("openwate.out")
output_results_structures: Path = Path("struct3b.out")
output_results_boundaries: Path = Path("bound3b.out")
output_results_pluvius: Path = Path("pluvius.out")
infiltration_definitions_unpaved: Path = Path("unpaved.inf")
run_debug_file: Path = Path("sobek_3b.dbg")
unpaved_seepage: Path = Path("unpaved.sep")
unpaved_initial_values_tables: Path = Path("unpaved.tbl")
green_house_general: Path = Path("greenhse.3b")
green_house_roof_storage: Path = Path("greenhse.rf")
pluvius_sewage_entry: Path = Path("runoff.out")
input_variable_gauges_on_edge_nodes: Path = Path("sbk_rtc.his")
input_salt_data: Path = Path("salt.3b")
input_crop_factors_open_water: Path = Path("crop_ow.prn")
restart_file_input: Path = Path("RSRR_IN")
restart_file_output: Path = Path("RSRR_OUT")
binary_file_input: Path = Path("3b_input.bin")
sacramento_input: Path = Path("sacrmnto.3b")
output_flow_rates_edge_nodes: Path = Path("aanvoer.abr")
output_salt_concentration_edge: Path = Path("saltbnd.out")
output_salt_exportation: Path = Path("salt.out")
greenhouse_silo_definitions: Path = Path("greenhse.sil")
open_water_general: Path = Path("openwate.3b")
open_water_seepage_definitions: Path = Path("openwate.sep")
open_water_tables_target_levels: Path = Path("openwate.tbl")
structure_general: Path = Path("struct3b.dat")
structure_definitions: Path = Path("struct3b.def")
controller_definitions: Path = Path("contr3b.def")
structure_tables: Path = Path("struct3b.tbl")
boundary_data: Path = Path("bound3b.3b")
boundary_tables: Path = Path("bound3b.tbl")
sobek_location_rtc: Path = Path("sbk_loc.rtc") # TODO 58.
wwtp_data: Path = Path("wwtp.3b")
wwtp_tables: Path = Path("wwtp.tbl")
industry_general: Path = Path("industry.3b")
verdampings_file: Optional[Path] = Path("default.evp")
unpaved_area_general: Optional[Path] = Path("unpaved.3b")
unpaved_area_storage: Optional[Path] = Path("unpaved.sto")
green_house_area_initialisation: Optional[Path] = Path("kasinit")
green_house_area_usage_data: Optional[Path] = Path("kasgebr")
crop_factors: Optional[Path] = Path("cropfact")
table_bergingscoef: Optional[Path] = Path("bergcoef")
unpaved_alpha_factor_definitions: Optional[Path] = Path("unpaved.alf")
run_log_file: Optional[Path] = Path("sobek_3b.log")
schema_overview: Optional[Path] = Path("3b_gener.out")
output_results_paved_area: Optional[Path] = Path("paved.out")
output_results_unpaved_area: Optional[Path] = Path("unpaved.out")
output_results_green_houses: Optional[Path] = Path("grnhous.out")
output_results_open_water: Optional[Path] = Path("openwate.out")
output_results_structures: Optional[Path] = Path("struct3b.out")
output_results_boundaries: Optional[Path] = Path("bound3b.out")
output_results_pluvius: Optional[Path] = Path("pluvius.out")
infiltration_definitions_unpaved: Optional[Path] = Path("unpaved.inf")
run_debug_file: Optional[Path] = Path("sobek_3b.dbg")
unpaved_seepage: Optional[Path] = Path("unpaved.sep")
unpaved_initial_values_tables: Optional[Path] = Path("unpaved.tbl")
green_house_general: Optional[Path] = Path("greenhse.3b")
green_house_roof_storage: Optional[Path] = Path("greenhse.rf")
pluvius_sewage_entry: Optional[Path] = Path("runoff.out")
input_variable_gauges_on_edge_nodes: Optional[Path] = Path("sbk_rtc.his")
input_salt_data: Optional[Path] = Path("salt.3b")
input_crop_factors_open_water: Optional[Path] = Path("crop_ow.prn")
restart_file_input: Optional[Path] = Path("RSRR_IN")
restart_file_output: Optional[Path] = Path("RSRR_OUT")
binary_file_input: Optional[Path] = Path("3b_input.bin")
sacramento_input: Optional[Path] = Path("sacrmnto.3b")
output_flow_rates_edge_nodes: Optional[Path] = Path("aanvoer.abr")
output_salt_concentration_edge: Optional[Path] = Path("saltbnd.out")
output_salt_exportation: Optional[Path] = Path("salt.out")
greenhouse_silo_definitions: Optional[Path] = Path("greenhse.sil")
open_water_general: Optional[Path] = Path("openwate.3b")
open_water_seepage_definitions: Optional[Path] = Path("openwate.sep")
open_water_tables_target_levels: Optional[Path] = Path("openwate.tbl")
structure_general: Optional[Path] = Path("struct3b.dat")
structure_definitions: Optional[Path] = Path("struct3b.def")
controller_definitions: Optional[Path] = Path("contr3b.def")
structure_tables: Optional[Path] = Path("struct3b.tbl")
boundary_data: Optional[Path] = Path("bound3b.3b")
boundary_tables: Optional[Path] = Path("bound3b.tbl")
sobek_location_rtc: Optional[Path] = Path("sbk_loc.rtc") # TODO 58.
wwtp_data: Optional[Path] = Path("wwtp.3b")
wwtp_tables: Optional[Path] = Path("wwtp.tbl")
industry_general: Optional[Path] = Path("industry.3b")

# Mappix paths should not change and always hold the defined values.
# As such these values have been implemented as Literal values with
Expand Down Expand Up @@ -162,52 +162,52 @@ def mappix_cumulative_balance(self) -> Path:
def mappix_salt_concentrations(self) -> Path:
return Path(self.mappix_salt_concentrations_name)

industry_tables: Path = Path("industry.tbl")
maalstop: Path = Path("rtc_3b.his")
time_series_temperature: Path = Path("default.tmp")
time_series_runoff: Path = Path("rnff.#")
discharges_totals_at_edge_nodes: Path = Path("bndfltot.his")
language_file: Path = Path("sobek_3b.lng")
ow_volume: Path = Path("ow_vol.his")
ow_levels: Path = Path("ow_level.his")
balance_file: Path = Path("3b_bal.out")
his_3B_area_length: Path = Path("3bareas.his")
his_3B_structure_data: Path = Path("3bstrdim.his")
his_rr_runoff: Path = Path("rrrunoff.his")
his_sacramento: Path = Path("sacrmnto.his")
his_rwzi: Path = Path("wwtpdt.his")
his_industry: Path = Path("industdt.his")
ctrl_ini: Path = Path("ctrl.ini")
root_capsim_input_file: Path = Path("root_sim.inp")
unsa_capsim_input_file: Path = Path("unsa_sim.inp")
capsim_message_file: Path = Path("capsim.msg")
capsim_debug_file: Path = Path("capsim.dbg")
restart_1_hour: Path = Path("restart1.out")
restart_12_hours: Path = Path("restart12.out")
rr_ready: Path = Path("RR-ready")
nwrw_areas: Path = Path("NwrwArea.His")
link_flows: Path = Path("3blinks.his")
modflow_rr: Path = Path("modflow_rr.His")
rr_modflow: Path = Path("rr_modflow.His")
rr_wlm_balance: Path = Path("rr_wlmbal.His")
sacramento_ascii_output: Path = Path("sacrmnto.out")
nwrw_input_dwa_table: Path = Path("pluvius.tbl")
rr_balance: Path = Path("rrbalans.his")
green_house_classes: Path = Path("KasKlasData.dat")
green_house_init: Path = Path("KasInitData.dat")
green_house_usage: Path = Path("KasGebrData.dat")
crop_factor: Path = Path("CropData.dat")
crop_ow: Path = Path("CropOWData.dat")
soil_data: Path = Path("SoilData.dat")
dio_config_ini_file: Path = Path("dioconfig.ini")
bui_file_for_continuous_calculation_series: Path = Path("NWRWCONT.#")
nwrw_output: Path = Path("NwrwSys.His")
rr_routing_link_definitions: Path = Path("3b_rout.3b")
cell_input_file: Path = Path("3b_cel.3b")
cell_output_file: Path = Path("3b_cel.his")
rr_simulate_log_file: Path = Path("sobek3b_progress.txt")
rtc_coupling_wq_salt: Path = Path("wqrtc.his")
rr_boundary_conditions_sobek3: Path = Path("BoundaryConditions.bc")
industry_tables: Optional[Path] = Path("industry.tbl")
maalstop: Optional[Path] = Path("rtc_3b.his")
time_series_temperature: Optional[Path] = Path("default.tmp")
time_series_runoff: Optional[Path] = Path("rnff.#")
discharges_totals_at_edge_nodes: Optional[Path] = Path("bndfltot.his")
language_file: Optional[Path] = Path("sobek_3b.lng")
ow_volume: Optional[Path] = Path("ow_vol.his")
ow_levels: Optional[Path] = Path("ow_level.his")
balance_file: Optional[Path] = Path("3b_bal.out")
his_3B_area_length: Optional[Path] = Path("3bareas.his")
his_3B_structure_data: Optional[Path] = Path("3bstrdim.his")
his_rr_runoff: Optional[Path] = Path("rrrunoff.his")
his_sacramento: Optional[Path] = Path("sacrmnto.his")
his_rwzi: Optional[Path] = Path("wwtpdt.his")
his_industry: Optional[Path] = Path("industdt.his")
ctrl_ini: Optional[Path] = Path("ctrl.ini")
root_capsim_input_file: Optional[Path] = Path("root_sim.inp")
unsa_capsim_input_file: Optional[Path] = Path("unsa_sim.inp")
capsim_message_file: Optional[Path] = Path("capsim.msg")
capsim_debug_file: Optional[Path] = Path("capsim.dbg")
restart_1_hour: Optional[Path] = Path("restart1.out")
restart_12_hours: Optional[Path] = Path("restart12.out")
rr_ready: Optional[Path] = Path("RR-ready")
nwrw_areas: Optional[Path] = Path("NwrwArea.His")
link_flows: Optional[Path] = Path("3blinks.his")
modflow_rr: Optional[Path] = Path("modflow_rr.His")
rr_modflow: Optional[Path] = Path("rr_modflow.His")
rr_wlm_balance: Optional[Path] = Path("rr_wlmbal.His")
sacramento_ascii_output: Optional[Path] = Path("sacrmnto.out")
nwrw_input_dwa_table: Optional[Path] = Path("pluvius.tbl")
rr_balance: Optional[Path] = Path("rrbalans.his")
green_house_classes: Optional[Path] = Path("KasKlasData.dat")
green_house_init: Optional[Path] = Path("KasInitData.dat")
green_house_usage: Optional[Path] = Path("KasGebrData.dat")
crop_factor: Optional[Path] = Path("CropData.dat")
crop_ow: Optional[Path] = Path("CropOWData.dat")
soil_data: Optional[Path] = Path("SoilData.dat")
dio_config_ini_file: Optional[Path] = Path("dioconfig.ini")
bui_file_for_continuous_calculation_series: Optional[Path] = Path("NWRWCONT.#")
nwrw_output: Optional[Path] = Path("NwrwSys.His")
rr_routing_link_definitions: Optional[Path] = Path("3b_rout.3b")
cell_input_file: Optional[Path] = Path("3b_cel.3b")
cell_output_file: Optional[Path] = Path("3b_cel.his")
rr_simulate_log_file: Optional[Path] = Path("sobek3b_progress.txt")
rtc_coupling_wq_salt: Optional[Path] = Path("wqrtc.his")
rr_boundary_conditions_sobek3: Optional[Path] = Path("BoundaryConditions.bc")

rr_ascii_restart_openda: Optional[Path] = None
lgsi_cachefile: Optional[Path] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*
*
'delft_3b.ini' * 1. Control file I
'3b_nod.tp' * 2. Knoop data I
'3b_link.tp' * 3. Tak data I
'3B_NOD.TP' * 2. Knoop data I
'3B_LINK.TP' * 3. Tak data I
'3brunoff.tp' * 4. Open water data I
'paved.3b' * 5. Verhard gebied algemeen I
'paved.sto' * 6. Verhard gebied storage I
Expand Down
Empty file.
Empty file.
28 changes: 25 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from hydrolib.core.io.mdu.models import Geometry, Output
from hydrolib.core.utils import get_substring_between, str_is_empty_or_none
from .utils import test_input_dir


class TestSplitString:
Expand All @@ -14,11 +15,32 @@ def test_split_string_strip_whitespace(self):
assert output.statsinterval == [1.0, 5.0]

def test_split_string_strip_semicolon(self):
string_with_multiple_files = "file1 ; file2"
e02 = (
test_input_dir
/ "e02"
)

file1 = (
e02
/ "c11_korte-woerden-1d"
/ "dimr_model"
/ "dflowfm"
/ "structures.ini"
)

file2 = (
e02
/ "f152_1d2d_projectmodels_rhu"
/ "c04_DHydamo-MGB-initialisation"
/ "fm"
/ "structure.ini"
)

string_with_multiple_files = f"{file1} ; {file2}"
output = Geometry(structurefile=string_with_multiple_files)

assert output.structurefile[0].filepath == Path("file1")
assert output.structurefile[1].filepath == Path("file2")
assert output.structurefile[0].filepath == Path(file1)
assert output.structurefile[1].filepath == Path(file2)


class TestStrIsEmptyOrNone:
Expand Down

0 comments on commit ed896f9

Please sign in to comment.