# -*- coding: utf-8 -*-# vim: tabstop=4 shiftwidth=4 softtabstop=4## Copyright (C) 2012-2025 GEM Foundation## OpenQuake 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.## OpenQuake is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU Affero General Public License for more details.## You should have received a copy of the GNU Affero General Public License# along with OpenQuake. If not, see <http://www.gnu.org/licenses/>."""Package :mod:`openquake.hazardlib.scalerel` contains base classes andimplementations of magnitude-area and area-magnitude scaling relationships."""importosimportinspectimportimportlibfromopenquake.hazardlib.scalerel.baseimport(BaseMSR,BaseASR,BaseMSRSigma,BaseASRSigma)fromopenquake.hazardlib.scalerel.peerimportPeerMSR# noqafromopenquake.hazardlib.scalerel.pointimportPointMSR# noqafromopenquake.hazardlib.scalerel.wc1994importWC1994# noqadef_get_available_class(base_class):''' Return an ordered dictionary with the available classes in the scalerel submodule with classes that derives from `base_class`, keyed by class name. '''classes={}# class_name -> classforfnameinos.listdir(os.path.dirname(__file__)):iffname.endswith('.py'):modname,_ext=os.path.splitext(fname)mod=importlib.import_module('openquake.hazardlib.scalerel.'+modname)forclsinmod.__dict__.values():ifinspect.isclass(cls)andissubclass(cls,base_class) \
andcls!=base_class \
andnotinspect.isabstract(cls):classes[cls.__name__]=clsreturndict((k,classes[k])forkinsorted(classes))
[docs]defget_available_magnitude_scalerel():''' Return a list of the available Magnitude ScaleRel instances. '''dic=_get_available_class(BaseMSR)msrs=[]forname,clsindic.items():ifinspect.signature(cls).parameters:# ignore CScalingpasselse:msrs.append(cls())returnmsrs
[docs]defget_available_sigma_magnitude_scalerel():''' Return an ordered dictionary with the available Sigma Magnitude ScaleRel classes, keyed by class name. '''return_get_available_class(BaseMSRSigma)
[docs]defget_available_area_scalerel():''' Return an ordered dictionary with the available Area ScaleRel classes, keyed by class name. '''return_get_available_class(BaseASR)
[docs]defget_available_sigma_area_scalerel():''' Return an ordered dictionary with the available Sigma Area ScaleRel classes, keyed by class name. '''return_get_available_class(BaseASRSigma)
[docs]defget_available_scalerel():''' Return an ordered dictionary with the available ScaleRel classes, keyed by class name. '''ret=get_available_area_scalerel()ret.update(_get_available_class(BaseMSR))returnret