def test_dewpoint(self): t = [293.15, 293.15, 300] rh = [1, 0.8, 1] td = [293.15, 289.783630, 300] for i in range(len(t)): self.assertAlmostEqual(gridpp.dewpoint(t[i], rh[i]), td[i], 4) np.testing.assert_almost_equal(gridpp.dewpoint(t, rh), td, 4)
def test_invalid_input(self): """Check that dimension missmatch results in error""" with self.assertRaises(Exception) as e: gridpp.relative_humidity([293.15], [290, 290]) with self.assertRaises(Exception) as e: gridpp.dewpoint([293.15], [0.9, 0.9]) with self.assertRaises(Exception) as e: gridpp.wetbulb([293.15], [101325], [0.9, 0.9])
def test_memory_leak_input(self): """Checks if there is a memory leak when passing vectors """ N = 1000 last = None min = None max = None for i in range(5): vec = np.random.rand(N * N) vec2 = np.random.rand(N, N) output2 = gridpp.neighbourhood(vec2, 7, gridpp.Mean) output = gridpp.dewpoint(vec, vec) curr = memory_usage() if min is None or max is None: min = curr max = curr if curr < min: min = curr if curr > max: max = curr last = curr self.assertTrue(max / min < 2)
def test_dewpoint_invalid(self): t = [np.nan, np.nan, 293.15] rh = [293.15, np.nan, np.nan] for i in range(len(t)): self.assertTrue(np.isnan(gridpp.dewpoint(t[i], rh[i]))) self.assertTrue(np.isnan(gridpp.dewpoint(t, rh)).all())