Source code for openquake.hmtk.sources.complex_fault_source
# -*- coding: utf-8 -*-# vim: tabstop=4 shiftwidth=4 softtabstop=4## LICENSE## Copyright (C) 2010-2023 GEM Foundation, G. Weatherill, M. Pagani,# D. Monelli.## The Hazard Modeller's Toolkit is free software: you can redistribute# it and/or modify it under the terms of the GNU Affero General Public# License as published by the Free Software Foundation, either version# 3 of the License, or (at your option) any later version.## You should have received a copy of the GNU Affero General Public License# along with OpenQuake. If not, see <http://www.gnu.org/licenses/>## DISCLAIMER## The software Hazard Modeller's Toolkit (openquake.hmtk) provided herein# is released as a prototype implementation on behalf of# scientists and engineers working within the GEM Foundation (Global# Earthquake Model).## It is distributed for the purpose of open collaboration and in the# hope that it will be useful to the scientific, engineering, disaster# risk and software design communities.## The software is NOT distributed as part of GEM's OpenQuake suite# (https://www.globalquakemodel.org/tools-products) and must be considered as a# separate entity. The software provided herein is designed and implemented# by scientific staff. It is not developed to the design standards, nor# subject to same level of critical review by professional software# developers, as GEM's OpenQuake software suite.## Feedback and contribution to the software is welcome, and can be# directed to the hazard scientific staff of the GEM Model Facility# (hazard@globalquakemodel.org).## The Hazard Modeller's Toolkit (openquake.hmtk) is therefore distributed# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License# for more details.## The GEM Foundation, and the authors of the software, assume no# liability for use of the software."""Defines the :class:`openquake.hmtk.sources.complex_fault_source.mtkComplexFaultSource`, whichrepresents the openquake.hmtk defition of a complex fault source. This extendsthe :class:`nrml.models.ComplexFaultSource`"""importwarningsimportnumpyasnpfrommathimportfabsfromopenquake.hazardlib.geo.pointimportPointfromopenquake.hazardlib.geo.lineimportLinefromopenquake.hazardlib.geo.surface.complex_faultimportComplexFaultSurfacefromopenquake.hazardlib.source.complex_faultimportComplexFaultSourceimportopenquake.hmtk.sources.source_conversion_utilsasconv
[docs]classmtkComplexFaultSource(object):""" New class to describe the mtk complex fault source object :param str identifier: ID code for the source :param str name: Source name :param str trt: Tectonic region type :param geometry: Instance of :class: nhlib.geo.surface.complex_fault.ComplexFaultSource :param str mag_scale_rel: Magnitude scaling relationsip :param float rupt_aspect_ratio: Rupture aspect ratio :param mfd: Magnitude frequency distribution as instance of :class:`nrml.models.IncrementalMFD` or :class:`nrml.models.TGRMFD` :param float rake: Rake of fault :param float upper_depth: Upper seismogenic depth (km) :param float lower_depth: Lower seismogenic depth (km) :param catalogue: Earthquake catalogue associated to source as instance of :class:`openquake.hmtk.seismicity.catalogue.Catalogue` object """def__init__(self,identifier,name,trt=None,geometry=None,mag_scale_rel=None,rupt_aspect_ratio=None,mfd=None,rake=None,):""" Instantiate class with just the basic attributes: identifier and name """self.typology="ComplexFault"self.id=identifierself.name=nameself.trt=trtself.geometry=geometryself.fault_edges=Noneself.mag_scale_rel=mag_scale_relself.rupt_aspect_ratio=rupt_aspect_ratioself.mfd=mfdself.rake=rakeself.upper_depth=Noneself.lower_depth=Noneself.catalogue=Noneself.dip=None
[docs]defcreate_geometry(self,input_geometry,mesh_spacing=1.0):""" If geometry is defined as a numpy array then create instance of nhlib.geo.line.Line class, otherwise if already instance of class accept class :param input_geometry: List of at least two fault edges of the fault source from shallowest to deepest. Each edge can be represented as as either i) instance of nhlib.geo.polygon.Polygon class ii) numpy.ndarray [Longitude, Latitude, Depth] :param float mesh_spacing: Spacing of the fault mesh (km) {default = 1.0} """ifnotisinstance(input_geometry,list)orlen(input_geometry)<2:raiseValueError("Complex fault geometry incorrectly defined")self.fault_edges=[]foredgeininput_geometry:ifnotisinstance(edge,Line):ifnotisinstance(edge,np.ndarray):raiseValueError("Unrecognised or unsupported geometry ""definition")else:self.fault_edges.append(Line([Point(row[0],row[1],row[2])forrowinedge]))else:self.fault_edges.append(edge)# Updates the upper and lower sesmogenic depths to reflect geometryself._get_minmax_edges(edge)# Build fault surfaceself.geometry=ComplexFaultSurface.from_fault_data(self.fault_edges,mesh_spacing)# Get a mean dipself.dip=self.geometry.get_dip()
def_get_minmax_edges(self,edge):""" Updates the upper and lower depths based on the input edges """ifisinstance(edge,Line):# For instance of line class need to loop over valuesdepth_vals=np.array([node.depthfornodeinedge.points])else:depth_vals=edge[:,2]temp_upper_depth=np.min(depth_vals)ifnotself.upper_depth:self.upper_depth=temp_upper_depthelse:iftemp_upper_depth<self.upper_depth:self.upper_depth=temp_upper_depthtemp_lower_depth=np.max(depth_vals)ifnotself.lower_depth:self.lower_depth=temp_lower_depthelse:iftemp_lower_depth>self.lower_depth:self.lower_depth=temp_lower_depth
[docs]defselect_catalogue(self,selector,distance,distance_metric="joyner-boore",upper_eq_depth=None,lower_eq_depth=None,):""" Selects earthquakes within a distance of the fault :param selector: Populated instance of :class: `openquake.hmtk.seismicity.selector.CatalogueSelector` :param distance: Distance from point (km) for selection :param str distance_metric Choice of fault source distance metric 'joyner-boore' or 'rupture' :param float upper_eq_depth: Upper hypocentral depth of hypocentres to be selected :param float lower_eq_depth: Lower hypocentral depth of hypocentres to be selected """ifselector.catalogue.get_number_events()<1:raiseValueError("No events found in catalogue!")# If dip is != 90 and 'rupture' distance metric is selectedif("rupture"indistance_metric)and(fabs(self.dip-90)>1e-5):# Use rupture distanceself.catalogue=selector.within_rupture_distance(self.geometry,distance,upper_depth=upper_eq_depth,lower_depth=lower_eq_depth,)else:# Use Joyner-Boore distanceself.catalogue=selector.within_joyner_boore_distance(self.geometry,distance,upper_depth=upper_eq_depth,lower_depth=lower_eq_depth,)ifself.catalogue.get_number_events()<5:# Throw a warning regarding the small number of earthquakes in# the source!warnings.warn("Source %s (%s) has fewer than 5 events"%(self.id,self.name))
[docs]defcreate_oqhazardlib_source(self,tom,mesh_spacing,use_defaults=False):""" Creates an instance of the source model as :class: openquake.hazardlib.source.complex_fault.ComplexFaultSource """ifnotself.mfd:raiseValueError("Cannot write to hazardlib without MFD")returnComplexFaultSource(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,)