Exemplo n.º 1
0
 def test_area_with_tgr_mfd(self):
     trunc_mfd = mfd.TruncatedGRMFD(
         a_val=2.1, b_val=4.2, bin_width=0.1, min_mag=6.55, max_mag=8.91
     )
     np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0)
     np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0)
     npd = pmf.PMF([(0.3, np1), (0.7, np2)])
     hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)])
     polygon = geo.Polygon(
         [geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5),
          geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5)]
     )
     area = source.AreaSource(
         source_id="1",
         name="source A",
         tectonic_region_type="Active Shallow Crust",
         mfd=trunc_mfd,
         rupture_mesh_spacing=self.rupture_mesh_spacing,
         magnitude_scaling_relationship=scalerel.PeerMSR(),
         rupture_aspect_ratio=1.0,
         upper_seismogenic_depth=0.0,
         lower_seismogenic_depth=10.0,
         nodal_plane_distribution=npd,
         hypocenter_distribution=hd,
         polygon=polygon,
         area_discretization=10,
         temporal_occurrence_model=PoissonTOM(50.),
     )
     actual = list(s.area_to_point_sources(area))
     self.assertEqual(len(actual), 96)  # expected 96 points
     self.assertAlmostEqual(actual[0].mfd.a_val, 0.1177287669604317)
Exemplo n.º 2
0
 def _get_area_rates(self, source, mmin, mmax=np.inf):
     """
     Adds the rates from the area source by discretising the source
     to a set of point sources
     :param source:
         Area source as instance of :class:
         openquake.hazardlib.source.area.AreaSource
     """
     points = list(area_to_point_sources(source))
     for point in points:
         self._get_point_rates(point, mmin, mmax)
Exemplo n.º 3
0
    def _get_area_rates(self, source, mmin, mmax=np.inf):
        """
        Adds the rates from the area source by discretising the source
        to a set of point sources

        :param source:
            Area source as instance of :class:
            openquake.hazardlib.source.area.AreaSource
        """
        points = list(area_to_point_sources(source))
        for point in points:
            self._get_point_rates(point, mmin, mmax)
Exemplo n.º 4
0
def get_pt_sources(area_source_file, discretisation=50.):
    """Calls OpenQuake parsers to read area source model
    from source_mode.xml type file, convert to point sources
    and return to calculate ruptures.
    :params area_source_file:
        nrml format file of the area source
    :params discretisation:
        Grid size (km) for the area source discretisation, 
        which defines the distance between resulting point
        sources.
    :returns new_pt_sources
        Point source for the area source model
    """
    converter = SourceConverter(50,
                                10,
                                width_of_mfd_bin=0.1,
                                area_source_discretization=discretisation)
    parser = SourceModelParser(converter)
    try:
        sources = parser.parse_sources(area_source_file)
    except AttributeError:  # Handle version 2.1 and above
        sources = []
        groups = parser.parse_src_groups(area_source_file)
        for group in groups:
            for source in group:
                sources.append(source)
    name = 'test_point_model'
    new_pt_sources = {}
    for source in sources:
        pt_sources = area_to_point_sources(source)
        for pt in pt_sources:
            pt.source_id = pt.source_id.replace(':', '')
            pt.name = pt.name.replace(':', '_')
            try:
                new_pt_sources[pt.tectonic_region_type].append(pt)
            except KeyError:
                new_pt_sources[pt.tectonic_region_type] = [pt]
    return new_pt_sources
Exemplo n.º 5
0
 def test_area_with_incr_mfd(self):
     incr_mfd = mfd.EvenlyDiscretizedMFD(
         min_mag=6.55, bin_width=0.1,
         occurrence_rates=[
             0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4,
             5.080653E-4,
         ]
     )
     np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0)
     np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0)
     npd = pmf.PMF([(0.3, np1), (0.7, np2)])
     hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)])
     polygon = geo.Polygon(
         [geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5),
          geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5)]
     )
     area = source.AreaSource(
         source_id="1",
         name="source A",
         tectonic_region_type="Active Shallow Crust",
         mfd=incr_mfd,
         rupture_mesh_spacing=self.rupture_mesh_spacing,
         magnitude_scaling_relationship=scalerel.PeerMSR(),
         rupture_aspect_ratio=1.0,
         upper_seismogenic_depth=0.0,
         lower_seismogenic_depth=10.0,
         nodal_plane_distribution=npd,
         hypocenter_distribution=hd,
         polygon=polygon,
         area_discretization=10,
         temporal_occurrence_model=PoissonTOM(50.0),
     )
     actual = list(s.area_to_point_sources(area))
     self.assertEqual(len(actual), 96)  # expected 96 points
     assert_allclose(
         actual[0].mfd.occurrence_rates,
         [1.10572802083e-05, 9.197044479166666e-06, 7.6497684375e-06,
          6.3627999999999995e-06, 5.292346875e-06])
Exemplo n.º 6
0
def area2pt_source(area_source_file,
                   sources=None,
                   investigation_time=50,
                   rupture_mesh_spacing=10.,
                   width_of_mfd_bin=0.1,
                   area_source_discretisation=10.,
                   filename=None,
                   nrml_version='04',
                   name=None):
    """Calls OpenQuake parsers to read area source model
    from source_mode.xml type file, convert to point sources
    and write to a new nrml source model file.
    :params area_source_file:
        nrml format file of the area source
    :params discretisation:
        Grid size (km) for the area source discretisation, 
        which defines the distance between resulting point
        sources.
    """
    if sources is None:
        sources = nrml2sourcelist(
            area_source_file,
            investigation_time=investigation_time,
            rupture_mesh_spacing=rupture_mesh_spacing,
            width_of_mfd_bin=width_of_mfd_bin,
            area_source_discretisation=area_source_discretisation)
    if name is None:
        name = '%s_points' % filename
    new_pt_sources = {}
    for source in sources:
        pt_sources = area_to_point_sources(source)
        for pt in pt_sources:
            pt.source_id = pt.source_id.replace(':', '')
            pt.name = pt.name.replace(':', '_')
            try:
                new_pt_sources[pt.tectonic_region_type].append(pt)
            except KeyError:
                new_pt_sources[pt.tectonic_region_type] = [pt]
        # print [method for method in dir(pt) if callable(getattr(pt, method))]
        #  print [attribute for attribute in dir(pt)]
    nrml_pt_file = area_source_file[:-4] + '_pts.xml'
    source_group_list = []
    id = 0
    for trt, sources in new_pt_sources.iteritems():
        source_group = SourceGroup(trt, sources=sources, id=id)
        id += 1
        source_group_list.append(source_group)
    if filename is not None:
        if nrml_version == '04':
            source_list = []
            for trt, sources in new_pt_sources.iteritems():
                for source in sources:
                    source_list.append(source)
            nodes = list(map(obj_to_node, sorted(source_list)))
            source_model = Node("sourceModel", {"name": name}, nodes=nodes)
            with open(nrml_pt_file, 'wb') as f:
                nrml.write([source_model], f, '%s', xmlns=NAMESPACE)
        # This will write version 0.5
        elif nrml_version == '05':
            write_source_model(nrml_pt_file, source_group_list, name=filename)
        else:
            print 'Warning: nrml version not specfied, xml not created'
    return source_group_list