Exemple #1
0
    def test_filters(self):
        def source_site_filter(sources_sites):
            for source, sites in sources_sites:
                if source is self.source2:
                    continue
                yield source, sites
        def rupture_site_filter(rupture_sites):
            for rupture, sites in rupture_sites:
                if rupture.mag < 6:
                    continue
                yield rupture, sites

        mags, dists, lons, \
        lats, joint_probs, trts, trt_bins = disagg._collect_bins_data(
            self.sources, self.site, self.imt, self.iml, self.gsims,
            self.tom, self.truncation_level, n_epsilons=3,
            source_site_filter=source_site_filter,
            rupture_site_filter=rupture_site_filter
        )

        aae = numpy.testing.assert_array_equal
        aaae = numpy.testing.assert_array_almost_equal

        aae(mags, [9, 6, 6, 6])
        aae(dists, [14, 12, 12, 11])
        aae(lons, [21, 22, 21, 22])
        aae(lats, [44, 44, 44, 45])
        aaae(joint_probs, [[0., 0., 0.],
                           [0.03, 0.04, 0.03],
                           [0., 0., 0.01],
                           [0., 0., 0.]])
        aae(trts, [0, 0, 0, 0])
        self.assertEqual(trt_bins, ['trt1'])
Exemple #2
0
    def test_no_filters(self):
        mags, dists, lons, \
        lats, joint_probs, trts, trt_bins = disagg._collect_bins_data(
            self.sources, self.site, self.imt, self.iml, self.gsims,
            self.tom, self.truncation_level, n_epsilons=3,
            source_site_filter=filters.source_site_noop_filter,
            rupture_site_filter=filters.rupture_site_noop_filter
        )

        aae = numpy.testing.assert_array_equal
        aaae = numpy.testing.assert_array_almost_equal

        aae(mags, [5, 5, 5, 5, 9, 5, 5, 5, 6, 6, 6, 8, 7])
        aae(dists, [3, 11, 12, 13, 14, 11, 11, 10, 12, 12, 11, 5, 5])
        aae(lons, [22, 22, 22, 22, 21, 21, 21, 21, 22, 21, 22, 11, 11])
        aae(lats, [44, 44, 45, 45, 44, 44, 45, 45, 44, 44, 45, 45, 46])
        aaae(joint_probs, [[0., 0., 0.],
                           [0.02, 0.04, 0.02],
                           [0., 0., 0.003],
                           [0., 0.0165, 0.00033],
                           [0., 0., 0.],
                           [0., 0., 0.001],
                           [0.0212, 0.053, 0.0212],
                           [0.0132, 0.0198, 0.0132],
                           [0.03, 0.04, 0.03],
                           [0., 0., 0.01],
                           [0., 0., 0.],
                           [0., 0.004, 0.0016],
                           [0.003, 0.015, 0.003]])
        aae(trts, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1])
        self.assertEqual(trt_bins, ['trt1', 'trt2'])