コード例 #1
0
def render_hdd(hypo_depth_dist, use_default=False):
    '''
    Check to see if hypocentral depth distribution exists. If it
    is already defined as an instance of
    openquake.nrmllib.HypocentralDepth then returns. If it is an instance
    of openquake.hazardlib.pmf.PMF then convert to nrmllib version
    '''
    if isinstance(hypo_depth_dist, list):
        for hdd in hypo_depth_dist:
            assert isinstance(hdd, models.HypocentralDepth)

        return hypo_depth_dist
    elif isinstance(hypo_depth_dist, PMF):
        prob_sum = Decimal('0.0')
        output_hdd = []
        for (prob, value) in hypo_depth_dist.data:
            prob_sum += Decimal(str(prob))
            output_hdd.append(models.HypocentralDepth(prob, value))

        if not prob_sum == Decimal('1.0'):
            raise ValueError('Hypocentral depth disribution probabilities '
                             'do not sum to 1.0')
        return output_hdd
    else:
        if use_default:
            # Default to a single hypocentral depth of 1.0
            return [models.HypocentralDepth(Decimal('1.0'), 10.)]
        else:
            raise ValueError('Hypocentral depth distribution not defined!')
コード例 #2
0
    def setUp(self):
        '''
        '''
        self.depth_as_list = [
            models.HypocentralDepth(0.5, 5.),
            models.HypocentralDepth(0.5, 10.)
        ]

        self.depth_as_pmf = PMF([(0.5, 5.), (0.5, 10.)])
コード例 #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 write_to_nrml(self,
                      output_filename,
                      mmin,
                      upper_depth=0.,
                      lower_depth=50.,
                      source_model_name="POINT SOURCE MODEL",
                      trt=DEFAULT_TRT,
                      msr=DEFAULT_MSR,
                      aspect=ASPECT_RATIO,
                      hdd=None):
        """
        Converts the smoothed seismicity data to a set of oq-nrml point
        sources and writes to the output file
        """
        writer = SourceModelXMLWriter(output_filename)
        source_model = models.SourceModel(source_model_name)
        source_model.sources = []

        print 'Building source model ...'
        for iloc, row in enumerate(self.data):
            # Geometry
            #trt =(row[18])

            geom = models.PointGeometry(
                "POINT (%9.4f %9.4f)" % (row[0], row[1]), upper_depth,
                lower_depth)
            if hdd:
                src_hdd = []
                #each tuple with probality and depth
                for d in hdd:
                    src_hdd.append(models.HypocentralDepth(d[1], d[0]))
            else:
                src_hdd = [models.HypocentralDepth(Decimal("1.0"), row[2])]

            npd = [models.NodalPlane(1, 0, 90, 0)]
            #if row[5]==1:
            #    npd = [models.NodalPlane(row[6], row[7], row[9], row[8])]
            #elif row[5] ==2:
            #    npd = [models.NodalPlane(row[6], row[7], row[9], row[8]), models.NodalPlane(row[10], row[11], row[13], row[12])]
            #else:
            #    npd =  [models.NodalPlane(row[6], row[7], row[9], row[8]), models.NodalPlane(row[10], row[11], row[13], row[12]), models.NodalPlane(row[14], row[15], row[17], row[16])]

            source_model.sources.append(
                models.PointSource(str(iloc), "PNT_%s" % str(iloc), trt,
                                   geom, msr, aspect,
                                   self.get_mfd(iloc, row,
                                                mmin), npd, src_hdd))
        print 'done!'
        print 'Writing to file ...'
        writer.serialize(source_model)
        print 'done!'
コード例 #5
0
    def setUp(self):
        self.area_source_attrib = dict(
            id='1',
            name='source A',
            trt='Active Shallow Crust',
            geometry=nrml_models.AreaGeometry(
                upper_seismo_depth=10,
                lower_seismo_depth=20,
                wkt=('POLYGON((1.0 1.0, 1.0 -1.0, -1.0 -1.0, -1.0 1.0, '
                     '1.0 1.0))'),
            ),
            mag_scale_rel='WC1994',
            rupt_aspect_ratio=1.0,
            mfd=None,
            nodal_plane_dist=[
                nrml_models.NodalPlane(probability=1.0,
                                       strike=0.0,
                                       dip=90.0,
                                       rake=0.0)
            ],
            hypo_depth_dist=[
                nrml_models.HypocentralDepth(probability=1.0, depth=10.0)
            ],
        )

        self.expected = []
        lons = [
            -0.100677001712, 0.798645996576, -0.100591068089, 0.798817863822
        ]
        lats = [
            0.100830691185, 0.100830691185, -0.798490914733, -0.798490914733
        ]
        for i, (lon, lat) in enumerate(zip(lons, lats)):
            point_attrib = self.area_source_attrib.copy()
            del point_attrib['geometry']
            point_attrib['id'] = '1-%s' % i
            point_attrib['name'] = 'source A-%s' % i

            pt_source = nrml_models.PointSource(**point_attrib)
            pt_source.geometry = nrml_models.PointGeometry(
                upper_seismo_depth=10,
                lower_seismo_depth=20,
                wkt='POINT(%s %s)' % (lon, lat),
            )
            self.expected.append(pt_source)
コード例 #6
0
ファイル: parsers.py プロジェクト: gvallarelli/NRML
    def _parse_hypo_depth_dist(cls, src_elem):
        """
        :param src_elem:
            :class:`lxml.etree._Element` instance representing a source.
        :returns:
            `list` of :class:`openquake.nrmllib.models.HypocentralDepth`
            objects.
        """
        hdd = []

        for elem in _xpath(src_elem, './/nrml:hypoDepth'):
            hdepth = models.HypocentralDepth()
            hdepth.probability = decimal.Decimal(elem.get('probability'))
            hdepth.depth = float(elem.get('depth'))

            hdd.append(hdepth)

        return hdd
コード例 #7
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