def _verify_aggregate_curve(self): job = OqJob.objects.latest("id") [output] = Output.objects.filter(oq_job=job.id, output_type="agg_loss_curve") export_agg_loss_curve(output, OUTPUT_DIR) filename = "%s/aggregate_loss_curve.xml" % OUTPUT_DIR root = self._root(filename) xpath = "//nrml:aggregateLossCurve//nrml:poE" poes = [float(x) for x in self._get(root, xpath).split()] expected_poes = [ 1.0000000000, 1.0000000000, 0.9999991685, 0.9932621249, 0.9502177204, 0.8646647795, 0.8646752036, 0.6321506245, 0.6321525149 ] self.assertTrue( numpy.allclose(poes, expected_poes, atol=0.0, rtol=0.05)) xpath = "//nrml:aggregateLossCurve//nrml:loss" losses = [float(x) for x in self._get(root, xpath).split()] expected_losses = [ 18.5629274028, 55.6887822085, 92.8146370142, 129.9404918199, 167.0663466256, 204.1922014313, 241.3180562370, 278.4439110427, 315.5697658484 ] self.assertTrue( numpy.allclose(losses, expected_losses, atol=0.0, rtol=0.05))
def _verify_aggregate_curve(self): job = OqJob.objects.latest("id") [output] = Output.objects.filter( oq_job=job.id, output_type="agg_loss_curve") export_agg_loss_curve(output, OUTPUT_DIR) filename = "%s/aggregate_loss_curve.xml" % OUTPUT_DIR root = self._root(filename) xpath = "//nrml:aggregateLossCurve//nrml:poE" poes = [float(x) for x in self._get(root, xpath).split()] expected_poes = [1.0000000000, 1.0000000000, 0.9999991685, 0.9932621249, 0.9502177204, 0.8646647795, 0.8646752036, 0.6321506245, 0.6321525149] self.assertTrue(numpy.allclose( poes, expected_poes, atol=0.0, rtol=0.05)) xpath = "//nrml:aggregateLossCurve//nrml:loss" losses = [float(x) for x in self._get(root, xpath).split()] expected_losses = [18.5629274028, 55.6887822085, 92.8146370142, 129.9404918199, 167.0663466256, 204.1922014313, 241.3180562370, 278.4439110427, 315.5697658484] self.assertTrue(numpy.allclose( losses, expected_losses, atol=0.0, rtol=0.05))
def test_insured_loss_mean_based(self): try: cfg = helpers.qa_file( "probabilistic_event_based_risk/m_il_config.gem") self._run_job(cfg) job_id = OqJob.objects.latest("id").id [output] = Output.objects.filter(oq_job=job_id, output_type="agg_loss_curve") export_agg_loss_curve(output, QA_OUTPUT_DIR) expected_files = [ "loss_curves-block-#%s-block#0.xml" % job_id, "loss_curves-loss-block-#%s-block#0.xml" % job_id, "loss_curves-insured-block=#%s-block#0.xml" % job_id, "losses_at-0.99.xml", "aggregate_loss_curve.xml", "insured_loss_curves-insured-loss-block=#%s-block#0.xml" % job_id] self._verify_job_succeeded() self._verify_outputs(QA_OUTPUT_DIR, expected_files) expected_poes = {} expected_losses = {} expected_poes["a1"] = test_data.EXPECTED_POES_LR_A1_MB_IL expected_poes["a2"] = test_data.EXPECTED_POES_LR_A2_MB_IL expected_poes["a3"] = test_data.EXPECTED_POES_LR_A3_MB_IL expected_losses["a1"] = test_data.EXPECTED_LOSS_RATIOS_A1_MB_IL expected_losses["a2"] = test_data.EXPECTED_LOSS_RATIOS_A2_MB_IL expected_losses["a3"] = test_data.EXPECTED_LOSS_RATIOS_A3_MB_IL self._verify_loss_ratio_curves(expected_poes, expected_losses, QA_OUTPUT_DIR, 0.05, "%s/loss_curves-insured-block=#%s-block#0.xml") expected_poes["a1"] = test_data.EXPECTED_POES_LC_A1_MB_IL expected_poes["a2"] = test_data.EXPECTED_POES_LC_A2_MB_IL expected_poes["a3"] = test_data.EXPECTED_POES_LC_A3_MB_IL expected_losses["a1"] = test_data.EXPECTED_LOSSES_A1_MB_IL expected_losses["a2"] = test_data.EXPECTED_LOSSES_A2_MB_IL expected_losses["a3"] = test_data.EXPECTED_LOSSES_A3_MB_IL self._verify_loss_curves(expected_poes, expected_losses, QA_OUTPUT_DIR, 0.05, "%s/insured_loss_curves-insured-loss-block=#%s-block#0.xml") finally: rmtree(QA_OUTPUT_DIR)
def test_insured_loss_mean_based(self): try: cfg = helpers.qa_file( "probabilistic_event_based_risk/m_il_config.gem") self._run_job(cfg) job_id = OqJob.objects.latest("id").id [output] = Output.objects.filter(oq_job=job_id, output_type="agg_loss_curve") export_agg_loss_curve(output, QA_OUTPUT_DIR) expected_files = [ "loss_curves-block-#%s-block#0.xml" % job_id, "loss_curves-loss-block-#%s-block#0.xml" % job_id, "loss_curves-insured-block=#%s-block#0.xml" % job_id, "losses_at-0.99.xml", "aggregate_loss_curve.xml", "insured_loss_curves-insured-loss-block=#%s-block#0.xml" % job_id ] self._verify_job_succeeded() self._verify_outputs(QA_OUTPUT_DIR, expected_files) expected_poes = {} expected_losses = {} expected_poes["a1"] = test_data.EXPECTED_POES_LR_A1_MB_IL expected_poes["a2"] = test_data.EXPECTED_POES_LR_A2_MB_IL expected_poes["a3"] = test_data.EXPECTED_POES_LR_A3_MB_IL expected_losses["a1"] = test_data.EXPECTED_LOSS_RATIOS_A1_MB_IL expected_losses["a2"] = test_data.EXPECTED_LOSS_RATIOS_A2_MB_IL expected_losses["a3"] = test_data.EXPECTED_LOSS_RATIOS_A3_MB_IL self._verify_loss_ratio_curves( expected_poes, expected_losses, QA_OUTPUT_DIR, 0.05, "%s/loss_curves-insured-block=#%s-block#0.xml") expected_poes["a1"] = test_data.EXPECTED_POES_LC_A1_MB_IL expected_poes["a2"] = test_data.EXPECTED_POES_LC_A2_MB_IL expected_poes["a3"] = test_data.EXPECTED_POES_LC_A3_MB_IL expected_losses["a1"] = test_data.EXPECTED_LOSSES_A1_MB_IL expected_losses["a2"] = test_data.EXPECTED_LOSSES_A2_MB_IL expected_losses["a3"] = test_data.EXPECTED_LOSSES_A3_MB_IL self._verify_loss_curves( expected_poes, expected_losses, QA_OUTPUT_DIR, 0.05, "%s/insured_loss_curves-insured-loss-block=#%s-block#0.xml") finally: rmtree(QA_OUTPUT_DIR)
def _verify_aggregate_curve(self, expected_poes, expected_losses, output_dir, tol): job = OqJob.objects.latest("id") [output] = Output.objects.filter( oq_job=job.id, output_type="agg_loss_curve") export_agg_loss_curve(output, output_dir) filename = "%s/aggregate_loss_curve.xml" % output_dir root = self._root(filename) xpath = "//nrml:aggregateLossCurve//nrml:poE" poes = [float(x) for x in self._get(root, xpath).split()] self.assertTrue(numpy.allclose( poes, expected_poes, atol=0.0, rtol=tol)) xpath = "//nrml:aggregateLossCurve//nrml:loss" losses = [float(x) for x in self._get(root, xpath).split()] self.assertTrue(numpy.allclose( losses, expected_losses, atol=0.0, rtol=0.05))
def _verify_aggregate_curve(self, expected_poes, expected_losses, output_dir, tol): job = OqJob.objects.latest("id") [output] = Output.objects.filter(oq_job=job.id, output_type="agg_loss_curve") export_agg_loss_curve(output, output_dir) filename = "%s/aggregate_loss_curve.xml" % output_dir root = self._root(filename) xpath = "//nrml:aggregateLossCurve//nrml:poE" poes = [float(x) for x in self._get(root, xpath).split()] self.assertTrue(numpy.allclose(poes, expected_poes, atol=0.0, rtol=tol)) xpath = "//nrml:aggregateLossCurve//nrml:loss" losses = [float(x) for x in self._get(root, xpath).split()] self.assertTrue( numpy.allclose(losses, expected_losses, atol=0.0, rtol=0.05))