Example #1
0
    def test_precip_sub_day(self):
        """Tests that interpretation of precip works"""

        # testing certain scalars
        self.assertLess(
            fm.precip_duration_sub_day([0] / u.day, 4 / u.day) - 0 * u.hour,
            1e-5 * u.hour, "Failed to produce zero precip!")
        self.assertLess(
            fm.precip_duration_sub_day([1] / u.day, 4 / u.day) - 1 * u.hour,
            1e-5 * u.hour, "Single rain observation should be 1 hour rain")
        interpval = (1 + (3 - 1) * (24 - 1) / (4 - 1.))
        self.assertLess(
            fm.precip_duration_sub_day([3] / u.day, 4 / u.day) -
            interpval * u.hour, 1e-5 * u.hour,
            "More than one rain observation should be interpolated")

        # testing array
        self.assertTrue(
            np.all(
                fm.precip_duration_sub_day([0, 1, 3] / u.day, 4 / u.day) -
                [0, 1, interpval] * u.hour < 1.e-5 * u.hour),
            "Array data type failed")

        # testing the "no units" case
        self.assertLess(
            fm.precip_duration_sub_day(np.array([1]), 4) - 1 * u.hour,
            1e-5 * u.hour, "Single rain observation should be 1 hour rain")
Example #2
0
 def test_precip_sub_day(self):
     """Tests that interpretation of precip works"""
     
     # testing certain scalars
     self.assertLess(fm.precip_duration_sub_day([0]/u.day, 4 / u.day) - 0 * u.hour, 
         1e-5*u.hour, "Failed to produce zero precip!")
     self.assertLess(fm.precip_duration_sub_day([1]/u.day, 4 / u.day) - 1 * u.hour, 
         1e-5*u.hour, "Single rain observation should be 1 hour rain")
     interpval = (1 + (3-1)*(24-1)/(4-1.))
     self.assertLess(fm.precip_duration_sub_day([3]/u.day, 4 / u.day) - interpval * u.hour,
         1e-5*u.hour, "More than one rain observation should be interpolated") 
         
     # testing array
     self.assertTrue(np.all(fm.precip_duration_sub_day( [0,1,3]/u.day, 4/u.day) - 
                            [0,1,interpval] * u.hour < 1.e-5 * u.hour),
                            "Array data type failed")
                            
     # testing the "no units" case
     self.assertLess(fm.precip_duration_sub_day(np.array([1]), 4) - 1 * u.hour, 
         1e-5*u.hour, "Single rain observation should be 1 hour rain")
Example #3
0
 def compute_precip_duration(self) : 
     bufs = self.get_buffer_group()
     
     rainf = bufs.get('Rainf')
     landpts = self.get_num_land_points()
     
     # count the number of times rain was observed
     # in the past day
     rain_count = np.empty( (landpts,) )
     raining = (rainf.get_preceeding_day() > 0)
     i_raining = [ slice(None,None,None) ] * 2
     for i in range(landpts) : 
         i_raining[not rainf.time_axis] = i
         rain_count[i] = np.count_nonzero(raining[i_raining])
     
     daily_obs = self.get_samples_per_day() / u.day
     return fm.precip_duration_sub_day(rain_count, daily_obs)
Example #4
0
    def compute_precip_duration(self):
        bufs = self.get_buffer_group()

        rainf = bufs.get('Rainf')
        landpts = self.get_num_land_points()

        # count the number of times rain was observed
        # in the past day
        rain_count = np.empty((landpts, ))
        raining = (rainf.get_preceeding_day() > 0)
        i_raining = [slice(None, None, None)] * 2
        for i in range(landpts):
            i_raining[not rainf.time_axis] = i
            rain_count[i] = np.count_nonzero(raining[i_raining])

        daily_obs = self.get_samples_per_day() / u.day
        return fm.precip_duration_sub_day(rain_count, daily_obs)