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)
def test_del_risk_calc(self): risk_job, _ = helpers.get_fake_risk_job( self.risk_cfg, self.hazard_cfg, output_type='curves', 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())
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)
def test_with_input_type(self): job, files = helpers.get_fake_risk_job( get_data_path('classical_psha_based_risk/job.ini'), get_data_path('simple_fault_demo_hazard/job.ini')) rc = job.risk_calculation inputs = models.inputs4rcalc(rc.id, input_type='exposure') self.assertEqual(1, inputs.count())
def test_del_risk_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='curves', username=helpers.random_string() ) risk_calc = risk_job.risk_calculation self.assertRaises(RuntimeError, engine.del_risk_calc, risk_calc.id)
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)
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()
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='curves', username=getpass.getuser() ) hazard_job = risk_job.risk_calculation.hazard_output.oq_job hazard_calc = hazard_job.hazard_calculation self.assertRaises(RuntimeError, engine.del_haz_calc, hazard_calc.id)
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.calculator.pre_execute() self.job.is_running = True self.job.status = 'executing' self.job.save()
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()
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)
def test_a_few_inputs(self): job, files = helpers.get_fake_risk_job( get_data_path('classical_psha_based_risk/job.ini'), get_data_path('simple_fault_demo_hazard/job.ini')) rc = job.risk_calculation expected_ids = sorted([x.id for x in files.values()]) inputs = models.inputs4rcalc(rc.id) actual_ids = sorted([x.id for x in inputs]) self.assertEqual(expected_ids, actual_ids)
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")
def test_with_input_type(self): job, files = helpers.get_fake_risk_job( get_data_path('classical_psha_based_risk/job.ini'), get_data_path('simple_fault_demo_hazard/job.ini')) rc = job.risk_calculation # It should only be 1 id, actually. expected_ids = [x.id for x in files.values() if x.input_type == 'exposure'] inputs = models.inputs4rcalc(rc.id, input_type='exposure') actual_ids = sorted([x.id for x in inputs]) self.assertEqual(expected_ids, actual_ids)
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( calculation_mode="classical_bcr", lrem_steps_per_interval=5, interest_rate=0.05, asset_life_expectancy=40) self.other_args = dict( owner=helpers.default_user(), 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)
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()
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()
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)
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'))
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') )