Skip to content

Commit 8bfcbee

Browse files
committed
Remove tests of regridding with masks that involve randomness
My original thinking was to reduce the regridding tests considerably, to end up with only 2 regidding tests: - I'm thinking we don't need to cover the case with node_mask=None, because I assume that's already implicitly covered in pre-existing tests - I think we could keep a single test of test_regrid_with_node_mask using one of the five current masks and a single regridding method - I would remove test_regrid_with_random_node_mask, because I don't like randomness in tests: it can be problematic when you get a test failure and then can't reproduce it later. It does look like this test differs a bit from test_regrid_with_node_mask, in the destination coordinates in this random one differ from the source coordinates, whereas the destination and source are identical in the non-random version (if I understand the code correctly)... but I think that, for the purpose of what this is trying to test, that shouldn't matter. - I would keep a single test of test_regrid_with_multivalued_node_mask, using a single regridding method. I would reduce the size considerably – e.g., a 3x4 array rather than 100x200 – and use a hard-coded array for src_data rather than the current random values But Ryan O. pointed out that it can be good to have some extra test coverage of regridding via ESMPy, so supported keeping more tests in place. So I'm doing a more limited reduction: - I'm removing `test_regrid_with_random_node_mask`, to remove this test with randomness and because it doesn't look to me like it adds significant coverage - I'm changing `test_regrid_with_multivalued_node_mask` to use a small, hard-coded source array rather than a random array, both to remove randomness and to reduce the test time. (With this change, the added test time from this PR is insignificant, whereas previously, the tests in this PR added about 9 seconds, I _think_ mainly due to this larger test.) I considered also changing test_regrid_with_node_mask to use a single mask... I tried creating a mask that felt like a hybrid of the existing masks, `[[1, 0, 0, 1], [0, 1, 1, 0], [1, 1, 0, 0]]`, but bilinear and patch remapping failed with that mask. This made me think that I don't understand this well enough to choose a single mask for this test, so I left this parametrized test as is.
1 parent 3fbcbd9 commit 8bfcbee

File tree

1 file changed

+9
-40
lines changed

1 file changed

+9
-40
lines changed

src/addon/esmpy/src/esmpy/test/test_api/test_regrid.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -171,60 +171,29 @@ def test_regrid_with_node_mask(mask, method):
171171
assert_array_almost_equal(dst.data[mask], -999)
172172

173173

174-
@pytest.mark.parametrize("method", NON_CONSERVATIVE_METHODS)
175-
def test_regrid_with_random_node_mask(method):
176-
"""Check regridding that masks random input data."""
177-
n_rows, n_cols = 100, 200
178-
179-
src_data = np.random.uniform(-1.0, 1.0, size=n_rows * n_cols)
180-
mask = src_data > 0.0
181-
182-
src = create_raster_field(
183-
np.linspace(0.0, 200.0, num=n_cols, endpoint=True),
184-
np.linspace(0.0, 100.0, num=n_rows, endpoint=True),
185-
node_mask=mask,
186-
)
187-
dst = create_raster_field(
188-
np.linspace(0.25, 199.25, num=n_cols - 1, endpoint=True),
189-
np.linspace(0.25, 99.25, num=n_rows - 1, endpoint=True),
190-
node_mask=None,
191-
)
192-
193-
src.data[:] = src_data
194-
dst.data[:] = 999.0
195-
196-
regrid = Regrid(
197-
src,
198-
dst,
199-
regrid_method=method,
200-
unmapped_action=UnmappedAction.IGNORE,
201-
src_mask_values=(True,),
202-
dst_mask_values=(True,),
203-
)
204-
205-
assert np.all((dst.data <= 0.0) | (dst.data == 999.0))
206-
207-
208174
@pytest.mark.parametrize("method", NON_CONSERVATIVE_METHODS)
209175
def test_regrid_with_multivalued_node_mask(method):
210176
"""Check regridding that masks multiple values."""
211-
n_rows, n_cols = 100, 200
177+
n_rows, n_cols = 4, 5
212178

213-
src_data = np.random.uniform(-1.0, 1.0, size=n_rows * n_cols)
179+
src_data = np.array([-0.75, 0.75, 0.4, -0.25, 0.25,
180+
0.6, 0.8, -0.9, -0.3, -0.1,
181+
0.2, -0.6, 0.3, 0.7, -0.2,
182+
0.7, 0.6, 0.1, -0.7, -0.6])
214183

215184
mask = np.zeros(src_data.size, dtype=int)
216185
mask[src_data < -0.5] = 1
217186
mask[(src_data >= -0.5) & (src_data < 0.5)] = 2
218187
mask[src_data >= 0.5] = 3
219188

220189
src = create_raster_field(
221-
np.linspace(0.0, 200.0, num=n_cols, endpoint=True),
222-
np.linspace(0.0, 100.0, num=n_rows, endpoint=True),
190+
np.linspace(0.0, 5.0, num=n_cols, endpoint=True),
191+
np.linspace(0.0, 4.0, num=n_rows, endpoint=True),
223192
node_mask=mask,
224193
)
225194
dst = create_raster_field(
226-
np.linspace(0.25, 199.25, num=n_cols - 1, endpoint=True),
227-
np.linspace(0.25, 99.25, num=n_rows - 1, endpoint=True),
195+
np.linspace(0.25, 4.25, num=n_cols - 1, endpoint=True),
196+
np.linspace(0.25, 3.25, num=n_rows - 1, endpoint=True),
228197
node_mask=None,
229198
)
230199

0 commit comments

Comments
 (0)