# The Hazard Library# Copyright (C) 2012-2023 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/>."""A Magnitude Frequency Distribution (MFD) is a function that describes the rate(per year) of earthquakes across all magnitudes.Package `mfd` contains the basic class for MFD --:class:`openquake.hazardlib.mfd.base.BaseMFD`, and three actualimplementations::class:`openquake.hazardlib.mfd.evenly_discretized.EvenlyDiscretizedMFD`:class:`openquake.hazardlib.mfd.truncated_gr.TruncatedGRMFD` and:class:`openquake.hazardlib.mfd.youngs_coppersmith_1985.YoungsCoppersmith1985MFD`."""importtomlfromopenquake.hazardlib.mfd.evenly_discretizedimport(# noqaEvenlyDiscretizedMFD)fromopenquake.hazardlib.mfd.truncated_grimportTruncatedGRMFD# noqafromopenquake.hazardlib.mfd.youngs_coppersmith_1985import(# noqaYoungsCoppersmith1985MFD)fromopenquake.hazardlib.mfd.arbitrary_mfdimportArbitraryMFD# noqafromopenquake.hazardlib.mfd.tapered_gr_mfdimportTaperedGRMFD# noqafromopenquake.hazardlib.mfdimportmulti_mfd# noqa
[docs]deffrom_toml(string,bin_width):""" Convert a TOML string into an MFD instance """[(name,params)]=toml.loads(string).items()ifname=='multiMFD':returnmulti_mfd.MultiMFD.from_params(params,bin_width)cls,*required=multi_mfd.ASSOC[name]kw={}forparam,valueinparams.items():kw[multi_mfd.TOML2PY.get(param,param)]=valueif'bin_width'inrequiredandbin_widthnotinkw:kw['bin_width']=bin_widthreturncls(**kw)