Source code for openquake.hmtk.sources.source_model
# -*- 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."""Module implements:class:`openquake.hmtk.sources.source_model.mtkSourceModel`, thegeneral class to describe a set of seismogenic sources"""fromopenquake.hazardlib.tomimportPoissonTOMfromopenquake.hazardlib.sourcewriterimportwrite_source_modelfromopenquake.hmtk.sources.point_sourceimportmtkPointSourcefromopenquake.hmtk.sources.area_sourceimportmtkAreaSourcefromopenquake.hmtk.sources.simple_fault_sourceimportmtkSimpleFaultSourcefromopenquake.hmtk.sources.complex_fault_sourceimportmtkComplexFaultSource
[docs]classmtkSourceModel(object):""" Object to describe a seismogenic source model (composite of multiple sources with mixed typologies) :param str id: Identifier for the source model :param str name: Source model name :param list sources: List of seismogenic sources """def__init__(self,identifier=None,name=None,sources=None):self.id=identifierself.name=nameifisinstance(sources,list):self.sources=sourceselse:ifsources:raiseValueError("Sources must be input as list!")self.sources=[]def__iter__(self):forsourceinself.sources:yieldsourcedef__len__(self):returnlen(self.sources)
[docs]defget_number_sources(self):""" Returns the number of sources in the model """returnlen(self.sources)
[docs]defserialise_to_nrml(self,filename,complex_mesh_spacing=2,use_defaults=False):""" Writes the source model to a nrml source model file given by the filename :param str filename: Path to output file :param bool use_defaults: Boolean to indicate whether to use default values (True) or not. If set to False, ValueErrors will be raised when an essential attribute is missing. """source_model=self.convert_to_oqhazardlib(PoissonTOM(1.0),2.0,complex_mesh_spacing,10.0,use_defaults=use_defaults,)write_source_model(filename,source_model,name=self.name)
[docs]defconvert_to_oqhazardlib(self,tom,simple_mesh_spacing=1.0,complex_mesh_spacing=2.0,area_discretisation=10.0,use_defaults=False,):""" Converts the source model to an iterator of sources of :class: `openquake.hazardlib.source.base.BaseSeismicSource` """oq_source_model=[]forsourceinself.sources:ifisinstance(source,mtkAreaSource):oq_source_model.append(source.create_oqhazardlib_source(tom,simple_mesh_spacing,area_discretisation,use_defaults,))elifisinstance(source,mtkPointSource):oq_source_model.append(source.create_oqhazardlib_source(tom,simple_mesh_spacing,use_defaults))elifisinstance(source,mtkSimpleFaultSource):oq_source_model.append(source.create_oqhazardlib_source(tom,simple_mesh_spacing,use_defaults))elifisinstance(source,mtkComplexFaultSource):oq_source_model.append(source.create_oqhazardlib_source(tom,complex_mesh_spacing,use_defaults))else:raiseValueError("Source type not recognised!")returnoq_source_model