Beispiel #1
0
    def test_simple_fault_surface_vertical(self):

        # Create the rupture
        mag = 10.0
        rake = 90.0
        trt = TRT.ACTIVE_SHALLOW_CRUST
        hypoc = Point(0.25, 0.0, 5)
        pmf = PMF([(0.8, 0), (0.2, 1)])
        rup = NPPR(mag, rake, trt, hypoc, self.srfc1, pmf)

        # Compute distances
        param = 'closest_point'
        sites = SiteCollection(
            [Site(Point(0.25, -0.1, 0.0)),
             Site(Point(-0.1, 0.0, 0.0))])
        dsts = get_distances(rup, sites, param)

        # Check first point
        msg = 'The longitude of the first point is wrong'
        self.assertTrue(abs(dsts[0, 0] - 0.25) < 1e-2, msg)
        msg = 'The latitude of the first point is wrong'
        self.assertTrue(abs(dsts[0][1] - 0.0) < 1e-2, msg)

        # Check second point
        msg = 'The longitude of the second point is wrong'
        self.assertTrue(abs(dsts[1, 0] - 0.0) < 1e-2, msg)
        msg = 'The latitude of the second point is wrong'
        self.assertTrue(abs(dsts[1][1] - 0.0) < 1e-2, msg)
Beispiel #2
0
    def get_gsim_contexts(self):
        """
        Returns a comprehensive set of GMPE contecxt objects
        """
        assert isinstance(self.rupture, Rupture)
        assert isinstance(self.target_sites, SiteCollection)
        # Distances
        dctx = DistancesContext()
        # Rupture distance
        setattr(dctx, 'rrup',
                self.rupture.surface.get_min_distance(self.target_sites.mesh))
        # Rx
        setattr(dctx, 'rx',
                self.rupture.surface.get_rx_distance(self.target_sites.mesh))
        # Rjb
        setattr(dctx, 'rjb', self.rupture.surface.get_joyner_boore_distance(
                    self.target_sites.mesh))
        # Rhypo
        setattr(dctx,
                'rhypo',
                self.rupture.hypocenter.distance_to_mesh(
                    self.target_sites.mesh))
        # Repi
        setattr(dctx, 'repi',
                self.rupture.hypocenter.distance_to_mesh(
                    self.target_sites.mesh,
                    with_depths=False))
        # Ry0
        setattr(dctx, 'ry0',
                self.rupture.surface.get_ry0_distance(self.target_sites.mesh))
        # Rcdpp - ignored at present
        setattr(dctx, 'rcdpp', None)
        # Azimuth
        setattr(dctx, 'azimuth', get_distances(self.rupture,
                                               self.target_sites.mesh,
                                               'azimuth'))
        setattr(dctx, 'hanging_wall', None)
        # Rvolc
        setattr(dctx, "rvolc", np.zeros_like(self.target_sites.mesh.lons))
        # Sites
        sctx = SitesContext(slots=self.target_sites.array.dtype.names)
        for key in sctx._slots_:
            setattr(sctx, key, self.target_sites.array[key])

        # Rupture
        rctx = RuptureContext()
        setattr(rctx, 'mag', self.magnitude)
        setattr(rctx, 'strike', self.strike)
        setattr(rctx, 'dip', self.dip)
        setattr(rctx, 'rake', self.rake)
        setattr(rctx, 'ztor', self.ztor)
        setattr(rctx, 'hypo_depth', self.rupture.hypocenter.depth)
        setattr(rctx, 'hypo_lat', self.rupture.hypocenter.latitude)
        setattr(rctx, 'hypo_lon', self.rupture.hypocenter.longitude)
        setattr(rctx, 'hypo_loc', self.hypo_loc)
        setattr(rctx, 'width', self.rupture.surface.get_width())
        return sctx, rctx, dctx
Beispiel #3
0
    def get_gsim_contexts(self):
        """
        Returns a comprehensive set of GMPE contecxt objects
        """
        assert isinstance(self.rupture, Rupture)
        assert isinstance(self.target_sites, SiteCollection)
        # Distances
        dctx = DistancesContext()
        # Rupture distance
        setattr(dctx, 'rrup',
                self.rupture.surface.get_min_distance(self.target_sites.mesh))
        # Rx
        setattr(dctx, 'rx',
                self.rupture.surface.get_rx_distance(self.target_sites.mesh))
        # Rjb
        setattr(dctx, 'rjb', self.rupture.surface.get_joyner_boore_distance(
                    self.target_sites.mesh))
        # Rhypo
        setattr(dctx,
                'rhypo',
                self.rupture.hypocenter.distance_to_mesh(
                    self.target_sites.mesh))
        # Repi
        setattr(dctx, 'repi',
                self.rupture.hypocenter.distance_to_mesh(
                    self.target_sites.mesh,
                    with_depths=False))
        # Ry0
        setattr(dctx, 'ry0',
                self.rupture.surface.get_ry0_distance(self.target_sites.mesh))
        # Rcdpp - ignored at present
        setattr(dctx, 'rcdpp', None)
        # Azimuth
        setattr(dctx, 'azimuth', get_distances(self.rupture,
                                               self.target_sites.mesh,
                                               'azimuth'))
        setattr(dctx, 'hanging_wall', None)
        # Rvolc
        setattr(dctx, "rvolc", np.zeros_like(self.target_sites.mesh.lons))
        # Sites
        sctx = SitesContext(slots=self.target_sites.array.dtype.names)
        for key in sctx._slots_:
            setattr(sctx, key, self.target_sites.array[key])

        # Rupture
        rctx = RuptureContext()
        setattr(rctx, 'mag', self.magnitude)
        setattr(rctx, 'strike', self.strike)
        setattr(rctx, 'dip', self.dip)
        setattr(rctx, 'rake', self.rake)
        setattr(rctx, 'ztor', self.ztor)
        setattr(rctx, 'hypo_depth', self.rupture.hypocenter.depth)
        setattr(rctx, 'hypo_lat', self.rupture.hypocenter.latitude)
        setattr(rctx, 'hypo_lon', self.rupture.hypocenter.longitude)
        setattr(rctx, 'hypo_loc', self.hypo_loc)
        setattr(rctx, 'width', self.rupture.surface.get_width())
        return sctx, rctx, dctx
Beispiel #4
0
    def build_sites_distances_contexts(self,
                                       event,
                                       sites,
                                       vs30measured=False,
                                       backarc=False):
        """
        Builds the contexts from the event and sites
        """
        # Get distances
        mesh = Mesh(sites["lon"], sites["lat"])
        mshape = mesh.lons.shape
        dctx = DistancesContext()
        for param in self.context.REQUIRES_DISTANCES:
            setattr(dctx, param, get_distances(event.get_rupture(), mesh,
                                               param))
        # Get sites context
        sctx = SitesContext()
        for key in self.site_attribs:
            if key.startswith("z1pt0") and not "z1pt0" in sites:
                setattr(sctx, "z1pt0",
                        vs30_to_z1pt0_cy14(sites["vs30"], japan=False))

            elif key.startswith("z2pt5") and not "z5pt5" in sites:
                setattr(sctx, "z2pt5",
                        vs30_to_z2pt5_cb14(sites["vs30"], japan=False))

            elif key.startswith(
                    "vs30measured") and not "vs30measured" in sites:
                if vs30measured:
                    setattr(sctx, "vs30measured", np.ones(mshape, dtype=bool))
                else:
                    setattr(sctx, "vs30measured", np.zeros(mshape, dtype=bool))
            elif key.startswith(
                    "vs30measured") and not "vs30measured" in sites:
                if vs30measured:
                    setattr(sctx, "vs30measured", np.ones(mshape, dtype=bool))
                else:
                    setattr(sctx, "vs30measured", np.zeros(mshape, dtype=bool))
            elif key.startswith("backarc") and not "backarc" in sites:
                if vs30measured:
                    setattr(sctx, "backarc", np.ones(mshape, dtype=bool))
                else:
                    setattr(sctx, "backarc", np.zeros(mshape, dtype=bool))
            else:
                setattr(sctx, key, sites[key])
        return sctx, dctx
Beispiel #5
0
    def test_point_surface(self):

        sid = 0
        name = 'test'
        trt = TRT.ACTIVE_SHALLOW_CRUST
        mfd = ArbitraryMFD([7.0], [1.])
        rms = 2.5
        msr = WC1994()
        rar = 1.0
        tom = PoissonTOM(1.)
        usd = 0.0
        lsd = 20.0
        loc = Point(0.0, 0.0)
        npd = PMF([(1.0, NodalPlane(90., 90., 90.))])
        hyd = PMF([(1.0, 10.)])
        src = PointSource(sid, name, trt, mfd, rms, msr, rar, tom, usd, lsd,
                          loc, npd, hyd)
        rups = [r for r in src.iter_ruptures()]

        # Compute distances
        param = 'closest_point'
        sites = SiteCollection(
            [Site(Point(0.0, 0.0, 0.0)),
             Site(Point(-0.2, 0.0, 0.0))])
        dsts = get_distances(rups[0], sites, param)

        # Check first point
        msg = 'The longitude of the first point is wrong'
        self.assertTrue(abs(dsts[0, 0] - 0.0) < 1e-2, msg)
        msg = 'The latitude of the first point is wrong'
        self.assertTrue(abs(dsts[0, 1] - 0.0) < 1e-2, msg)

        # Check second point
        msg = 'The longitude of the second point is wrong'
        self.assertTrue(abs(dsts[1, 0] + 0.1666) < 1e-2, msg)
        msg = 'The latitude of the second point is wrong'
        self.assertTrue(abs(dsts[1, 1] - 0.0) < 1e-2, msg)