Esempio n. 1
0
class LossMapCurveSerialization(unittest.TestCase):

    def setUp(self):
        cfg_path = helpers.demo_file(
            'probabilistic_event_based_risk/config.gem')

        job_profile, params, sections = engine.import_job_profile(cfg_path)

        calc_proxy = engine.CalculationProxy(
            params, 1, sections=sections, base_path='/tmp',
            serialize_results_to=['db', 'xml'],
            oq_job_profile=job_profile)
        calc_proxy.blocks_keys = []

        self.calculator = EventBasedRiskCalculator(calc_proxy)
        self.calculator.store_exposure_assets = lambda: None
        self.calculator.store_vulnerability_model = lambda: None
        self.calculator.partition = lambda: None

    def test_loss_map_serialized_if_conditional_loss_poes(self):
        self.calculator.calc_proxy.params['CONDITIONAL_LOSS_POE'] = (
            '0.01 0.02')

        with helpers.patch('openquake.calculators.risk.event_based.core'
                           '.plot_aggregate_curve'):
            with helpers.patch(
                'openquake.output.risk.create_loss_map_writer') as clw:

                clw.return_value = None

                self.calculator.execute()
                self.assertTrue(clw.called)

    def test_loss_map_not_serialized_unless_conditional_loss_poes(self):
        with helpers.patch('openquake.calculators.risk.event_based.core'
                           '.plot_aggregate_curve'):
            with helpers.patch(
                'openquake.output.risk.create_loss_map_writer') as clw:

                clw.return_value = None

                self.calculator.execute()
                self.assertFalse(clw.called)
class LossMapCurveSerialization(unittest.TestCase):
    def setUp(self):
        cfg_path = helpers.demo_file("probabilistic_event_based_risk/config.gem")

        job = engine.prepare_job()
        jp, params, sections = engine.import_job_profile(cfg_path, job)

        job_ctxt = engine.JobContext(
            params,
            1,
            sections=sections,
            base_path="/tmp",
            serialize_results_to=["db", "xml"],
            oq_job_profile=jp,
            oq_job=job,
        )
        job_ctxt.blocks_keys = []

        self.calculator = EventBasedRiskCalculator(job_ctxt)
        self.calculator.store_exposure_assets = lambda: None
        self.calculator.store_fragility_model = lambda: None
        self.calculator.store_vulnerability_model = lambda: None
        self.calculator.partition = lambda: None

    def test_loss_map_serialized_if_conditional_loss_poes(self):
        self.calculator.job_ctxt.params["CONDITIONAL_LOSS_POE"] = "0.01 0.02"

        with helpers.patch("openquake.output.risk.create_loss_map_writer") as clw:

            clw.return_value = None

            self.calculator.execute()
            self.calculator.post_execute()
            self.assertTrue(clw.called)

    def test_loss_map_not_serialized_unless_conditional_loss_poes(self):
        with helpers.patch("openquake.output.risk.create_loss_map_writer") as clw:

            clw.return_value = None

            self.calculator.execute()
            self.assertFalse(clw.called)
Esempio n. 3
0
class LossMapCurveSerialization(unittest.TestCase):

    def setUp(self):
        cfg_path = helpers.demo_file(
            'probabilistic_event_based_risk/config.gem')

        job = engine.prepare_job()
        jp, params, sections = engine.import_job_profile(cfg_path, job)

        job_ctxt = engine.JobContext(
            params, 1, sections=sections, base_path='/tmp',
            serialize_results_to=['db', 'xml'], oq_job_profile=jp, oq_job=job)
        job_ctxt.blocks_keys = []

        self.calculator = EventBasedRiskCalculator(job_ctxt)
        self.calculator.store_exposure_assets = lambda: None
        self.calculator.store_fragility_model = lambda: None
        self.calculator.store_vulnerability_model = lambda: None
        self.calculator.partition = lambda: None

    def test_loss_map_serialized_if_conditional_loss_poes(self):
        self.calculator.job_ctxt.params['CONDITIONAL_LOSS_POE'] = (
            '0.01 0.02')

        with helpers.patch(
            'openquake.output.risk.create_loss_map_writer') as clw:

            clw.return_value = None

            self.calculator.execute()
            self.calculator.post_execute()
            self.assertTrue(clw.called)

    def test_loss_map_not_serialized_unless_conditional_loss_poes(self):
        with helpers.patch(
            'openquake.output.risk.create_loss_map_writer') as clw:

            clw.return_value = None

            self.calculator.execute()
            self.assertFalse(clw.called)