Exemplo n.º 1
0
    def test_spatial_correlation(self):
        expected = {sc1: [0.99, 0.41], sc2: [0.99, 0.64], sc3: [0.99, 0.22]}

        for case in expected:
            self.run_calc(case.__file__, 'job.ini')
            oq = self.calc.oqparam
            self.assertEqual(list(oq.imtls), ['PGA'])
            dstore = DataStore(self.calc.datastore.calc_id)
            gmf_by_rupid = groupby(
                dstore['gmfs/col00'].value, lambda row: row['idx'],
                lambda rows: [row['BooreAtkinson2008']['PGA'] for row in rows])
            dstore.close()
            gmvs_site_1 = []
            gmvs_site_2 = []
            for rupid, gmf in gmf_by_rupid.items():
                gmvs_site_1.append(gmf[0])
                gmvs_site_2.append(gmf[1])
            joint_prob_0_5 = joint_prob_of_occurrence(
                gmvs_site_1, gmvs_site_2, 0.5, oq.investigation_time,
                oq.ses_per_logic_tree_path)
            joint_prob_1_0 = joint_prob_of_occurrence(
                gmvs_site_1, gmvs_site_2, 1.0, oq.investigation_time,
                oq.ses_per_logic_tree_path)

            p05, p10 = expected[case]
            numpy.testing.assert_almost_equal(joint_prob_0_5, p05, decimal=1)
            numpy.testing.assert_almost_equal(joint_prob_1_0, p10, decimal=1)
Exemplo n.º 2
0
 def test_parent(self):
     # copy the attributes of the parent datastore on the child datastore,
     # without overriding the attributes with the same name
     self.dstore.attrs['a'] = 2
     parent = DataStore(params=[('a', 1), ('b', 2)])
     self.dstore.set_parent(parent)
     attrs = sorted(self.dstore.attrs.items())
     self.assertEqual(attrs, [('a', 2), ('b', 2)])
Exemplo n.º 3
0
 def test_case_1(self):
     # test for the fatalities
     self.run_calc(case_1.__file__, 'job_ebr.ini')
     ds = DataStore(self.calc.datastore.calc_id,
                    export_dir=self.calc.datastore.export_dir)
     fnames = export(('assetcol', 'csv'), ds) + export(
         ('event_loss_table-rlzs', 'csv'), ds)
     for fname in fnames:
         self.assertEqualFiles('expected/' + os.path.basename(fname), fname)
Exemplo n.º 4
0
def get_mesh(oqparam):
    """
    Extract the mesh of points to compute from the sites,
    the sites_csv, or the region.

    :param oqparam:
        an :class:`openquake.commonlib.oqvalidation.OqParam` instance
    """
    if oqparam.sites:
        lons, lats = zip(*sorted(oqparam.sites))
        return geo.Mesh(numpy.array(lons), numpy.array(lats))
    elif 'sites' in oqparam.inputs:
        csv_data = open(oqparam.inputs['sites'], 'U').read()
        coords = valid.coordinates(
            csv_data.strip().replace(',', ' ').replace('\n', ','))
        lons, lats = zip(*sorted(coords))
        return geo.Mesh(numpy.array(lons), numpy.array(lats))
    elif oqparam.region:
        # close the linear polygon ring by appending the first
        # point to the end
        firstpoint = geo.Point(*oqparam.region[0])
        points = [geo.Point(*xy) for xy in oqparam.region] + [firstpoint]
        try:
            mesh = geo.Polygon(points).discretize(oqparam.region_grid_spacing)
            lons, lats = zip(*sorted(zip(mesh.lons, mesh.lats)))
            return geo.Mesh(numpy.array(lons), numpy.array(lats))
        except:
            raise ValueError(
                'Could not discretize region %(region)s with grid spacing '
                '%(region_grid_spacing)s' % vars(oqparam))
    elif 'gmfs' in oqparam.inputs:
        return get_gmfs(oqparam)[0].mesh
    elif oqparam.hazard_calculation_id:
        sitemesh = DataStore(oqparam.hazard_calculation_id)['sitemesh']
        return geo.Mesh(sitemesh['lon'], sitemesh['lat'])
    elif 'exposure' in oqparam.inputs:
        # the mesh is extracted from get_sitecol_assets
        return
    elif 'site_model' in oqparam.inputs:
        coords = [(param.lon, param.lat) for param in get_site_model(oqparam)]
        lons, lats = zip(*sorted(coords))
        return geo.Mesh(numpy.array(lons), numpy.array(lats))
Exemplo n.º 5
0
    def test_spatial_correlation(self):
        expected = {sc1: [0.99, 0.41], sc2: [0.99, 0.64], sc3: [0.99, 0.22]}

        for case in expected:
            self.run_calc(case.__file__, 'job.ini')
            oq = self.calc.oqparam
            self.assertEqual(list(oq.imtls), ['PGA'])
            dstore = DataStore(self.calc.datastore.calc_id)
            gmfa = dstore['gmf_data/1']['BooreAtkinson2008']['PGA']
            dstore.close()
            gmvs_site_1 = gmfa[:, 0]
            gmvs_site_2 = gmfa[:, 1]
            joint_prob_0_5 = joint_prob_of_occurrence(
                gmvs_site_1, gmvs_site_2, 0.5, oq.investigation_time,
                oq.ses_per_logic_tree_path)
            joint_prob_1_0 = joint_prob_of_occurrence(
                gmvs_site_1, gmvs_site_2, 1.0, oq.investigation_time,
                oq.ses_per_logic_tree_path)

            p05, p10 = expected[case]
            numpy.testing.assert_almost_equal(joint_prob_0_5, p05, decimal=1)
            numpy.testing.assert_almost_equal(joint_prob_1_0, p10, decimal=1)
Exemplo n.º 6
0
 def setUp(self):
     self.dstore = DataStore()