Exemple #1
0
 def test_missing_value_no_default(self):
     '''
     Tests the case when the attribute is missing and the use_defaults
     option is not selected. Should raise ValueError
     '''
     with self.assertRaises(ValueError) as ae:
         conv.render_aspect_ratio(None)
     self.assertEqual(str(ae.exception),
                      'Rupture aspect ratio not defined!')
 def test_missing_value_no_default(self):
     '''
     Tests the case when the attribute is missing and the use_defaults
     option is not selected. Should raise ValueError
     '''
     with self.assertRaises(ValueError) as ae:
         conv.render_aspect_ratio(None)
     self.assertEqual(str(ae.exception),
                      'Rupture aspect ratio not defined!')
 def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
     """
     Returns an instance of the :class:
     openquake.hazardlib.source.simple_fault.SimpleFaultSource
     :param tom:
          Temporal occurrance model
     :param float mesh_spacing:
          Mesh spacing
     
     """
     if not self.mfd:
         raise ValueError("Cannot write to hazardlib without MFD")
     return SimpleFaultSource(
         self.id,
         self.name,
         self.trt,
         self.mfd,
         mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
         tom,
         self.upper_depth,
         self.lower_depth,
         self.fault_trace,
         self.dip,
         self.rake)
    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,
        )
Exemple #5
0
    def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
        """
        Converts the point source model into an instance of the :class:
        openquake.hazardlib.source.point_source.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.
        """
        if not self.mfd:
            raise ValueError("Cannot write to hazardlib without MFD")
        return PointSource(
            self.id,
            self.name,
            self.trt,
            self.mfd,
            mesh_spacing,
            conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
            conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
            tom,
            self.upper_depth,
            self.lower_depth,
            self.geometry,
            conv.npd_to_pmf(self.nodal_plane_dist, use_defaults),
            conv.hdd_to_pmf(self.hypo_depth_dist, use_defaults))
    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)
Exemple #7
0
 def create_oqhazardlib_source(self,
                               tom,
                               mesh_spacing,
                               area_discretisation,
                               use_defaults=False):
     """
     Converts the source model into an instance of the :class:
     openquake.hazardlib.source.area.AreaSource
     
     :param tom:
         Temporal Occurrence model as instance of :class:
         openquake.hazardlib.tom.TOM
     :param float mesh_spacing:
         Mesh spacing
     """
     if not self.mfd:
         raise ValueError("Cannot write to hazardlib without MFD")
     return AreaSource(
         self.id, self.name, self.trt, self.mfd, mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
         tom, self.upper_depth, self.lower_depth,
         conv.npd_to_pmf(self.nodal_plane_dist, use_defaults),
         conv.hdd_to_pmf(self.hypo_depth_dist,
                         use_defaults), self.geometry, area_discretisation)
Exemple #8
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)
Exemple #9
0
 def create_oqhazardlib_source(self, tom, mesh_spacing, area_discretisation,
         use_defaults=False):
     """
     Converts the source model into an instance of the :class:
     openquake.hazardlib.source.area.AreaSource
     
     :param tom:
         Temporal Occurrence model as instance of :class:
         openquake.hazardlib.tom.TOM
     :param float mesh_spacing:
         Mesh spacing
     """
     return AreaSource(
         self.id,
         self.name,
         self.trt,
         conv.mfd_to_hazardlib(self.mfd),
         mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
         tom,
         self.upper_depth,
         self.lower_depth,
         conv.npd_to_pmf(self.nodal_plane_dist, use_defaults),
         conv.hdd_to_pmf(self.hypo_depth_dist, use_defaults),
         self.geometry,
         area_discretisation)
Exemple #10
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)
Exemple #11
0
 def test_missing_value_with_default(self):
     '''
     Tests the case when the attibute is missing but the use_defaults
     option is selected
     '''
     self.assertAlmostEqual(
         conv.render_aspect_ratio(None, use_default=True), 1.0)
 def test_missing_value_with_default(self):
     '''
     Tests the case when the attibute is missing but the use_defaults
     option is selected
     '''
     self.assertAlmostEqual(
         conv.render_aspect_ratio(None, use_default=True),
         1.0)
 def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
     """
     Creates an instance of the source model as :class:
     openquake.hazardlib.source.complex_fault.ComplexFaultSource
     """
     if not self.mfd:
         raise ValueError("Cannot write to hazardlib without MFD")
     return ComplexFaultSource(
         self.id, self.name, self.trt, self.mfd, mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
         tom, self.fault_edges, self.rake)
Exemple #14
0
 def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
     """
     Creates an instance of the source model as :class:
     openquake.hazardlib.source.complex_fault.ComplexFaultSource
     """
     return ComplexFaultSource(
         self.id,
         self.name,
         self.trt,
         conv.mfd_to_hazardlib(self.mfd),
         mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
         tom,
         self.fault_edges,
         self.rake)
 def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
     """
     Returns an instance of the :class:
     openquake.hazardlib.source.simple_fault.SimpleFaultSource
     :param tom:
          Temporal occurrance model
     :param float mesh_spacing:
          Mesh spacing
     
     """
     if not self.mfd:
         raise ValueError("Cannot write to hazardlib without MFD")
     return SimpleFaultSource(
         self.id, self.name, self.trt, self.mfd, mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio,
                                  use_defaults), tom, self.upper_depth,
         self.lower_depth, self.fault_trace, self.dip, self.rake)
 def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
     """
     Creates an instance of the source model as :class:
     openquake.hazardlib.source.complex_fault.ComplexFaultSource
     """
     if not self.mfd:
         raise ValueError("Cannot write to hazardlib without MFD")
     return ComplexFaultSource(
         self.id,
         self.name,
         self.trt,
         self.mfd,
         mesh_spacing,
         conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
         conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
         tom,
         self.fault_edges,
         self.rake)
Exemple #17
0
    def create_oqhazardlib_source(self, tom, mesh_spacing, use_defaults=False):
        """
        Converts the point source model into an instance of the :class:
        openquake.hazardlib.source.point_source.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.
        """
        return PointSource(
            self.id, self.name, self.trt, conv.mfd_to_hazardlib(self.mfd),
            mesh_spacing,
            conv.mag_scale_rel_to_hazardlib(self.mag_scale_rel, use_defaults),
            conv.render_aspect_ratio(self.rupt_aspect_ratio, use_defaults),
            tom, self.upper_depth, self.lower_depth, self.geometry,
            conv.npd_to_pmf(self.nodal_plane_dist, use_defaults),
            conv.hdd_to_pmf(self.hypo_depth_dist, use_defaults))
Exemple #18
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))
Exemple #19
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))
Exemple #20
0
 def test_good_aspect_ratio(self):
     '''
     Test the simple case when a valid aspect ratio is input
     '''
     self.assertAlmostEqual(conv.render_aspect_ratio(1.5), 1.5)
 def test_good_aspect_ratio(self):
     '''
     Test the simple case when a valid aspect ratio is input
     '''
     self.assertAlmostEqual(conv.render_aspect_ratio(1.5), 1.5)