From 27128cbdbac38b2c2c1d40516e6399e042607f5d Mon Sep 17 00:00:00 2001 From: Zain-Mahmoud Date: Fri, 14 Aug 2026 01:14:29 +0300 Subject: [PATCH 1/3] define pipeline and blur/clean functions --- src/terrain_diffusion/pipeline.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/terrain_diffusion/pipeline.py b/src/terrain_diffusion/pipeline.py index b098397..cf40663 100644 --- a/src/terrain_diffusion/pipeline.py +++ b/src/terrain_diffusion/pipeline.py @@ -19,3 +19,38 @@ - It asks Model Inference to run a named model on a patch. - It asks Elevation Encoding to turn the models' base and detail outputs into real elevations. """ +import numpy as np +import itertools + +from terrain_diffusion.inference import load_model +from terrain_diffusion import encoding + +class ModelPipeline: + + def generate(self, patch: np.ndarray) -> np.ndarray: + return self.blur(patch) + + def blur(self, grid: np.ndarry) -> np.ndarray: + ret_grid = np.zeros(grid.shape) + for (i,j) in np.ndindex(grid.shape): + + top = max(0, i-1) + bottom = min(grid.shape[0] - 1, i+1) + left = max(0, j-1) + right = min(grid.shape[1] - 1, j+1) + all_indices = set(itertools.product(range(top, bottom + 1), range(left, right+1))) + valid_indices = [(x,y) for (x,y) in all_indices if (x, y) != (i, j)] + + ret_grid[i][j] = sum(grid[x][y] for (x,y) in valid_indices) / len(valid_indices) + return ret_grid + + + def clean_patch(patch: np.ndarray) -> np.ndarray: + core, decoder = load_model("core"), load_model("decoder") + + core_output = core.predict(patch) + decoder_output = decoder.predict(core_output.latent_map) + + #TODO: update functions and output once elevation encoding is complete + some_output = encoding.some_function(core_output.low_res_grid, decoder_output.full_res_grid) + return some_output \ No newline at end of file From c0ec82c25bcd7c1f0188976030c6e1ec6b7584e6 Mon Sep 17 00:00:00 2001 From: Zain-Mahmoud Date: Fri, 14 Aug 2026 01:14:58 +0300 Subject: [PATCH 2/3] define pipeline tests --- tests/test_pipeline.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/test_pipeline.py diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py new file mode 100644 index 0000000..b101158 --- /dev/null +++ b/tests/test_pipeline.py @@ -0,0 +1,26 @@ +""" +Tests ModelPipeline generation functions +""" + +import numpy as np +import pytest +from terrain_diffusion.pipeline import * +from terrain_diffusion.inference import PATCH_SIZE + +class TestModelPipeline: + @pytest.fixture + def initial_pipeline(self) -> ModelPipeline: + return ModelPipeline() + + @pytest.fixture + def initial_patch(self) -> np.ndarray: + return np.ones(PATCH_SIZE) + + def test_generate_size(self, initial_pipeline, initial_patch): + output = initial_pipeline.generate(initial_patch) + assert output.shape == initial_patch.shape, "input and output sizes do not match" + + def test_generate_deterministic(self, initial_pipeline, initial_patch): + output_1 = initial_pipeline.generate(initial_patch) + output_2 = initial_pipeline.generate(initial_patch) + assert output_1 == output_2, "outputs are not the same" #TODO: implement __eq__ for elevation encoding output or smth \ No newline at end of file From 8640e7675ea01c2e8111c9e00e6404f3ea6f9ace Mon Sep 17 00:00:00 2001 From: Zain-Mahmoud Date: Fri, 14 Aug 2026 01:15:42 +0300 Subject: [PATCH 3/3] rename blur function --- src/terrain_diffusion/pipeline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/terrain_diffusion/pipeline.py b/src/terrain_diffusion/pipeline.py index cf40663..9d8cdf0 100644 --- a/src/terrain_diffusion/pipeline.py +++ b/src/terrain_diffusion/pipeline.py @@ -28,9 +28,9 @@ class ModelPipeline: def generate(self, patch: np.ndarray) -> np.ndarray: - return self.blur(patch) + return self.blur_patch(patch) - def blur(self, grid: np.ndarry) -> np.ndarray: + def blur_patch(self, grid: np.ndarry) -> np.ndarray: ret_grid = np.zeros(grid.shape) for (i,j) in np.ndindex(grid.shape):