def test_unlimited(self):
        """Test interpolation to complete an incomplete field using a reference
        field. No limit is imposed upon the returned interpolated values."""

        expected = np.array(
            [[4.0, 4.0, 4.0], [8.5, 8.5, 8.5], [3.0, 3.0, 3.0]], dtype=np.float32
        )

        result = InterpolateUsingDifference().process(self.sleet_rain, self.snow_sleet)

        assert_array_equal(result.data, expected)
        self.assertEqual(result.coords(), self.sleet_rain.coords())
        self.assertEqual(result.metadata, self.sleet_rain.metadata)
    def test_minimum_limited(self):
        """Test interpolation to complete an incomplete field using a reference
        field. A limit is imposed upon the returned interpolated values,
        forcing these values to the minimum limit if they are below it."""

        expected = np.array(
            [[4.0, 4.0, 4.0], [10.0, 8.5, 8.5], [3.0, 3.0, 3.0]], dtype=np.float32
        )

        result = InterpolateUsingDifference().process(
            self.sleet_rain, self.snow_sleet, limit=self.limit, limit_as_maximum=False
        )

        assert_array_equal(result.data, expected)
        self.assertEqual(result.coords(), self.sleet_rain.coords())
        self.assertEqual(result.metadata, self.sleet_rain.metadata)
    def test_convert_units(self):
        """Test that a reference cube and limit cube with different but
        compatible units are converted for use and return the expected
        result."""

        expected = np.array(
            [[4.0, 4.0, 4.0], [8.5, 8.0, 6.0], [3.0, 3.0, 3.0]], dtype=np.float32
        )

        self.snow_sleet.convert_units("cm")
        self.limit.convert_units("cm")

        result = InterpolateUsingDifference().process(
            self.sleet_rain, self.snow_sleet, limit=self.limit
        )

        assert_array_equal(result.data, expected)
        self.assertEqual(result.coords(), self.sleet_rain.coords())
        self.assertEqual(result.metadata, self.sleet_rain.metadata)
    def test_linear_failure(self):
        """Test that if the use of linear interpolation does not result in a
        complete difference field, and thus a complete field of interest, the
        secondary use of nearest neighbour interpolation completes the
        field."""

        sleet_rain = np.array(
            [[np.nan, np.nan, 4.0], [np.nan, np.nan, np.nan], [3.0, 3.0, 3.0]],
            dtype=np.float32,
        )
        sleet_rain = np.ma.masked_invalid(sleet_rain)
        self.sleet_rain.data = sleet_rain

        expected = np.array(
            [[3.5, 4.0, 4.0], [8.5, 8.5, 8.5], [3.0, 3.0, 3.0]], dtype=np.float32
        )

        result = InterpolateUsingDifference().process(self.sleet_rain, self.snow_sleet)

        assert_array_equal(result.data, expected)
        self.assertEqual(result.coords(), self.sleet_rain.coords())
        self.assertEqual(result.metadata, self.sleet_rain.metadata)
    def test_multi_realization_limited(self):
        """Test interpolation to complete an incomplete field using a reference
        field. A limit is imposed upon the returned interpolated values,
        forcing these values to the minimum limit if they are below it. The
        inputs are multi-realization."""

        snow_sleet = add_coordinate(self.snow_sleet, [0, 1], "realization")
        sleet_rain = add_coordinate(self.sleet_rain, [0, 1], "realization")

        expected = np.array(
            [[4.0, 4.0, 4.0], [10.0, 8.5, 8.5], [3.0, 3.0, 3.0]], dtype=np.float32
        )

        result = InterpolateUsingDifference().process(
            sleet_rain, snow_sleet, limit=self.limit, limit_as_maximum=False
        )

        assert_array_equal(result[0].data, expected)
        assert_array_equal(result[1].data, expected)
        self.assertEqual(result.shape, sleet_rain.shape)
        self.assertEqual(result.coords(), sleet_rain.coords())
        self.assertEqual(result.metadata, sleet_rain.metadata)