Source code for openquake.hazardlib.mfd.arbitrary_mfd
# The Hazard Library# Copyright (C) 2016-2025 GEM Foundation## This program 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.## This program 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 this program. If not, see <http://www.gnu.org/licenses/>."""Module :mod:`openquake.hazardlib.mfd.evenly_discretized` defines an evenlydiscretized MFD."""fromopenquake.hazardlib.mfd.baseimportBaseMFD
[docs]classArbitraryMFD(BaseMFD):""" An arbitrary MFD is defined as a list of tuples of magnitude values and their corresponding rates :param magnitudes: List of magnitudes :param occurrence_rates: The list of non-negative float values representing the actual annual occurrence rates. The resulting histogram has as many bins as this list length. """MODIFICATIONS={'set_mfd'}def__init__(self,magnitudes,occurrence_rates):self.magnitudes=magnitudesself.occurrence_rates=occurrence_ratesself.check_constraints()
[docs]defcheck_constraints(self):""" Checks the following constraints: * Magnitude list and occurrence rate lists are the same length * Occurrence rates list is not empty. * Each number in occurrence rates list is non-negative. * Minimum magnitude is positive. """ifnotlen(self.occurrence_rates):raiseValueError('at least one bin must be specified')ifnotall(value>=0forvalueinself.occurrence_rates):raiseValueError('all occurrence rates must not be negative')ifnotany(value>0forvalueinself.occurrence_rates):raiseValueError('at least one occurrence rate must be positive')ifnotlen(self.magnitudes)==len(self.occurrence_rates):raiseValueError('lists of magnitudes and rates must have same length')
[docs]defget_annual_occurrence_rates(self):""" Returns the predefined annual occurrence rates. """returnlist(zip(self.magnitudes,self.occurrence_rates))
[docs]defget_min_max_mag(self):""" Returns the minumun and maximum magnitudes """returnmin(self.magnitudes),max(self.magnitudes)
[docs]defmodify_set_mfd(self,magnitudes,occurrence_rates):""" Applies absolute modification of the MFD from the ``magnitudes``, ``occurrence_rates`` modification. :param magnitudes: List of magnitudes :param occurrence_rates: The list of non-negative float values representing the actual annual occurrence rates. The resulting histogram has as many bins as this list length. """self.magnitudes=magnitudesself.occurrence_rates=occurrence_ratesself.check_constraints()