def test_assets_for_cell_with_one(self): # A single asset in the risk cell is found. site = shapes.Site(10.15, 46.15) self.job_ctxt.oq_job_profile.region_grid_spacing = 0.3 self.job_ctxt.oq_job_profile.save() [asset] = BaseRiskCalculator.assets_for_cell(self.job.id, site) self.assertEqual(self.sites[1], self._to_site(asset.site))
def test_assets_for_cell_with_one(self): # A single asset in the risk cell is found. site = shapes.Site(10.15, 46.15) self.job_ctxt.oq_job_profile.region_grid_spacing = 0.3 self.job_ctxt.oq_job_profile.save() [asset] = BaseRiskCalculator.assets_for_cell(self.job.id, site) self.assertEqual(self.sites[1], self._to_site(asset.site))
def test_assets_for_cell_with_no_assets_matching(self): # An empty list is returned when no assets exist for a given # risk cell. site = shapes.Site(99.15000, 15.16667) self.job_ctxt.oq_job_profile.region_grid_spacing = 0.05 self.job_ctxt.oq_job_profile.save() self.assertEqual([], BaseRiskCalculator.assets_for_cell(self.job.id, site))
def test_assets_for_cell_with_no_assets_matching(self): # An empty list is returned when no assets exist for a given # risk cell. site = shapes.Site(99.15000, 15.16667) self.job_ctxt.oq_job_profile.region_grid_spacing = 0.05 self.job_ctxt.oq_job_profile.save() self.assertEqual([], BaseRiskCalculator.assets_for_cell(self.job.id, site))
def test_assets_for_cell_with_more_than_one(self): # All assets in the risk cell are found. site = shapes.Site(10.3, 46.3) self.job_ctxt.oq_job_profile.region_grid_spacing = 0.6 self.job_ctxt.oq_job_profile.save() assets = BaseRiskCalculator.assets_for_cell(self.job.id, site) self.assertEqual(3, len(assets)) # Make sure the assets associated with the first 3 added sites were # selected. for s, a in zip(self.sites, sorted(assets, key=lambda a: a.site.x)): self.assertEqual(s, self._to_site(a.site))
def test_assets_for_cell_with_more_than_one(self): # All assets in the risk cell are found. site = shapes.Site(10.3, 46.3) self.job_ctxt.oq_job_profile.region_grid_spacing = 0.6 self.job_ctxt.oq_job_profile.save() assets = BaseRiskCalculator.assets_for_cell(self.job.id, site) self.assertEqual(3, len(assets)) # Make sure the assets associated with the first 3 added sites were # selected. for s, a in zip(self.sites, sorted(assets, key=lambda a: a.site.x)): self.assertEqual(s, self._to_site(a.site))
def test_compute_risk_in_the_classical_psha_calculator(self): """ tests ClassicalRiskCalculator.compute_risk by retrieving all the loss curves in the kvs and checks their presence """ helpers.delete_profile(self.job) cls_risk_cfg = helpers.demo_file( 'classical_psha_based_risk/config.gem') job_profile, params, sections = engine.import_job_profile( cls_risk_cfg, self.job) # We need to adjust a few of the parameters for this test: params['REGION_VERTEX'] = '0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0' job_profile.region = GEOSGeometry(shapes.polygon_ewkt_from_coords( params['REGION_VERTEX'])) job_profile.save() job_ctxt = engine.JobContext( params, self.job_id, sections=sections, oq_job_profile=job_profile) self._compute_risk_classical_psha_setup() calculator = classical_core.ClassicalRiskCalculator(job_ctxt) calculator.vuln_curves = {"ID": self.vuln_function} block = Block.from_kvs(self.job_id, self.block_id) # computes the loss curves and puts them in kvs calculator.compute_risk(self.block_id) for point in block.grid(job_ctxt.region): assets = BaseRiskCalculator.assets_for_cell( self.job_id, point.site) for asset in assets: loss_ratio_key = kvs.tokens.loss_ratio_key( self.job_id, point.row, point.column, asset.asset_ref) self.assertTrue(kvs.get_client().get(loss_ratio_key)) loss_key = kvs.tokens.loss_curve_key( self.job_id, point.row, point.column, asset.asset_ref) self.assertTrue(kvs.get_client().get(loss_key))