Exemple #1
0
    def test_full_init(self):
        self.eval = Evaluation(
            self.test_dataset, [self.test_dataset, self.another_test_dataset],
            [Bias(), Bias(), TemporalStdDev()])
        ref_dataset = self.test_dataset
        target_datasets = [self.test_dataset, self.another_test_dataset]
        metrics = [Bias(), Bias()]
        unary_metrics = [TemporalStdDev()]

        self.eval = Evaluation(ref_dataset, target_datasets,
                               metrics + unary_metrics)

        self.assertEqual(self.eval.ref_dataset.variable, self.variable)

        # Make sure the two target datasets were added properly
        self.assertEqual(self.eval.target_datasets[0].variable, self.variable)
        self.assertEqual(self.eval.target_datasets[1].variable, self.other_var)

        # Make sure the three metrics were added properly
        # The two Bias metrics are "binary" metrics
        self.assertEqual(len(self.eval.metrics), 2)
        # TemporalStdDev is a "unary" metric and should be stored as such
        self.assertEqual(len(self.eval.unary_metrics), 1)
        self.eval.run()
        out_str = ("<Evaluation - ref_dataset: {}, "
                   "target_dataset(s): {}, "
                   "binary_metric(s): {}, "
                   "unary_metric(s): {}, "
                   "subregion(s): {}>").format(str(
                       self.test_dataset), [str(ds) for ds in target_datasets],
                                               [str(m) for m in metrics],
                                               [str(u)
                                                for u in unary_metrics], None)
        self.assertEqual(str(self.eval), out_str)
Exemple #2
0
    def test_subregion_unary_result_shape(self):
        bound = Bounds(
            lat_min=10, lat_max=18,
            lon_min=100, lon_max=108,
            start=dt.datetime(2000, 1, 1), end=dt.datetime(2000, 3, 1))

        new_eval = Evaluation(
            self.test_dataset,
            [self.another_test_dataset, self.another_test_dataset],
            [TemporalStdDev(), TemporalStdDev()],
            [bound, bound, bound, bound, bound]
        )
        new_eval.run()

        # Expected result shape is
        # [
        #       [   # Subregions cause this extra layer
        #           [3, temporalstddev.run(reference).shape],
        #       ]
        # ]

        # 5 = number of subregions
        self.assertTrue(len(new_eval.unary_results) == 5)
        # number of metrics
        self.assertTrue(len(new_eval.unary_results[0]) == 2)
        self.assertTrue(isinstance(new_eval.unary_results, type([])))
        # number of datasets (ref + target)
        self.assertTrue(new_eval.unary_results[0][0].shape[0] == 3)
Exemple #3
0
 def setUp(self):
     self.temporal_std_dev = TemporalStdDev()
     # Initialize target dataset
     self.target_lat = np.array([10, 12, 14, 16, 18])
     self.target_lon = np.array([100, 102, 104, 106, 108])
     self.target_time = np.array(
         [dt.datetime(2000, x, 1) for x in range(1, 13)])
     flat_array = np.array(range(300))
     self.target_value = flat_array.reshape(12, 5, 5)
     self.target_variable = 'prec'
     self.target_dataset = Dataset(self.target_lat, self.target_lon,
                                   self.target_time, self.target_value,
                                   self.target_variable)
Exemple #4
0
    def test_add_valid_metric(self):
        # Add a "binary" metric
        self.assertEqual(len(self.eval.metrics), 0)
        self.eval.add_metric(Bias())
        self.assertEqual(len(self.eval.metrics), 1)

        # Add a "unary" metric
        self.assertEqual(len(self.eval.unary_metrics), 0)
        self.eval.add_metric(TemporalStdDev())
        self.assertEqual(len(self.eval.unary_metrics), 1)
Exemple #5
0
 def setUp(self):
     self.temporal_std_dev = TemporalStdDev()
     # Initialize target dataset
     self.target_lat = np.array([10, 12, 14, 16, 18])
     self.target_lon = np.array([100, 102, 104, 106, 108])
     self.target_time = np.array([dt.datetime(2000, x, 1) for x in range(1, 13)])
     flat_array = np.array(range(300))
     self.target_value = flat_array.reshape(12, 5, 5)
     self.target_variable = 'prec'
     self.target_dataset = Dataset(self.target_lat, self.target_lon, self.target_time,
         self.target_value, self.target_variable)
Exemple #6
0
    def test_unary_result_shape(self):
        new_eval = Evaluation(self.test_dataset, [
            self.another_test_dataset, self.another_test_dataset,
            self.another_test_dataset, self.another_test_dataset
        ], [TemporalStdDev()])
        new_eval.run()

        # Expected result shape is
        # [stddev] where stddev.shape[0] = number of datasets

        self.assertTrue(len(new_eval.unary_results) == 1)
        self.assertTrue(new_eval.unary_results[0].shape[0] == 5)
Exemple #7
0
    def test_full_init(self):
        self.eval = Evaluation(
            self.test_dataset, [self.test_dataset, self.another_test_dataset],
            [Bias(), Bias(), TemporalStdDev()])

        self.assertEqual(self.eval.ref_dataset.variable, self.variable)

        # Make sure the two target datasets were added properly
        self.assertEqual(self.eval.target_datasets[0].variable, self.variable)
        self.assertEqual(self.eval.target_datasets[1].variable, self.other_var)

        # Make sure the three metrics were added properly
        # The two Bias metrics are "binary" metrics
        self.assertEqual(len(self.eval.metrics), 2)
        # TemporalStdDev is a "unary" metric and should be stored as such
        self.assertEqual(len(self.eval.unary_metrics), 1)
Exemple #8
0
class TestTemporalStdDev(unittest.TestCase):
    '''Test the metrics.TemporalStdDev metric.'''
    def setUp(self):
        self.temporal_std_dev = TemporalStdDev()
        # Initialize target dataset
        self.target_lat = np.array([10, 12, 14, 16, 18])
        self.target_lon = np.array([100, 102, 104, 106, 108])
        self.target_time = np.array([dt.datetime(2000, x, 1) for x in range(1, 13)])
        flat_array = np.array(range(300))
        self.target_value = flat_array.reshape(12, 5, 5)
        self.target_variable = 'prec'
        self.target_dataset = Dataset(self.target_lat, self.target_lon, self.target_time,
            self.target_value, self.target_variable)


    def test_function_run(self):
        '''Test TemporalStdDev function for target dataset.'''
        expected_result = np.zeros((5, 5),)
        expected_result.fill(90.13878189)
        npt.assert_almost_equal(self.temporal_std_dev.run(self.target_dataset), expected_result)
Exemple #9
0
class TestTemporalStdDev(unittest.TestCase):
    '''Test the metrics.TemporalStdDev metric.'''
    def setUp(self):
        self.temporal_std_dev = TemporalStdDev()
        # Initialize target dataset
        self.target_lat = np.array([10, 12, 14, 16, 18])
        self.target_lon = np.array([100, 102, 104, 106, 108])
        self.target_time = np.array(
            [dt.datetime(2000, x, 1) for x in range(1, 13)])
        flat_array = np.array(range(300))
        self.target_value = flat_array.reshape(12, 5, 5)
        self.target_variable = 'prec'
        self.target_dataset = Dataset(self.target_lat, self.target_lon,
                                      self.target_time, self.target_value,
                                      self.target_variable)

    def test_function_run(self):
        '''Test TemporalStdDev function for target dataset.'''
        expected_result = np.zeros((5, 5), )
        expected_result.fill(90.13878189)
        npt.assert_almost_equal(self.temporal_std_dev.run(self.target_dataset),
                                expected_result)