예제 #1
0
    def create_oqnrml_source(self, use_defaults=False):
        """
        Turns source into instance of the :class:
        openquake.nrmllib.model.SimpleFaultSource
        :param bool use_defaults:
            If set to True, will use default values for rupture aspect ratio
            and magnitude scaling relation. If False, will raise value error
            if this information is missing
        """
        if not isinstance(self.rake, float):
            raise ValueError("Cannot render fault source - rake is missing!")
        simple_geometry = models.SimpleFaultGeometry(
            wkt=conv.simple_trace_to_wkt_linestring(self.fault_trace),
            dip=self.dip,
            upper_seismo_depth=self.upper_depth,
            lower_seismo_depth=self.lower_depth,
        )

        return models.SimpleFaultSource(
            self.id,
            self.name,
            self.trt,
            simple_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),
            self.rake,
        )
예제 #2
0
    def create_oqnrml_source(self, use_defaults=False):
        '''
        Converts the complex source into an instance of the :class:
        openquake.nrmllib.models.ComplexFaultSource

        :param bool use_defaults:
            If set to True, will input default values of rupture aspect
            ratio and magnitude scaling relation where missing. If false,
            value errors will be raised if information is missing.
        '''
        if not isinstance(self.rake, float):
            raise ValueError('Cannot create complex source - rake is missing!')

        # Render complex geometry to linestrings
        complex_geometry = conv.complex_trace_to_wkt_linestring(
            self.fault_edges)

        return models.ComplexFaultSource(
            self.id,
            self.name,
            self.trt,
            complex_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),
            self.rake)
예제 #3
0
    def create_oqnrml_source(self, use_defaults=False):
        '''
        Converts the complex source into an instance of the :class:
        openquake.nrmllib.models.ComplexFaultSource

        :param bool use_defaults:
            If set to True, will input default values of rupture aspect
            ratio and magnitude scaling relation where missing. If false,
            value errors will be raised if information is missing.
        '''
        if not isinstance(self.rake, float):
            raise ValueError('Cannot create complex source - rake is missing!')

        # Render complex geometry to linestrings
        complex_geometry = conv.complex_trace_to_wkt_linestring(
            self.fault_edges)

        return models.ComplexFaultSource(
            self.id,
            self.name,
            self.trt,
            complex_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),
            self.rake)
예제 #4
0
    def create_oqnrml_source(self, use_defaults=False):
        '''
        Turns source into instance of the :class:
        openquake.nrmllib.model.SimpleFaultSource
        :param bool use_defaults:
            If set to True, will use default values for rupture aspect ratio
            and magnitude scaling relation. If False, will raise value error
            if this information is missing
        '''
        if not isinstance(self.rake, float):
            raise ValueError('Cannot render fault source - rake is missing!')
        simple_geometry = models.SimpleFaultGeometry(
            wkt=conv.simple_trace_to_wkt_linestring(self.fault_trace),
            dip=self.dip,
            upper_seismo_depth=self.upper_depth,
            lower_seismo_depth=self.lower_depth)

        return models.SimpleFaultSource(
            self.id,
            self.name,
            self.trt,
            simple_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),
            self.rake)
예제 #5
0
 def test_render_mfd_truncgr(self):
     '''
     Tests the function to render the mfd given a valid :class:
     openquake.hazardlib.mfd.truncated_gr.TruncGRMFD
     '''
     expected = {'a_val': 4.0, 'b_val': 1.0, 'min_mag': 5.0, 'max_mag': 8.0}
     output = conv.render_mfd(self.model_gr)
     for key in expected.keys():
         self.assertAlmostEqual(expected[key], output.__dict__[key])
 def test_render_mfd_truncgr(self):
     '''
     Tests the function to render the mfd given a valid :class:
     openquake.hazardlib.mfd.truncated_gr.TruncGRMFD
     '''
     expected = {'a_val': 4.0, 'b_val': 1.0, 'min_mag': 5.0, 'max_mag': 8.0}
     output = conv.render_mfd(self.model_gr)
     for key in expected.keys():
         self.assertAlmostEqual(expected[key], output.__dict__[key])
 def test_render_mfd_evenly_discrtized(self):
     '''
     Tests the function to render the mfd given a valid :class:
     openquake.hazardlib.mfd.evenly_discretized.EvenlyDiscretizedMFD
     '''
     expected = {'min_mag': 5.0, 'bin_width': 0.1,
                 'occur_rates': np.ones(5, dtype=float)}
     output = conv.render_mfd(self.model_ed)
     self.assertAlmostEqual(output.__dict__['min_mag'], 5.0)
     self.assertAlmostEqual(output.__dict__['bin_width'], 0.1)
     np.testing.assert_array_almost_equal(
         output.__dict__['occur_rates'], np.ones(5, dtype=float))
    def test_raise_error_unrecognised_mfd(self):
        '''
        Tests that the render_mfd function raises an error when
        rendering an unsupported MFD
        '''
        class BadInput(object):
            def __init__(self):
                return

        with self.assertRaises(ValueError) as ae:
            _ = conv.render_mfd(BadInput())
            self.assertEqual(ae.exception.message,
                             'Magnitude frequency distribution BadInput not '
                             'supported')
예제 #9
0
    def test_mfd_to_hazardlib_unsupported_class(self):
        """
        Tests the conversion to the hazardlib using an unsupported class
        """
        class BadInput(object):
            def __init__(self):
                return

        with self.assertRaises(ValueError) as ae:
            _ = conv.render_mfd(BadInput())
            self.assertEqual(
                ae.exception.message,
                'Magnitude frequency distribution BadInput not '
                'supported')
예제 #10
0
    def test_raise_error_unrecognised_mfd(self):
        '''
        Tests that the render_mfd function raises an error when 
        rendering an unsupported MFD
        '''
        class BadInput(object):
            def __init__(self):
                return

        with self.assertRaises(ValueError) as ae:
            _ = conv.render_mfd(BadInput())
            self.assertEqual(
                ae.exception.message,
                'Magnitude frequency distribution BadInput not '
                'supported')
예제 #11
0
 def test_render_mfd_evenly_discrtized(self):
     '''
     Tests the function to render the mfd given a valid :class:
     openquake.hazardlib.mfd.evenly_discretized.EvenlyDiscretizedMFD
     '''
     expected = {
         'min_mag': 5.0,
         'bin_width': 0.1,
         'occur_rates': np.ones(5, dtype=float)
     }
     output = conv.render_mfd(self.model_ed)
     self.assertAlmostEqual(output.__dict__['min_mag'], 5.0)
     self.assertAlmostEqual(output.__dict__['bin_width'], 0.1)
     np.testing.assert_array_almost_equal(output.__dict__['occur_rates'],
                                          np.ones(5, dtype=float))
예제 #12
0
 def create_oqnrml_source(self, use_defaults=False):
     '''
     Converts the source model into  an instance of the :class:
     openquake.nrmllib.models.PointSource
     :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.
     '''
     point_geometry = models.PointGeometry(self.geometry.wkt2d,
                                           self.upper_depth,
                                           self.lower_depth)
     return models.PointSource(
         self.id, self.name, self.trt, point_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))
예제 #13
0
 def create_oqnrml_source(self, use_defaults=False):
     '''
     Converts the source model into  an instance of the :class:
     openquake.nrmllib.models.PointSource
     :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.
     '''
     point_geometry = models.PointGeometry(self.geometry.wkt2d,
                                           self.upper_depth,
                                           self.lower_depth)
     return models.PointSource(
         self.id, 
         self.name, 
         self.trt,
         point_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))