Ejemplo n.º 1
0
    def test_one_at_points_set_to_one(self):
        result = qc.bilinear_interp(0., 1., 0., 1., 0., 1., 0., 1., 1., 1.)
        self.assertEqual(result, 1)

        result = qc.bilinear_interp(0., 1., 0., 1., 1., 1., 0., 1., 1., 1.)
        self.assertEqual(result, 1)

        result = qc.bilinear_interp(0., 1., 0., 1., 1., 0., 0., 1., 1., 1.)
        self.assertEqual(result, 1)
Ejemplo n.º 2
0
 def test_gradient_across_square(self):
     result = qc.bilinear_interp(0., 1., 0., 1., 0.5, 0.5, 0., 1., 1., 2.)
     self.assertEqual(result, 1)
     result = qc.bilinear_interp(0., 1., 0., 1., 0.0, 0.0, 0., 1., 1., 2.)
     self.assertEqual(result, 0)
     result = qc.bilinear_interp(0., 1., 0., 1., 1.0, 1.0, 0., 1., 1., 2.)
     self.assertEqual(result, 2)
     result = qc.bilinear_interp(0., 1., 0., 1., 0.0, 1.0, 0., 1., 1., 2.)
     self.assertEqual(result, 1)
     result = qc.bilinear_interp(0., 1., 0., 1., 1.0, 0.0, 0., 1., 1., 2.)
     self.assertEqual(result, 1)
Ejemplo n.º 3
0
 def test_half_at_point_halfway_between_zero_and_one(self):
     result = qc.bilinear_interp(0., 1., 0., 1., 0.5, 0., 0., 0., 1., 1.)
     self.assertEqual(result, 0.5)
     result = qc.bilinear_interp(0., 1., 0., 1., 0.5, 0.5, 0., 0., 1., 1.)
     self.assertEqual(result, 0.5)
Ejemplo n.º 4
0
 def test_zero_at_point_set_to_zero(self):
     result = qc.bilinear_interp(0., 1., 0., 1., 0., 0., 0., 1., 1., 1.)
     self.assertEqual(result, 0)
Ejemplo n.º 5
0
 def test_zero_when_all_zero(self):
     result = qc.bilinear_interp(0., 1., 0., 1., 0., 0., 0., 0., 0., 0.)
     self.assertEqual(result, 0)
Ejemplo n.º 6
0
    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)