예제 #1
0
    def setUp(self):
        self.s1 = models.SourceModel(name='s1')
        self.a1 = models.AreaSource(
            name='a1', geometry=models.AreaGeometry(wkt=self.POLY))
        self.p1 = models.PointSource(
            name='p1', geometry=models.PointGeometry(wkt=self.POINT))
        self.s1.sources = [self.a1, self.p1]

        self.s2 = models.SourceModel(name='s1')
        self.a2 = models.AreaSource(
            name='a1', geometry=models.AreaGeometry(wkt=self.POLY))
        self.p2 = models.PointSource(
            name='p1', geometry=models.PointGeometry(wkt=self.POINT))
        self.s2.sources = [self.a2, self.p2]
예제 #2
0
파일: parsers.py 프로젝트: gvallarelli/NRML
    def _parse_area(cls, src_elem):
        """
        :param src_elem:
            :class:`lxml.etree._Element` instance representing a source.
        :returns:
            Fully populated :class:`openquake.nrmllib.models.AreaSource`
            object.
        """
        area = models.AreaSource()
        cls._set_common_attrs(area, src_elem)

        area_geom = models.AreaGeometry()
        area.geometry = area_geom

        [gml_pos_list] = _xpath(src_elem, './/gml:posList')
        coords = gml_pos_list.text.split()
        # Area source polygon geometries are always 2-dimensional and on the
        # Earth's surface (depth == 0.0).
        area_geom.wkt = utils.coords_to_poly_wkt(coords, 2)

        area_geom.upper_seismo_depth = float(
            _xpath(src_elem, './/nrml:upperSeismoDepth')[0].text)
        area_geom.lower_seismo_depth = float(
            _xpath(src_elem, './/nrml:lowerSeismoDepth')[0].text)

        area.mfd = cls._parse_mfd(src_elem)
        area.nodal_plane_dist = cls._parse_nodal_plane_dist(src_elem)
        area.hypo_depth_dist = cls._parse_hypo_depth_dist(src_elem)

        return area
예제 #3
0
    def test_raises_useful_error(self):
        # Test that the source id and name are included with conversion errors,
        # to help the users deal with problems in their source models.
        area_geom = nrml_models.AreaGeometry(
            wkt='POLYGON((0.0 0.0, 1.0 0.0, 0.0 0.0 ))',
            upper_seismo_depth=0.0,
            lower_seismo_depth=10.0,
        )
        area_mfd = nrml_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 = [
            nrml_models.NodalPlane(probability=decimal.Decimal("0.3"),
                                   strike=0.0,
                                   dip=90.0,
                                   rake=0.0),
            nrml_models.NodalPlane(probability=decimal.Decimal("0.7"),
                                   strike=90.0,
                                   dip=45.0,
                                   rake=90.0),
        ]
        area_hdd = [
            nrml_models.HypocentralDepth(probability=decimal.Decimal("0.5"),
                                         depth=4.0),
            nrml_models.HypocentralDepth(probability=decimal.Decimal("0.5"),
                                         depth=8.0),
        ]
        area_src = nrml_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,
        )

        with self.assertRaises(Exception) as ar:
            source_input.nrml_to_hazardlib(area_src, MESH_SPACING, BIN_WIDTH,
                                           AREA_SRC_DISC)
        expected_error = (
            "The following error has occurred with source id='1', "
            "name='Quito': Could not create geometry because of errors while "
            "reading input.")
        self.assertEqual(expected_error, ar.exception.message)
예제 #4
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)
예제 #5
0
    def test_area_with_incr_mfd(self):
        area_mfd = nrml_models.IncrementalMFD(min_mag=6.55,
                                              bin_width=0.1,
                                              occur_rates=[0.1, 0.2, 0.3, 0.4])
        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.IncrementalMFD(
            min_mag=6.55, bin_width=0.1, occur_rates=[0.025, 0.05, 0.075, 0.1])

        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)
예제 #6
0
파일: area_source.py 프로젝트: lcui24/hmtk
    def create_oqnrml_source(self, use_defaults=False):
        '''
        Converts the source model into  an instance of the :class:
        openquake.nrmllib.models.AreaSource

        :param bool use_defaults:
            If set to true, will use put in default values for magitude
            scaling relation, rupture aspect ratio, nodal plane distribution
            or hypocentral depth distribution where missing. If set to False
            then value errors will be raised when information is missing.
        '''
        area_geometry = models.AreaGeometry(self.geometry.wkt,
                                            self.upper_depth, self.lower_depth)
        return models.AreaSource(
            self.id, self.name, self.trt, area_geometry,
            conv.render_mag_scale_rel(self.mag_scale_rel, use_defaults),
            conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
            conv.render_mfd(self.mfd),
            conv.render_npd(self.nodal_plane_dist, use_defaults),
            conv.render_hdd(self.hypo_depth_dist, use_defaults))
예제 #7
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)
예제 #8
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