def _rup_to_point(distance, surface, origin, azimuth, distance_type='rjb', iter_stop=1E-3, maxiter=1000): """ Place a point at a given distance from a rupture along a specified azimuth """ pt0 = origin pt1 = origin.point_at(distance, 0., azimuth) #print pt0, pt1 r_diff = np.inf dip = surface.dip sin_dip = np.sin(np.radians(dip)) dist_sin_dip = distance / sin_dip #max_surf_dist = surface.width / np.cos(np.radians(dip)) iterval = 0 while (np.fabs(r_diff) >= iter_stop) and (iterval <= maxiter): pt1mesh = Mesh(np.array([pt1.longitude]), np.array([pt1.latitude]), None) if distance_type == 'rjb' or np.fabs(dip - 90.0) < 1.0E-3: r_diff = (distance - surface.get_joyner_boore_distance(pt1mesh)).flatten() pt0 = Point(pt1.longitude, pt1.latitude) if r_diff > 0.: pt1 = pt0.point_at(r_diff, 0., azimuth) else: pt1 = pt0.point_at(np.fabs(r_diff), 0., (azimuth + 180.) % 360.) elif distance_type == 'rrup': rrup = surface.get_min_distance(pt1mesh).flatten() if azimuth >= 0.0 and azimuth <= 180.0: # On hanging wall r_diff = dist_sin_dip - (rrup / sin_dip) else: # On foot wall r_diff = distance - rrup pt0 = Point(pt1.longitude, pt1.latitude) #print azimuth, (azimuth + 180.0) % 360, rrup, r_diff, np.fabs(r_diff) if r_diff > 0.: pt1 = pt0.point_at(r_diff, 0., azimuth) else: pt1 = pt0.point_at(np.fabs(r_diff), 0., (azimuth + 180.) % 360.) else: raise ValueError('Distance type must be rrup or rjb!') iterval += 1 return pt1
class PointSourceRuptureFilterTestCase(unittest.TestCase): SITES = PointSourceSourceFilterTestCase.SITES def setUp(self): super(PointSourceRuptureFilterTestCase, self).setUp() self.hypocenter = Point(2, 0, 50) self.sitecol = SiteCollection(self.SITES) def _make_rupture(self, width, length, dip): mid_left = self.hypocenter.point_at(length / 2.0, 0, azimuth=270) mid_right = self.hypocenter.point_at(length / 2.0, 0, azimuth=90) hwidth = width * numpy.cos(numpy.radians(dip)) / 2.0 vwidth = width * numpy.sin(numpy.radians(dip)) / 2.0 top_left = mid_left.point_at(hwidth, -vwidth, azimuth=0) bottom_left = mid_left.point_at(hwidth, vwidth, azimuth=180) top_right = mid_right.point_at(hwidth, -vwidth, azimuth=0) bottom_right = mid_right.point_at(hwidth, vwidth, azimuth=180) surface = PlanarSurface(1, 2, dip, top_left, top_right, bottom_right, bottom_left) rupture = ProbabilisticRupture( mag=1, rake=2, tectonic_region_type=TRT.VOLCANIC, hypocenter=self.hypocenter, surface=surface, source_typology=PointSource, occurrence_rate=3, temporal_occurrence_model=PoissonTOM(1) ) return rupture def test_zero_integration_distance(self): rup = self._make_rupture(10, 15, 45) # 8 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=0, sites=self.sitecol ) self.assertIsInstance(filtered, SiteCollection) self.assertIsNot(filtered, self.sitecol) numpy.testing.assert_array_equal(filtered.indices, [0]) numpy.testing.assert_array_equal(filtered.vs30, [0.1]) rup = self._make_rupture(50, 30, 90) # 14.8 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=0, sites=self.sitecol ) numpy.testing.assert_array_equal(filtered.indices, [0, 1]) def test_495_km(self): rup = self._make_rupture(5, 8, 5) # 4.68 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=495, sites=self.sitecol ) numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2, 3]) rup = self._make_rupture(7, 10, 30) # 5.8 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=495, sites=self.sitecol ) self.assertIs(filtered.indices, None) self.assertIs(filtered, self.sitecol) def test_filter_all_out(self): rup = self._make_rupture(50, 80, 9) # 46.64 km radius self.hypocenter.longitude = 11.515 for int_dist in (0, 1, 10, 100, 1000): filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=int_dist, sites=self.sitecol ) self.assertIs(filtered, None)
class PointSourceRuptureFilterTestCase(unittest.TestCase): SITES = PointSourceSourceFilterTestCase.SITES def setUp(self): super(PointSourceRuptureFilterTestCase, self).setUp() self.hypocenter = Point(2, 0, 50) self.sitecol = SiteCollection(self.SITES) def _make_rupture(self, width, length, dip): mid_left = self.hypocenter.point_at(length / 2.0, 0, azimuth=270) mid_right = self.hypocenter.point_at(length / 2.0, 0, azimuth=90) hwidth = width * numpy.cos(numpy.radians(dip)) / 2.0 vwidth = width * numpy.sin(numpy.radians(dip)) / 2.0 top_left = mid_left.point_at(hwidth, -vwidth, azimuth=0) bottom_left = mid_left.point_at(hwidth, vwidth, azimuth=180) top_right = mid_right.point_at(hwidth, -vwidth, azimuth=0) bottom_right = mid_right.point_at(hwidth, vwidth, azimuth=180) surface = PlanarSurface(1, 2, dip, top_left, top_right, bottom_right, bottom_left) rupture = ParametricProbabilisticRupture( mag=1, rake=2, tectonic_region_type=TRT.VOLCANIC, hypocenter=self.hypocenter, surface=surface, source_typology=PointSource, occurrence_rate=3, temporal_occurrence_model=PoissonTOM(1)) return rupture def test_zero_integration_distance(self): rup = self._make_rupture(10, 15, 45) # the JB distances are [8.29156163, 5.05971598, 15.13297135, # 495.78630103, 496.89812309], so given that the integration # distance is 0 all sites are filtered out filtered = filters.filter_sites_by_distance_to_rupture( rup, integration_distance=0, sites=self.sitecol) self.assertIs(filtered, None) def test_495_km(self): rup = self._make_rupture(7, 10, 30) # the JB distance area [5.84700762, 6.8290327, 14.53519629, # 496.25926891, 497.37116174] so given that the integration # distance is 495 only the first 3 sites are kept filtered = filters.filter_sites_by_distance_to_rupture( rup, integration_distance=495, sites=self.sitecol) expected_filtered = SiteCollection(self.SITES[:3]) numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2]) numpy.testing.assert_array_equal(filtered.vs30, expected_filtered.vs30) numpy.testing.assert_array_equal(filtered.vs30measured, expected_filtered.vs30measured) numpy.testing.assert_array_equal(filtered.z1pt0, expected_filtered.z1pt0) numpy.testing.assert_array_equal(filtered.z2pt5, expected_filtered.z2pt5) numpy.testing.assert_array_equal(filtered.mesh.lons, expected_filtered.mesh.lons) numpy.testing.assert_array_equal(filtered.mesh.lats, expected_filtered.mesh.lats) numpy.testing.assert_array_equal(filtered.mesh.depths, expected_filtered.mesh.depths) def test_filter_all_out(self): rup = self._make_rupture(50, 80, 9) # the JB distances are [47.0074159, 37.99716685, 40.7944923, # 476.2521365, 477.36015879] for int_dist in (0, 1, 10, 20, 37.99): filtered = filters.filter_sites_by_distance_to_rupture( rup, integration_distance=int_dist, sites=self.sitecol) self.assertIs(filtered, None)
class PointSourceRuptureFilterTestCase(unittest.TestCase): SITES = PointSourceSourceFilterTestCase.SITES def setUp(self): super(PointSourceRuptureFilterTestCase, self).setUp() self.hypocenter = Point(2, 0, 50) self.sitecol = SiteCollection(self.SITES) def _make_rupture(self, width, length, dip): mid_left = self.hypocenter.point_at(length / 2.0, 0, azimuth=270) mid_right = self.hypocenter.point_at(length / 2.0, 0, azimuth=90) hwidth = width * numpy.cos(numpy.radians(dip)) / 2.0 vwidth = width * numpy.sin(numpy.radians(dip)) / 2.0 top_left = mid_left.point_at(hwidth, -vwidth, azimuth=0) bottom_left = mid_left.point_at(hwidth, vwidth, azimuth=180) top_right = mid_right.point_at(hwidth, -vwidth, azimuth=0) bottom_right = mid_right.point_at(hwidth, vwidth, azimuth=180) surface = PlanarSurface(1, 2, dip, top_left, top_right, bottom_right, bottom_left) rupture = ProbabilisticRupture( mag=1, rake=2, tectonic_region_type=TRT.VOLCANIC, hypocenter=self.hypocenter, surface=surface, source_typology=PointSource, occurrence_rate=3, temporal_occurrence_model=PoissonTOM(1) ) return rupture def test_zero_integration_distance(self): rup = self._make_rupture(10, 15, 45) # the JB distances are [8.29156163, 5.05971598, 15.13297135, # 495.78630103, 496.89812309], so given that the integration # distance is 0 all sites are filtered out filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=0, sites=self.sitecol ) self.assertIs(filtered, None) def test_495_km(self): rup = self._make_rupture(7, 10, 30) # the JB distance area [5.84700762, 6.8290327, 14.53519629, # 496.25926891, 497.37116174] so given that the integration # distance is 495 only the first 3 sites are kept filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=495, sites=self.sitecol ) expected_filtered = SiteCollection(self.SITES[:3]) numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2]) numpy.testing.assert_array_equal( filtered.vs30, expected_filtered.vs30 ) numpy.testing.assert_array_equal( filtered.vs30measured, expected_filtered.vs30measured ) numpy.testing.assert_array_equal( filtered.z1pt0, expected_filtered.z1pt0 ) numpy.testing.assert_array_equal( filtered.z2pt5, expected_filtered.z2pt5 ) numpy.testing.assert_array_equal( filtered.mesh.lons, expected_filtered.mesh.lons ) numpy.testing.assert_array_equal( filtered.mesh.lats, expected_filtered.mesh.lats ) numpy.testing.assert_array_equal( filtered.mesh.depths, expected_filtered.mesh.depths ) def test_filter_all_out(self): rup = self._make_rupture(50, 80, 9) # the JB distances are [47.0074159, 37.99716685, 40.7944923, # 476.2521365, 477.36015879] for int_dist in (0, 1, 10, 20, 37.99): filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=int_dist, sites=self.sitecol ) self.assertIs(filtered, None)
class PointSourceRuptureFilterTestCase(unittest.TestCase): SITES = PointSourceSourceFilterTestCase.SITES def setUp(self): super(PointSourceRuptureFilterTestCase, self).setUp() self.hypocenter = Point(2, 0, 50) self.sitecol = SiteCollection(self.SITES) def _make_rupture(self, width, length, dip): mid_left = self.hypocenter.point_at(length / 2.0, 0, azimuth=270) mid_right = self.hypocenter.point_at(length / 2.0, 0, azimuth=90) hwidth = width * numpy.cos(numpy.radians(dip)) / 2.0 vwidth = width * numpy.sin(numpy.radians(dip)) / 2.0 top_left = mid_left.point_at(hwidth, -vwidth, azimuth=0) bottom_left = mid_left.point_at(hwidth, vwidth, azimuth=180) top_right = mid_right.point_at(hwidth, -vwidth, azimuth=0) bottom_right = mid_right.point_at(hwidth, vwidth, azimuth=180) surface = PlanarSurface(1, 2, dip, top_left, top_right, bottom_right, bottom_left) rupture = ProbabilisticRupture(mag=1, rake=2, tectonic_region_type=TRT.VOLCANIC, hypocenter=self.hypocenter, surface=surface, source_typology=PointSource, occurrence_rate=3, temporal_occurrence_model=PoissonTOM(1)) return rupture def test_zero_integration_distance(self): rup = self._make_rupture(10, 15, 45) # 8 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=0, sites=self.sitecol) self.assertIsInstance(filtered, SiteCollection) self.assertIsNot(filtered, self.sitecol) numpy.testing.assert_array_equal(filtered.indices, [0]) numpy.testing.assert_array_equal(filtered.vs30, [0.1]) rup = self._make_rupture(50, 30, 90) # 14.8 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=0, sites=self.sitecol) numpy.testing.assert_array_equal(filtered.indices, [0, 1]) def test_495_km(self): rup = self._make_rupture(5, 8, 5) # 4.68 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=495, sites=self.sitecol) numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2, 3]) rup = self._make_rupture(7, 10, 30) # 5.8 km radius filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=495, sites=self.sitecol) self.assertIs(filtered.indices, None) self.assertIs(filtered, self.sitecol) def test_filter_all_out(self): rup = self._make_rupture(50, 80, 9) # 46.64 km radius self.hypocenter.longitude = 11.515 for int_dist in (0, 1, 10, 100, 1000): filtered = PointSource.filter_sites_by_distance_to_rupture( rup, integration_distance=int_dist, sites=self.sitecol) self.assertIs(filtered, None)