def test_scenario_risk_sample_based(self):
        # This QA test is a longer-running test of the Scenario Risk
        # calculator.

        # The vulnerabiilty model has non-zero Coefficients of Variation and
        # therefore exercises the 'sample-based' path through the calculator.
        # This test is configured to produce 1000 ground motion fields at each
        # location of interest (in the test above, only 10 are produced).

        # Since we're seeding the random epsilon sampling, we can consistently
        # reproduce all result values.

        # When these values are compared to the results computed by a similar
        # config which takes the 'mean-based' path (with CoVs = 0), we expect
        # the following:
        # All of the mean values in the 'sample-based' results should be with
        # 5%, + or -, of the 'mean-based' results.
        # The standard deviation values of the 'sample-based' results should
        # simply be greater than those produced with the 'mean-based' method.

        # For comparison, mean and stddev values for the region were computed
        # with 1000 GMFs using the mean-based approach. These values (rounded
        # to 2 decimal places) are:
        mb_mean_loss = 1233.26
        mb_stddev_loss = 443.63
        # Loss map for the mean-based approach:
        mb_loss_map = [
            dict(asset='a3', pos='15.48 38.25', mean=200.54874638,
                stddev=94.2302991022),
            dict(asset='a2', pos='15.56 38.17', mean=510.821363253,
                stddev=259.964152622),
            dict(asset='a1', pos='15.48 38.09', mean=521.885458891,
                stddev=244.825980356),
        ]

        # Sanity checks are done. Let's do this.
        scen_cfg = helpers.demo_file(
            'scenario_risk/config_sample-based_qa.gem')
        result = helpers.run_job(scen_cfg, ['--output-type=xml'],
            check_output=True)

        job = OqJob.objects.latest('id')
        self.assertEqual('succeeded', job.status)

        expected_loss_map_file = helpers.demo_file(
            'scenario_risk/computed_output/loss-map-%s.xml' % job.id)
        self.assertTrue(os.path.exists(expected_loss_map_file))

        loss_map = helpers.loss_map_result_from_file(expected_loss_map_file)
        self._verify_loss_map_within_range(sorted(mb_loss_map),
            sorted(loss_map), 0.05)

        exp_mean_loss, exp_stddev_loss = helpers.mean_stddev_from_result_line(
            result)
        self.assertAlmostEqual(mb_mean_loss, exp_mean_loss,
            delta=mb_mean_loss * 0.05)
        self.assertTrue(exp_stddev_loss > mb_stddev_loss)
Exemplo n.º 2
0
    def test_scenario_risk_insured_losses(self):
        # This test exercises the 'mean-based' path through the Scenario Risk
        # calculator. There is no random sampling done here so the results are
        # 100% predictable.
        scen_cfg = helpers.qa_file('scenario_risk_insured_losses/config.gem')

        exp_mean_loss = 799.102578
        exp_stddev_loss = 382.148808
        expected_loss_map = [
            dict(asset='a3',
                 pos='15.48 38.25',
                 mean=156.750910806,
                 stddev=100.422061776),
            dict(asset='a2',
                 pos='15.56 38.17',
                 mean=314.859579324,
                 stddev=293.976254984),
            dict(asset='a1',
                 pos='15.48 38.09',
                 mean=327.492087529,
                 stddev=288.47906994),
        ]

        result = helpers.run_job(scen_cfg, ['--output-type=xml'],
                                 check_output=True)

        job = OqJob.objects.latest('id')
        self.assertEqual('succeeded', job.status)

        expected_loss_map_file = helpers.qa_file(
            'scenario_risk_insured_losses/computed_output/insured-loss-map%s'
            '.xml' % job.id)

        self.assertTrue(os.path.exists(expected_loss_map_file))

        helpers.verify_loss_map(self, expected_loss_map_file,
                                expected_loss_map, self.LOSSMAP_PRECISION)

        actual_mean, actual_stddev = helpers.mean_stddev_from_result_line(
            result)

        self.assertAlmostEqual(exp_mean_loss,
                               actual_mean,
                               places=self.TOTAL_LOSS_PRECISION)
        self.assertAlmostEqual(exp_stddev_loss,
                               actual_stddev,
                               places=self.TOTAL_LOSS_PRECISION)

        # Cleaning generated results file.
        rmtree(QA_OUTPUT_DIR)
Exemplo n.º 3
0
    def test_scenario_risk(self):
        # This test exercises the 'mean-based' path through the Scenario Risk
        # calculator. There is no random sampling done here so the results are
        # 100% predictable.
        scen_cfg = helpers.demo_file('scenario_risk/config.gem')

        exp_mean_loss = 1053.09
        exp_stddev_loss = 246.62
        expected_loss_map = [
            dict(asset='a3',
                 pos='15.48 38.25',
                 mean=180.717534009275,
                 stddev=92.2122644809969),
            dict(asset='a2',
                 pos='15.56 38.17',
                 mean=432.225448142534,
                 stddev=186.864456949986),
            dict(asset='a1',
                 pos='15.48 38.09',
                 mean=440.147078317589,
                 stddev=182.615976701858),
        ]

        result = helpers.run_job(scen_cfg, ['--output-type=xml'],
                                 check_output=True)

        job = OqJob.objects.latest('id')
        self.assertEqual('succeeded', job.status)

        expected_loss_map_file = helpers.demo_file(
            'scenario_risk/computed_output/loss-map-%s.xml' % job.id)

        self.assertTrue(os.path.exists(expected_loss_map_file))

        helpers.verify_loss_map(self, expected_loss_map_file,
                                expected_loss_map, self.LOSSMAP_PRECISION)

        actual_mean, actual_stddev = helpers.mean_stddev_from_result_line(
            result)

        self.assertAlmostEqual(exp_mean_loss,
                               actual_mean,
                               places=self.TOTAL_LOSS_PRECISION)
        self.assertAlmostEqual(exp_stddev_loss,
                               actual_stddev,
                               places=self.TOTAL_LOSS_PRECISION)
    def test_scenario_risk_insured_losses(self):
        # This test exercises the 'mean-based' path through the Scenario Risk
        # calculator. There is no random sampling done here so the results are
        # 100% predictable.
        scen_cfg = helpers.qa_file('scenario_risk_insured_losses/config.gem')

        exp_mean_loss = 799.102578
        exp_stddev_loss = 382.148808
        expected_loss_map = [
            dict(asset='a3', pos='15.48 38.25', mean=156.750910806,
                stddev=100.422061776),
            dict(asset='a2', pos='15.56 38.17', mean=314.859579324,
                stddev=293.976254984),
            dict(asset='a1', pos='15.48 38.09', mean=327.492087529,
                stddev=288.47906994),
            ]

        result = helpers.run_job(scen_cfg, ['--output-type=xml'],
            check_output=True)

        job = OqJob.objects.latest('id')
        self.assertEqual('succeeded', job.status)

        expected_loss_map_file = helpers.qa_file(
            'scenario_risk_insured_losses/computed_output/insured-loss-map%s'
            '.xml' % job.id)

        self.assertTrue(os.path.exists(expected_loss_map_file))

        helpers.verify_loss_map(self, expected_loss_map_file,
            expected_loss_map, self.LOSSMAP_PRECISION)

        actual_mean, actual_stddev = helpers.mean_stddev_from_result_line(result)

        self.assertAlmostEqual(
            exp_mean_loss, actual_mean, places=self.TOTAL_LOSS_PRECISION)
        self.assertAlmostEqual(
            exp_stddev_loss, actual_stddev, places=self.TOTAL_LOSS_PRECISION)

        # Cleaning generated results file.
        rmtree(QA_OUTPUT_DIR)
    def test_scenario_risk(self):
        # This test exercises the 'mean-based' path through the Scenario Risk
        # calculator. There is no random sampling done here so the results are
        # 100% predictable.
        scen_cfg = helpers.demo_file('scenario_risk/config.gem')

        exp_mean_loss = 1053.09
        exp_stddev_loss = 246.62
        expected_loss_map = [
            dict(asset='a3', pos='15.48 38.25', mean=180.717534009275,
                 stddev=92.2122644809969),
            dict(asset='a2', pos='15.56 38.17', mean=432.225448142534,
                 stddev=186.864456949986),
            dict(asset='a1', pos='15.48 38.09', mean=440.147078317589,
                 stddev=182.615976701858),
        ]

        result = helpers.run_job(scen_cfg, ['--output-type=xml'],
                                 check_output=True)

        job = OqJob.objects.latest('id')
        self.assertEqual('succeeded', job.status)

        expected_loss_map_file = helpers.demo_file(
            'scenario_risk/computed_output/loss-map-%s.xml' % job.id)

        self.assertTrue(os.path.exists(expected_loss_map_file))

        helpers.verify_loss_map(self, expected_loss_map_file,
            expected_loss_map, self.LOSSMAP_PRECISION)

        actual_mean, actual_stddev = helpers.mean_stddev_from_result_line(result)

        self.assertAlmostEqual(
            exp_mean_loss, actual_mean, places=self.TOTAL_LOSS_PRECISION)
        self.assertAlmostEqual(
            exp_stddev_loss, actual_stddev, places=self.TOTAL_LOSS_PRECISION)
Exemplo n.º 6
0
    def test_scenario_risk_sample_based(self):
        # This QA test is a longer-running test of the Scenario Risk
        # calculator.

        # The vulnerabiilty model has non-zero Coefficients of Variation and
        # therefore exercises the 'sample-based' path through the calculator.
        # This test is configured to produce 1000 ground motion fields at each
        # location of interest (in the test above, only 10 are produced).

        # Since we're seeding the random epsilon sampling, we can consistently
        # reproduce all result values.

        # When these values are compared to the results computed by a similar
        # config which takes the 'mean-based' path (with CoVs = 0), we expect
        # the following:
        # All of the mean values in the 'sample-based' results should be with
        # 5%, + or -, of the 'mean-based' results.
        # The standard deviation values of the 'sample-based' results should
        # simply be greater than those produced with the 'mean-based' method.

        # For comparison, mean and stddev values for the region were computed
        # with 1000 GMFs using the mean-based approach. These values (rounded
        # to 2 decimal places) are:
        mb_mean_loss = 1233.26
        mb_stddev_loss = 443.63
        # Loss map for the mean-based approach:
        mb_loss_map = [
            dict(asset='a3',
                 pos='15.48 38.25',
                 mean=200.54874638,
                 stddev=94.2302991022),
            dict(asset='a2',
                 pos='15.56 38.17',
                 mean=510.821363253,
                 stddev=259.964152622),
            dict(asset='a1',
                 pos='15.48 38.09',
                 mean=521.885458891,
                 stddev=244.825980356),
        ]

        # Sanity checks are done. Let's do this.
        scen_cfg = helpers.demo_file(
            'scenario_risk/config_sample-based_qa.gem')
        result = helpers.run_job(scen_cfg, ['--output-type=xml'],
                                 check_output=True)

        job = OqJob.objects.latest('id')
        self.assertEqual('succeeded', job.status)

        expected_loss_map_file = helpers.demo_file(
            'scenario_risk/computed_output/loss-map-%s.xml' % job.id)
        self.assertTrue(os.path.exists(expected_loss_map_file))

        loss_map = helpers.loss_map_result_from_file(expected_loss_map_file)
        self._verify_loss_map_within_range(sorted(mb_loss_map),
                                           sorted(loss_map), 0.05)

        exp_mean_loss, exp_stddev_loss = helpers.mean_stddev_from_result_line(
            result)
        self.assertAlmostEqual(mb_mean_loss,
                               exp_mean_loss,
                               delta=mb_mean_loss * 0.05)
        self.assertTrue(exp_stddev_loss > mb_stddev_loss)