示例#1
0
    def test_create_oqnmrl_simple_fault_source(self):
        '''
        Tests the conversion of a point source to an instance of the :class:
        oqnrmllib.models.SimpleFaultSource 
        '''
        trace = line.Line([point.Point(10., 10.), point.Point(11., 10.)])
        #sflt_geom = SimpleFaultSurface.from_fault_data(trace, 0., 20., 90., 1.)

        # Define a complete source
        self.fault_source = mtkSimpleFaultSource('001',
                                                 'A Fault Source',
                                                 trt='Active Shallow Crust',
                                                 geometry=None,
                                                 dip=90.,
                                                 upper_depth=0.,
                                                 lower_depth=20.,
                                                 mag_scale_rel=None,
                                                 rupt_aspect_ratio=1.0,
                                                 mfd=models.TGRMFD(
                                                     a_val=3.,
                                                     b_val=1.0,
                                                     min_mag=5.0,
                                                     max_mag=8.0),
                                                 rake=0.)
        self.fault_source.create_geometry(trace, 90., 0., 20., 1.0)

        expected_geometry = models.SimpleFaultGeometry(
            wkt='LINESTRING (10.0 10.0, 11.0 10.0)',
            dip=90.,
            upper_seismo_depth=0.,
            lower_seismo_depth=20.)
        expected_source = models.SimpleFaultSource('001',
                                                   'A Fault Source',
                                                   trt='Active Shallow Crust',
                                                   geometry=expected_geometry,
                                                   mag_scale_rel='WC1994',
                                                   rupt_aspect_ratio=1.0,
                                                   mfd=models.TGRMFD(
                                                       a_val=3.,
                                                       b_val=1.0,
                                                       min_mag=5.0,
                                                       max_mag=8.0),
                                                   rake=0.)
        test_source = self.fault_source.create_oqnrml_source(use_defaults=True)
        self.assertTrue(isinstance(test_source, models.SimpleFaultSource))
        self.assertEqual(test_source.id, expected_source.id)
        self.assertEqual(test_source.name, expected_source.name)
        self.assertDictEqual(test_source.geometry.__dict__,
                             expected_source.geometry.__dict__)
        self.assertAlmostEqual(test_source.mfd.b_val,
                               expected_source.mfd.b_val)
示例#2
0
    def test_create_oqnmrl_complex_fault_source(self):
        '''
        Tests the conversion of a point source to an instance of the :class:
        oqnrmllib.models.AreaSource 
        '''
        # Define a complete source
        complex_edges = [
            line.Line([point.Point(10., 10., 0.),
                       point.Point(11., 10., 0.)]),
            line.Line(
                [point.Point(10., 10., 20.),
                 point.Point(11.5, 10., 21.)])
        ]
        self.fault_source = mtkComplexFaultSource('001',
                                                  'A Fault Source',
                                                  trt='Active Shallow Crust',
                                                  geometry=None,
                                                  mag_scale_rel=None,
                                                  rupt_aspect_ratio=1.0,
                                                  mfd=models.TGRMFD(
                                                      a_val=3.,
                                                      b_val=1.0,
                                                      min_mag=5.0,
                                                      max_mag=8.0),
                                                  rake=0.)
        self.fault_source.create_geometry(complex_edges, 2.0)

        expected_geometry = models.ComplexFaultGeometry(
            top_edge_wkt='LINESTRING (10.0 10.0 0.0, 11.0 10.0 0.0)',
            bottom_edge_wkt='LINESTRING (10.0 10.0 20.0, 11.5 10.0 21.0)')

        expected_source = models.ComplexFaultSource('001',
                                                    'A Fault Source',
                                                    trt='Active Shallow Crust',
                                                    geometry=expected_geometry,
                                                    mag_scale_rel='WC1994',
                                                    rupt_aspect_ratio=1.0,
                                                    mfd=models.TGRMFD(
                                                        a_val=3.,
                                                        b_val=1.0,
                                                        min_mag=5.0,
                                                        max_mag=8.0),
                                                    rake=90.)

        test_source = self.fault_source.create_oqnrml_source(use_defaults=True)
        self.assertTrue(isinstance(test_source, models.ComplexFaultSource))
        self.assertEqual(test_source.id, expected_source.id)
        self.assertEqual(test_source.name, expected_source.name)
        self.assertAlmostEqual(test_source.mfd.b_val,
                               expected_source.mfd.b_val)
示例#3
0
    def _parse_mfd(cls, src_elem):
        """
        :param src_elem:
            :class:`lxml.etree._Element` instance representing a source.
        """
        [mfd_elem] = _xpath(src_elem, ('.//nrml:truncGutenbergRichterMFD | '
                                       './/nrml:incrementalMFD'))

        if mfd_elem.tag == '{%s}truncGutenbergRichterMFD' % (
                openquake.nrmllib.NAMESPACE):
            mfd = models.TGRMFD()
            mfd.a_val = float(mfd_elem.get('aValue'))
            mfd.b_val = float(mfd_elem.get('bValue'))
            mfd.min_mag = float(mfd_elem.get('minMag'))
            mfd.max_mag = float(mfd_elem.get('maxMag'))

        elif mfd_elem.tag == '{%s}incrementalMFD' % (
                openquake.nrmllib.NAMESPACE):
            mfd = models.IncrementalMFD()
            mfd.min_mag = float(mfd_elem.get('minMag'))
            mfd.bin_width = float(mfd_elem.get('binWidth'))

            [occur_rates] = _xpath(mfd_elem, './nrml:occurRates')
            mfd.occur_rates = [float(x) for x in occur_rates.text.split()]

        return mfd
示例#4
0
    def _parse_mfd(cls, src_elem):
        """
        :param src_elem:
        :class:`lxml.etree._Element` instance representing a source.
        """
        [mfd_elem] = _xpath(src_elem, ('.//nrml:truncGutenbergRichterMFD | '
                                       './/nrml:incrementalMFD'))

        value_set = False
        if mfd_elem.tag == '{%s}truncGutenbergRichterMFD' % (nrml.NAMESPACE):
            mfd = models.TGRMFD()
            for key in TGR_MAP.keys():
                key_string = mfd_elem.get(key)
                if key_string:
                    value_set = True
                    setattr(mfd, TGR_MAP[key], float(key_string))

        elif mfd_elem.tag == '{%s}incrementalMFD' % (nrml.NAMESPACE):
            mfd = models.IncrementalMFD()
            if mfd_elem.get('minMag'):
                value_set = True
                mfd.min_mag = float(mfd_elem.get('minMag'))
            if mfd_elem.get('binWidth'):
                value_set = True
                mfd.bin_width = float(mfd_elem.get('binWidth'))

            [occur_rates] = _xpath(mfd_elem, './nrml:occurRates')
            if occur_rates.text:
                value_set = True
                mfd.occur_rates = [float(x) for x in occur_rates.text.split()]
        if value_set:
            return mfd
        else:
            return None
示例#5
0
 def test_create_oqhazardlib_source(self):
     """
     """
     # Define a complete source
     area_geom = polygon.Polygon([
         point.Point(10., 10.),
         point.Point(12., 10.),
         point.Point(12., 8.),
         point.Point(10., 8.)
     ])
     self.area_source = mtkAreaSource('001',
                                      'A Point Source',
                                      trt='Active Shallow Crust',
                                      geometry=area_geom,
                                      upper_depth=0.,
                                      lower_depth=20.,
                                      mag_scale_rel=None,
                                      rupt_aspect_ratio=1.0,
                                      mfd=models.TGRMFD(a_val=3.,
                                                        b_val=1.0,
                                                        min_mag=5.0,
                                                        max_mag=8.0),
                                      nodal_plane_dist=None,
                                      hypo_depth_dist=None)
     test_source = self.area_source.create_oqhazardlib_source(
         TOM, 1.0, 10.0, True)
     self.assertIsInstance(test_source, AreaSource)
     self.assertIsInstance(test_source.mfd, TruncatedGRMFD)
     self.assertAlmostEqual(test_source.mfd.b_val, 1.0)
     self.assertIsInstance(test_source.nodal_plane_distribution, PMF)
     self.assertIsInstance(test_source.hypocenter_distribution, PMF)
     self.assertIsInstance(test_source.magnitude_scaling_relationship,
                           WC1994)
示例#6
0
 def test_create_oqhazardlib_source(self):
     """
     Tests to ensure the hazardlib source is created
     """
     trace = line.Line([point.Point(10., 10.), point.Point(11., 10.)])
     self.fault_source = mtkSimpleFaultSource('001',
                                              'A Fault Source',
                                              trt='Active Shallow Crust',
                                              geometry=None,
                                              dip=90.,
                                              upper_depth=0.,
                                              lower_depth=20.,
                                              mag_scale_rel=None,
                                              rupt_aspect_ratio=1.0,
                                              mfd=models.TGRMFD(
                                                  a_val=3.,
                                                  b_val=1.0,
                                                  min_mag=5.0,
                                                  max_mag=8.0),
                                              rake=0.)
     self.fault_source.create_geometry(trace, 90., 0., 20., 1.0)
     test_source = self.fault_source.create_oqhazardlib_source(
         TOM, 2.0, True)
     self.assertIsInstance(test_source, SimpleFaultSource)
     self.assertIsInstance(test_source.mfd, TruncatedGRMFD)
     self.assertAlmostEqual(test_source.mfd.b_val, 1.0)
     self.assertIsInstance(test_source.magnitude_scaling_relationship,
                           WC1994)
示例#7
0
 def test_create_oq_hazardlib_point_source(self):
     """
     Tests the function to create a point source model
     """
     self.point_source = mtkPointSource('001',
                                        'A Point Source',
                                        trt='Active Shallow Crust',
                                        geometry=Point(10., 10.),
                                        upper_depth=0.,
                                        lower_depth=20.,
                                        mag_scale_rel=None,
                                        rupt_aspect_ratio=1.0,
                                        mfd=models.TGRMFD(a_val=3.,
                                                          b_val=1.0,
                                                          min_mag=5.0,
                                                          max_mag=8.0),
                                        nodal_plane_dist=None,
                                        hypo_depth_dist=None)
     test_source = self.point_source.create_oqhazardlib_source(
         TOM, 2.0, True)
     self.assertIsInstance(test_source, PointSource)
     self.assertIsInstance(test_source.mfd, TruncatedGRMFD)
     self.assertAlmostEqual(test_source.mfd.b_val, 1.0)
     self.assertIsInstance(test_source.nodal_plane_distribution, PMF)
     self.assertIsInstance(test_source.hypocenter_distribution, PMF)
     self.assertIsInstance(test_source.magnitude_scaling_relationship,
                           WC1994)
示例#8
0
 def test_create_oqhazardlib_complex_fault_source(self):
     """
     Tests the conversion of a point source to an instance of the :class:
     openquake.hazardlib.source.complex_fault.ComplexFaultSource
     """
     complex_edges = [
         line.Line([point.Point(11., 10., 0.),
                    point.Point(10., 10., 0.)]),
         line.Line(
             [point.Point(11.5, 10., 21.),
              point.Point(10.0, 10., 21.)])
     ]
     self.fault_source = mtkComplexFaultSource('001',
                                               'A Fault Source',
                                               trt='Active Shallow Crust',
                                               geometry=None,
                                               mag_scale_rel=None,
                                               rupt_aspect_ratio=1.0,
                                               mfd=models.TGRMFD(
                                                   a_val=3.,
                                                   b_val=1.0,
                                                   min_mag=5.0,
                                                   max_mag=8.0),
                                               rake=0.)
     self.fault_source.create_geometry(complex_edges, 2.0)
     test_source = self.fault_source.create_oqhazardlib_source(
         TOM, 5.0, True)
     self.assertIsInstance(test_source, ComplexFaultSource)
     self.assertIsInstance(test_source.mfd, TruncatedGRMFD)
     self.assertAlmostEqual(test_source.mfd.b_val, 1.0)
     self.assertIsInstance(test_source.magnitude_scaling_relationship,
                           WC1994)
示例#9
0
    def test_create_oqnmrl_area_source(self):
        '''
        Tests the conversion of a point source to an instance of the :class:
        oqnrmllib.models.AreaSource
        '''
        # Define a complete source
        area_geom = polygon.Polygon([
            point.Point(10., 10.),
            point.Point(12., 10.),
            point.Point(12., 8.),
            point.Point(10., 8.)
        ])
        self.area_source = mtkAreaSource('001',
                                         'A Point Source',
                                         trt='Active Shallow Crust',
                                         geometry=area_geom,
                                         upper_depth=0.,
                                         lower_depth=20.,
                                         mag_scale_rel=None,
                                         rupt_aspect_ratio=1.0,
                                         mfd=models.TGRMFD(a_val=3.,
                                                           b_val=1.0,
                                                           min_mag=5.0,
                                                           max_mag=8.0),
                                         nodal_plane_dist=None,
                                         hypo_depth_dist=None)

        expected_source = models.AreaSource('001',
                                            'A Point Source',
                                            geometry=models.AreaGeometry(
                                                area_geom.wkt, 0., 20.),
                                            mag_scale_rel='WC1994',
                                            rupt_aspect_ratio=1.0,
                                            mfd=models.TGRMFD(a_val=3.,
                                                              b_val=1.0,
                                                              min_mag=5.0,
                                                              max_mag=8.0),
                                            nodal_plane_dist=None,
                                            hypo_depth_dist=None)
        test_source = self.area_source.create_oqnrml_source(use_defaults=True)
        self.assertTrue(isinstance(test_source, models.AreaSource))
        self.assertEqual(test_source.id, expected_source.id)
        self.assertEqual(test_source.name, expected_source.name)
        self.assertAlmostEqual(test_source.mfd.b_val,
                               expected_source.mfd.b_val)
示例#10
0
 def test_mfd_to_hazardlib_nrmllib_tgr(self):
     """
     Tests the conversion to hazardlib fomrulation for the 
     models.TGRMFD case
     """
     output = conv.mfd_to_hazardlib(models.TGRMFD(3.0, 1.0, 4.5, 6.5))
     self.assertIsInstance(output, mfd.truncated_gr.TruncatedGRMFD)
     self.assertAlmostEqual(output.b_val, 1.0)
     self.assertAlmostEqual(output.bin_width, 0.1)
示例#11
0
    def test_area_with_tgr_mfd(self):
        area_mfd = nrml_models.TGRMFD(a_val=-3.5,
                                      b_val=1.0,
                                      min_mag=5.0,
                                      max_mag=6.5)
        self.area_source_attrib['mfd'] = area_mfd

        area_source = nrml_models.AreaSource(**self.area_source_attrib)

        # Re-scaled MFD for the points
        point_mfd = nrml_models.TGRMFD(a_val=-4.1020599913279625,
                                       b_val=1.0,
                                       min_mag=5.0,
                                       max_mag=6.5)
        for exp in self.expected:
            exp.mfd = point_mfd

        actual = list(
            source_input.area_source_to_point_sources(area_source, 100))
        equal, err = helpers.deep_eq(self.expected, actual)
        self.assertTrue(equal, err)
示例#12
0
    def get_mfd(self, iloc, row, mmin):
        """
        Builds the truncated Gutenberg Richter distribution for the point
        from the smoothed seismicity data
        """
        if self.bvalue is None:
            bval = row[-1]
        else:
            bval = self.bvalue
        if row[4] != 0:
            #aval = row[4]
            aval = np.log10(row[4])
        else:
            aval = -2

        if self.mmax is None:
            raise ValueError('Maximum magnitude must be specified!')
        elif isinstance(self.mmax, np.ndarray):
            return models.TGRMFD(aval, bval, mmin, self.mmax[iloc])
        else:
            return models.TGRMFD(aval, bval, mmin, self.mmax)
示例#13
0
def area_source_to_point_sources(area_src, area_src_disc):
    """
    Split an area source into a generator of point sources.

    MFDs will be rescaled appropriately for the number of points in the area
    mesh.

    :param area_src:
        :class:`openquake.nrmllib.models.AreaSource`
    :param float area_src_disc:
        Area source discretization step, in kilometers.
    """
    shapely_polygon = wkt.loads(area_src.geometry.wkt)
    area_polygon = geo.Polygon(
        # We ignore the last coordinate in the sequence here, since it is a
        # duplicate of the first. hazardlib will close the loop for us.
        [geo.Point(*x) for x in list(shapely_polygon.exterior.coords)[:-1]])

    mesh = area_polygon.discretize(area_src_disc)
    num_points = len(mesh)

    area_mfd = area_src.mfd

    if isinstance(area_mfd, nrml_models.TGRMFD):
        new_a_val = math.log10(10**area_mfd.a_val / float(num_points))
        new_mfd = nrml_models.TGRMFD(a_val=new_a_val,
                                     b_val=area_mfd.b_val,
                                     min_mag=area_mfd.min_mag,
                                     max_mag=area_mfd.max_mag)
    elif isinstance(area_mfd, nrml_models.IncrementalMFD):
        new_occur_rates = [float(x) / num_points for x in area_mfd.occur_rates]
        new_mfd = nrml_models.IncrementalMFD(min_mag=area_mfd.min_mag,
                                             bin_width=area_mfd.bin_width,
                                             occur_rates=new_occur_rates)

    for i, (lon, lat) in enumerate(izip(mesh.lons, mesh.lats)):
        pt = nrml_models.PointSource(
            # Generate a new ID and name
            id='%s-%s' % (area_src.id, i),
            name='%s-%s' % (area_src.name, i),
            trt=area_src.trt,
            geometry=nrml_models.PointGeometry(
                upper_seismo_depth=area_src.geometry.upper_seismo_depth,
                lower_seismo_depth=area_src.geometry.lower_seismo_depth,
                wkt='POINT(%s %s)' % (lon, lat)),
            mag_scale_rel=area_src.mag_scale_rel,
            rupt_aspect_ratio=area_src.rupt_aspect_ratio,
            mfd=new_mfd,
            nodal_plane_dist=area_src.nodal_plane_dist,
            hypo_depth_dist=area_src.hypo_depth_dist)
        yield pt
示例#14
0
    def convert(self, mag_freq_dist):
        '''
        Converts the input truncated Gutenberg-Richter magnitude frequency
        distribution to the required openquake.nrmlib implementation

        :param mag_freq_dist:
            Magnitude frequency distribution as either instance of the :class:
            openquake.hazardlib.mfd.truncated_gr.TruncatedGRMFD

        :returns:
            Truncated Gutenberg-Richter distribution as an instance of the
            :class: openquake.nrmllib.models.TGRMFD

        '''
        assert isinstance(mag_freq_dist, mfd.truncated_gr.TruncatedGRMFD)
        return models.TGRMFD(a_val=mag_freq_dist.a_val,
                             b_val=mag_freq_dist.b_val,
                             min_mag=mag_freq_dist.min_mag,
                             max_mag=mag_freq_dist.max_mag)
示例#15
0
    delimiter=",",
    skip_header=True)
for i, line in enumerate(smooth):
    if not np.isnan(line[2]):
        #print line
        p = mtkPointSource(
            identifier=i,
            name="%s" % i,
            trt='Stable Continental Crust',
            geometry=geo.point.Point(line[0], line[1]),
            upper_depth=0.,
            lower_depth=40.,
            mag_scale_rel="WC1994",  # default
            rupt_aspect_ratio=1.0,
            mfd=models.TGRMFD(min_mag=m0,
                              max_mag=7.0,
                              a_val=float(line[2]),
                              b_val=1.0),
            nodal_plane_dist=None,
            hypo_depth_dist=None)

        sources.append(p)

s = source_model.mtkSourceModel(identifier="03",
                                name="pshab woo1996 TGRMFD",
                                sources=sources)

#s.serialise_to_nrml(filename = "../smoothing/source_model_pshab_decluster_frankel1995.xml",
s.serialise_to_nrml(
    filename="../woo/source_model_pshab_pp_decluster_woo1996.xml",
    use_defaults=True)
示例#16
0
    def _expected_source_model(cls):
        # Area:
        area_geom = models.AreaGeometry(
            wkt=('POLYGON((-122.5 37.5, -121.5 37.5, -121.5 38.5, -122.5 38.5,'
                 ' -122.5 37.5))'),
            upper_seismo_depth=0.0,
            lower_seismo_depth=10.0,
        )
        area_mfd = models.IncrementalMFD(
            min_mag=6.55,
            bin_width=0.1,
            occur_rates=[
                0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4,
                5.080653E-4
            ],
        )
        area_npd = [
            models.NodalPlane(probability=decimal.Decimal("0.3"),
                              strike=0.0,
                              dip=90.0,
                              rake=0.0),
            models.NodalPlane(probability=decimal.Decimal("0.7"),
                              strike=90.0,
                              dip=45.0,
                              rake=90.0),
        ]
        area_hdd = [
            models.HypocentralDepth(probability=decimal.Decimal("0.5"),
                                    depth=4.0),
            models.HypocentralDepth(probability=decimal.Decimal("0.5"),
                                    depth=8.0),
        ]
        area_src = models.AreaSource(
            id='1',
            name='Quito',
            trt='Active Shallow Crust',
            geometry=area_geom,
            mag_scale_rel='PeerMSR',
            rupt_aspect_ratio=1.5,
            mfd=area_mfd,
            nodal_plane_dist=area_npd,
            hypo_depth_dist=area_hdd,
        )

        # Point:
        point_geom = models.PointGeometry(
            wkt='POINT(-122.0 38.0)',
            upper_seismo_depth=0.0,
            lower_seismo_depth=10.0,
        )
        point_mfd = models.TGRMFD(
            a_val=-3.5,
            b_val=1.0,
            min_mag=5.0,
            max_mag=6.5,
        )
        point_npd = [
            models.NodalPlane(probability=decimal.Decimal("0.3"),
                              strike=0.0,
                              dip=90.0,
                              rake=0.0),
            models.NodalPlane(probability=decimal.Decimal("0.7"),
                              strike=90.0,
                              dip=45.0,
                              rake=90.0),
        ]
        point_hdd = [
            models.HypocentralDepth(probability=decimal.Decimal("0.5"),
                                    depth=4.0),
            models.HypocentralDepth(probability=decimal.Decimal("0.5"),
                                    depth=8.0),
        ]
        point_src = models.PointSource(
            id='2',
            name='point',
            trt='Stable Continental Crust',
            geometry=point_geom,
            mag_scale_rel='WC1994',
            rupt_aspect_ratio=0.5,
            mfd=point_mfd,
            nodal_plane_dist=point_npd,
            hypo_depth_dist=point_hdd,
        )

        # Simple:
        simple_geom = models.SimpleFaultGeometry(
            wkt='LINESTRING(-121.82290 37.73010, -122.03880 37.87710)',
            dip=45.0,
            upper_seismo_depth=10.0,
            lower_seismo_depth=20.0,
        )
        simple_mfd = models.IncrementalMFD(
            min_mag=5.0,
            bin_width=0.1,
            occur_rates=[
                0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4,
                5.080653E-4
            ],
        )
        simple_src = models.SimpleFaultSource(
            id='3',
            name='Mount Diablo Thrust',
            trt='Active Shallow Crust',
            geometry=simple_geom,
            mag_scale_rel='WC1994',
            rupt_aspect_ratio=1.5,
            mfd=simple_mfd,
            rake=30.0,
        )

        # Complex:
        complex_geom = models.ComplexFaultGeometry(
            top_edge_wkt=('LINESTRING(-124.704 40.363 0.5493260E+01, '
                          '-124.977 41.214 0.4988560E+01, '
                          '-125.140 42.096 0.4897340E+01)'),
            bottom_edge_wkt=('LINESTRING(-123.829 40.347 0.2038490E+02, '
                             '-124.137 41.218 0.1741390E+02, '
                             '-124.252 42.115 0.1752740E+02)'),
            int_edges=[
                ('LINESTRING(-124.704 40.363 0.5593260E+01, '
                 '-124.977 41.214 0.5088560E+01, '
                 '-125.140 42.096 0.4997340E+01)'),
                ('LINESTRING(-124.704 40.363 0.5693260E+01, '
                 '-124.977 41.214 0.5188560E+01, '
                 '-125.140 42.096 0.5097340E+01)'),
            ])
        complex_mfd = models.TGRMFD(a_val=-3.5,
                                    b_val=1.0,
                                    min_mag=5.0,
                                    max_mag=6.5)
        complex_src = models.ComplexFaultSource(
            id='4',
            name='Cascadia Megathrust',
            trt='Subduction Interface',
            geometry=complex_geom,
            mag_scale_rel='WC1994',
            rupt_aspect_ratio=2.0,
            mfd=complex_mfd,
            rake=30.0,
        )

        # 3 Characteristic Sources:
        char_src_simple = models.CharacteristicSource(
            id='5',
            name='characteristic source, simple fault',
            trt='Volcanic',
            mfd=models.TGRMFD(a_val=-3.5, b_val=1.0, min_mag=5.0, max_mag=6.5),
            rake=30.0,
            surface=simple_geom)

        char_src_complex = models.CharacteristicSource(
            id='6',
            name='characteristic source, complex fault',
            trt='Volcanic',
            mfd=models.IncrementalMFD(
                min_mag=5.0,
                bin_width=0.1,
                occur_rates=[
                    0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4,
                    5.080653E-4
                ],
            ),
            rake=60.0,
            surface=complex_geom)

        char_src_multi = models.CharacteristicSource(
            id='7',
            name='characteristic source, multi surface',
            trt='Volcanic',
            mfd=models.TGRMFD(a_val=-3.6, b_val=1.0, min_mag=5.2, max_mag=6.4),
            rake=90.0)
        psurface_1 = models.PlanarSurface(
            strike=0.0,
            dip=90.0,
            top_left=models.Point(longitude=-1.0, latitude=1.0, depth=21.0),
            top_right=models.Point(longitude=1.0, latitude=1.0, depth=21.0),
            bottom_left=models.Point(longitude=-1.0, latitude=-1.0,
                                     depth=59.0),
            bottom_right=models.Point(longitude=1.0, latitude=-1.0,
                                      depth=59.0),
        )
        psurface_2 = models.PlanarSurface(
            strike=20.0,
            dip=45.0,
            top_left=models.Point(longitude=1.0, latitude=1.0, depth=20.0),
            top_right=models.Point(longitude=3.0, latitude=1.0, depth=20.0),
            bottom_left=models.Point(longitude=1.0, latitude=-1.0, depth=80.0),
            bottom_right=models.Point(longitude=3.0, latitude=-1.0,
                                      depth=80.0),
        )
        char_src_multi.surface = [psurface_1, psurface_2]

        source_model = models.SourceModel()
        source_model.name = 'Some Source Model'
        # Generator:
        source_model.sources = (x for x in [
            area_src, point_src, simple_src, complex_src, char_src_simple,
            char_src_complex, char_src_multi
        ])
        return source_model
示例#17
0
r = [l for l in csv.reader(open(filename), delimiter=',', quotechar='"')]
#smooth = np.genfromtxt("../data_output/hmtk_bsb2013_decluster_woo_rates.csv", delimiter=",",skip_header=True)
for i, line in enumerate(r[1:]):
    rate = line[2].strip
    #print rates
    
    p = mtkPointSource(identifier = i,
        name = "%s"%i,
        trt='Stable Continental Crust',
        geometry = geo.point.Point(float(line[0]), float(line[1])),
        upper_depth = 0.,
        lower_depth = 30.,
        mag_scale_rel="WC1994", # default
        rupt_aspect_ratio=1.0,
        mfd=models.TGRMFD(min_mag=m0, 
                          max_mag=7.0,
                          a_val=np.log10(float(line[2])*m0) + 1.0*m0, 
                          b_val=1.0),
        nodal_plane_dist=None,
        hypo_depth_dist=None)
    #print p
 
    sources.append(p)
 
s = source_model.mtkSourceModel(identifier="04", 
                                name = "PSHAB-Helmstetter2012", 
                                sources = sources)
 
s.serialise_to_nrml(filename = "../helmstetter2012/source_model_pshab_helmstetter2012.xml", 
                    use_defaults = True)
示例#18
0
from hmtk.sources import source_model, point_source
from hmtk.sources.point_source import mtkPointSource

from decimal import Decimal

p = mtkPointSource(
    identifier='001',
    name='A Point Source',
    trt='Stable Continental Crust',
    geometry=geo.point.Point(10., 10.),
    upper_depth=0.,
    lower_depth=30.,
    mag_scale_rel="WC1994",  # default
    rupt_aspect_ratio=1.0,
    mfd=models.TGRMFD(a_val=3., b_val=1.0, min_mag=2.5, max_mag=7.0),
    nodal_plane_dist=None,
    hypo_depth_dist=None)

s = source_model.mtkSourceModel(identifier="09",
                                name="nick smoothed",
                                sources=[p])

s.serialise_to_nrml(filename="smoothed_model.xml", use_defaults=True)

#
# # Define a complete source
# area_geom = polygon.Polygon([point.Point(10., 10.),
#                              point.Point(12., 10.),
#                              point.Point(12., 8.),
#                              point.Point(10., 8.)])
m_min, m_max = 3.0, 7.0
sources = []
smooth = np.genfromtxt("data_output/hmtk_bsb2013_decluster_frankel1995.csv", delimiter=",",skip_header=True)
for i, line in enumerate(smooth):
    if str(line[4]) != "nan":
    	#print line[4]
        p = mtkPointSource(identifier = i,
            name = "%s"%i,
            trt='Stable Continental Crust',
            geometry = geo.point.Point(line[0], line[1]),
            upper_depth = 0.,
            lower_depth = 30.,
            mag_scale_rel="WC1994", # default
            rupt_aspect_ratio=1.0,
            mfd=models.TGRMFD(min_mag=m_min, 
                              max_mag=m_max,
                              a_val=float(line[4]), 
                              b_val=1.0),
            nodal_plane_dist=None,
            hypo_depth_dist=None)
     
        sources.append(p)
 
s = source_model.mtkSourceModel(identifier="02", 
                                name = "PSHAB-Smoothed Frankel1995 (decluster)", 
                                sources = sources)
 
s.serialise_to_nrml(filename = "smoothing/source_model_pshab_decluster_frankel1995.xml", 
                    use_defaults = True)
示例#20
0
        #_a = sum(r[5])
        l = [line[0], line[1], _a]
        o.append(l)
        #print l

        p = mtkPointSource(
            identifier=i,
            name="%s" % i,
            trt='Stable Continental Crust',
            geometry=geo.point.Point(line[0], line[1]),
            upper_depth=0.,
            lower_depth=20.,
            mag_scale_rel="WC1994",  # default
            rupt_aspect_ratio=1.0,
            mfd=models.TGRMFD(min_mag=m_min,
                              max_mag=m_max,
                              a_val=_a,
                              b_val=1.0),
            nodal_plane_dist=None,
            hypo_depth_dist=None)

        sources.append(p)

s = source_model.mtkSourceModel(identifier="04",
                                name="PSHAB-Smoothed Helmstetter2012",
                                sources=sources)

s.serialise_to_nrml(
    filename="helmstetter2012/source_model_pshab_helmstetter2012.xml",
    use_defaults=True)

o = np.array(o)
示例#21
0
from decimal import Decimal

a = area_source.mtkAreaSource(identifier = "01", 
                  name = "area source name", 
                  trt = "stable crust", 
                  geometry = geo.Polygon([geo.Point(-58.73, -10.33),
                                          geo.Point(-58.74, -13.54),
                                          geo.Point(-55.94, -13.59), 
                                          geo.Point(-56.58, -10.31),
                                          geo.Point(-58.73, -10.33)]), 
                  upper_depth = "0", 
                  lower_depth = "30", 
                  mag_scale_rel = "WC1994", # default 
                  rupt_aspect_ratio = 1, 
                  mfd = models.TGRMFD(min_mag=3.0,
                                      max_mag=7.0, 
                                      b_val=0.847, 
                                      a_val=0.737), 
                  nodal_plane_dist = models.NodalPlane(Decimal('1.0'), 
                                                       strike=0., 
                                                       dip=90.,
                                                       rake=0.), 
                  hypo_depth_dist = None)

#a.create_oqnrml_source

s = source_model.mtkSourceModel(identifier="09", 
                                        name = "sources model name", 
                                        sources = [a])

s.serialise_to_nrml(filename = "s03.xml", 
                    use_defaults = True)