def test_expand_2d(self): col = SiteCollection(self.SITES) col.indices = numpy.array([1, 3, 5, 6]) data_condensed = numpy.array([[1, 2, 3], [5, 6, 7], [10, 11, 12], [15, 16, 17]]) data_expanded = col.expand(data_condensed, total_sites=8, placeholder=-1) data_expanded_expected = numpy.array([[-1, -1, -1], [1, 2, 3], [-1, -1, -1], [5, 6, 7], [-1, -1, -1], [10, 11, 12], [15, 16, 17], [-1, -1, -1]]) numpy.testing.assert_array_equal(data_expanded, data_expanded_expected)
def test_sites_of_interest(self): calc = hazard_getters.GroundMotionValuesCalcGetter( self.imt, self.sites, self.sites_assets, 0, self.gsims, None) r = ProbabilisticRupture( mag=5.5, rake=123.45, tectonic_region_type=mock.Mock(), hypocenter=Point(5, 6, 7), surface=PlanarSurface(10, 11, 12, Point(0, 0, 1), Point(1, 0, 1), Point(1, 0, 2), Point(0, 0, 2) ), occurrence_rate=1, temporal_occurrence_model=mock.Mock(), source_typology=mock.Mock()) r.source_typology.filter_sites_by_distance_to_rupture = mock.Mock( return_value=None) sites, _idxs = calc.sites_of_interest(r, 0) self.assertEqual([], sites) ret = SiteCollection(list(iter(self.sites))) ret.indices = [1] r.source_typology.filter_sites_by_distance_to_rupture = mock.Mock( return_value=ret) sites, idxs = calc.sites_of_interest(r, 100) self.assertEqual(1, len(sites)) self.assertEqual(1, len(idxs)) self.assertEqual(1, idxs[0]) self.assertEqual(1, sites.get_by_id(1).id) ret.indices = [0, 2] r.source_typology.filter_sites_by_distance_to_rupture = mock.Mock( return_value=ret) sites, idxs = calc.sites_of_interest(r, 1000) self.assertEqual(2, len(sites)) self.assertEqual([0, 2], idxs)
def test_expand_2d(self): col = SiteCollection(self.SITES) col.indices = numpy.array([1, 3, 5, 6]) data_condensed = numpy.array([ [1, 2, 3], [5, 6, 7], [10, 11, 12], [15, 16, 17] ]) data_expanded = col.expand(data_condensed, total_sites=8, placeholder=-1) data_expanded_expected = numpy.array([ [-1, -1, -1], [1, 2, 3], [-1, -1, -1], [5, 6, 7], [-1, -1, -1], [10, 11, 12], [15, 16, 17], [-1, -1, -1] ]) numpy.testing.assert_array_equal(data_expanded, data_expanded_expected)