From e79fc17f1cf5a53492908fd23a9a775b5cc62580 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 12 Aug 2026 16:52:30 -0400 Subject: [PATCH 01/25] first subticket: defining boundaries --- src/terrain_diffusion/sampler.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index e85f0e5..eec4736 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -10,3 +10,17 @@ - Asks the Model Pipeline to clean patches. - Writes results into the Terrain Store and reads them back. """ + +# What value does the window sampler take from generation orchestration? +# Seed, Region Size, and Region coordinates + +# What does it expect from the model inference? +# It gives a noisy patch to the model and gets a processed full resolution onne back + +# What does the sampler generate? +# The sampler generates noise, overlapping windows over region, processes each one through model pipleine, then stores in terrain cache. Terrain Store makes and and returns heightgrid (2D numpy array). + +# What do we store in the terrain cache? +# It holds weight grids for tiles being generated and finished (Sum grid: running total of value × weight and Weight grid: running total of weight) + + From 5e18683baad2b614370f16270bb68fe6cf28d4cd Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 12 Aug 2026 18:56:28 -0400 Subject: [PATCH 02/25] starting on second subticket --- tests/test_sampler.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/test_sampler.py diff --git a/tests/test_sampler.py b/tests/test_sampler.py new file mode 100644 index 0000000..49f9f13 --- /dev/null +++ b/tests/test_sampler.py @@ -0,0 +1,14 @@ +""" +Testing for window blending sampler. +""" + +# import pytest + +# from terrain_diffusion.sampler import (--, --) + + +# class TestSampler: +# @pytest.fixture + +# def test_name(self): +# assert -- \ No newline at end of file From 3d64f9b5e3d99659059af8a9b912330695ce5c41 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 12 Aug 2026 23:48:37 -0400 Subject: [PATCH 03/25] starting on second subticket --- src/terrain_diffusion/sampler.py | 11 +++++++++++ tests/test_sampler.py | 30 ++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index eec4736..a458702 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -23,4 +23,15 @@ # What do we store in the terrain cache? # It holds weight grids for tiles being generated and finished (Sum grid: running total of value × weight and Weight grid: running total of weight) +import numpy as np +def window_positions(region_height, region_width, window_size, step) -> list[tuple]: + """ Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. + The step is smaller than the window, which is what makes them overlap. + If step does not divide evenly, push last window to row/column pf region_cl/row - window_size, so that no window hangs over the edge.""" + + #rows: + + #columns: + + raise NotImplementedError \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 49f9f13..280d498 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -2,13 +2,31 @@ Testing for window blending sampler. """ -# import pytest +import pytest -# from terrain_diffusion.sampler import (--, --) +from terrain_diffusion.sampler import window_positions -# class TestSampler: -# @pytest.fixture +class TestSampler: + @pytest.fixture -# def test_name(self): -# assert -- \ No newline at end of file + # def ideal_case_test(self): + # "Assert every cell in the region is covered by at least one window" + # assert + + # def edge_test(self): + # "Assert no window exceeds past the region" + # assert + + def one_size_test(self): + "Assert a region exactly one window in size returns one position" + positions = window_positions(4, 4, 4, 3) + assert positions == [(0, 0)] + + def not_even_case(self): + "Assert a region whose size does not divide evenly by the step still covers the far edge" + positions = window_positions(8, 8, 4, 3) + assert positions == [ + (0, 0), (0, 3), (0, 4), + (3, 0), (3, 3), (3, 4), + (4, 0), (4, 3), (4, 4)] \ No newline at end of file From 89ba124ca57a0f1df573c91229d2896551d9b99e Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 12 Aug 2026 23:49:40 -0400 Subject: [PATCH 04/25] working on window_postions function --- src/terrain_diffusion/sampler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index a458702..d0054c0 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -23,7 +23,8 @@ # What do we store in the terrain cache? # It holds weight grids for tiles being generated and finished (Sum grid: running total of value × weight and Weight grid: running total of weight) -import numpy as np + +# import numpy as np def window_positions(region_height, region_width, window_size, step) -> list[tuple]: """ Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. From beb39310de38cac770d547b676a039c99b0dd711 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Mon, 17 Aug 2026 20:17:15 -0400 Subject: [PATCH 05/25] adding to sampler.py --- src/terrain_diffusion/sampler.py | 44 +++++++++++++++++++++++++++----- tests/test_sampler.py | 39 ++++++++++++++++++---------- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index d0054c0..f75bc6b 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -15,7 +15,7 @@ # Seed, Region Size, and Region coordinates # What does it expect from the model inference? -# It gives a noisy patch to the model and gets a processed full resolution onne back +# It gives a noisy patch to the model and gets a processed full resolution one back # What does the sampler generate? # The sampler generates noise, overlapping windows over region, processes each one through model pipleine, then stores in terrain cache. Terrain Store makes and and returns heightgrid (2D numpy array). @@ -26,13 +26,45 @@ # import numpy as np -def window_positions(region_height, region_width, window_size, step) -> list[tuple]: +def window_positions(region_height: int, region_width: int, window_size: int, step: int) -> list[tuple[int, int]]: """ Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. The step is smaller than the window, which is what makes them overlap. - If step does not divide evenly, push last window to row/column pf region_cl/row - window_size, so that no window hangs over the edge.""" + If step does not divide evenly (extends), push last window to row/column of region_cl/row - window_size, so that no window hangs over the edge.""" - #rows: + # Find row positions + row_positions = [] + row = 0 - #columns: + while row + window_size <= region_height: + row_positions.append(row) - raise NotImplementedError \ No newline at end of file + if row + step + window_size > region_height: + final = region_height - window_size + if row_positions[-1] != final: + row_positions.append(final) + break + + row += step + + # Find column positions + column_positions = [] + column = 0 + + while column + window_size <= region_width: + column_positions.append(column) + + if column + step + window_size > region_width: + final = region_width - window_size + if column_positions[-1] != final: + column_positions.append(final) + break + + column += step + + # Combine every row position with every column position + positions = [] + for row in row_positions: + for column in column_positions: + positions.append((row, column)) + + return positions \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 280d498..37c4b23 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -3,27 +3,40 @@ """ import pytest - from terrain_diffusion.sampler import window_positions class TestSampler: @pytest.fixture - # def ideal_case_test(self): - # "Assert every cell in the region is covered by at least one window" - # assert - - # def edge_test(self): - # "Assert no window exceeds past the region" - # assert - - def one_size_test(self): + def test_all_covered(self): + "Assert every cell in the region is covered by at least one window" + height = 4 + width = 4 + window = 2 + step = 1 + positions = window_positions(height, width, window, step) + assert all(any(window_r <= row < window_r + window + and window_c <= column < window_c + window + for window_r, window_c in positions) + for row in range(height) for column in range(width)) + + def test_exceed_region(self): + "Assert no window exceeds past the region" + height = 4 + width = 4 + size = 2 + step = 1 + positions = window_positions(height, width, size, step) + assert all(x[0] + size <= height and x[1] + size <= width for x in positions) + + def test_one_window(self): "Assert a region exactly one window in size returns one position" - positions = window_positions(4, 4, 4, 3) - assert positions == [(0, 0)] + WindowRegionSize = 4 + positions = window_positions(WindowRegionSize, WindowRegionSize, WindowRegionSize, WindowRegionSize) + assert len(positions) == 1 - def not_even_case(self): + def test_not_dividing(self): "Assert a region whose size does not divide evenly by the step still covers the far edge" positions = window_positions(8, 8, 4, 3) assert positions == [ From fb3d75709cafe9b2cb372e2af94111ae05e6b976 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Tue, 18 Aug 2026 01:10:31 -0400 Subject: [PATCH 06/25] fixed problem in test_sampler --- tests/test_sampler.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 37c4b23..cd1538a 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -2,12 +2,10 @@ Testing for window blending sampler. """ -import pytest from terrain_diffusion.sampler import window_positions class TestSampler: - @pytest.fixture def test_all_covered(self): "Assert every cell in the region is covered by at least one window" @@ -16,10 +14,9 @@ def test_all_covered(self): window = 2 step = 1 positions = window_positions(height, width, window, step) - assert all(any(window_r <= row < window_r + window - and window_c <= column < window_c + window - for window_r, window_c in positions) - for row in range(height) for column in range(width)) + assert all(any(window_r <= row < window_r + window and window_c <= column < window_c + window + for window_r, window_c in positions) + for row in range(height) for column in range(width)) def test_exceed_region(self): "Assert no window exceeds past the region" From cb3be372acb06fbf94d21cf9e86911cd3e394298 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Tue, 18 Aug 2026 19:09:49 -0400 Subject: [PATCH 07/25] adding to #33 --- src/terrain_diffusion/sampler.py | 11 +++++++++-- tests/test_sampler.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index f75bc6b..facd98d 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -24,7 +24,7 @@ # It holds weight grids for tiles being generated and finished (Sum grid: running total of value × weight and Weight grid: running total of weight) -# import numpy as np +import numpy as np def window_positions(region_height: int, region_width: int, window_size: int, step: int) -> list[tuple[int, int]]: """ Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. @@ -67,4 +67,11 @@ def window_positions(region_height: int, region_width: int, window_size: int, st for column in column_positions: positions.append((row, column)) - return positions \ No newline at end of file + return positions + + +def weight_grid(height: int, width: int) -> np.ndarray: + """Create a function that returns a grid of weights the size of a patch, since the weights get applied to what is written into the store. + Weights should be largest in the middle and get smaller toward the edges. Every weight must be greater than zero. + A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. + The same grid is used for every window so it only needs to be worked out once.""" \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index cd1538a..80a2aee 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -2,10 +2,11 @@ Testing for window blending sampler. """ -from terrain_diffusion.sampler import window_positions +from terrain_diffusion.sampler import window_positions, weight_grid +import numpy as np -class TestSampler: +class TestWindowPositions: def test_all_covered(self): "Assert every cell in the region is covered by at least one window" @@ -39,4 +40,27 @@ def test_not_dividing(self): assert positions == [ (0, 0), (0, 3), (0, 4), (3, 0), (3, 3), (3, 4), - (4, 0), (4, 3), (4, 4)] \ No newline at end of file + (4, 0), (4, 3), (4, 4)] + + + +class TestWeights: + + def test_grid_equal_patch(self): + "Assert the grid is the size of a patch" + weights = weight_grid(5, 5) + assert weights.shape == (5, 7) + + def test_palidrome(self): + "Assert it reads the same forwards and backwards in both directions" + weights = weight_grid(5, 5) + assert np.array_equal(weights, weights[::-1]) + + def test_large_middle(self): + "Assert the largest value is in the middle" + + def test_edges_smaller(self): + "Assert values at the edges are smaller than values in the middle" + + def test_greater_zero(self): + "Assert every value is greater than zero" \ No newline at end of file From 10897e99d9dadf8978d1d8d7c73c45a78d86c167 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Tue, 18 Aug 2026 21:12:04 -0400 Subject: [PATCH 08/25] adding to tests/sampler --- src/terrain_diffusion/sampler.py | 4 +++- tests/test_sampler.py | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index facd98d..7e16ac7 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -74,4 +74,6 @@ def weight_grid(height: int, width: int) -> np.ndarray: """Create a function that returns a grid of weights the size of a patch, since the weights get applied to what is written into the store. Weights should be largest in the middle and get smaller toward the edges. Every weight must be greater than zero. A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. - The same grid is used for every window so it only needs to be worked out once.""" \ No newline at end of file + The same grid is used for every window so it only needs to be worked out once.""" + + #numpy array: [[row 1 contents], [row 2 contents]] \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 80a2aee..653ad0a 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -48,16 +48,30 @@ class TestWeights: def test_grid_equal_patch(self): "Assert the grid is the size of a patch" - weights = weight_grid(5, 5) - assert weights.shape == (5, 7) + height = 10 + width = 20 + weights = weight_grid(height, width) + assert weights.shape == (height, width) def test_palidrome(self): "Assert it reads the same forwards and backwards in both directions" - weights = weight_grid(5, 5) + height = 10 + width = 20 + weights = weight_grid(height, width) assert np.array_equal(weights, weights[::-1]) + # assert vertically def test_large_middle(self): "Assert the largest value is in the middle" + height = 10 + width = 20 + weights = weight_grid(height, width) + + # middle + center_row = height // 2 + center_column = width // 2 + + assert weights[center_row, center_column] == weights.max() def test_edges_smaller(self): "Assert values at the edges are smaller than values in the middle" From 7dba7ee114307d74a9020e3bef19098be9b46f13 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Tue, 18 Aug 2026 22:55:26 -0400 Subject: [PATCH 09/25] finished test class for #33 --- src/terrain_diffusion/sampler.py | 3 ++- tests/test_sampler.py | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 7e16ac7..52ab619 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -76,4 +76,5 @@ def weight_grid(height: int, width: int) -> np.ndarray: A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. The same grid is used for every window so it only needs to be worked out once.""" - #numpy array: [[row 1 contents], [row 2 contents]] \ No newline at end of file + #numpy array: [[row 1 contents], [row 2 contents]] + # indexing in 2D Array: array[row, column] \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 653ad0a..0be97dd 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -58,13 +58,13 @@ def test_palidrome(self): height = 10 width = 20 weights = weight_grid(height, width) - assert np.array_equal(weights, weights[::-1]) - # assert vertically + assert np.array_equal(weights, weights[::-1, :]) #vertical + assert np.array_equal(weights, weights[:, ::-1]) #horizontal def test_large_middle(self): "Assert the largest value is in the middle" - height = 10 - width = 20 + height = 11 + width = 21 weights = weight_grid(height, width) # middle @@ -75,6 +75,24 @@ def test_large_middle(self): def test_edges_smaller(self): "Assert values at the edges are smaller than values in the middle" + height = 11 + width = 21 + weights = weight_grid(height, width) + + # middle + center_row = height // 2 + center_column = width // 2 + middle_val = weights[center_row, center_column] + + # R/L edges + assert all(weights[x,0] < middle_val for x in range(height)) + assert all(weights[x,width-1] < middle_val for x in range(height)) + + # T/B edges + assert all(weights[0, y] < middle_val for y in range(width)) + assert all(weights[height - 1, y] < middle_val for y in range(width)) def test_greater_zero(self): - "Assert every value is greater than zero" \ No newline at end of file + "Assert every value is greater than zero" + weights = weight_grid(10, 20) + assert np.all(weights > 0) \ No newline at end of file From fc3fe36cf2263a6b83678ac3a1357ddb9eef4db8 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Tue, 18 Aug 2026 23:44:49 -0400 Subject: [PATCH 10/25] minor fix --- src/terrain_diffusion/sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 52ab619..4fb5c15 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -76,5 +76,5 @@ def weight_grid(height: int, width: int) -> np.ndarray: A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. The same grid is used for every window so it only needs to be worked out once.""" - #numpy array: [[row 1 contents], [row 2 contents]] + # numpy array: [[row 1 contents], [row 2 contents]] # indexing in 2D Array: array[row, column] \ No newline at end of file From 403610644257fb671d25a429efe2cc0cc01fda4b Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 09:57:48 -0400 Subject: [PATCH 11/25] completed #33 --- src/terrain_diffusion/sampler.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 4fb5c15..bb5c37e 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -70,11 +70,35 @@ def window_positions(region_height: int, region_width: int, window_size: int, st return positions + def weight_grid(height: int, width: int) -> np.ndarray: """Create a function that returns a grid of weights the size of a patch, since the weights get applied to what is written into the store. Weights should be largest in the middle and get smaller toward the edges. Every weight must be greater than zero. A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. The same grid is used for every window so it only needs to be worked out once.""" + #NOTES: + # Distance-Based Weighting For Vignettes or Radial Masks - linear distance decay function: each (row, column) = 1 - distance to center/maximum patch radius # numpy array: [[row 1 contents], [row 2 contents]] - # indexing in 2D Array: array[row, column] \ No newline at end of file + # indexing in 2D Array: array[row, column] + + # create 1D arrays + rows = np.arange(height) + columns = np.arange(width) + + # find center + center_row = (height - 1) / 2 # -1 because we start from 0 + center_column = (width - 1) / 2 + + # distance from center + row_distance = np.abs(rows - center_row) + column_distance = np.abs(columns - center_column) + + # weight: apply formula. multiplied 0.9 so values stay above 0 + row_weight = 1 - 0.9 * row_distance / (height / 2) + column_weight = 1 - 0.9 * column_distance / (width / 2) + + # combine + weights = np.outer(row_weight, column_weight) + + return weights \ No newline at end of file From afb2ea19ebca3b57bd2e8ce07afb7ecdeac20efc Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 10:08:30 -0400 Subject: [PATCH 12/25] starting #34 --- src/terrain_diffusion/sampler.py | 6 +++++- tests/test_sampler.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index bb5c37e..6452332 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -101,4 +101,8 @@ def weight_grid(height: int, width: int) -> np.ndarray: # combine weights = np.outer(row_weight, column_weight) - return weights \ No newline at end of file + return weights + + +def starting_noise(seed: int, height: int, width: int) -> np.ndarray: + "Takes a seed and a canvas size and returns a grid of random numbers that size" \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 0be97dd..38e9d4c 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -95,4 +95,19 @@ def test_edges_smaller(self): def test_greater_zero(self): "Assert every value is greater than zero" weights = weight_grid(10, 20) - assert np.all(weights > 0) \ No newline at end of file + assert np.all(weights > 0) + + + +class TestSeed: + + def test_same_seed(self): + """Assert the same seed twice gives identical grids.""" + + + def test_diff_seed(self): + """Assert two different seeds give different grids.""" + + + def test_right_size(self): + """Assert the grid is the size asked for""" \ No newline at end of file From c8765cbed12c41a41b40c22f80291dddd2917889 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 11:00:46 -0400 Subject: [PATCH 13/25] finished tests for #34 --- tests/test_sampler.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 38e9d4c..671e7a2 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -2,7 +2,7 @@ Testing for window blending sampler. """ -from terrain_diffusion.sampler import window_positions, weight_grid +from terrain_diffusion.sampler import window_positions, weight_grid, starting_noise import numpy as np @@ -103,11 +103,28 @@ class TestSeed: def test_same_seed(self): """Assert the same seed twice gives identical grids.""" - + seed = 123 + height = 10 + width = 20 + noise1 = starting_noise(seed, height, width) + noise2 = starting_noise(seed, height, width) + assert np.array_equal(noise1, noise2) def test_diff_seed(self): """Assert two different seeds give different grids.""" + seed1 = 123 + seed2 = 456 + height = 10 + width = 20 + noise1 = starting_noise(seed1, height, width) + noise2 = starting_noise(seed2, height, width) + assert not np.array_equal(noise1, noise2) def test_right_size(self): - """Assert the grid is the size asked for""" \ No newline at end of file + """Assert the grid is the size asked for""" + seed = 123 + height = 10 + width = 20 + noise = starting_noise(seed, height, width) + assert noise.shape == (height, width) \ No newline at end of file From 94f3a6f4ccf8403effb73a2d4cbde177d5832b95 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 11:01:32 -0400 Subject: [PATCH 14/25] finished #34 --- src/terrain_diffusion/sampler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 6452332..20074bc 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -105,4 +105,6 @@ def weight_grid(height: int, width: int) -> np.ndarray: def starting_noise(seed: int, height: int, width: int) -> np.ndarray: - "Takes a seed and a canvas size and returns a grid of random numbers that size" \ No newline at end of file + "Takes a seed and a canvas size and returns a grid of random numbers that size" + generator = np.random.default_rng(seed) + return generator.random((height, width)) \ No newline at end of file From 347bbae61b1c812a58cf051b6ff36e3ff8377682 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 18:59:12 -0400 Subject: [PATCH 15/25] setting up for #35 --- src/terrain_diffusion/sampler.py | 12 +++++++++++- tests/test_sampler.py | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 20074bc..6553463 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -104,7 +104,17 @@ def weight_grid(height: int, width: int) -> np.ndarray: return weights + def starting_noise(seed: int, height: int, width: int) -> np.ndarray: "Takes a seed and a canvas size and returns a grid of random numbers that size" generator = np.random.default_rng(seed) - return generator.random((height, width)) \ No newline at end of file + return generator.random((height, width)) + + + +def produce_region(seed: int, height: int, width: int, window_size: int, step: int, pipeline, store) -> np.ndarray: + """Make noise canvas of given dimensions. or each window position, cut the window out of the noise canvas, hand it to pipeline (#23). + Store the processed output from pipeline and weights in Terrain Store, read the finished height grid from store and return it. + """ + + \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 671e7a2..2a1379d 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -127,4 +127,19 @@ def test_right_size(self): height = 10 width = 20 noise = starting_noise(seed, height, width) - assert noise.shape == (height, width) \ No newline at end of file + assert noise.shape == (height, width) + + +class TestRegionProduction: + def test_all_fives(self): + """Assert the finished grid is all fives everywhere, including the overlaps and the corners. + If the overlaps read higher then the weights are not being divided out""" + + def test_full_size(self): + """Assert the finished grid is the region's full resolution size""" + + def test_once_per_windo(self): + """Assert the fake pipeline was called once per window position and no more""" + + def test_same_seed_grid(self): + """Assert the same seed and region run twice give identical grids""" \ No newline at end of file From 6d8af62e27c47cb7b7685dba855c78ef0f9d2583 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 19:58:46 -0400 Subject: [PATCH 16/25] layout structure for produce_region --- src/terrain_diffusion/sampler.py | 22 +++++++++++++++++++--- tests/test_sampler.py | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 6553463..d6b6c6a 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -113,8 +113,24 @@ def starting_noise(seed: int, height: int, width: int) -> np.ndarray: def produce_region(seed: int, height: int, width: int, window_size: int, step: int, pipeline, store) -> np.ndarray: - """Make noise canvas of given dimensions. or each window position, cut the window out of the noise canvas, hand it to pipeline (#23). - Store the processed output from pipeline and weights in Terrain Store, read the finished height grid from store and return it. + """Make noise canvas of given dimensions. Make noise and weight grid. + For each window position, cut the window out of the noise canvas, hand it to pipeline (#23), store the processed output from pipeline and weights in Terrain Store. + Read the finished height grid from store and return it. """ - \ No newline at end of file + noise = starting_noise(seed, height, width) + + positions = window_positions(height, width, window_size, step) + weights = weight_grid(window_size, window_size) #weight grid made on window_size + + for row, column in positions: + window = noise[ + row:row + window_size, + column:column + window_size + ] + + processed_patch = pipeline(window) #based on unmerged commit i believe this will be pipeline.generate(window) + + store.add(processed_patch, row, column, weights) + + return store.finish() \ No newline at end of file diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 2a1379d..7373331 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -138,7 +138,7 @@ def test_all_fives(self): def test_full_size(self): """Assert the finished grid is the region's full resolution size""" - def test_once_per_windo(self): + def test_once_per_window(self): """Assert the fake pipeline was called once per window position and no more""" def test_same_seed_grid(self): From fac8f56db0c393b92186c029136478299d5da7b6 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Wed, 19 Aug 2026 21:24:33 -0400 Subject: [PATCH 17/25] done produce_region, working on tests --- src/terrain_diffusion/sampler.py | 5 ++--- tests/test_sampler.py | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index d6b6c6a..8fa16b9 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -114,9 +114,8 @@ def starting_noise(seed: int, height: int, width: int) -> np.ndarray: def produce_region(seed: int, height: int, width: int, window_size: int, step: int, pipeline, store) -> np.ndarray: """Make noise canvas of given dimensions. Make noise and weight grid. - For each window position, cut the window out of the noise canvas, hand it to pipeline (#23), store the processed output from pipeline and weights in Terrain Store. - Read the finished height grid from store and return it. - """ + For each window position, cut the window out of the noise canvas, send it to pipeline (#23), add the processed output and its weight to Terrain Store (at that position). + Read the finished height grid from store and return it. """ noise = starting_noise(seed, height, width) diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 7373331..62efeb6 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -131,6 +131,7 @@ def test_right_size(self): class TestRegionProduction: + def test_all_fives(self): """Assert the finished grid is all fives everywhere, including the overlaps and the corners. If the overlaps read higher then the weights are not being divided out""" From 5f739e2077cb4c3d52cc6eaa8646623a8c4effc2 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Fri, 21 Aug 2026 17:52:43 -0400 Subject: [PATCH 18/25] working on fakestore --- tests/test_sampler.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 62efeb6..6e01b6e 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -2,8 +2,9 @@ Testing for window blending sampler. """ -from terrain_diffusion.sampler import window_positions, weight_grid, starting_noise +from terrain_diffusion.sampler import window_positions, weight_grid, starting_noise, produce_region import numpy as np +import pytest class TestWindowPositions: @@ -130,12 +131,43 @@ def test_right_size(self): assert noise.shape == (height, width) +class FakePipeline: + def __init__(self): + """For test_once_per_window""" + self.call_count = 0 + + def generate(self, patch): + """Igrones input and returns a patch of all fives.""" + self.call_count += 1 + return np.full(patch.shape, 5) + + +class FakeStore(): + + + class TestRegionProduction: - def test_all_fives(self): + @pytest.fixture + def pipeline(self): + return FakePipeline() + + def test_all_fives(self, pipeline): """Assert the finished grid is all fives everywhere, including the overlaps and the corners. If the overlaps read higher then the weights are not being divided out""" + seed = 123 + height = 8 + width = 8 + window_size = 4 + step = 3 + + store = FakeStore(height, width) + + result = produce_region(seed, height, width, window_size, step, pipeline, store) + + assert np.all(result == 5) + def test_full_size(self): """Assert the finished grid is the region's full resolution size""" From 13a135e597b0f5e5be4896b2acb472e05cb9cf60 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Fri, 21 Aug 2026 18:52:25 -0400 Subject: [PATCH 19/25] finished subissue 35 --- src/terrain_diffusion/sampler.py | 2 +- tests/test_sampler.py | 73 ++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 8fa16b9..5a64df5 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -128,7 +128,7 @@ def produce_region(seed: int, height: int, width: int, window_size: int, step: i column:column + window_size ] - processed_patch = pipeline(window) #based on unmerged commit i believe this will be pipeline.generate(window) + processed_patch = pipeline.generate(window) #based on unmerged commit i believe this will be pipeline.generate(window) store.add(processed_patch, row, column, weights) diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 6e01b6e..c588434 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -142,10 +142,27 @@ def generate(self, patch): return np.full(patch.shape, 5) -class FakeStore(): - - +class FakeStore: + #used ai help for this because store is not part of my ticket + def __init__(self, height, width): + self.sum_grid = np.zeros((height, width)) + self.weight_grid = np.zeros((height, width)) + + def add(self, patch, row, column, weights): + self.sum_grid[ + row:row + patch.shape[0], + column:column + patch.shape[1] + ] += patch * weights + + self.weight_grid[ + row:row + patch.shape[0], + column:column + patch.shape[1] + ] += weights + + def finish(self): + return self.sum_grid / self.weight_grid + class TestRegionProduction: @pytest.fixture @@ -163,16 +180,56 @@ def test_all_fives(self, pipeline): step = 3 store = FakeStore(height, width) - result = produce_region(seed, height, width, window_size, step, pipeline, store) + assert np.allclose(result, 5) #All close because was getting float error as some are 4.9999 due to the store - assert np.all(result == 5) - def test_full_size(self): + def test_full_size(self, pipeline): """Assert the finished grid is the region's full resolution size""" - def test_once_per_window(self): + seed = 123 + height = 8 + width = 8 + window_size = 4 + step = 3 + + store = FakeStore(height, width) + result = produce_region(seed, height, width, window_size, step, pipeline, store) + assert result.shape == (height, width) + + + def test_once_per_window(self, pipeline): """Assert the fake pipeline was called once per window position and no more""" + + seed = 123 + height = 8 + width = 8 + window_size = 4 + step = 3 + + positions = window_positions(height, width, window_size, step) + + store = FakeStore(height, width) + produce_region(seed, height, width, window_size, step, pipeline, store) + + assert pipeline.call_count == len(positions) + def test_same_seed_grid(self): - """Assert the same seed and region run twice give identical grids""" \ No newline at end of file + """Assert the same seed and region run twice give identical grids""" + height = 8 + width = 8 + window_size = 4 + step = 3 + + store1 = FakeStore(height, width) + store2 = FakeStore(height, width) + + #because using same pipeline might affect results? + pipeline1 = FakePipeline() + pipeline2 = FakePipeline() + + result1 = produce_region(123, height, width, window_size, step, pipeline1, store1) + result2 = produce_region(123, height, width, window_size, step, pipeline2, store2) + + assert np.array_equal(result1, result2) \ No newline at end of file From e6641ccd04c27c341c69b0617bbca4f5aa5890d3 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Fri, 21 Aug 2026 19:11:49 -0400 Subject: [PATCH 20/25] fixing script quality check errors --- src/terrain_diffusion/sampler.py | 52 +++++++++++------------ tests/test_sampler.py | 73 +++++++++++++++----------------- 2 files changed, 59 insertions(+), 66 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 5a64df5..9aedd2c 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -11,23 +11,25 @@ - Writes results into the Terrain Store and reads them back. """ -# What value does the window sampler take from generation orchestration? +# What value does the window sampler take from generation orchestration? # Seed, Region Size, and Region coordinates -# What does it expect from the model inference? +# What does it expect from the model inference? # It gives a noisy patch to the model and gets a processed full resolution one back -# What does the sampler generate? +# What does the sampler generate? # The sampler generates noise, overlapping windows over region, processes each one through model pipleine, then stores in terrain cache. Terrain Store makes and and returns heightgrid (2D numpy array). -# What do we store in the terrain cache? +# What do we store in the terrain cache? # It holds weight grids for tiles being generated and finished (Sum grid: running total of value × weight and Weight grid: running total of weight) - import numpy as np -def window_positions(region_height: int, region_width: int, window_size: int, step: int) -> list[tuple[int, int]]: - """ Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. + +def window_positions( + region_height: int, region_width: int, window_size: int, step: int +) -> list[tuple[int, int]]: + """Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. The step is smaller than the window, which is what makes them overlap. If step does not divide evenly (extends), push last window to row/column of region_cl/row - window_size, so that no window hangs over the edge.""" @@ -70,15 +72,14 @@ def window_positions(region_height: int, region_width: int, window_size: int, st return positions - def weight_grid(height: int, width: int) -> np.ndarray: """Create a function that returns a grid of weights the size of a patch, since the weights get applied to what is written into the store. - Weights should be largest in the middle and get smaller toward the edges. Every weight must be greater than zero. + Weights should be largest in the middle and get smaller toward the edges. Every weight must be greater than zero. A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. The same grid is used for every window so it only needs to be worked out once.""" - #NOTES: - # Distance-Based Weighting For Vignettes or Radial Masks - linear distance decay function: each (row, column) = 1 - distance to center/maximum patch radius + # NOTES: + # Distance-Based Weighting For Vignettes or Radial Masks - linear distance decay function: each (row, column) = 1 - distance to center/maximum patch radius # numpy array: [[row 1 contents], [row 2 contents]] # indexing in 2D Array: array[row, column] @@ -86,8 +87,8 @@ def weight_grid(height: int, width: int) -> np.ndarray: rows = np.arange(height) columns = np.arange(width) - # find center - center_row = (height - 1) / 2 # -1 because we start from 0 + # find center (-1 because we start from 0) + center_row = (height - 1) / 2 center_column = (width - 1) / 2 # distance from center @@ -98,38 +99,37 @@ def weight_grid(height: int, width: int) -> np.ndarray: row_weight = 1 - 0.9 * row_distance / (height / 2) column_weight = 1 - 0.9 * column_distance / (width / 2) - # combine + # combine weights = np.outer(row_weight, column_weight) return weights - def starting_noise(seed: int, height: int, width: int) -> np.ndarray: "Takes a seed and a canvas size and returns a grid of random numbers that size" generator = np.random.default_rng(seed) return generator.random((height, width)) - -def produce_region(seed: int, height: int, width: int, window_size: int, step: int, pipeline, store) -> np.ndarray: - """Make noise canvas of given dimensions. Make noise and weight grid. +def produce_region( + seed: int, height: int, width: int, window_size: int, step: int, pipeline, store +) -> np.ndarray: + """Make noise canvas of given dimensions. Make noise and weight grid. For each window position, cut the window out of the noise canvas, send it to pipeline (#23), add the processed output and its weight to Terrain Store (at that position). - Read the finished height grid from store and return it. """ + Read the finished height grid from store and return it.""" noise = starting_noise(seed, height, width) positions = window_positions(height, width, window_size, step) - weights = weight_grid(window_size, window_size) #weight grid made on window_size + weights = weight_grid(window_size, window_size) # weight grid made on window_size for row, column in positions: - window = noise[ - row:row + window_size, - column:column + window_size - ] + window = noise[row : row + window_size, column : column + window_size] - processed_patch = pipeline.generate(window) #based on unmerged commit i believe this will be pipeline.generate(window) + processed_patch = pipeline.generate( + window + ) # based on unmerged commit i believe this will be pipeline.generate(window) store.add(processed_patch, row, column, weights) - return store.finish() \ No newline at end of file + return store.finish() diff --git a/tests/test_sampler.py b/tests/test_sampler.py index c588434..31ba33f 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -1,14 +1,14 @@ """ -Testing for window blending sampler. +Testing for window blending sampler. """ -from terrain_diffusion.sampler import window_positions, weight_grid, starting_noise, produce_region import numpy as np import pytest +from terrain_diffusion.sampler import produce_region, starting_noise, weight_grid, window_positions -class TestWindowPositions: +class TestWindowPositions: def test_all_covered(self): "Assert every cell in the region is covered by at least one window" height = 4 @@ -16,9 +16,14 @@ def test_all_covered(self): window = 2 step = 1 positions = window_positions(height, width, window, step) - assert all(any(window_r <= row < window_r + window and window_c <= column < window_c + window - for window_r, window_c in positions) - for row in range(height) for column in range(width)) + assert all( + any( + window_r <= row < window_r + window and window_c <= column < window_c + window + for window_r, window_c in positions + ) + for row in range(height) + for column in range(width) + ) def test_exceed_region(self): "Assert no window exceeds past the region" @@ -32,21 +37,18 @@ def test_exceed_region(self): def test_one_window(self): "Assert a region exactly one window in size returns one position" WindowRegionSize = 4 - positions = window_positions(WindowRegionSize, WindowRegionSize, WindowRegionSize, WindowRegionSize) + positions = window_positions( + WindowRegionSize, WindowRegionSize, WindowRegionSize, WindowRegionSize + ) assert len(positions) == 1 def test_not_dividing(self): "Assert a region whose size does not divide evenly by the step still covers the far edge" positions = window_positions(8, 8, 4, 3) - assert positions == [ - (0, 0), (0, 3), (0, 4), - (3, 0), (3, 3), (3, 4), - (4, 0), (4, 3), (4, 4)] - + assert positions == [(0, 0), (0, 3), (0, 4), (3, 0), (3, 3), (3, 4), (4, 0), (4, 3), (4, 4)] class TestWeights: - def test_grid_equal_patch(self): "Assert the grid is the size of a patch" height = 10 @@ -59,8 +61,8 @@ def test_palidrome(self): height = 10 width = 20 weights = weight_grid(height, width) - assert np.array_equal(weights, weights[::-1, :]) #vertical - assert np.array_equal(weights, weights[:, ::-1]) #horizontal + assert np.array_equal(weights, weights[::-1, :]) # vertical + assert np.array_equal(weights, weights[:, ::-1]) # horizontal def test_large_middle(self): "Assert the largest value is in the middle" @@ -86,8 +88,8 @@ def test_edges_smaller(self): middle_val = weights[center_row, center_column] # R/L edges - assert all(weights[x,0] < middle_val for x in range(height)) - assert all(weights[x,width-1] < middle_val for x in range(height)) + assert all(weights[x, 0] < middle_val for x in range(height)) + assert all(weights[x, width - 1] < middle_val for x in range(height)) # T/B edges assert all(weights[0, y] < middle_val for y in range(width)) @@ -97,11 +99,9 @@ def test_greater_zero(self): "Assert every value is greater than zero" weights = weight_grid(10, 20) assert np.all(weights > 0) - class TestSeed: - def test_same_seed(self): """Assert the same seed twice gives identical grids.""" seed = 123 @@ -110,7 +110,7 @@ def test_same_seed(self): noise1 = starting_noise(seed, height, width) noise2 = starting_noise(seed, height, width) assert np.array_equal(noise1, noise2) - + def test_diff_seed(self): """Assert two different seeds give different grids.""" seed1 = 123 @@ -121,7 +121,6 @@ def test_diff_seed(self): noise2 = starting_noise(seed2, height, width) assert not np.array_equal(noise1, noise2) - def test_right_size(self): """Assert the grid is the size asked for""" seed = 123 @@ -143,34 +142,29 @@ def generate(self, patch): class FakeStore: - #used ai help for this because store is not part of my ticket + # used ai help for this because store is not part of my ticket def __init__(self, height, width): self.sum_grid = np.zeros((height, width)) self.weight_grid = np.zeros((height, width)) def add(self, patch, row, column, weights): - self.sum_grid[ - row:row + patch.shape[0], - column:column + patch.shape[1] - ] += patch * weights + self.sum_grid[row : row + patch.shape[0], column : column + patch.shape[1]] += ( + patch * weights + ) - self.weight_grid[ - row:row + patch.shape[0], - column:column + patch.shape[1] - ] += weights + self.weight_grid[row : row + patch.shape[0], column : column + patch.shape[1]] += weights def finish(self): return self.sum_grid / self.weight_grid - -class TestRegionProduction: +class TestRegionProduction: @pytest.fixture def pipeline(self): return FakePipeline() def test_all_fives(self, pipeline): - """Assert the finished grid is all fives everywhere, including the overlaps and the corners. + """Assert the finished grid is all fives everywhere, including the overlaps and the corners. If the overlaps read higher then the weights are not being divided out""" seed = 123 @@ -181,8 +175,9 @@ def test_all_fives(self, pipeline): store = FakeStore(height, width) result = produce_region(seed, height, width, window_size, step, pipeline, store) - assert np.allclose(result, 5) #All close because was getting float error as some are 4.9999 due to the store - + assert np.allclose( + result, 5 + ) # All close because was getting float error as some are 4.9999 due to the store def test_full_size(self, pipeline): """Assert the finished grid is the region's full resolution size""" @@ -197,10 +192,9 @@ def test_full_size(self, pipeline): result = produce_region(seed, height, width, window_size, step, pipeline, store) assert result.shape == (height, width) - def test_once_per_window(self, pipeline): """Assert the fake pipeline was called once per window position and no more""" - + seed = 123 height = 8 width = 8 @@ -214,7 +208,6 @@ def test_once_per_window(self, pipeline): assert pipeline.call_count == len(positions) - def test_same_seed_grid(self): """Assert the same seed and region run twice give identical grids""" height = 8 @@ -225,11 +218,11 @@ def test_same_seed_grid(self): store1 = FakeStore(height, width) store2 = FakeStore(height, width) - #because using same pipeline might affect results? + # because using same pipeline might affect results? pipeline1 = FakePipeline() pipeline2 = FakePipeline() result1 = produce_region(123, height, width, window_size, step, pipeline1, store1) result2 = produce_region(123, height, width, window_size, step, pipeline2, store2) - assert np.array_equal(result1, result2) \ No newline at end of file + assert np.array_equal(result1, result2) From 45f33c58862ac4b4b751b87f6bca12d75d7c4316 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Sat, 22 Aug 2026 15:32:16 -0400 Subject: [PATCH 21/25] working on requested changes --- .coverage | Bin 0 -> 53248 bytes src/terrain_diffusion/sampler.py | 44 +++++++--------------- tests/test_sampler.py | 62 ++++++++++++++----------------- 3 files changed, 42 insertions(+), 64 deletions(-) create mode 100644 .coverage diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..c25aed91a57badcf073acfc69e3e4f3633145f56 GIT binary patch literal 53248 zcmeI4ZEPGz8OL|`)_dN)m+=u2*F;ekl*lo$9jwGEX{mxqTpHS{4b4j_uFrdSYkSGv z?qzo`iGiryQc<9SA|!+&@qrJtARs}drF@_iln4Q>K&2p+@Rn8rR1qj3(Ju`jcxGSj z&Q9D$$wp10|LX2$cV3?7ncqA!vvYSlckQ~(@=bl#aT|uOZx;FlQ54><>w+L?^e)gl zIkI#jCl?foUFXZ4YQpH3e^Fq2g}idNz@`iDU?cgt{C{#^&A(UOle4nJ>L?}P009sH z0T8%m2n4(G+5Uk6@qr`0QK_50YgA1)`Yde!@Z`kqNqzUk2X33xqd0worqeMpqEG0q zb4YKRu0CtkP2I9K$b59zKsYr3XgHND7+4OVSP8~W6JTDE`13h^N` ztdrqZ>6Kel8;a;uW#=pjsyc3sTVHVvyE<=r!@AL~Vbvi!5BpJVU8k|hcl5etht;$_ z%eNd`HxHZDmT%V1Tft!tEjb8YcWp@446o2kR5I4pMW<8vJSF4oap74q&UO;4oq}97 z6%K8-Ta5}K|5&Th9i`c7Qg3vQe9v}LEhi<&b*&RaAp)v~PvEwkPD z!+NLWa99o78P<6v$OG2rl>V(NM1j20JnS8))2&n4X!%ZfU8cq_kI_f|!BTIwf9+cF zp#!0#a6ILT<$LWDb&=DwqnB|Vp1!=_@LsamNq8@+*L7z$>@vKx9yJbmb9bNFl)x}t z-qCa?&PbNNrQXJkB^&fg-Ki}0wa{ZclR5~E1xdEqmR;pt#p89TItNYHm@`M?)M!|E zs~w44XG~T4C)Y0LI&BvykF`&=U_i zNZx3WOiFY{$)u0ODO8=2tkOTRdb#Sv`O0JQNpFyqv;8Yqib2#P__)O1J&P*AV>(@6 z$wYAB<~I$0UO(4%9!-W1_9*=~u3XM=ZbEsCe<~05NukM~$%OP9H0bkpW|7G}repH0 z=EBH9qfVnq)399XvNQ%qGl0%B)(pyQRGgL{`Y*o>-ILEf9eX1Io$G`>bXuMs+Hmfyw5=nxl*tDyR=qr}U_cE|HlCjZ^uEmB=4$ z5)&@9Vbr4T&Kspm;-Pu-9C6WXw8QXC-)fjT&k`CFI@Te>)2psYiSb+-8b-wCms%Bx zxrI`aF*K^p&|v0`e1|u2d5nMZRdO%Cl?&F2+5U|i#h?}U;An6vdvqtzFp|2)m(n87 zT9VjtvO8#$rdyBnQ+qsm$aZR>gxf5HV-7n^8?~MKQAnrYVq+x5?8me`R zWKT1aJ(0F-B5}~Fnk2tgB>A_eE#GnZRvxsO2;X;rv`iI9%S~x(@qF61fTWl6Bz=3@ z(wkP(6qUUs-z~g zX;k;~eKnd3clVIc@l-6O$IxA;)(W@pAjvZ_Nltwzv+Q^?AJS0HkcQN|Qn_r|mR~ND zf;|!`*pw2Sj@|o261zDSv8H{{avi&2+CJIKfB!G3Cx!f6@!#r6ZGB!TenERV_h{kW zT9Er7`zG5}+)_AQ_+0+ED`K*P5g-5pAOHd&00JNY0)k-3!K8Tcw}x-N{x5x04z{MQ zAzJ_UmE~X}b=jTuKQrav_SEGsUH=#Fm4lm7*OILN3o~-CJ$30_>;L>^QP8#i&sF7M z=OxtOLe~Ga@^1RZa({#P%Lqqdjoy}RXLV@l??g=W(e+FAcAACZIcbSz!6{_nXg zLs|FwU%o7!-nIVE?3IH}X~F5N|D}C$uvxwMLB7km7q9=Z{~vB4KmY_l00ck)1V8`; zKmY_l00cnbnkJADGeUv?{x7os3G~7N0w4eaAOHd&00JNY0w4eaAOHd&a19d3WD08d z{D1Lvf&G`g%ucaq*yHR`7BGu_h>f!mww|qFD_Ma_lm!O}fB*=900@8p2!H?xfB*=9 z00>-#1eB62s>PC|_EGruK1p~%Rv3?Bl2YVhQBn##EJ#Y8hj~fK@h~T?&?wxXNmJkY z%IiNm_Q$85IP!@f-?~Pn$oHuq|LfoiK^N>jg})qs>Yn}2|6^a{56AXipIOyQ$)mlJ zAgr4?`@JIz>itKLz99epv3F%D{^o4u)P2AC?zc~!IrE)g9UVXW+KY4Jf3l`OdB-!) zz4-TEuF@3Bvr3Ux3ZMRMu7}RA>yf_rgMCjn24uR}B1^*a!cIXPkwmz)yEoVo;;S(L|Ij@JMlL8oxS1j|0VXYz|PV)0RLov zW2f2g*ss~M>?C`deV-kteF4A5jCzRSmCtd&3}`4Fg39gPxu+kmWGQWWqp_ zWcn5${QY0(yL96r0R%t*1V8`;KmY_l00ck)1V8`;K;X(Hz@Pue`v1ypA6NzgAOHd& z00JNY0w4eaAOHd&00L list[tuple[int, int]]: """Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at. The step is smaller than the window, which is what makes them overlap. - If step does not divide evenly (extends), push last window to row/column of region_cl/row - window_size, so that no window hangs over the edge.""" + If step does not divide evenly, throws an assertion error.""" + + assert region_height % window_size == 0 + assert region_width % window_size == 0 # Find row positions row_positions = [] @@ -39,13 +42,6 @@ def window_positions( while row + window_size <= region_height: row_positions.append(row) - - if row + step + window_size > region_height: - final = region_height - window_size - if row_positions[-1] != final: - row_positions.append(final) - break - row += step # Find column positions @@ -54,13 +50,6 @@ def window_positions( while column + window_size <= region_width: column_positions.append(column) - - if column + step + window_size > region_width: - final = region_width - window_size - if column_positions[-1] != final: - column_positions.append(final) - break - column += step # Combine every row position with every column position @@ -72,7 +61,7 @@ def window_positions( return positions -def weight_grid(height: int, width: int) -> np.ndarray: +def weight_grid(edge_len: int) -> np.ndarray: """Create a function that returns a grid of weights the size of a patch, since the weights get applied to what is written into the store. Weights should be largest in the middle and get smaller toward the edges. Every weight must be greater than zero. A weight of exactly zero means a cell in the corner of a region, covered by only one window, can never be filled in. @@ -84,28 +73,23 @@ def weight_grid(height: int, width: int) -> np.ndarray: # indexing in 2D Array: array[row, column] # create 1D arrays - rows = np.arange(height) - columns = np.arange(width) + positions = np.arange(edge_len) # find center (-1 because we start from 0) - center_row = (height - 1) / 2 - center_column = (width - 1) / 2 + center = (edge_len - 1) / 2 # distance from center - row_distance = np.abs(rows - center_row) - column_distance = np.abs(columns - center_column) + distance = np.abs(positions - center) # weight: apply formula. multiplied 0.9 so values stay above 0 - row_weight = 1 - 0.9 * row_distance / (height / 2) - column_weight = 1 - 0.9 * column_distance / (width / 2) - + weight = 1 - 0.9 * distance / (edge_len / 2) # combine - weights = np.outer(row_weight, column_weight) + weights = np.outer(weight, weight) return weights -def starting_noise(seed: int, height: int, width: int) -> np.ndarray: +def generate_noise_from_seed(seed: int, height: int, width: int) -> np.ndarray: "Takes a seed and a canvas size and returns a grid of random numbers that size" generator = np.random.default_rng(seed) return generator.random((height, width)) @@ -115,13 +99,13 @@ def produce_region( seed: int, height: int, width: int, window_size: int, step: int, pipeline, store ) -> np.ndarray: """Make noise canvas of given dimensions. Make noise and weight grid. - For each window position, cut the window out of the noise canvas, send it to pipeline (#23), add the processed output and its weight to Terrain Store (at that position). + For each window position, cut the window out of the noise canvas, send it to pipeline, add the processed output and its weight to Terrain Store (at that position). Read the finished height grid from store and return it.""" - noise = starting_noise(seed, height, width) + noise = generate_noise_from_seed(seed, height, width) positions = window_positions(height, width, window_size, step) - weights = weight_grid(window_size, window_size) # weight grid made on window_size + weights = weight_grid(window_size) # weight grid made on window_size for row, column in positions: window = noise[row : row + window_size, column : column + window_size] diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 31ba33f..509439a 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -5,7 +5,7 @@ import numpy as np import pytest -from terrain_diffusion.sampler import produce_region, starting_noise, weight_grid, window_positions +from terrain_diffusion.sampler import produce_region, generate_noise_from_seed, weight_grid, window_positions class TestWindowPositions: @@ -42,62 +42,56 @@ def test_one_window(self): ) assert len(positions) == 1 - def test_not_dividing(self): - "Assert a region whose size does not divide evenly by the step still covers the far edge" - positions = window_positions(8, 8, 4, 3) - assert positions == [(0, 0), (0, 3), (0, 4), (3, 0), (3, 3), (3, 4), (4, 0), (4, 3), (4, 4)] + # Had to modify test because added assertion to original function + def test_region_not_divisible(self): + with pytest.raises(AssertionError): + window_positions(10, 8, 4, 3) class TestWeights: def test_grid_equal_patch(self): "Assert the grid is the size of a patch" - height = 10 - width = 20 - weights = weight_grid(height, width) - assert weights.shape == (height, width) + edge = 10 + weights = weight_grid(edge) + assert weights.shape == (edge, edge) def test_palidrome(self): "Assert it reads the same forwards and backwards in both directions" - height = 10 - width = 20 - weights = weight_grid(height, width) + edge = 10 + weights = weight_grid(edge) assert np.array_equal(weights, weights[::-1, :]) # vertical assert np.array_equal(weights, weights[:, ::-1]) # horizontal def test_large_middle(self): "Assert the largest value is in the middle" - height = 11 - width = 21 - weights = weight_grid(height, width) + edge = 11 + weights = weight_grid(edge) # middle - center_row = height // 2 - center_column = width // 2 + center = edge // 2 - assert weights[center_row, center_column] == weights.max() + assert weights[center, center] == weights.max() def test_edges_smaller(self): "Assert values at the edges are smaller than values in the middle" - height = 11 - width = 21 - weights = weight_grid(height, width) + edge = 11 + weights = weight_grid(edge) # middle - center_row = height // 2 - center_column = width // 2 - middle_val = weights[center_row, center_column] + center = edge // 2 + middle_val = weights[center, center] # R/L edges - assert all(weights[x, 0] < middle_val for x in range(height)) - assert all(weights[x, width - 1] < middle_val for x in range(height)) + assert all(weights[x, 0] < middle_val for x in range(edge)) + assert all(weights[x, edge - 1] < middle_val for x in range(edge)) # T/B edges - assert all(weights[0, y] < middle_val for y in range(width)) - assert all(weights[height - 1, y] < middle_val for y in range(width)) + assert all(weights[0, y] < middle_val for y in range(edge)) + assert all(weights[edge - 1, y] < middle_val for y in range(edge)) def test_greater_zero(self): "Assert every value is greater than zero" - weights = weight_grid(10, 20) + weights = weight_grid(10) assert np.all(weights > 0) @@ -107,8 +101,8 @@ def test_same_seed(self): seed = 123 height = 10 width = 20 - noise1 = starting_noise(seed, height, width) - noise2 = starting_noise(seed, height, width) + noise1 = generate_noise_from_seed(seed, height, width) + noise2 = generate_noise_from_seed(seed, height, width) assert np.array_equal(noise1, noise2) def test_diff_seed(self): @@ -117,8 +111,8 @@ def test_diff_seed(self): seed2 = 456 height = 10 width = 20 - noise1 = starting_noise(seed1, height, width) - noise2 = starting_noise(seed2, height, width) + noise1 = generate_noise_from_seed(seed1, height, width) + noise2 = generate_noise_from_seed(seed2, height, width) assert not np.array_equal(noise1, noise2) def test_right_size(self): @@ -126,7 +120,7 @@ def test_right_size(self): seed = 123 height = 10 width = 20 - noise = starting_noise(seed, height, width) + noise = generate_noise_from_seed(seed, height, width) assert noise.shape == (height, width) From bc5b1e11924dacd72ec9276db3de8ea9231b0e6d Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Sat, 22 Aug 2026 15:50:19 -0400 Subject: [PATCH 22/25] sampler.py fixed, working on test_sampler.py --- src/terrain_diffusion/sampler.py | 22 ++++++++++---- tests/test_sampler.py | 49 +++++++++++++------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 9c601e5..c07e805 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -96,7 +96,7 @@ def generate_noise_from_seed(seed: int, height: int, width: int) -> np.ndarray: def produce_region( - seed: int, height: int, width: int, window_size: int, step: int, pipeline, store + seed: int, height: int, width: int, window_size: int, step: int, pipeline, ) -> np.ndarray: """Make noise canvas of given dimensions. Make noise and weight grid. For each window position, cut the window out of the noise canvas, send it to pipeline, add the processed output and its weight to Terrain Store (at that position). @@ -107,13 +107,23 @@ def produce_region( positions = window_positions(height, width, window_size, step) weights = weight_grid(window_size) # weight grid made on window_size + weighted_sum = np.zeros((height, width)) + weight_sum = np.zeros((height, width)) + for row, column in positions: window = noise[row : row + window_size, column : column + window_size] - processed_patch = pipeline.generate( - window - ) # based on unmerged commit i believe this will be pipeline.generate(window) + processed_patch = pipeline.generate(window) + + #From FakeStore() + weighted_sum[ + row : row + window_size, + column : column + window_size + ] += processed_patch * weights - store.add(processed_patch, row, column, weights) + weight_sum[ + row : row + window_size, + column : column + window_size + ] += weights - return store.finish() + return weighted_sum, weight_sum diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 509439a..c541a7d 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -135,23 +135,6 @@ def generate(self, patch): return np.full(patch.shape, 5) -class FakeStore: - # used ai help for this because store is not part of my ticket - def __init__(self, height, width): - self.sum_grid = np.zeros((height, width)) - self.weight_grid = np.zeros((height, width)) - - def add(self, patch, row, column, weights): - self.sum_grid[row : row + patch.shape[0], column : column + patch.shape[1]] += ( - patch * weights - ) - - self.weight_grid[row : row + patch.shape[0], column : column + patch.shape[1]] += weights - - def finish(self): - return self.sum_grid / self.weight_grid - - class TestRegionProduction: @pytest.fixture def pipeline(self): @@ -167,8 +150,10 @@ def test_all_fives(self, pipeline): window_size = 4 step = 3 - store = FakeStore(height, width) - result = produce_region(seed, height, width, window_size, step, pipeline, store) + weighted_sum, weight_sum = produce_region( + seed, height, width, window_size, step, pipeline + ) + result = weighted_sum / weight_sum # doing job of store assert np.allclose( result, 5 ) # All close because was getting float error as some are 4.9999 due to the store @@ -182,8 +167,11 @@ def test_full_size(self, pipeline): window_size = 4 step = 3 - store = FakeStore(height, width) - result = produce_region(seed, height, width, window_size, step, pipeline, store) + weighted_sum, weight_sum = produce_region( + seed, height, width, window_size, step, pipeline + ) + result = weighted_sum / weight_sum # doing job of store + assert result.shape == (height, width) def test_once_per_window(self, pipeline): @@ -197,26 +185,29 @@ def test_once_per_window(self, pipeline): positions = window_positions(height, width, window_size, step) - store = FakeStore(height, width) - produce_region(seed, height, width, window_size, step, pipeline, store) + produce_region(seed, height, width, window_size, step, pipeline) assert pipeline.call_count == len(positions) def test_same_seed_grid(self): """Assert the same seed and region run twice give identical grids""" + seed = 123 height = 8 width = 8 window_size = 4 step = 3 - store1 = FakeStore(height, width) - store2 = FakeStore(height, width) - - # because using same pipeline might affect results? + # because using same pipeline might affect results pipeline1 = FakePipeline() pipeline2 = FakePipeline() - result1 = produce_region(123, height, width, window_size, step, pipeline1, store1) - result2 = produce_region(123, height, width, window_size, step, pipeline2, store2) + weighted_sum1, weight_sum1 = produce_region( + seed, height, width, window_size, step, pipeline1 + ) + weighted_sum2, weight_sum2 = produce_region( + seed, height, width, window_size, step, pipeline2 + ) + result1 = weighted_sum1 / weight_sum1 + result2 = weighted_sum2 / weight_sum2 assert np.array_equal(result1, result2) From 6d314f704eca73f6c70fc914effdff295659b411 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Sat, 22 Aug 2026 15:56:27 -0400 Subject: [PATCH 23/25] fixing script errors --- src/terrain_diffusion/sampler.py | 22 +++++++++++----------- tests/test_sampler.py | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index c07e805..2a9fc65 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -96,7 +96,12 @@ def generate_noise_from_seed(seed: int, height: int, width: int) -> np.ndarray: def produce_region( - seed: int, height: int, width: int, window_size: int, step: int, pipeline, + seed: int, + height: int, + width: int, + window_size: int, + step: int, + pipeline, ) -> np.ndarray: """Make noise canvas of given dimensions. Make noise and weight grid. For each window position, cut the window out of the noise canvas, send it to pipeline, add the processed output and its weight to Terrain Store (at that position). @@ -115,15 +120,10 @@ def produce_region( processed_patch = pipeline.generate(window) - #From FakeStore() - weighted_sum[ - row : row + window_size, - column : column + window_size - ] += processed_patch * weights - - weight_sum[ - row : row + window_size, - column : column + window_size - ] += weights + # From FakeStore() + weighted_sum[row : row + window_size, column : column + window_size] += ( + processed_patch * weights + ) + weight_sum[row : row + window_size, column : column + window_size] += weights return weighted_sum, weight_sum diff --git a/tests/test_sampler.py b/tests/test_sampler.py index c541a7d..1868b5d 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -5,7 +5,12 @@ import numpy as np import pytest -from terrain_diffusion.sampler import produce_region, generate_noise_from_seed, weight_grid, window_positions +from terrain_diffusion.sampler import ( + generate_noise_from_seed, + produce_region, + weight_grid, + window_positions, +) class TestWindowPositions: @@ -150,9 +155,7 @@ def test_all_fives(self, pipeline): window_size = 4 step = 3 - weighted_sum, weight_sum = produce_region( - seed, height, width, window_size, step, pipeline - ) + weighted_sum, weight_sum = produce_region(seed, height, width, window_size, step, pipeline) result = weighted_sum / weight_sum # doing job of store assert np.allclose( result, 5 @@ -167,9 +170,7 @@ def test_full_size(self, pipeline): window_size = 4 step = 3 - weighted_sum, weight_sum = produce_region( - seed, height, width, window_size, step, pipeline - ) + weighted_sum, weight_sum = produce_region(seed, height, width, window_size, step, pipeline) result = weighted_sum / weight_sum # doing job of store assert result.shape == (height, width) @@ -203,10 +204,10 @@ def test_same_seed_grid(self): weighted_sum1, weight_sum1 = produce_region( seed, height, width, window_size, step, pipeline1 - ) + ) weighted_sum2, weight_sum2 = produce_region( seed, height, width, window_size, step, pipeline2 - ) + ) result1 = weighted_sum1 / weight_sum1 result2 = weighted_sum2 / weight_sum2 From e10439fba5bf5420a3faa1030c42883fa369c244 Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Sat, 22 Aug 2026 17:06:02 -0400 Subject: [PATCH 24/25] fixed all issues except 1, one more test to be added for window. added pytest-mocker to project dependencies --- pyproject.toml | 3 ++- src/terrain_diffusion/sampler.py | 2 +- tests/test_sampler.py | 39 ++++++++++++-------------------- uv.lock | 14 ++++++++++++ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ea3e3c..2574e5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ requires-python = ">=3.14" dependencies = [ "coveralls>=4.1.0", "numpy>=2.5.2", + "pytest-mock>=3.15.1", ] # The commands the project installs. `uv run terrain-diffusion` runs main() in @@ -81,4 +82,4 @@ markers = [ [tool.coverage.run] omit = [ # add omissions here -] \ No newline at end of file +] diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index 2a9fc65..e272e03 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -102,7 +102,7 @@ def produce_region( window_size: int, step: int, pipeline, -) -> np.ndarray: +) -> tuple[np.ndarray]: """Make noise canvas of given dimensions. Make noise and weight grid. For each window position, cut the window out of the noise canvas, send it to pipeline, add the processed output and its weight to Terrain Store (at that position). Read the finished height grid from store and return it.""" diff --git a/tests/test_sampler.py b/tests/test_sampler.py index 1868b5d..e57f359 100644 --- a/tests/test_sampler.py +++ b/tests/test_sampler.py @@ -129,21 +129,14 @@ def test_right_size(self): assert noise.shape == (height, width) -class FakePipeline: - def __init__(self): - """For test_once_per_window""" - self.call_count = 0 - - def generate(self, patch): - """Igrones input and returns a patch of all fives.""" - self.call_count += 1 - return np.full(patch.shape, 5) - - class TestRegionProduction: @pytest.fixture - def pipeline(self): - return FakePipeline() + def pipeline(self, mocker): + pipeline = mocker.Mock() # make it a Mock object, this way can count calls. + pipeline.generate.side_effect = lambda patch: np.full( + patch.shape, 5 + ) # added side_effect to keep it a Mock object + return pipeline def test_all_fives(self, pipeline): """Assert the finished grid is all fives everywhere, including the overlaps and the corners. @@ -153,7 +146,7 @@ def test_all_fives(self, pipeline): height = 8 width = 8 window_size = 4 - step = 3 + step = 2 weighted_sum, weight_sum = produce_region(seed, height, width, window_size, step, pipeline) result = weighted_sum / weight_sum # doing job of store @@ -168,7 +161,7 @@ def test_full_size(self, pipeline): height = 8 width = 8 window_size = 4 - step = 3 + step = 2 weighted_sum, weight_sum = produce_region(seed, height, width, window_size, step, pipeline) result = weighted_sum / weight_sum # doing job of store @@ -182,31 +175,27 @@ def test_once_per_window(self, pipeline): height = 8 width = 8 window_size = 4 - step = 3 + step = 2 positions = window_positions(height, width, window_size, step) produce_region(seed, height, width, window_size, step, pipeline) - assert pipeline.call_count == len(positions) + assert pipeline.generate.call_count == len(positions) - def test_same_seed_grid(self): + def test_same_seed_grid(self, pipeline): """Assert the same seed and region run twice give identical grids""" seed = 123 height = 8 width = 8 window_size = 4 - step = 3 - - # because using same pipeline might affect results - pipeline1 = FakePipeline() - pipeline2 = FakePipeline() + step = 2 weighted_sum1, weight_sum1 = produce_region( - seed, height, width, window_size, step, pipeline1 + seed, height, width, window_size, step, pipeline ) weighted_sum2, weight_sum2 = produce_region( - seed, height, width, window_size, step, pipeline2 + seed, height, width, window_size, step, pipeline ) result1 = weighted_sum1 / weight_sum1 result2 = weighted_sum2 / weight_sum2 diff --git a/uv.lock b/uv.lock index bbaf16a..eeee1b4 100644 --- a/uv.lock +++ b/uv.lock @@ -339,6 +339,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/24/25/1de2678b631f5a49215c6c96fff41ba892b0a34df68d6d80292b1b48aa7f/pytest-9.1.1-py3-none-any.whl", hash = "sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c", size = 386536, upload-time = "2026-06-19T10:58:31.347Z" }, ] +[[package]] +name = "pytest-mock" +version = "3.15.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/68/14/eb014d26be205d38ad5ad20d9a80f7d201472e08167f0bb4361e251084a9/pytest_mock-3.15.1.tar.gz", hash = "sha256:1849a238f6f396da19762269de72cb1814ab44416fa73a8686deac10b0d87a0f", size = 34036, upload-time = "2025-09-16T16:37:27.081Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5a/cc/06253936f4a7fa2e0f48dfe6d851d9c56df896a9ab09ac019d70b760619c/pytest_mock-3.15.1-py3-none-any.whl", hash = "sha256:0a25e2eb88fe5168d535041d09a4529a188176ae608a6d249ee65abc0949630d", size = 10095, upload-time = "2025-09-16T16:37:25.734Z" }, +] + [[package]] name = "requests" version = "2.34.2" @@ -408,6 +420,7 @@ source = { editable = "." } dependencies = [ { name = "coveralls" }, { name = "numpy" }, + { name = "pytest-mock" }, ] [package.dev-dependencies] @@ -420,6 +433,7 @@ dev = [ requires-dist = [ { name = "coveralls", specifier = ">=4.1.0" }, { name = "numpy", specifier = ">=2.5.2" }, + { name = "pytest-mock", specifier = ">=3.15.1" }, ] [package.metadata.requires-dev] From aaf1dac819772fc603626bfea9225f6c43e0bacb Mon Sep 17 00:00:00 2001 From: Yusyra Hossain Date: Sat, 22 Aug 2026 17:17:42 -0400 Subject: [PATCH 25/25] added assertion for edge_len >1 in weight_grid --- src/terrain_diffusion/sampler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/terrain_diffusion/sampler.py b/src/terrain_diffusion/sampler.py index e272e03..f754ab2 100644 --- a/src/terrain_diffusion/sampler.py +++ b/src/terrain_diffusion/sampler.py @@ -72,6 +72,8 @@ def weight_grid(edge_len: int) -> np.ndarray: # numpy array: [[row 1 contents], [row 2 contents]] # indexing in 2D Array: array[row, column] + assert edge_len > 1 + # create 1D arrays positions = np.arange(edge_len) @@ -82,7 +84,7 @@ def weight_grid(edge_len: int) -> np.ndarray: distance = np.abs(positions - center) # weight: apply formula. multiplied 0.9 so values stay above 0 - weight = 1 - 0.9 * distance / (edge_len / 2) + weight = 1 - 0.9 * distance / center # combine weights = np.outer(weight, weight)