Esempio n. 1
0
 def test_lons_ge_180(self):
     """test to make sure wrapping works"""
     self.assertEqual(180, qc.lon_to_xindex(360.0))
     self.assertEqual(5, qc.lon_to_xindex(185.1))
     for i in range(0, 520):
         self.assertEqual(math.fmod(i, 360),
                          qc.lon_to_xindex(-179.5 + float(i)))
Esempio n. 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
    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 }
Esempio n. 4
0
 def test_oneshift_along_at_hires(self):
     self.assertEqual(1, qc.lon_to_xindex(-179.9 + 0.25, 0.25))
Esempio n. 5
0
 def test_highlong_different_res(self):
     self.assertEqual(71, qc.lon_to_xindex(179.5, 5))
     self.assertEqual(1439, qc.lon_to_xindex(179.9, 0.25))
Esempio n. 6
0
 def test_highlong(self):
     self.assertEqual(179, qc.lon_to_xindex(359.5))
Esempio n. 7
0
 def test_gridcentres(self):
     self.assertEqual(0, qc.lon_to_xindex(-179.5))
     self.assertEqual(0, qc.lon_to_xindex(180.5))
Esempio n. 8
0
 def test_non180_borderline(self):
     self.assertEqual(106, qc.lon_to_xindex(-74.0))
Esempio n. 9
0
 def test_high_negative_long(self):
     self.assertEqual(359, qc.lon_to_xindex(-180.5))
     self.assertEqual(358, qc.lon_to_xindex(-181.5))
Esempio n. 10
0
 def test_borderline(self):
     self.assertEqual(0, qc.lon_to_xindex(-180))
     self.assertEqual(0, qc.lon_to_xindex(180))