Skip to content
Merged
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
18 changes: 6 additions & 12 deletions grid_apps-assets/uijson/grid_model_merger.ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"Cell"
],
"dataType": [
"Float",
"Integer"
"Float"
],
"group": "Input A",
"main": true,
Expand Down Expand Up @@ -77,8 +76,7 @@
"Cell"
],
"dataType": [
"Float",
"Integer"
"Float"
],
"group": "Input B",
"main": true,
Expand Down Expand Up @@ -107,8 +105,7 @@
"Cell"
],
"dataType": [
"Float",
"Integer"
"Float"
],
"group": "Input C",
"main": true,
Expand Down Expand Up @@ -137,8 +134,7 @@
"Cell"
],
"dataType": [
"Float",
"Integer"
"Float"
],
"group": "Input D",
"main": true,
Expand Down Expand Up @@ -167,8 +163,7 @@
"Cell"
],
"dataType": [
"Float",
"Integer"
"Float"
],
"group": "Input E",
"main": true,
Expand Down Expand Up @@ -197,8 +192,7 @@
"Cell"
],
"dataType": [
"Float",
"Integer"
"Float"
],
"group": "Input F",
"main": true,
Expand Down
11 changes: 10 additions & 1 deletion grid_apps/grid_model_merger/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,21 @@ def interpolate_models_to_output_grid(self):
)
weights = np.nansum([weights, cell_weights], axis=0)

if not np.any(weights > 0):
logger.warning(
"No valid model values found in any selection. No output model will be created."
)
return

# Normalizes weighted sum
non_zero = weights > 0
out_model[non_zero] /= weights[non_zero]
out_model[~non_zero] = np.nan

if self.params.scaling_type == ScalingTypeEnum.LOG:
if (
self.params.scaling_type == ScalingTypeEnum.LOG
and threshold is not None
):
out_model = inv_symlog(out_model, threshold=threshold)

if np.any(~np.isnan(out_model)):
Expand Down
9 changes: 7 additions & 2 deletions grid_apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,13 @@ def refine_tree_by_mesh(

elif isinstance(mesh, Grid2D):
centers = mesh.centroids
octree_level = np.max(
[0, int(np.min([mesh.u_cell_size, mesh.v_cell_size]) // np.min(tree.h)) - 1]
octree_level = np.maximum(
0,
int(
np.min([mesh.u_cell_size, mesh.v_cell_size])
// np.min(np.hstack(tree.h[:2]))
)
- 1,
)
levels = np.full(mesh.n_cells, tree.max_level - octree_level, dtype=int)

Expand Down
22 changes: 22 additions & 0 deletions tests/run_tests/grid_model_merger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import logging
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -112,6 +113,27 @@ def test_merge_block_model(tmp_path: Path): # pylint: disable=too-many-locals
np.testing.assert_almost_equal(merged_model.values[3406], 2.0, decimal=1)


def test_merge_all_nan(tmp_path: Path, caplog): # pylint: disable=too-many-locals

with Workspace.create(tmp_path / f"{__name__}.geoh5") as ws:
mesh = setup_block_model(ws)
model_a = mesh.add_data({"values": {"values": np.full(mesh.n_cells, np.nan)}})

options = GridModelMergerOptions.build(
{
"geoh5": ws,
"input_a_grid": mesh,
"input_a_model": model_a,
}
)

driver = Driver(options)
with caplog.at_level(logging.WARNING):
driver.run()

assert "No valid model values found" in caplog.text


def test_merge_grid2d_model(tmp_path: Path): # pylint: disable=too-many-locals

with Workspace.create(tmp_path / f"{__name__}.geoh5") as ws:
Expand Down
Loading