Skip to content

Commit

Permalink
Fix remaining stuff, all tests pass, something must be really wrong then
Browse files Browse the repository at this point in the history
  • Loading branch information
margrietpalm committed Mar 28, 2024
1 parent af51ee6 commit a9cdc43
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions threedigrid_builder/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def _make_gridadmin(
progress_callback(0.7, "Constructing 2D computational grid...")
quadtree = QuadTree(
subgrid_meta,
grid_settings.nr_grid_levels,
grid_settings.minimum_cell_size,
grid_settings.kmax,
grid_settings.grid_space,
grid_settings.use_2d_flow,
refinements,
)
Expand Down
10 changes: 5 additions & 5 deletions threedigrid_builder/base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class TablesSettings:
"""Settings necessary for threedi-tables."""

## from GlobalSettings
# TODO: update comments to reflect origins
minimum_table_step_size: float
friction_coefficient: float
# TODO figure out how to fix this
# frict_coef_type: InitializationType
friction_coefficient_type: InitializationType
friction_type: FrictionType = FrictionType.MANNING
interception_global: Optional[float] = None
interception: Optional[float] = None
interception_type: Optional[InitializationType] = None
table_step_size_1d: float = None # actual default is set in __post_init__
maximum_table_step_size: float = None # actual default is set in __post_init__
Expand All @@ -84,8 +84,8 @@ class TablesSettings:
initial_infiltration_rate_type: Optional[InitializationType] = None
infiltration_decay_period: Optional[float] = None
infiltration_decay_period_type: Optional[InitializationType] = None
groundwater_hydro_connectivity: Optional[float] = None
groundwater_hydro_connectivity_type: Optional[InitializationType] = None
groundwater_hydraulic_conductivity: Optional[float] = None
groundwater_hydraulic_conductivity_type: Optional[InitializationType] = None

## from Interflow
interflow_type: InterflowType = InterflowType.NO_INTERLFOW
Expand Down
4 changes: 2 additions & 2 deletions threedigrid_builder/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def from_meta(cls, **kwargs):
# set flags
s = meta.tables_settings # shorthand
meta.has_interception = s.interception_type is not None
meta.has_groundwater_flow = s.groundwater_hydro_connectivity_type is not None
meta.has_groundwater_flow = s.groundwater_hydraulic_conductivity_type is not None
meta.has_simple_infiltration = s.infiltration_rate_type is not None
meta.has_max_infiltration_capacity = (
s.max_infiltration_capacity_type is not None
Expand Down Expand Up @@ -332,7 +332,7 @@ def from_quadtree(cls, quadtree, area_mask, node_id_counter, line_id_counter):
# Some general quadtree grid statistics we need in the .h5 later on.
quadtree_stats = QuadtreeStats(
lgrmin=quadtree.lgrmin,
kmax=quadtree.nr_grid_levels,
kmax=quadtree.kmax,
mmax=quadtree.mmax,
nmax=quadtree.nmax,
dx=quadtree.dx,
Expand Down
2 changes: 1 addition & 1 deletion threedigrid_builder/grid/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_lines(
zoom_category = np.take(objs.zoom_category, segment_idx)
connection_node_start_id = np.take(objs.connection_node_start_id, segment_idx)
connection_node_end_id = np.take(objs.connection_node_end_id, segment_idx)
dist_calc_points = np.take(objs.calculation_point_distance_1d, segment_idx)
dist_calc_points = np.take(objs.dist_calc_points, segment_idx)

# set the right node indices for each segment
first_idx, last_idx = counts_to_ranges(np.bincount(segments.linestring_idx))
Expand Down
24 changes: 13 additions & 11 deletions threedigrid_builder/interface/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def _set_initialization_type(
file_field = f"{global_field}_file"
if not type_field:
type_field = f"{global_field}_type"

# If the ``file_field`` contains a value, the initialization type will be changed to
# the ``default_type``, if supplied.
if dct[file_field]:
Expand All @@ -94,6 +93,7 @@ def _set_initialization_type(
else:
# No file, no global value
dct[type_field] = None
print(f"dct[{type_field}]={dct[type_field]}")


class SQLite:
Expand Down Expand Up @@ -164,6 +164,10 @@ def get_settings(self) -> dict:
vegetation_drag = _object_as_dict(session.query(models.VegetationDrag).one())
else:
vegetation_drag = {}
if model_settings.use_interception:
interception = _object_as_dict(session.query(models.Interception).one())
else:
interception = {}
model_settings = _object_as_dict(model_settings)

# record if there is a DEM file to be expected
Expand All @@ -176,14 +180,13 @@ def get_settings(self) -> dict:
_set_initialization_type(
model_settings, "friction_coefficient", default=AVERAGE if model_settings["friction_averaging"] else NO_AGG
)
# TODO: figure out what to do here; there could be no interception
# _set_initialization_type(
# model_settings,
# "interception_global",
# file_field="interception_file",
# type_field="interception_type",
# default=NO_AGG,
# )
_set_initialization_type(
interception,
"interception",
file_field="interception_file",
type_field="interception_type",
default=NO_AGG,
)
if interflow:
_set_initialization_type(interflow, "porosity", default=NO_AGG)
_set_initialization_type(
Expand All @@ -194,7 +197,6 @@ def get_settings(self) -> dict:
_set_initialization_type(
infiltration, "max_infiltration_volume", default=NO_AGG
)

if groundwater:
# default is what the user supplied (MIN/MAX/AVERAGE)
_set_initialization_type(groundwater, "groundwater_impervious_layer_level")
Expand Down Expand Up @@ -224,7 +226,7 @@ def get_settings(self) -> dict:

grid_settings = GridSettings.from_dict(model_settings)
tables_settings = TablesSettings.from_dict(
{**groundwater, **interflow, **infiltration, **vegetation_drag, **model_settings}
{**groundwater, **interflow, **infiltration, **vegetation_drag, **model_settings, **interception}
)
return {
"epsg_code": model_settings["epsg_code"],
Expand Down
2 changes: 1 addition & 1 deletion threedigrid_builder/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def grid_all():
tables_settings=TablesSettings(
minimum_table_step_size=0.05,
friction_coefficient=0.03,
frict_coef_type=9,
friction_coefficient_type=9,
),
)
quadtree_stats = QuadtreeStats(
Expand Down
12 changes: 6 additions & 6 deletions threedigrid_builder/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_init(tmp_path):
with mock.patch(
"threedigrid_builder.interface.db.ThreediDatabase"
) as db, mock.patch.object(SQLite, "get_version") as get_version:
get_version.return_value = 217
get_version.return_value = 300
sqlite = SQLite(path)

db.assert_called_with(path)
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_init_bad_version(tmp_path):


def test_get_version(db):
assert db.get_version() == 220
assert db.get_version() == 300


def test_get_boundary_conditions_1d(db):
Expand Down Expand Up @@ -251,8 +251,8 @@ def test_get_settings(db):
assert s.minimum_table_step_size == 0.05
assert s.friction_type == 2
assert s.friction_coefficient == 0.03
assert s.frict_coef_type == InitializationType.GLOBAL
assert s.interception_global == 100.0
assert s.friction_coefficient_type == InitializationType.GLOBAL
assert s.interception == 100.0
assert s.interception_type == InitializationType.NO_AGG
assert s.table_step_size_1d == 0.05
assert s.maximum_table_step_size == 5.0
Expand All @@ -269,8 +269,8 @@ def test_get_settings(db):
assert s.initial_infiltration_rate_type == InitializationType.GLOBAL
assert s.infiltration_decay_period == 0.1
assert s.infiltration_decay_period_type == InitializationType.GLOBAL
assert s.groundwater_hydro_connectivity == 1.0
assert s.groundwater_hydro_connectivity_type == InitializationType.GLOBAL
assert s.groundwater_hydraulic_conductivity == 1.0
assert s.groundwater_hydraulic_conductivity_type == InitializationType.GLOBAL

# there are interflow settings, but most are unset
assert s.interflow_type == 0 # means: no interflow
Expand Down
4 changes: 2 additions & 2 deletions threedigrid_builder/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def meta():
tables_settings=TablesSettings(
minimum_table_step_size=0.05,
friction_coefficient=0.03,
frict_coef_type=9,
friction_coefficient_type=9,
),
)

Expand Down Expand Up @@ -92,7 +92,7 @@ def grid1d(meta):
"setting,expected_true",
[
("interception_type", "has_interception"),
("groundwater_hydro_connectivity_type", "has_groundwater_flow"),
("groundwater_hydraulic_conductivity_type", "has_groundwater_flow"),
("infiltration_rate_type", "has_simple_infiltration"),
("groundwater_impervious_layer_level_type", "has_groundwater"),
("interflow_type", "has_interflow"),
Expand Down
6 changes: 3 additions & 3 deletions threedigrid_builder/tests/test_quadtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def quadtree_poly_refinement(subgrid_meta):


def test_quadtree_no_refinement(quadtree_no_refinement):
assert quadtree_no_refinement.nr_grid_levels == 1
assert quadtree_no_refinement.kmax == 1
assert np.size(quadtree_no_refinement.mmax) == 1
assert quadtree_no_refinement.mmax[0] == 3
assert quadtree_no_refinement.nmax[0] == 2
Expand All @@ -107,7 +107,7 @@ def test_quadtree_no_even_pixels(subgrid_meta):


def test_quadtree_line_refinement(quadtree_line_refinement):
assert quadtree_line_refinement.nr_grid_levels == 3
assert quadtree_line_refinement.kmax == 3
assert np.size(quadtree_line_refinement.mmax) == 3
assert quadtree_line_refinement.mmax[2] == 3
assert quadtree_line_refinement.nmax[2] == 2
Expand All @@ -129,7 +129,7 @@ def test_quadtree_line_refinement(quadtree_line_refinement):


def test_quadtree_poly_refinement(quadtree_poly_refinement):
assert quadtree_poly_refinement.nr_grid_levels == 2
assert quadtree_poly_refinement.kmax == 2
assert np.size(quadtree_poly_refinement.mmax) == 2
assert quadtree_poly_refinement.mmax[1] == 3
assert quadtree_poly_refinement.nmax[1] == 2
Expand Down

0 comments on commit a9cdc43

Please sign in to comment.