def test_render_nodal_planes_null(self): ''' Tests the rendering of the nodal planes when no input is specified and no defaults are permitted. Should raise ValueError ''' with self.assertRaises(ValueError) as ae: output = conv.render_npd(None) self.assertEqual(ae.exception.message, 'Nodal Plane distribution not defined')
def test_render_nodal_planes_as_pmf_bad_1(self): ''' Tests the workflow when nodal planes input as a PMF without instance of openquake.hazardlib.geo.nodal_plane.NodalPlane :class: ''' with self.assertRaises(ValueError) as ae: output = conv.render_npd(self.npd_as_pmf_bad) self.assertEqual(ae.exception.message, 'Nodal Planes incorrectly formatted!')
def test_render_nodal_planes_null_default(self): ''' Tests the rendering of the nodal planes when no input is specified, but the use_defaults is on. ''' output = conv.render_npd(None, use_default=True) self.assertAlmostEqual(output[0].probability, 1.0) self.assertAlmostEqual(output[0].strike, 0.) self.assertAlmostEqual(output[0].dip, 90.) self.assertAlmostEqual(output[0].rake, 0.)
def test_render_nodal_planes_as_pmf_bad_2(self): ''' Tests the workflow when nodal planes input as a PMF without probabilities summing to 1.0 ''' self.npd_as_pmf.data[1] = (0.4, NodalPlane(90., 90., 180.)) with self.assertRaises(ValueError) as ae: output = conv.render_npd(self.npd_as_pmf) self.assertEqual(ae.exception.message, 'Nodal Plane probabilities do not sum to 1.0')
def test_render_nodal_planes_as_pmf_good(self): ''' Tests the workflow when nodal planes input as a PMF ''' output = conv.render_npd(self.npd_as_pmf) self.assertAlmostEqual(output[0].probability, 0.5) self.assertAlmostEqual(output[0].strike, 0.) self.assertAlmostEqual(output[0].dip, 90.) self.assertAlmostEqual(output[0].rake, 0.) self.assertAlmostEqual(output[1].probability, 0.5) self.assertAlmostEqual(output[1].strike, 90.) self.assertAlmostEqual(output[1].dip, 90.) self.assertAlmostEqual(output[1].rake, 180.)
def test_render_nodal_planes_as_list(self): ''' Tests the workflow when nodal planes already input as a list of models.NodalPlane class ''' output = conv.render_npd(self.npd_as_list) self.assertAlmostEqual(output[0].probability, 0.5) self.assertAlmostEqual(output[0].strike, 0.) self.assertAlmostEqual(output[0].dip, 90.) self.assertAlmostEqual(output[0].rake, 0.) self.assertAlmostEqual(output[1].probability, 0.5) self.assertAlmostEqual(output[1].strike, 90.) self.assertAlmostEqual(output[1].dip, 90.) self.assertAlmostEqual(output[1].rake, 180.)
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))