Esempio n. 1
0
    def test(self):
        npd = PMF([(0.5, NodalPlane(1, 20, 3)),
                   (0.5, NodalPlane(2, 2, 4))])
        hd = PMF([(1, 14)])
        mesh = Mesh(numpy.array([0, 1]), numpy.array([0.5, 1]))
        mmfd = MultiMFD('incrementalMFD',
                        size=2,
                        min_mag=[4.5],
                        bin_width=[2.0],
                        occurRates=[[.3, .1], [.4, .2, .1]])
        mps = MultiPointSource('mp1', 'multi point source',
                               'Active Shallow Crust',
                               mmfd, PeerMSR(), 1.0,
                               10, 20, npd, hd, mesh)
        # test the splitting
        splits = list(mps)
        self.assertEqual(len(splits), 2)
        for split in splits:
            self.assertEqual(split.grp_id, mps.grp_id)

        got = obj_to_node(mps).to_str()
        print(got)
        exp = '''\
multiPointSource{id='mp1', name='multi point source'}
  multiPointGeometry
    gml:posList [0.0, 0.5, 1.0, 1.0]
    upperSeismoDepth 10
    lowerSeismoDepth 20
  magScaleRel 'PeerMSR'
  ruptAspectRatio 1.0
  multiMFD{kind='incrementalMFD', size=2}
    bin_width [2.0]
    min_mag [4.5]
    occurRates [0.3, 0.1, 0.4, 0.2, 0.1]
    lengths [2, 3]
  nodalPlaneDist
    nodalPlane{dip=20, probability=0.5, rake=3, strike=1}
    nodalPlane{dip=2, probability=0.5, rake=4, strike=2}
  hypoDepthDist
    hypoDepth{depth=14, probability=1.0}
'''
        self.assertEqual(got, exp)

        # test serialization to and from hdf5
        tmp = general.gettemp(suffix='.hdf5')
        with hdf5.File(tmp, 'w') as f:
            f[mps.source_id] = mps
        with hdf5.File(tmp, 'r') as f:
            f[mps.source_id]

        # test the bounding box
        bbox = mps.get_bounding_box(maxdist=100)
        numpy.testing.assert_almost_equal(
            (-0.8994569916564479, -0.39932, 1.8994569916564479, 1.89932),
            bbox)
Esempio n. 2
0
    def test(self):
        npd = PMF([(0.5, NodalPlane(1, 20, 3)),
                   (0.5, NodalPlane(2, 2, 4))])
        hd = PMF([(1, 14)])
        mesh = Mesh(numpy.array([0, 1]), numpy.array([0.5, 1]))
        tom = PoissonTOM(50.)
        mmfd = MultiMFD('incrementalMFD',
                        size=2,
                        min_mag=[4.5],
                        bin_width=[2.0],
                        occurRates=[[.3, .1], [.4, .2, .1]])
        mps = MultiPointSource('mp1', 'multi point source',
                               'Active Shallow Crust',
                               mmfd, 2.0, PeerMSR(), 1.0,
                               tom, 10, 20, npd, hd, mesh)
        mps.src_group_id = 1

        # test the splitting
        splits = list(split_source(mps))
        self.assertEqual(len(splits), 2)
        for split in splits:
            self.assertEqual(split.src_group_id, mps.src_group_id)

        got = obj_to_node(mps).to_str()
        print(got)
        self.assertEqual(got, '''\
multiPointSource{id='mp1', name='multi point source', tectonicRegion='Active Shallow Crust'}
  multiPointGeometry
    gml:posList [0, 0.5, 1, 1.0]
    upperSeismoDepth 10
    lowerSeismoDepth 20
  magScaleRel 'PeerMSR'
  ruptAspectRatio 1.0
  multiMFD{kind='incrementalMFD', size=2}
    bin_width [2.0]
    min_mag [4.5]
    occurRates [0.29999999999999999, 0.10000000000000001, 0.40000000000000002, 0.20000000000000001, 0.10000000000000001]
    lengths [2, 3]
  nodalPlaneDist
    nodalPlane{dip=20, probability=0.5, rake=3, strike=1}
    nodalPlane{dip=2, probability=0.5, rake=4, strike=2}
  hypoDepthDist
    hypoDepth{depth=14, probability=1.0}
''')
Esempio n. 3
0
 def __fromh5__(self, dic, attrs):
     self.source_id = attrs['source_id']
     self.name = attrs['name']
     self.tectonic_region_type = attrs['tectonic_region_type']
     self.magnitude_scaling_relationship = SCALEREL[
         attrs['magnitude_scaling_relationship']]
     npd = dic.pop('nodal_plane_distribution').value
     hdd = dic.pop('hypocenter_distribution').value
     mesh = dic.pop('mesh').value
     self.rupture_aspect_ratio = dic.pop('rupture_aspect_ratio').value
     self.lower_seismogenic_depth = dic.pop('lower_seismogenic_depth').value
     self.upper_seismogenic_depth = dic.pop('upper_seismogenic_depth').value
     [(mfd_kind, mfd)] = dic.items()
     self.nodal_plane_distribution = PMF([
         (prob, NodalPlane(strike, dip, rake))
         for prob, strike, dip, rake in npd])
     self.hypocenter_distribution = PMF(hdd)
     self.mesh = Mesh(mesh['lon'], mesh['lat'])
     kw = {k: dset.value for k, dset in mfd.items()}
     kw['size'] = len(mesh)
     kw['kind'] = mfd_kind
     self.mfd = MultiMFD(**kw)
def write_as_multipoint_sources(df, model, src_id, module, subzones,
                                model_subz, mmin, bwid, rms, tom, folder_out):

    # We do not support subzones in this case
    assert subzones is False
    srcd = model['sources'][src_id]

    # Prefix
    pfx = model.get("source_prefix", "")
    pfx += "_" if len(pfx) else pfx

    # Looping over the points
    lons = []
    lats = []
    avals = []
    settings = False
    for idx, pnt in df.iterrows():

        # Get mmax and set the MFD
        mmx = srcd['mmax']
        avals.append(pnt.agr)

        lons.append(pnt.lon)
        lats.append(pnt.lat)

        if not settings:

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

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

            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)

    name = model['sources'][src_id]
    mmfd = MultiMFD('truncGutenbergRichterMFD',
                    size=len(avals),
                    min_mag=[mmin],
                    max_mag=[mmx],
                    bin_width=[bwid],
                    b_val=[pnt.bgr],
                    a_val=avals)

    mesh = Mesh(np.array(lons), np.array(lats))
    srcmp = MultiPointSource(src_id, name, trt, mmfd, msr, rar, usd, lsd,
                             npd, hyd, mesh, tom)

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