def __init__(self, source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio, # simple fault specific parameters upper_seismogenic_depth, lower_seismogenic_depth, fault_trace, dip, rake): super(SimpleFaultSource, self).__init__( source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio ) NodalPlane.check_rake(rake) SimpleFaultSurface.check_fault_data( fault_trace, upper_seismogenic_depth, lower_seismogenic_depth, dip, rupture_mesh_spacing ) self.fault_trace = fault_trace self.upper_seismogenic_depth = upper_seismogenic_depth self.lower_seismogenic_depth = lower_seismogenic_depth self.dip = dip self.rake = rake min_mag = self.mfd.get_min_mag() cols_rows = self._get_rupture_dimensions(float('inf'), float('inf'), min_mag) if 1 in cols_rows: raise ValueError('mesh spacing %s is too low to represent ' 'ruptures of magnitude %s' % (rupture_mesh_spacing, min_mag))
def __init__(self, mag, rake, tectonic_region_type, hypocenter, surface): if not mag > 0: raise ValueError('magnitude must be positive') if not hypocenter.depth > 0: raise ValueError('rupture hypocenter must have positive depth') NodalPlane.check_rake(rake) self.tectonic_region_type = tectonic_region_type self.rake = rake self.mag = mag self.hypocenter = hypocenter self.surface = surface
def __init__(self, mesh_spacing, strike, dip, top_left, top_right, bottom_right, bottom_left): super(PlanarSurface, self).__init__() if not (top_left.depth == top_right.depth and bottom_left.depth == bottom_right.depth): raise ValueError("top and bottom edges must be parallel " "to the earth surface") if not mesh_spacing > 0: raise ValueError("mesh spacing must be positive") self.mesh_spacing = mesh_spacing NodalPlane.check_dip(dip) NodalPlane.check_strike(strike) self.dip = dip self.strike = strike self.corner_lons = numpy.array([ top_left.longitude, top_right.longitude, bottom_left.longitude, bottom_right.longitude ]) self.corner_lats = numpy.array([ top_left.latitude, top_right.latitude, bottom_left.latitude, bottom_right.latitude ]) self.corner_depths = numpy.array([ top_left.depth, top_right.depth, bottom_left.depth, bottom_right.depth ]) self._init_plane() # now we can check surface for validity dists, xx, yy = self._project(self.corner_lons, self.corner_lats, self.corner_depths) # "length" of the rupture is measured along the top edge length1, length2 = xx[1] - xx[0], xx[3] - xx[2] # "width" of the rupture is measured along downdip direction width1, width2 = yy[2] - yy[0], yy[3] - yy[1] self.width = (width1 + width2) / 2.0 self.length = (length1 + length2) / 2.0 # calculate the imperfect rectangle tolerance # relative to surface's area tolerance = self.width * self.length \ * self.IMPERFECT_RECTANGLE_TOLERANCE if numpy.max(numpy.abs(dists)) > tolerance: raise ValueError("corner points do not lie on the same plane") if length2 < 0: raise ValueError("corners are in the wrong order") if abs(length1 - length2) > tolerance: raise ValueError("top and bottom edges have different lengths") if abs(xx[0] - xx[2]) > tolerance: raise ValueError("surface's angles are not right")
def __init__(self, mag, rake, tectonic_region_type, hypocenter, surface, source_typology): if not mag > 0: raise ValueError('magnitude must be positive') if not hypocenter.depth > 0: raise ValueError('rupture hypocenter must have positive depth') NodalPlane.check_rake(rake) self.tectonic_region_type = tectonic_region_type self.rake = rake self.mag = mag self.hypocenter = hypocenter self.surface = surface self.source_typology = source_typology
def __init__(self, source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio, # complex fault specific parameters edges, rake): super(ComplexFaultSource, self).__init__( source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio ) NodalPlane.check_rake(rake) ComplexFaultSurface.check_fault_data(edges, rupture_mesh_spacing) self.edges = edges self.rake = rake
def __init__(self, mesh_spacing, strike, dip, top_left, top_right, bottom_right, bottom_left): super(PlanarSurface, self).__init__() if not (top_left.depth == top_right.depth and bottom_left.depth == bottom_right.depth): raise ValueError("top and bottom edges must be parallel " "to the earth surface") if not mesh_spacing > 0: raise ValueError("mesh spacing must be positive") self.mesh_spacing = mesh_spacing NodalPlane.check_dip(dip) NodalPlane.check_strike(strike) self.dip = dip self.strike = strike self.corner_lons = numpy.array([ top_left.longitude, top_right.longitude, bottom_left.longitude, bottom_right.longitude ]) self.corner_lats = numpy.array([ top_left.latitude, top_right.latitude, bottom_left.latitude, bottom_right.latitude ]) self.corner_depths = numpy.array([ top_left.depth, top_right.depth, bottom_left.depth, bottom_right.depth ]) self._init_plane() # now we can check surface for validity dists, xx, yy = self._project(self.corner_lons, self.corner_lats, self.corner_depths) # "length" of the rupture is measured along the top edge length1, length2 = xx[1] - xx[0], xx[3] - xx[2] # "width" of the rupture is measured along downdip direction width1, width2 = yy[2] - yy[0], yy[3] - yy[1] if numpy.max(numpy.abs(dists)) > self.IMPERFECT_RECTANGLE_TOLERANCE \ or abs(width1 - width2) > self.IMPERFECT_RECTANGLE_TOLERANCE \ or width2 < 0 \ or abs(xx[0] - xx[2]) > self.IMPERFECT_RECTANGLE_TOLERANCE \ or abs(length1 - length2) > self.IMPERFECT_RECTANGLE_TOLERANCE: raise ValueError("planar surface corners must " "represent a rectangle") self.width = (width1 + width2) / 2.0 self.length = (length1 + length2) / 2.0
def _test_broken_input(self, broken_parameter, **kwargs): with self.assertRaises(ValueError) as ae: NodalPlane(**kwargs) self.assertTrue(ae.exception.message.startswith(broken_parameter), ae.exception.message) checker = getattr(NodalPlane, 'check_%s' % broken_parameter) with self.assertRaises(ValueError) as ae: checker(kwargs[broken_parameter]) self.assertTrue(ae.exception.message.startswith(broken_parameter), ae.exception.message)
def __init__( self, source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio, # simple fault specific parameters upper_seismogenic_depth, lower_seismogenic_depth, fault_trace, dip, rake): super(SimpleFaultSource, self).__init__(source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio) NodalPlane.check_rake(rake) SimpleFaultSurface.check_fault_data(fault_trace, upper_seismogenic_depth, lower_seismogenic_depth, dip, rupture_mesh_spacing) self.fault_trace = fault_trace self.upper_seismogenic_depth = upper_seismogenic_depth self.lower_seismogenic_depth = lower_seismogenic_depth self.dip = dip self.rake = rake min_mag = self.mfd.get_min_mag() cols_rows = self._get_rupture_dimensions(float('inf'), float('inf'), min_mag) if 1 in cols_rows: raise ValueError('mesh spacing %s is too low to represent ' 'ruptures of magnitude %s' % (rupture_mesh_spacing, min_mag))
def __init__( self, source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio, # complex fault specific parameters edges, rake): super(ComplexFaultSource, self).__init__(source_id, name, tectonic_region_type, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio) NodalPlane.check_rake(rake) ComplexFaultSurface.check_fault_data(edges, rupture_mesh_spacing) self.edges = edges self.rake = rake
def test_corner_cases(self): np = NodalPlane(strike=0, dip=0.001, rake=-180 + 1e-5) self.assertEqual((np.strike, np.dip, np.rake), (0, 0.001, -180 + 1e-5)) np = NodalPlane(strike=360 - 1e-5, dip=90, rake=+180) self.assertEqual((np.strike, np.dip, np.rake), (360 - 1e-5, 90, +180))