Skip to content

Commit

Permalink
Adds missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonb5 committed Apr 10, 2024
1 parent 647a786 commit 79a4cd1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/test_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def test_regrid_input_mask(self):

output_data = regridder.horizontal("ts", self.coarse_2d_ds)

# replace nan with 1e20 as np.nan != np.nan
# np.nan != np.nan, replace with 1e20
output_data = output_data.fillna(1e20)

expected_output = np.array(
Expand All @@ -511,6 +511,28 @@ def test_regrid_input_mask(self):

assert np.all(output_data.ts.values == expected_output)

@pytest.mark.filterwarnings("ignore:.*invalid value.*true_divide.*:RuntimeWarning")
def test_regrid_input_mask_unmapped_to_nan(self):
regridder = regrid2.Regrid2Regridder(
self.coarse_2d_ds, self.fine_2d_ds, unmapped_to_nan=False
)

self.coarse_2d_ds["mask"] = (("lat", "lon"), [[0, 0], [1, 1], [0, 0]])

output_data = regridder.horizontal("ts", self.coarse_2d_ds)

expected_output = np.array(
[
[0.0] * 4,
[1.0] * 4,
[1.0] * 4,
[0.0] * 4,
],
dtype=np.float32,
)

assert np.all(output_data.ts.values == expected_output)

def test_preserve_attrs(self):
regridder = regrid2.Regrid2Regridder(self.coarse_2d_ds, self.fine_2d_ds)

Expand Down

0 comments on commit 79a4cd1

Please sign in to comment.