def test_no_input_with_defaults(self): ''' Tests hypocentral depth distribution renderer when no input is supplied but the user opts to accept defaults ''' output = conv.render_hdd(None, use_default=True) self.assertAlmostEqual(output[0].probability, 1.0) self.assertAlmostEqual(output[0].depth, 10.0)
def test_good_instance_pmf(self): ''' Tests good output when openquake.hazardlib.pmf.PMF class is passed ''' output = conv.render_hdd(self.depth_as_pmf) self.assertAlmostEqual(output[0].probability, 0.5) self.assertAlmostEqual(output[0].depth, 5.) self.assertAlmostEqual(output[1].probability, 0.5) self.assertAlmostEqual(output[1].depth, 10.)
def test_no_input_without_defaults(self): ''' Tests hypocentral depth distribution renderer when no input is supplied but the user does not accept defaults. Should raise ValueError ''' with self.assertRaises(ValueError) as ae: output = conv.render_hdd(None) self.assertEqual(ae.exception.message, 'Hypocentral depth distribution not defined!')
def test_good_instance_list(self): ''' Tests good output when list of instances of :class: models.HypocentralDepth are passed ''' output = conv.render_hdd(self.depth_as_list) self.assertAlmostEqual(output[0].probability, 0.5) self.assertAlmostEqual(output[0].depth, 5.) self.assertAlmostEqual(output[1].probability, 0.5) self.assertAlmostEqual(output[1].depth, 10.)
def test_bad_instance_pmf(self): ''' Tests function when openquake.hazardlib.pmf.PMF class is passed with probabilities not equal to 1.0. Should raise ValueError ''' self.depth_as_pmf.data[1] = (0.4, 10.) with self.assertRaises(ValueError) as ae: output = conv.render_hdd(self.depth_as_pmf) self.assertEqual(ae.exception.message, 'Hypocentral depth distribution probabilities do not sum to ' '1.0')
def test_bad_instance_pmf(self): ''' Tests function when openquake.hazardlib.pmf.PMF class is passed with probabilities not equal to 1.0. Should raise ValueError ''' self.depth_as_pmf.data[1] = (0.4, 10.) with self.assertRaises(ValueError) as ae: output = conv.render_hdd(self.depth_as_pmf) self.assertEqual( ae.exception.message, 'Hypocentral depth distribution probabilities do not sum to ' '1.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))