Esempio n. 1
0
    def test_high_n_lat(self):
        x1, x2, y1, y2 = qc.get_four_surrounding_points(89.9, 0.1, 1)
        self.assertEqual(x1, -0.5)
        self.assertEqual(x2, 0.5)
        self.assertEqual(y1, 89.5)
        self.assertEqual(y2, 89.5)

        x1, x2, y1, y2 = qc.get_four_surrounding_points(89.9, 0.1, 0)
        self.assertEqual(x1, -0.5)
        self.assertEqual(x2, 0.5)
        self.assertEqual(y1, 89.5)
        self.assertEqual(y2, 90.5)
Esempio n. 2
0
 def test_negative_dateline_crossover(self):
     x1, x2, y1, y2 = qc.get_four_surrounding_points(0.0, -179.9)
     self.assertEqual(x1, -180.5)
     self.assertEqual(x2, -179.5)
     self.assertEqual(y1, -0.5)
     self.assertEqual(y2, 0.5)
Esempio n. 3
0
 def test_zero_zero(self):
     x1, x2, y1, y2 = qc.get_four_surrounding_points(0.0, 0.0)
     self.assertEqual(x1, -0.5)
     self.assertEqual(x2, 0.5)
     self.assertEqual(y1, -0.5)
     self.assertEqual(y2, 0.5)
Esempio n. 4
0
 def test_high_lon(self):
     x1, x2, y1, y2 = qc.get_four_surrounding_points(0.4, 322.2 - 360, 1)
     self.assertEqual(x1, -38.5)
     self.assertEqual(x2, -37.5)
     self.assertEqual(y1, -0.5)
     self.assertEqual(y2, 0.5)
Esempio n. 5
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)