def test_three_missing_corners(self): q11, q12, q21, q22 = qc.fill_missing_vals(None, None, 3., None) self.assertEqual(q11, 3.) self.assertEqual(q12, 3.) self.assertEqual(q21, 3.) self.assertEqual(q22, 3.)
def test_two_missing_corners(self): q11, q12, q21, q22 = qc.fill_missing_vals(None, 2., 3., None) self.assertEqual(q11, 2.5) self.assertEqual(q12, 2.) self.assertEqual(q21, 3.) self.assertEqual(q22, 2.5)
def test_all_missing_in_square(self): q11, q12, q21, q22 = qc.fill_missing_vals(None, None, None, None) self.assertEqual(q11, None) self.assertEqual(q12, None) self.assertEqual(q21, None) self.assertEqual(q22, None)
def test_one_missing_corner(self): q11, q12, q21, q22 = qc.fill_missing_vals(1., 2., 3., None) self.assertEqual(q11, 1.) self.assertEqual(q12, 2.) self.assertEqual(q21, 3.) self.assertEqual(q22, 2.5)
def get_interpolated_value(self, lat, lon, mo, dy): ''' Get the value from the climatology interpolated to the precise location of the observation in time and space :param lat: latitude of location to extract value from in degrees :param lon: longitude of location to extract value from in degrees :param month: month for which the value is required :param day: day for which the value is required :type lat: float :type lon: float :type month: integer :type day: integer :return: climatology value at specified location and time. :rtype: float ''' #check that the lat lon point falls in a grid cell with a value or on #the border of one if lat + 0.001 < 90: pert1 = self.get_value(lat + 0.001, lon + 0.001, mo, dy) pert2 = self.get_value(lat + 0.001, lon - 0.001, mo, dy) else: pert1 = None pert2 = None if lat - 0.001 > -90: pert3 = self.get_value(lat - 0.001, lon + 0.001, mo, dy) pert4 = self.get_value(lat - 0.001, lon - 0.001, mo, dy) else: pert3 = None pert4 = None if (pert1 == None and pert2 == None and pert3 == None and pert4 == None): return None x1, x2, y1, y2 = qc.get_four_surrounding_points(lat, lon, 1) try: Q11 = self.get_value(y1, x1, mo, dy) except: Q11 = None if Q11 != None: Q11 = float(Q11) try: Q22 = self.get_value(y2, x2, mo, dy) except: Q22 = None if Q22 != None: Q22 = float(Q22) try: Q12 = self.get_value(y2, x1, mo, dy) except: Q12 = None if Q12 != None: Q12 = float(Q12) try: Q21 = self.get_value(y1, x2, mo, dy) except: Q21 = None if Q21 != None: Q21 = float(Q21) Q11, Q12, Q21, Q22 = qc.fill_missing_vals(Q11, Q12, Q21, Q22) x1, x2, y1, y2 = qc.get_four_surrounding_points(lat, lon, 0) return qc.bilinear_interp(x1, x2, y1, y2, lon, lat, Q11, Q12, Q21, Q22)