コード例 #1
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
    def test_latitude_varying_res(self):
        self.assertEqual(0, qc.lat_to_yindex(89.9, 0.25))
        self.assertEqual(0, qc.lat_to_yindex(89.9, 0.5))
        self.assertEqual(0, qc.lat_to_yindex(89.9, 1.0))
        self.assertEqual(0, qc.lat_to_yindex(89.9, 2.0))
        self.assertEqual(0, qc.lat_to_yindex(89.9, 5.0))

        self.assertEqual(719, qc.lat_to_yindex(-89.9, 0.25))
        self.assertEqual(359, qc.lat_to_yindex(-89.9, 0.5))
        self.assertEqual(179, qc.lat_to_yindex(-89.9, 1.0))
        self.assertEqual(89, qc.lat_to_yindex(-89.9, 2.0))
        self.assertEqual(35, qc.lat_to_yindex(-89.9, 5.0))
コード例 #2
0
    def get_value(self, lat, lon, month, day):
        '''
        Get the value from the climatology at the give position and time
        
        :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
        '''
        if month < 1 or month > 12:
            return None
        ml = qc.month_lengths(2004)
        if day < 1 or day > ml[month - 1]:
            return None

        yindex = qc.lat_to_yindex(lat, self.res)
        xindex = qc.lon_to_xindex(lon, self.res)
        tindex = self.get_tindex(month, day)

        result = self.field[tindex, yindex, xindex]

        if type(result) is np.float64 or type(result) is np.float32:
            pass
        else:
            if result.mask:
                result = None
            else:
                result = result.data[0]

        return result
コード例 #3
0
    def __init__(self, lat, lon, year, month=None, day=None):
        '''
        Make a :class:`.Gridpt` object from lat, lon, year, month and day
        
        :param lat: latitude of the observation
        :param lon: longitude of observation
        :param year: year of the observation
        :param month: month of the observation
        :param day: day of the observation
        :type lat: float
        :type lon: float
        :type year: integer
        :type month: integer
        :type day: integer
        '''
        self.lat = lat
        self.lon = lon
        
        self.year = year
        self.month = month
        self.day = day
        
        if month == None:
            self.ptd = year
        else:
            self.ptd = qc.which_pentad(month, day)

        self.xindex = qc.lon_to_xindex(lon)
        self.yindex = qc.lat_to_yindex(lat)
        
        self.latitude_approx = 89.5 - self.yindex
        self.longitude_approx = -179.5 + self.xindex

        self.idstring = '%(lat)04d%(lon)04d%(ptd)04d' % {"lat": self.yindex, 
                                                         "lon": self.xindex, 
                                                         "ptd": self.ptd }
コード例 #4
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
 def test_some_points(self):
     self.assertEqual(9, qc.lat_to_yindex(87.52, 0.25))
     self.assertEqual(18, qc.lat_to_yindex(-2.5, 5))
コード例 #5
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
 def test_gridcentres(self):
     for i in range(0, 180):
         self.assertEqual(i, qc.lat_to_yindex(90 - i - 0.5))
コード例 #6
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
 def test_borderline(self):
     for i in range(0, 180):
         self.assertEqual(i, qc.lat_to_yindex(90 - i))
コード例 #7
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
 def test_latitude_too_low(self):
     self.assertEqual(179, qc.lat_to_yindex(-199.3))
コード例 #8
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
 def test_borderline37(self):
     self.assertEqual(53, qc.lat_to_yindex(37.00))
     self.assertEqual(11, qc.lat_to_yindex(35.00, 5))
コード例 #9
0
ファイル: test_qc.py プロジェクト: zqtzt/MarineQC
 def test_latitude_too_high(self):
     self.assertEqual(0, qc.lat_to_yindex(99.2))