示例#1
0
    def test_mean(self):
        chunk = curve_chunks_getter(
            self.curve_db, self.location_db, self.curves_per_location)

        mean_fn = persite_result_decorator(mean_curves)

        mean_fn(chunk, self.curve_writer, False)

        self.assertAlmostEqual(self.location_nr, len(self.curve_writer.curves))
        locations = [v['wkb'] for v in self.curve_writer.curves]

        expected_mean_curves = [
            dict(wkb=locations[i],
                 poes=[1. / (1 + i + j)
                       for j in range(0, self.level_nr)])
            for i in range(0, self.location_nr)]

        for i in range(0, self.location_nr):
            self.assertEqual(
                expected_mean_curves[i]['wkb'],
                self.curve_writer.curves[i]['wkb'])
            numpy.testing.assert_allclose(
                expected_mean_curves[i]['poes'],
                self.curve_writer.curves[i]['poes'],
                atol=self.__class__.SIGMA * 10)
示例#2
0
    def test_mean_with_weights(self):
        chunk = curve_chunks_getter(
            self.curve_db, self.location_db, self.curves_per_location)

        mean_fn = persite_result_decorator(mean_curves_weighted)
        mean_fn(chunk, self.curve_writer, True)

        expected_mean_curves = [
            numpy.array([0.909707, 0.882379, 0.849248]),
            numpy.array([0.912911, 0.85602, 0.771468])]

        for i in range(0, self.location_nr):
            numpy.testing.assert_allclose(
                expected_mean_curves[i],
                self.curve_writer.curves[i]['poes'])
示例#3
0
    def test_quantile_with_weights(self):
        chunk = curve_chunks_getter(
            self.curve_db, self.location_db, self.curves_per_location)

        quantile_fn = persite_result_decorator(quantile_curves_weighted)

        quantile_fn(chunk, self.curve_writer, True, quantile=0.3)
        self.assertAlmostEqual(self.location_nr, len(self.curve_writer.curves))

        expected_quantile_curves = [
            numpy.array([0.69909, 0.60859, 0.50328]),
            numpy.array([0.89556, 0.83045, 0.73646])
            ]

        for i in range(0, self.location_nr):
            numpy.testing.assert_allclose(
                expected_quantile_curves[i],
                self.curve_writer.curves[i]['poes'])
示例#4
0
    def test_persite_result_decorator(self):
        chunk = curve_chunks_getter(
            self.curve_db, self.location_db, self.curves_per_location)

        func = mock.Mock()

        with mock.patch(MOCK_PREFIX + '._fetch_curves') as fc:
            with mock.patch(
                    MOCK_PREFIX + '._write_aggregate_results') as war:
                fc.return_value = (1, 2, 3)

                new_func = persite_result_decorator(func)

                a_value = random.random()
                new_func(chunk, self.curve_writer, True, ya_arg=a_value)

                self.assertEqual(1, fc.call_count)
                self.assertEqual(1, war.call_count)
                self.assertEqual(1, func.call_count)
示例#5
0
    def test_quantile(self):
        chunk = curve_chunks_getter(
            self.curve_db, self.location_db, self.curves_per_location)

        quantile_fn = persite_result_decorator(quantile_curves)

        quantile_fn(chunk, self.curve_writer, False, quantile=0.5)
        self.assertAlmostEqual(self.location_nr, len(self.curve_writer.curves))

        expected_quantile_curves = [
            dict(wkb=location,
                 poes=[1. / (1 + i + j) for j in range(0, self.level_nr)])
            for i, location in enumerate(self.location_db)]

        for i in range(0, self.location_nr):
            self.assertEqual(
                expected_quantile_curves[i]['wkb'],
                self.curve_writer.curves[i]['wkb'])
            numpy.testing.assert_allclose(
                expected_quantile_curves[i]['poes'],
                self.curve_writer.curves[i]['poes'],
                atol=self.__class__.SIGMA * 10)