Ejemplo n.º 1
0
def example_calc(apply):
    sitecol = SiteCollection([
        Site(Point(30.0, 30.0), 760., 1.0, 1.0),
        Site(Point(30.25, 30.25), 760., 1.0, 1.0),
        Site(Point(30.4, 30.4), 760., 1.0, 1.0)
    ])
    mfd_1 = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0)
    mfd_2 = TruncatedGRMFD(4.5, 7.5, 0.1, 3.5, 1.1)
    sources = [
        PointSource('001', 'Point1', 'Active Shallow Crust', mfd_1, 1.0,
                    WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                    Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                    PMF([(1.0, 10.0)])),
        PointSource('002', 'Point2', 'Active Shallow Crust', mfd_2, 1.0,
                    WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                    Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                    PMF([(1.0, 10.0)]))
    ]
    imtls = {
        'PGA': [0.01, 0.1, 0.2, 0.5, 0.8],
        'SA(0.5)': [0.01, 0.1, 0.2, 0.5, 0.8]
    }
    gsims = {'Active Shallow Crust': AkkarBommer2010()}
    return calc_hazard_curves(sources, sitecol, imtls, gsims, apply=apply)
Ejemplo n.º 2
0
    def setUp(self):

        mfd = TruncatedGRMFD(min_mag=4.0,
                             max_mag=6.0,
                             bin_width=0.1,
                             a_val=2.0,
                             b_val=1.0)
        msr = WC1994()
        tom = PoissonTOM(1.0)
        loc = Point(longitude=0.0,
                    latitude=0.0)
        npd = PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))])
        hpd = PMF([(0.7, 10.), (0.3, 20.0)])

        self.src1 = PointSource(source_id='1',
                                name='1',
                                tectonic_region_type='Test',
                                mfd=mfd,
                                rupture_mesh_spacing=1,
                                magnitude_scaling_relationship=msr,
                                rupture_aspect_ratio=1.,
                                temporal_occurrence_model=tom,
                                upper_seismogenic_depth=0,
                                lower_seismogenic_depth=100.,
                                location=loc,
                                nodal_plane_distribution=npd,
                                hypocenter_distribution=hpd)

        mfd = EvenlyDiscretizedMFD(min_mag=4.0,
                                   bin_width=0.1,
                                   occurrence_rates=[3., 2., 1.])

        self.src2 = PointSource(source_id='1',
                                name='1',
                                tectonic_region_type='Test',
                                mfd=mfd,
                                rupture_mesh_spacing=1,
                                magnitude_scaling_relationship=msr,
                                rupture_aspect_ratio=1.,
                                temporal_occurrence_model=tom,
                                upper_seismogenic_depth=0,
                                lower_seismogenic_depth=100.,
                                location=loc,
                                nodal_plane_distribution=npd,
                                hypocenter_distribution=hpd)
Ejemplo n.º 3
0
def write_as_set_point_sources(df, model, src_id, module, subzones,
                               model_subz, mmin, bwid, rms, tom, folder_out):

    srcd = model['sources'][src_id]

    # Looping over the points
    name = ""
    srcs = []
    for idx, pnt in df.iterrows():

        if subzones:
            srcd_sz = model_subz['sources'][pnt.id]

        pfx = model.get("source_prefix", "")
        pfx += "_" if len(pfx) else pfx
        sid = '{:s}{:s}_{:d}'.format(pfx, src_id, idx)

        trt = srcd['tectonic_region_type']
        msr_str = model['msr'][trt]

        my_class = getattr(module, msr_str)
        msr = my_class()

        # Get mmax and set the MFD
        mmx = srcd['mmax']
        mfd = TruncatedGRMFD(mmin, mmx, bwid, pnt.agr, pnt.bgr)

        key = 'rupture_aspect_ratio'
        rar = get_param(srcd, model['default'], key)

        key = 'upper_seismogenic_depth'
        usd = get_param(srcd, model['default'], key)

        key = 'lower_seismogenic_depth'
        lsd = get_param(srcd, model['default'], key)

        key = 'nodal_plane_distribution'
        tmp = get_param(srcd, model['default'], key)
        npd = _get_nodal_plane_distribution(tmp)

        key = 'hypocenter_distribution'
        tmp = get_param(srcd, model['default'], key)
        hyd = _get_hypocenter_distribution(tmp)

        if subzones:
            tmp = get_param(srcd_sz, model['default'], key)
            npd = _get_nodal_plane_distribution(tmp)

        loc = Point(pnt.lon, pnt.lat)
        src = PointSource(sid, name, trt, mfd, rms, msr, rar, tom, usd, lsd,
                          loc, npd, hyd)
        srcs.append(src)

    # Write output file
    fname_out = os.path.join(folder_out, 'src_{:s}.xml'.format(src_id))
    write_source_model(fname_out, srcs, 'Zone {:s}'.format(src_id))
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test(self):
     sitecol = SiteCollection([Site(Point(30.0, 30.0), 760., 1.0, 1.0)])
     mfd = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0)
     sources = [PointSource('001', 'Point1', 'Active Shallow Crust',
                            mfd, 1.0, WC1994(), 1.0, PoissonTOM(50.0),
                            0.0, 30.0, Point(30.0, 30.5),
                            PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]),
                            PMF([(1.0, 10.0)]))]
     imtls = {'PGA': [0.01, 0.1, 0.2, 0.5, 0.8]}
     hc1 = calc_hazard_curves(sources, sitecol, imtls, {
         'Active Shallow Crust': AkkarBommer2010()})['PGA']
     hc2 = calc_hazard_curves(sources, sitecol, imtls, {
         'Active Shallow Crust': SadighEtAl1997()})['PGA']
     hc = .6 * hc1 + .4 * hc2
     ag = AvgGMPE(b1=dict(AkkarBommer2010={'weight': .6}),
                  b2=dict(SadighEtAl1997={'weight': .4}))
     hcm = calc_hazard_curves(sources, sitecol, imtls, {
         'Active Shallow Crust': ag})['PGA']
     # the AvgGMPE is not producing real means!!
     numpy.testing.assert_almost_equal(hc, hcm, decimal=3)
Ejemplo n.º 6
0
 def setUp(self):
     """
     """
     #
     # coordinates of point sources
     lons = [10.00, 10.10, 10.20, 10.00, 10.10, 10.20, 10.00, 10.10, 10.20]
     lats = [45.10, 45.10, 45.10, 45.05, 45.05, 45.05, 45.00, 45.00, 45.00]
     deps = [10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00]
     self.lons = lons
     self.lats = lats
     #
     # set main parameters
     mfd = TruncatedGRMFD(min_mag=4.0,
                          max_mag=6.0,
                          bin_width=0.1,
                          a_val=2.0,
                          b_val=1.0)
     msr = WC1994()
     tom = PoissonTOM(1.0)
     npd = PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))])
     hdd = PMF([(0.7, 4.), (0.3, 8.0)])
     #
     # create the list of sources
     srcs = []
     for idx, (lon, lat, dep) in enumerate(zip(lons, lats, deps)):
         src = PointSource(source_id='1',
                           name='Test',
                           tectonic_region_type=TRT.ACTIVE_SHALLOW_CRUST,
                           mfd=mfd,
                           rupture_mesh_spacing=5.0,
                           magnitude_scaling_relationship=msr,
                           rupture_aspect_ratio=1.0,
                           temporal_occurrence_model=tom,
                           upper_seismogenic_depth=0,
                           lower_seismogenic_depth=10.,
                           location=Point(lon, lat, dep),
                           nodal_plane_distribution=npd,
                           hypocenter_distribution=hdd)
         srcs.append(src)
     self.points = srcs
Ejemplo n.º 7
0
def create_nrml_sources(fname_input_pattern: str, fname_config: str, 
                        folder_out: str, fname_subzone_shp: str="", 
                        fname_subzone_config: str=""):

    create_folder(folder_out)
    
    # If true we take some of the information from subzones
    subzones = (len(fname_subzone_shp) > 0 and len(fname_subzone_config) > 0)
    if subzones:
        polygons_gdf = gpd.read_file(fname_subzone_shp)
        model_subz = toml.load(fname_subzone_config) 

    # This is used to instantiate the MSR
    module = importlib.import_module('openquake.hazardlib.scalerel')

    # Parsing config
    model = toml.load(fname_config)

    rms = model['rupture_mesh_spacing']
    mmin = model['mmin']
    bwid = model['bin_width']
    tom = PoissonTOM(1.0)

    # Processing files
    for fname in glob(fname_input_pattern):

        src_id = os.path.basename(fname).split('.')[0]
        rc_id = _get_src_id(fname)
        
        df = pd.read_csv(fname)
        
        # Create a geodataframe with the points in a given zone
        if subzones:

            # Create a geodataframe with points
            geom = [PointShapely(xy) for xy in zip(df.lon, df.lat)]
            gdf = gpd.GeoDataFrame(df, crs='epsg:4326', geometry=geom)

            # Select subzones within a zone
            tdf = polygons_gdf[polygons_gdf["parent"] == src_id]

            # Should contain the points within
            df = gpd.sjoin(gdf, tdf, op='within')

        # This is the information on the source in the config file
        srcd = model['sources'][src_id]

        # Looping over the points
        srcs = []
        for idx, pnt in df.iterrows():

            if subzones:
                srcd_sz = model_subz['sources'][pnt.id]

            pfx = model.get("source_prefix", "")
            pfx += "_" if len(pfx) else pfx
            sid = '{:s}{:s}_{:d}'.format(pfx, src_id, idx)
            name = ""

            trt = srcd['tectonic_region_type']
            msr_str = model['msr'][trt]

            my_class = getattr(module, msr_str)
            msr = my_class()

            # Get mmax and set the MFD
            mmx = srcd['mmax']
            mfd = TruncatedGRMFD(mmin, mmx, bwid, pnt.agr, pnt.bgr)

            key = 'rupture_aspect_ratio'
            rar = get_param(srcd, model['default'], key)

            key = 'upper_seismogenic_depth'
            usd = get_param(srcd, model['default'], key)

            key = 'lower_seismogenic_depth'
            lsd = get_param(srcd, model['default'], key)

            key = 'nodal_plane_distribution'
            tmp = get_param(srcd, model['default'], key)
            npd = _get_nodal_plane_distribution(tmp)

            key = 'hypocenter_distribution'
            tmp = get_param(srcd, model['default'], key)
            hyd = _get_hypocenter_distribution(tmp)

            if subzones:
                tmp = get_param(srcd_sz, model['default'], key)
                npd = _get_nodal_plane_distribution(tmp)

            loc = Point(pnt.lon, pnt.lat)
            src = PointSource(sid, name, trt, mfd, rms, msr, rar, tom,
                              usd, lsd, loc, npd, hyd)
            srcs.append(src)

        # Write output file
        fname_out = os.path.join(folder_out, 'src_{:s}.xml'.format(src_id))
        write_source_model(fname_out, srcs, 'Zone {:s}'.format(src_id))