# -*- 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/>."""Module :mod:`openquake.hazardlib.scalerel.base` defines abstract baseclasses for :class:`ASR <BaseASR>`, :class:`MSR <BaseMSR>`,:class:`ASRSigma <BaseASRSigma>`, and :class:`MSRSigma <BaseMSRSigma>`"""importabcimportinspect
[docs]defcheck_args(func,expected):got=inspect.getfullargspec(func).argsifgot!=expected:raiseSyntaxError('%s must must have signature (%s), got (%s)'%(func.__name__,', '.join(expected),', '.join(got)))
[docs]classBaseASR(metaclass=abc.ABCMeta):""" A base class for Area-Magnitude Scaling Relationship. Allows calculation of rupture magnitude from area. """def__init_subclass__(cls):forkey,funcincls.__dict__.items():ifkey=='get_std_dev_mag':check_args(func,['self','area','rake'])elifkey=='get_median_area':check_args(func,['self','mag','rake'])
[docs]@abc.abstractmethoddefget_median_mag(self,area,rake):""" Return median magnitude (Mw) given the area and rake. :param area: Area in square km. :param rake: Rake angle (the rupture propagation direction) in degrees, from -180 to 180. """
def__str__(self):""" Returns a TOML representation of the instance """returnself.__class__.__name__def__repr__(self):""" Returns the name of the class in angular brackets """return"<%s>"%self.__class__.__name__
[docs]classBaseASRSigma(BaseASR,metaclass=abc.ABCMeta):""" Extend :class:`BaseASR` and allows to include uncertainties (sigma) in rupture magnitude estimation. """
[docs]@abc.abstractmethoddefget_std_dev_mag(self,area,rake):""" Return the standard deviation on the magnitude. :param rake: Rake angle (the rupture propagation direction) in degrees, from -180 to 180. """
[docs]classBaseMSR(metaclass=abc.ABCMeta):""" A base class for Magnitude-Area Scaling Relationship. Allows calculation of rupture area from magnitude. """
[docs]@abc.abstractmethoddefget_median_area(self,mag,rake):""" Return median area (in square km) from magnitude ``mag`` and ``rake``. To be overridden by subclasses. :param mag: Moment magnitude (Mw). :param rake: Rake angle (the rupture propagation direction) in degrees, from -180 to 180. """
def__eq__(self,other):""" Two instances of the same class are considered equal """returnself.__class__isother.__class__def__str__(self):""" Returns a TOML representation of the instance """returnself.__class__.__name__def__repr__(self):""" Returns the name of the class """return"<%s>"%self.__class__.__name__
[docs]classBaseMSRSigma(BaseMSR,metaclass=abc.ABCMeta):""" Extends :class:`BaseMSR` and allows to include uncertainties (sigma) in rupture area estimation. """
[docs]@abc.abstractmethoddefget_std_dev_area(self,mag,rake):""" Return the standard deviation of the area distribution given magnitude ``mag`` and rake. To be overridden by subclasses. :param mag: Moment magnitude (Mw). :param rake: Rake angle (the rupture propagation direction) in degrees, from -180 to 180. """