Example #1
0
    def test_del_calc(self):
        risk_job, _ = helpers.get_fake_risk_job(self.risk_cfg,
                                                self.hazard_cfg,
                                                output_type='curve',
                                                username=getpass.getuser())
        models.Output.objects.create_output(risk_job,
                                            'test_curves_1',
                                            output_type='loss_curve')
        models.Output.objects.create_output(risk_job,
                                            'test_curves_2',
                                            output_type='loss_curve')

        # Sanity check: make sure the risk calculation and outputs exist in
        # the database:
        risk_calcs = models.OqJob.objects.filter(id=risk_job.id)
        self.assertEqual(1, risk_calcs.count())

        outputs = models.Output.objects.filter(oq_job=risk_job.id)
        self.assertEqual(2, outputs.count())

        # Delete the calculation
        engine.del_calc(risk_job.id)

        # Check that the risk calculation and its outputs were deleted:
        outputs = models.Output.objects.filter(oq_job=risk_job.id)
        self.assertEqual(0, outputs.count())

        risk_calcs = models.OqJob.objects.filter(id=risk_job.id)
        self.assertEqual(0, risk_calcs.count())
Example #2
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            get_data_path('event_based_bcr/job.ini'),
            get_data_path('event_based_hazard/job.ini'), output_type="gmf")

        self.calculator = core.EventBasedBCRRiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
Example #3
0
 def setUp(self):
     self.job, _ = helpers.get_fake_risk_job(
         get_data_path('classical_psha_based_risk/job.ini'),
         get_data_path('simple_fault_demo_hazard/job.ini'))
     models.JobStats.objects.create(oq_job=self.job)
     self.job.is_running = True
     self.job.save()
Example #4
0
    def test_del_risk_calc(self):
        risk_job, _ = helpers.get_fake_risk_job(
            self.risk_cfg, self.hazard_cfg,
            output_type='curve', username=getpass.getuser()
        )
        risk_calc = risk_job.risk_calculation

        models.Output.objects.create_output(
            risk_job, 'test_curves_1', output_type='loss_curve'
        )
        models.Output.objects.create_output(
            risk_job, 'test_curves_2', output_type='loss_curve'
        )

        # Sanity check: make sure the risk calculation and outputs exist in
        # the database:
        risk_calcs = models.RiskCalculation.objects.filter(
            id=risk_calc.id
        )
        self.assertEqual(1, risk_calcs.count())

        outputs = models.Output.objects.filter(oq_job=risk_job.id)
        self.assertEqual(2, outputs.count())

        # Delete the calculation
        engine.del_risk_calc(risk_calc.id)

        # Check that the risk calculation and its outputs were deleted:
        outputs = models.Output.objects.filter(oq_job=risk_job.id)
        self.assertEqual(0, outputs.count())

        risk_calcs = models.RiskCalculation.objects.filter(
            id=risk_calc.id
        )
        self.assertEqual(0, risk_calcs.count())
Example #5
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            get_data_path('classical_bcr/job.ini'),
            get_data_path('simple_fault_demo_hazard/job.ini'))

        self.calculator = classical_bcr.ClassicalBCRRiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
Example #6
0
 def setUp(self):
     self.job, _ = helpers.get_fake_risk_job(
         get_data_path('classical_psha_based_risk/job.ini'),
         get_data_path('simple_fault_demo_hazard/job.ini'))
     models.JobStats.objects.create(oq_job=self.job)
     self.job.is_running = True
     self.job.save()
Example #7
0
 def test_del_calc_no_access(self):
     # Test the case where we try to delete a risk calculation which does
     # not belong to current user.
     # In this case, deletion is now allowed and should raise an exception.
     risk_job, _ = helpers.get_fake_risk_job(
         self.risk_cfg, self.hazard_cfg,
         output_type='curve', username=helpers.random_string()
     )
     self.assertRaises(RuntimeError, engine.del_calc, risk_job.id)
Example #8
0
 def test_del_calc_output_referenced_by_risk_calc(self):
     # Test the case where a risk calculation is referencing one of the
     # belonging to the hazard calculation we want to delete.
     # In this case, deletion is not allowed and should raise an exception.
     risk_job, _ = helpers.get_fake_risk_job(self.risk_cfg,
                                             self.hazard_cfg,
                                             output_type='curve',
                                             username=getpass.getuser())
     hc = risk_job.hazard_calculation
     self.assertRaises(RuntimeError, engine.del_calc, hc.id)
Example #9
0
 def test_del_calc_no_access(self):
     # Test the case where we try to delete a risk calculation which does
     # not belong to current user.
     # In this case, deletion is now allowed and should raise an exception.
     risk_job, _ = helpers.get_fake_risk_job(
         self.risk_cfg,
         self.hazard_cfg,
         output_type='curve',
         username=helpers.random_string())
     self.assertRaises(RuntimeError, engine.del_calc, risk_job.id)
Example #10
0
 def test_del_haz_calc_output_referenced_by_risk_calc(self):
     # Test the case where a risk calculation is referencing one of the
     # belonging to the hazard calculation we want to delete.
     # In this case, deletion is not allowed and should raise an exception.
     risk_job, _ = helpers.get_fake_risk_job(
         self.risk_cfg, self.hazard_cfg,
         output_type='curve', username=getpass.getuser()
     )
     hazard_job = risk_job.risk_calculation.hazard_output.oq_job
     self.assertRaises(RuntimeError, engine.del_haz_calc, hazard_job.id)
Example #11
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            get_data_path('event_based_risk/job.ini'),
            get_data_path('event_based_hazard/job.ini'), output_type="gmf")

        self.calculator = event_based.EventBasedRiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
        self.calculator.pre_execute()
        self.job.is_running = True
        self.job.status = 'executing'
        self.job.save()
Example #12
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            get_data_path('scenario_risk/job.ini'),
            get_data_path('scenario_hazard/job.ini'),
            output_type="gmf_scenario")

        self.calculator = scenario.ScenarioRiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
        self.job.is_running = True
        self.job.save()
        self.calculator.pre_execute()
        self.job.status = 'executing'
        self.job.save()
 def setUp(self):
     job, _ = helpers.get_fake_risk_job(
         get_data_path('classical_psha_based_risk/job.ini'),
         get_data_path('simple_fault_demo_hazard/job.ini')
     )
     self.compulsory_arguments = dict(
         lrem_steps_per_interval=5)
     self.other_args = dict(
         calculation_mode="classical",
         region_constraint=(
             'POLYGON((-122.0 38.113, -122.114 38.113, -122.57 38.111, '
             '-122.0 38.113))'),
         hazard_output=job.risk_calculation.hazard_output)
Example #14
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            self.risk_demo, self.hazard_demo, self.hazard_output_type)

        # need to run pre-execute to parse exposure model
        calc = RiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
        calc.pre_execute()

        self._assets = models.ExposureData.objects.filter(
            exposure_model=self.job.risk_calculation.exposure_model).order_by(
                'asset_ref')

        self.getter = self.getter_class(self.ho(), self.assets(), 500, "PGA")
Example #15
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            get_data_path("classical_psha_based_risk/job.ini"), get_data_path("simple_fault_demo_hazard/job.ini")
        )
        calculator = base.RiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
        calculator.pre_execute()
        self.rc = self.job.risk_calculation

        common_fake_args = dict(exposure_model=self.rc.exposure_model, taxonomy="test")

        asset = models.ExposureData(site=Point(0.5, 0.5), asset_ref="test1", **common_fake_args)
        asset.save()

        asset = models.ExposureData(site=Point(179.1, 0), asset_ref="test2", **common_fake_args)
        asset.save()
Example #16
0
    def test_del_haz_calc_referenced_by_risk_calc(self):
        # Test the case where a risk calculation is referencing the hazard
        # calculation we want to delete.
        # In this case, deletion is not allowed and should raise an exception.
        risk_job, _ = helpers.get_fake_risk_job(
            self.risk_cfg, self.hazard_cfg,
            output_type='curve', username=getpass.getuser()
        )
        risk_calc = risk_job.risk_calculation

        hazard_job = risk_job.risk_calculation.hazard_output.oq_job
        hazard_calc = hazard_job.hazard_calculation

        risk_calc.hazard_output = None
        risk_calc.hazard_calculation = hazard_calc
        risk_calc.save(using='admin')

        self.assertRaises(RuntimeError, engine.del_haz_calc, hazard_calc.id)
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            self.risk_demo, self.hazard_demo, self.hazard_output_type)

        # need to run pre-execute to parse exposure model
        calc = RiskCalculator(self.job)
        self.job.is_running = True
        self.job.save()
        calc.pre_execute()

        self.builder = hazard_getters.RiskInitializer(
            self.taxonomy, calc)
        self.builder.init_assocs()

        assocs = models.AssetSite.objects.filter(job=self.job)
        self.assets = models.ExposureData.objects.get_asset_chunk(
            calc.exposure_model, calc.time_event, assocs)
        self.getter = self.getter_class(
            self.imt, self.taxonomy, calc.get_hazard_outputs(), self.assets)
Example #18
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            get_data_path('classical_psha_based_risk/job.ini'),
            get_data_path('simple_fault_demo_hazard/job.ini'))
        calculator = base.RiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
        calculator.pre_execute()

        common_fake_args = dict(exposure_model=self.job.exposure_model,
                                taxonomy="test")

        asset = models.ExposureData(site=Point(0.5, 0.5),
                                    asset_ref="test1",
                                    **common_fake_args)
        asset.save()

        asset = models.ExposureData(site=Point(179.1, 0),
                                    asset_ref="test2",
                                    **common_fake_args)
        asset.save()
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            self.risk_demo, self.hazard_demo, self.hazard_output_type)

        # need to run pre-execute to parse exposure model
        calc = RiskCalculator(self.job)
        models.JobStats.objects.create(oq_job=self.job)
        self.job.is_running = True
        self.job.save()
        calc.pre_execute()

        self.builder = hazard_getters.GetterBuilder(
            self.taxonomy, self.job.risk_calculation)

        self.assets = models.ExposureData.objects.filter(
            exposure_model=self.job.risk_calculation.exposure_model).order_by(
            'asset_ref').filter(taxonomy=self.taxonomy)

        ho = self.job.risk_calculation.hazard_output
        self.nbytes = self.builder.calc_nbytes([ho])
        [self.getter] = self.builder.make_getters(
            self.getter_class, [ho], self.assets)
Example #20
0
    def setUp(self):
        self.job, _ = helpers.get_fake_risk_job(
            self.risk_demo, self.hazard_demo, self.hazard_output_type)
        models.JobParam.objects.create(
            job=self.job, name='intensity_measure_types',
            value=repr([self.imt]))

        # need to run pre-execute to parse exposure model
        calc = RiskCalculator(self.job)
        self.job.is_running = True
        self.job.save()
        calc.pre_execute()

        self.builder = hazard_getters.RiskInitializer(
            self.taxonomy, calc.rc)
        self.builder.init_assocs()

        assocs = models.AssetSite.objects.filter(job=self.job)
        self.assets = models.ExposureData.objects.get_asset_chunk(
            calc.rc, assocs)
        self.nbytes = self.builder.calc_nbytes()
        self.builder.init_epsilons()
        self.getter = self.getter_class(
            self.imt, self.taxonomy, calc.rc.hazard_outputs(), self.assets)
 def setUp(self):
     self.job, _ = helpers.get_fake_risk_job(
         get_data_path('event_based_risk/job.ini'),
         get_data_path('event_based_hazard/job.ini')
     )