def test_returns_correct_values(self): """ Test that the output of this function matches the matlab version value by value. We cannot compare NaNs directly (as it will always give false, so only do a direct comparison if they are both not NaN :return: Nothing """ print("Testing that interp_climatology returns matrices with correct values") sal, pres = interp_climatology(self.grid_sal, self.grid_theta, self.grid_pres, self.float_sal, self.float_theta, self.float_pres) np.testing.assert_allclose( sal, self.expected_interp_sal, rtol=0, atol=1e-12, equal_nan=True, err_msg="Interpolated salinity does not match expected value", ) np.testing.assert_allclose( pres, self.expected_interp_pres, rtol=0, atol=1e-12, equal_nan=True, err_msg="Interpolated pressure does not match expected value", )
def test_returns_same_shape(self): """ Test that the salinity and pressures matrices are equal shapes :return: Nothing """ print("Testing that interp_climatology returns a matrices of the same shape") sal, pres = interp_climatology(self.grid_sal, self.grid_theta, self.grid_pres, self.float_sal, self.float_theta, self.float_pres) self.assertTrue(sal.shape == pres.shape, "salinity and pressure matrices shaped differently")
def test_no_finite_grid_data_returns_nans(self): """ Test that an we get NaNs for grid data with all values infinite. """ bad_grid_sal = bad_grid_theta = bad_grid_pres = np.full((5, 5), np.inf) sal, pres = interp_climatology(bad_grid_sal, bad_grid_theta, bad_grid_pres, self.float_sal, self.float_theta, self.float_pres) self.assertTrue(np.all(np.isnan(sal))) self.assertTrue(np.all(np.isnan(pres)))
def test_returns_correct_shape(self): """ Test that the returned matrix is the shape we expect it to be :return: Nothing """ print("Testing that interp_climatology returns a matrix of the correct shape") sal, pres = interp_climatology(self.grid_sal, self.grid_theta, self.grid_pres, self.float_sal, self.float_theta, self.float_pres) self.assertTrue(sal.shape == self.expected_interp_sal.shape, "salinity matrix shape is incorrect") self.assertTrue(pres.shape == self.expected_interp_pres.shape, "pressure matrix shape is incorrect")
def test_mismatched_grid_data_returns_nans(self): """ Test that an we get NaNs for bad data :return: Nothing """ print("Testing that interp_climatology gives NaNs if all data is bad") bad_grid_sal = np.full((5, 5), np.inf) sal, pres = interp_climatology(bad_grid_sal, self.grid_theta, self.grid_pres, self.float_sal, self.float_theta, self.float_pres) self.assertTrue(np.all(np.isnan(sal))) self.assertTrue(np.all(np.isnan(pres)))