<commit_before># -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2014-2019 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 exports :class:`RietbrockEdwards2019`
"""

import numpy as np
# standard acceleration of gravity in m/s**2
from scipy.constants import g

from openquake.hazardlib.gsim.base import CoeffsTable, GMPE
from openquake.hazardlib import const
from openquake.hazardlib.imt import PGA, PGV, SA


class RietbrockEdwards2019Mean(GMPE):
    """
    Implements the ground motion prediction equation of Rietbrock et al
    (2019):

    <NAME>., <NAME>. (2019). Update of the UK stochastic ground
    motion model using a decade of broadband data. In Proceedings of the
    2019 SECED conference.
    """
    #: Supported tectonic region type is stabe continental crust,
    DEFINED_FOR_TECTONIC_REGION_TYPE = const.TRT.STABLE_CONTINENTAL

    #: Supported intensity measure types are spectral acceleration, peak
    #: ground acceleration and peak ground velocity.
    DEFINED_FOR_INTENSITY_MEASURE_TYPES = set([
        PGA,
        PGV,
        SA
    ])

    #: Supported intensity measure component is the geometric mean of two
    #: horizontal components
    DEFINED_FOR_INTENSITY_MEASURE_COMPONENT = const.IMC.AVERAGE_HORIZONTAL

    #: Supported standard deviation types are inter-event, intra-event and
    #: total
    DEFINED_FOR_STANDARD_DEVIATION_TYPES = set([
        const.StdDev.INTER_EVENT,
        const.StdDev.INTRA_EVENT,
        const.StdDev.TOTAL
    ])

    #: No site parameter is required
    REQUIRES_SITES_PARAMETERS = set()

    #: Required rupture parameters are magnitude
    REQUIRES_RUPTURE_PARAMETERS = set(('mag',))

    #: Required distance measure is Rjb
    REQUIRES_DISTANCES = set(('rjb', ))

    def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        """
        See :meth:`superclass method
        <.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
        for spec of input and result values.
        """
        # extract dictionaries of coefficients specific to required
        # intensity measure type
        C = self.COEFFS[imt]
        imean = C["c1"] + (self._get_magnitude_term(C, rup.mag) +
                           self._get_distance_term(C, dists.rjb, rup.mag))
        # convert from cm/s**2 to g for SA and from cm/s**2 to g for PGA (PGV
        # is already in cm/s) and also convert from base 10 to base e.
        if imt.name in "SA PGA":
            mean = np.log((10.0 ** (imean - 2.0)) / g)
        else:
            mean = np.log(10 ** imean)

        stddevs = self._get_stddevs(C, stddev_types, dists.rjb.shape[0])

        return mean, stddevs

    def _get_magnitude_term(self, C, mag):
        """
        Returns the magnitude scaling component of the model
        Equation 10, Page 63
        """
        return (C["c2"] * mag) + (C["c3"] * (mag ** 2.0))

    def _get_distance_term(self, C, rjb, mag):
        """
        Returns the distance scaling component of the model
        Equation 10, Page 63
        """
        # Depth adjusted distance, equation 11 (Page 63)
        rval = np.sqrt(rjb ** 2.0 + C["c11"] ** 2.0)
        f_0, f_1, f_2 = self._get_distance_segment_coefficients(rval)
        return ((C["c4"] + C["c5"] * mag) * f_0 +
                (C["c6"] + C["c7"] * mag) * f_1 +
                (C["c8"] + C["c9"] * mag) * f_2 +
                (C["c10"] * rval))

    def _get_distance_segment_coefficients(self, rval):
        """
        Returns the coefficients describing the distance attenuation shape
        for three different distance bins, equations 12a - 12c
        """
        # Get distance segment ends
        # Equation 12a
        f_0 = np.log10(self.CONSTS["r0"] / rval)
        f_0[rval > self.CONSTS["r0"]] = 0.0

        # Equation 12b
        f_1 = np.log10(rval)
        f_1[rval > self.CONSTS["r1"]] = np.log10(self.CONSTS["r1"])
        # Equation 12c
        f_2 = np.log10(rval / self.CONSTS["r2"])
        f_2[rval <= self.CONSTS["r2"]] = 0.0
        return f_0, f_1, f_2

    def _get_stddevs(self, C, stddev_types, num_sites):
        """
        Returns the standard deviation. Original standard deviations are in
        logarithms of base 10. Converts to natural logarithm.
        """
        stddevs = []
        for stddev_type in stddev_types:
            assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            if stddev_type == const.StdDev.TOTAL:
                stddevs.append(np.log(10.0 **
                                      (C["total"] + np.zeros(num_sites))))
            elif stddev_type == const.StdDev.INTRA_EVENT:
                stddevs.append(np.log(10.0 **
                                      (C["phi"] + np.zeros(num_sites))))
            elif stddev_type == const.StdDev.INTER_EVENT:
                stddevs.append(np.log(10.0 **
                                      (C["tau"] + np.zeros(num_sites))))
        return stddevs


    COEFFS = CoeffsTable(sa_damping=5, table="""\
     IMT      c1      c2      c3      c4      c5      c6      c7      c8      c9       c10     c11   total     tau     phi
0    pgv -4.4578  1.6540 -0.1044 -1.6308  0.2082 -1.6465  0.1568 -2.3547  0.0676 -0.000991  2.8899  0.2704  0.2199  0.1573
1    pga -2.1780  1.6355 -0.1241 -1.8303  0.2165 -1.8318  0.1622 -1.9899  0.0678 -0.002073  2.3460  0.3323  0.2858  0.1695
2   0.03 -1.3946  1.5566 -0.1210 -2.1447  0.2324 -2.0955  0.1777 -1.7240  0.0891 -0.003079  1.5613  0.3642  0.2951  0.2133
3   0.04 -1.5298  1.5684 -0.1181 -1.8704  0.1906 -1.8175  0.1420 -1.5458  0.0827 -0.003522  1.4637  0.3573  0.2977  0.1975
4   0.05 -1.6747  1.5876 -0.1178 -1.7218  0.1719 -1.6779  0.1258 -1.5486  0.0695 -0.003350  1.5137  0.3506  0.2976  0.1853
5   0.06 -1.8507  1.6171 -0.1187 -1.5996  0.1587 -1.5637  0.1136 -1.6102  0.0560 -0.002996  1.6318  0.3422  0.2959  0.1718
6   0.08 -2.0520  1.6568 -0.1209 -1.5126  0.1517 -1.4804  0.1057 -1.7039  0.0458 -0.002586  1.8079  0.3336  0.2928  0.1598
7    0.1 -2.3048  1.7127 -0.1246 -1.4463  0.1480 -1.4141  0.1000 -1.8096  0.0382 -0.002172  2.0171  0.3250  0.2880  0.1506
8   0.12 -2.5981  1.7821 -0.1295 -1.3958  0.1454 -1.3622  0.0956 -1.9028  0.0331 -0.001822  2.1704  0.3174  0.2821  0.1454
9   0.16 -2.9711  1.8735 -0.1360 -1.3507  0.1428 -1.3141  0.0915 -1.9872  0.0290 -0.001508  2.2948  0.3097  0.2745  0.1433
10   0.2 -3.4163  1.9839 -0.1439 -1.3080  0.1393 -1.2687  0.0872 -2.0567  0.0256 -0.001243  2.3514  0.3023  0.2657  0.1441
11  0.25 -3.9043  2.1039 -0.1522 -1.2667  0.1347 -1.2260  0.0829 -2.1103  0.0228 -0.001030  2.3495  0.2954  0.2563  0.1470
12  0.31 -4.4356  2.2302 -0.1606 -1.2230  0.1286 -1.1838  0.0783 -2.1517  0.0202 -0.000850  2.2892  0.2889  0.2462  0.1512
13   0.4 -4.9975  2.3558 -0.1683 -1.1762  0.1213 -1.1419  0.0736 -2.1841  0.0178 -0.000694  2.1896  0.2827  0.2355  0.1563
14   0.5 -5.5468  2.4664 -0.1741 -1.1287  0.1135 -1.1038  0.0693 -2.2080  0.0155 -0.000560  2.0648  0.2770  0.2248  0.1618
15  0.63 -6.0465  2.5499 -0.1771 -1.0857  0.1067 -1.0742  0.0663 -2.2253  0.0133 -0.000442  1.9685  0.2719  0.2144  0.1673
16  0.79 -6.4705  2.5968 -0.1765 -1.0512  0.1016 -1.0584  0.0655 -2.2384  0.0115 -0.000334  1.8968  0.2676  0.2044  0.1726
17     1 -6.7771  2.5981 -0.1719 -1.0343  0.1002 -1.0642  0.0681 -2.2491  0.0102 -0.000239  1.8893  0.2640  0.1954  0.1775
18  1.25 -6.9495  2.5538 -0.1637 -1.0411  0.1032 -1.0957  0.0748 -2.2593  0.0101 -0.000157  1.9356  0.2610  0.1872  0.1819
19  1.59 -6.9977  2.4597 -0.1513 -1.0802  0.1121 -1.1604  0.0866 -2.2724  0.0117 -0.000086  2.0388  0.2580  0.1787  0.1862
20     2 -6.9298  2.3348 -0.1370 -1.1486  0.1257 -1.2477  0.1018 -2.2897  0.0158 -0.000043  2.1604  0.2550  0.1703  0.1898
21   2.5 -6.7909  2.1932 -0.1220 -1.2383  0.1424 -1.3473  0.1184 -2.3139  0.0230 -0.000029  2.2903  0.2517  0.1616  0.1930
22  3.13 -6.6206  2.0449 -0.1069 -1.3397  0.1604 -1.4492  0.1350 -2.3503  0.0340 -0.000047  2.4199  0.2480  0.1523  0.1957
23     4 -6.4512  1.8930 -0.0918 -1.4444  0.1782 -1.5462  0.1501 -2.4088  0.0503 -0.000098  2.5430  0.2440  0.1423  0.1982
24     5 -6.3504  1.7758 -0.0801 -1.5184  0.1896 -1.6103  0.1596 -2.4808  0.0678 -0.000161  2.6018  0.2407  0.1339  0.2001
    """)

    CONSTS = {"r0": 10.0,
              "r1": 50.0,
              "r2": 100.0}


class RietbrockEdwards2019Low(RietbrockEdwards2019Mean):
    COEFFS = CoeffsTable(sa_damping=5, table="""\
  IMT        c1        c2        c3        c4        c5        c6        c7        c8        c9       c10       c11   total     tau     phi
  pgv -4.050789  1.464279 -0.089983 -1.601674  0.203569 -1.631609  0.158215 -2.350490  0.073923 -0.001023  2.586154  0.2704  0.2199  0.1573
  pga -1.602600  1.372858 -0.103539 -1.812823  0.213073 -1.825891  0.164323 -2.000910  0.074914 -0.002077  2.114503  0.3323  0.2858  0.1695
 0.03 -0.790036  1.283008 -0.099421 -2.144925  0.235832 -2.098336  0.181157 -1.746444  0.095772 -0.003049  1.586174  0.3642  0.2951  0.2133
 0.04 -0.906116  1.287112 -0.095811 -1.869237  0.192674 -1.824192  0.145697 -1.561070  0.089274 -0.003506  1.442346  0.3573  0.2977  0.1975
 0.05 -1.047114  1.304685 -0.095302 -1.718532  0.173286 -1.684453  0.129369 -1.558280  0.076518 -0.003353  1.477278  0.3506  0.2976  0.1853
 0.06 -1.225291  1.334566 -0.096194 -1.591443  0.158739 -1.568253  0.116837 -1.615303  0.063388 -0.003017  1.552572  0.3422  0.2959  0.1718
 0.08 -1.433217  1.376769 -0.098557 -1.498502  0.149998 -1.482202  0.108457 -1.705298  0.053426 -0.002621  1.672666  0.3336  0.2928  0.1598
  0.1 -1.696528  1.437020 -0.102635 -1.425589  0.144472 -1.412740  0.102258 -1.807380  0.046042 -0.002219  1.814939  0.3250  0.2880  0.1506
 0.12 -2.001843  1.512088 -0.108088 -1.370848  0.140990 -1.358351  0.097572 -1.896326  0.040947 -0.001882  1.947594  0.3174  0.2821  0.1454
 0.16 -2.389539  1.611400 -0.115493 -1.323602  0.138439 -1.308238  0.093184 -1.975279  0.036790 -0.001581  2.083505  0.3097  0.2745  0.1433
  0.2 -2.853373  1.732364 -0.124532 -1.280205  0.135511 -1.261162  0.088805 -2.038277  0.033263 -0.001331  2.179432  0.3023  0.2657  0.1441
 0.25 -3.364498  1.865762 -0.134369 -1.240574  0.132088 -1.217502  0.084424 -2.085034  0.030185 -0.001131  2.228441  0.2954  0.2563  0.1470
 0.31 -3.926917  2.009717 -0.144692 -1.199840  0.127369 -1.174620  0.079845 -2.119388  0.027230 -0.000964  2.216469  0.2889  0.2462  0.1512
  0.4 -4.531461  2.158406 -0.154864 -1.156084  0.121167 -1.132080  0.075091 -2.144637  0.024287 -0.000820  2.144979  0.2827  0.2355  0.1563
  0.5 -5.135576  2.297300 -0.163647 -1.112090  0.114455 -1.093263  0.070734 -2.161615  0.021350 -0.000696  2.051407  0.2770  0.2248  0.1618
 0.63 -5.703343  2.413949 -0.170001 -1.070070  0.107758 -1.061769  0.067407 -2.172911  0.018486 -0.000586  1.944523  0.2719  0.2144  0.1673
 0.79 -6.207284  2.498075 -0.173076 -1.035716  0.102617 -1.043028  0.066077 -2.180726  0.015791 -0.000483  1.864091  0.2676  0.2044  0.1726
    1 -6.600271  2.537527 -0.172119 -1.017080  0.100573 -1.044345  0.067905 -2.187061  0.013600 -0.000389  1.829097  0.2640  0.1954  0.1775
 1.25 -6.856601  2.528594 -0.167155 -1.021087  0.102771 -1.070451  0.073611 -2.193911  0.012399 -0.000305  1.844186  0.2610  0.1872  0.1819
 1.59 -6.987493  2.467754 -0.157662 -1.056388  0.110727 -1.129109  0.084539 -2.204473  0.012864 -0.000229  1.911293  0.2580  0.1787  0.1862
    2 -6.983067  2.366916 -0.145352 -1.121234  0.123631 -1.211810  0.099039 -2.220237  0.015936 -0.000178  2.011335  0.2550  0.1703  0.1898
  2.5 -6.885276  2.239661 -0.131332 -1.209222  0.140025 -1.309217  0.115543 -2.244450  0.022303 -0.000154  2.117389  0.2517  0.1616  0.1930
 3.13 -6.733710  2.096126 -0.116301 -1.310276  0.157796 -1.411122  0.132373 -2.282364  0.032795 -0.000161  2.200571  0.2480  0.1523  0.1957
    4 -6.557265  1.938255 -0.100190 -1.417275  0.176102 -1.511310  0.148479 -2.344235  0.049037 -0.000200  2.295618  0.2440  0.1423  0.1982
    5 -6.427828  1.806941 -0.086864 -1.496519  0.189163 -1.580867  0.159253 -2.421209  0.067257 -0.000255  2.370543  0.2407  0.1339  0.2001
    """)


class RietbrockEdwards2019Up(RietbrockEdwards2019Mean):
    COEFFS = CoeffsTable(sa_damping=5, table="""\
  IMT        c1        c2        c3        c4        c5        c6        c7        c8        c9       c10       c11   total     tau     phi
  pgv -4.981684  1.878978 -0.122569 -1.643356  0.214777 -1.644371  0.154776 -2.280684  0.060683 -0.001094  3.263968  0.2704  0.2199  0.1573
  pga -2.889044  1.943094 -0.149585 -1.847270  0.220942 -1.829099  0.159762 -1.937059  0.063218 -0.002155  2.536970  0.3323  0.2858  0.1695
 0.03 -2.115693  1.870543 -0.147206 -2.162455  0.235406 -2.092884  0.175793 -1.672453  0.086058 -0.003181  1.656856  0.3642  0.2951  0.2133
 0.04 -2.287706  1.893869 -0.145364 -1.869818  0.190807 -1.805317  0.138882 -1.500749  0.079550 -0.003606  1.548389  0.3573  0.2977  0.1975
 0.05 -2.446015  1.917613 -0.145433 -1.716653  0.171551 -1.663766  0.122327 -1.507668  0.066122 -0.003418  1.611714  0.3506  0.2976  0.1853
 0.06 -2.629831  1.949240 -0.146492 -1.591547  0.158201 -1.548603  0.109961 -1.571862  0.052205 -0.003050  1.746983  0.3422  0.2959  0.1718
 0.08 -2.830706  1.988156 -0.148546 -1.505846  0.152296 -1.465736  0.102084 -1.665320  0.041534 -0.002633  1.986910  0.3336  0.2928  0.1598
  0.1 -3.077407  2.040398 -0.151802 -1.439795  0.148929 -1.399674  0.096351 -1.769936  0.033553 -0.002214  2.211167  0.3250  0.2880  0.1506
 0.12 -3.358808  2.103258 -0.155966 -1.389538  0.146602 -1.347961  0.092033 -1.860671  0.027998 -0.001863  2.383604  0.3174  0.2821  0.1454
 0.16 -3.712548  2.184174 -0.161388 -1.341531  0.143250 -1.299220  0.087846 -1.941688  0.023493 -0.001551  2.482992  0.3097  0.2745  0.1433
  0.2 -4.126654  2.279004 -0.167641 -1.298645  0.139947 -1.254046  0.083760 -2.006836  0.019741 -0.001290  2.558665  0.3023  0.2657  0.1441
 0.25 -4.574128  2.378899 -0.173920 -1.255899  0.135133 -1.211366  0.079602 -2.055888  0.016617 -0.001081  2.556151  0.2954  0.2563  0.1470
 0.31 -5.053253  2.479932 -0.179736 -1.210697  0.128764 -1.169323  0.075279 -2.092892  0.013818 -0.000907  2.488110  0.2889  0.2462  0.1512
  0.4 -5.550797  2.574752 -0.184331 -1.160946  0.120681 -1.127581  0.070869 -2.121025  0.011259 -0.000758  2.357324  0.2827  0.2355  0.1563
  0.5 -6.024928  2.650266 -0.186670 -1.112021  0.112487 -1.090386  0.067039 -2.141286  0.008965 -0.000630  2.214113  0.2770  0.2248  0.1618
 0.63 -6.442512  2.696143 -0.185979 -1.067464  0.105073 -1.062017  0.064522 -2.156032  0.006992 -0.000518  2.077460  0.2719  0.2144  0.1673
 0.79 -6.778511  2.703961 -0.181648 -1.033764  0.100231 -1.048646  0.064395 -2.167265  0.005454 -0.000418  1.999468  0.2676  0.2044  0.1726
    1 -6.999152  2.668100 -0.173598 -1.018809  0.099665 -1.057664  0.067790 -2.176429  0.004644 -0.000329  2.020849  0.2640  0.1954  0.1775
 1.25 -7.094791  2.591830 -0.162522 -1.027936  0.104119 -1.092984  0.075215 -2.185386  0.004984 -0.000256  2.142086  0.2610  0.1872  0.1819
 1.59 -7.073314  2.470200 -0.147786 -1.068542  0.115151 -1.162018  0.087904 -2.196997  0.007238 -0.000196  2.391041  0.2580  0.1787  0.1862
    2 -6.953357  2.327134 -0.132177 -1.141334  0.132392 -1.255280  0.103880 -2.212836  0.011914 -0.000163  2.751502  0.2550  0.1703  0.1898
  2.5 -6.780811  2.176579 -0.116747 -1.239755  0.153487 -1.361503  0.121240 -2.236528  0.019511 -0.000156  3.125958  0.2517  0.1616  0.1930
 3.13 -6.597814  2.028414 -0.102111 -1.352330  0.175412 -1.468453  0.138054 -2.272683  0.030609 -0.000178  3.436732  0.2480  0.1523  0.1957
    4 -6.431232  1.885300 -0.088318 -1.484766  0.200454 -1.572520  0.153408 -2.331412  0.046326 -0.000227  3.783623  0.2440  0.1423  0.1982
    5 -6.357532  1.782921 -0.078404 -1.568280  0.213472 -1.635864  0.162220 -2.400811  0.062760 -0.000290  3.879334  0.2407  0.1339  0.2001
""")
<commit_msg>Fix table<commit_after># -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2014-2019 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 exports :class:`RietbrockEdwards2019`
"""

import numpy as np
# standard acceleration of gravity in m/s**2
from scipy.constants import g

from openquake.hazardlib.gsim.base import CoeffsTable, GMPE
from openquake.hazardlib import const
from openquake.hazardlib.imt import PGA, PGV, SA


class RietbrockEdwards2019Mean(GMPE):
    """
    Implements the ground motion prediction equation of Rietbrock et al
    (2019):

    <NAME>., <NAME>. (2019). Update of the UK stochastic ground
    motion model using a decade of broadband data. In Proceedings of the
    2019 SECED conference.
    """
    #: Supported tectonic region type is stabe continental crust,
    DEFINED_FOR_TECTONIC_REGION_TYPE = const.TRT.STABLE_CONTINENTAL

    #: Supported intensity measure types are spectral acceleration, peak
    #: ground acceleration and peak ground velocity.
    DEFINED_FOR_INTENSITY_MEASURE_TYPES = set([
        PGA,
        PGV,
        SA
    ])

    #: Supported intensity measure component is the geometric mean of two
    #: horizontal components
    DEFINED_FOR_INTENSITY_MEASURE_COMPONENT = const.IMC.AVERAGE_HORIZONTAL

    #: Supported standard deviation types are inter-event, intra-event and
    #: total
    DEFINED_FOR_STANDARD_DEVIATION_TYPES = set([
        const.StdDev.INTER_EVENT,
        const.StdDev.INTRA_EVENT,
        const.StdDev.TOTAL
    ])

    #: No site parameter is required
    REQUIRES_SITES_PARAMETERS = set()

    #: Required rupture parameters are magnitude
    REQUIRES_RUPTURE_PARAMETERS = set(('mag',))

    #: Required distance measure is Rjb
    REQUIRES_DISTANCES = set(('rjb', ))

    def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        """
        See :meth:`superclass method
        <.base.GroundShakingIntensityModel.get_mean_and_stddevs>`
        for spec of input and result values.
        """
        # extract dictionaries of coefficients specific to required
        # intensity measure type
        C = self.COEFFS[imt]
        imean = C["c1"] + (self._get_magnitude_term(C, rup.mag) +
                           self._get_distance_term(C, dists.rjb, rup.mag))
        # convert from cm/s**2 to g for SA and from cm/s**2 to g for PGA (PGV
        # is already in cm/s) and also convert from base 10 to base e.
        if imt.name in "SA PGA":
            mean = np.log((10.0 ** (imean - 2.0)) / g)
        else:
            mean = np.log(10 ** imean)

        stddevs = self._get_stddevs(C, stddev_types, dists.rjb.shape[0])

        return mean, stddevs

    def _get_magnitude_term(self, C, mag):
        """
        Returns the magnitude scaling component of the model
        Equation 10, Page 63
        """
        return (C["c2"] * mag) + (C["c3"] * (mag ** 2.0))

    def _get_distance_term(self, C, rjb, mag):
        """
        Returns the distance scaling component of the model
        Equation 10, Page 63
        """
        # Depth adjusted distance, equation 11 (Page 63)
        rval = np.sqrt(rjb ** 2.0 + C["c11"] ** 2.0)
        f_0, f_1, f_2 = self._get_distance_segment_coefficients(rval)
        return ((C["c4"] + C["c5"] * mag) * f_0 +
                (C["c6"] + C["c7"] * mag) * f_1 +
                (C["c8"] + C["c9"] * mag) * f_2 +
                (C["c10"] * rval))

    def _get_distance_segment_coefficients(self, rval):
        """
        Returns the coefficients describing the distance attenuation shape
        for three different distance bins, equations 12a - 12c
        """
        # Get distance segment ends
        # Equation 12a
        f_0 = np.log10(self.CONSTS["r0"] / rval)
        f_0[rval > self.CONSTS["r0"]] = 0.0

        # Equation 12b
        f_1 = np.log10(rval)
        f_1[rval > self.CONSTS["r1"]] = np.log10(self.CONSTS["r1"])
        # Equation 12c
        f_2 = np.log10(rval / self.CONSTS["r2"])
        f_2[rval <= self.CONSTS["r2"]] = 0.0
        return f_0, f_1, f_2

    def _get_stddevs(self, C, stddev_types, num_sites):
        """
        Returns the standard deviation. Original standard deviations are in
        logarithms of base 10. Converts to natural logarithm.
        """
        stddevs = []
        for stddev_type in stddev_types:
            assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            if stddev_type == const.StdDev.TOTAL:
                stddevs.append(np.log(10.0 **
                                      (C["total"] + np.zeros(num_sites))))
            elif stddev_type == const.StdDev.INTRA_EVENT:
                stddevs.append(np.log(10.0 **
                                      (C["phi"] + np.zeros(num_sites))))
            elif stddev_type == const.StdDev.INTER_EVENT:
                stddevs.append(np.log(10.0 **
                                      (C["tau"] + np.zeros(num_sites))))
        return stddevs


    COEFFS = CoeffsTable(sa_damping=5, table="""\
  IMT      c1      c2      c3      c4      c5      c6      c7      c8      c9       c10     c11   total     tau     phi
  pgv -4.4578  1.6540 -0.1044 -1.6308  0.2082 -1.6465  0.1568 -2.3547  0.0676 -0.000991  2.8899  0.2704  0.2199  0.1573
  pga -2.1780  1.6355 -0.1241 -1.8303  0.2165 -1.8318  0.1622 -1.9899  0.0678 -0.002073  2.3460  0.3323  0.2858  0.1695
 0.03 -1.3946  1.5566 -0.1210 -2.1447  0.2324 -2.0955  0.1777 -1.7240  0.0891 -0.003079  1.5613  0.3642  0.2951  0.2133
 0.04 -1.5298  1.5684 -0.1181 -1.8704  0.1906 -1.8175  0.1420 -1.5458  0.0827 -0.003522  1.4637  0.3573  0.2977  0.1975
 0.05 -1.6747  1.5876 -0.1178 -1.7218  0.1719 -1.6779  0.1258 -1.5486  0.0695 -0.003350  1.5137  0.3506  0.2976  0.1853
 0.06 -1.8507  1.6171 -0.1187 -1.5996  0.1587 -1.5637  0.1136 -1.6102  0.0560 -0.002996  1.6318  0.3422  0.2959  0.1718
 0.08 -2.0520  1.6568 -0.1209 -1.5126  0.1517 -1.4804  0.1057 -1.7039  0.0458 -0.002586  1.8079  0.3336  0.2928  0.1598
  0.1 -2.3048  1.7127 -0.1246 -1.4463  0.1480 -1.4141  0.1000 -1.8096  0.0382 -0.002172  2.0171  0.3250  0.2880  0.1506
 0.12 -2.5981  1.7821 -0.1295 -1.3958  0.1454 -1.3622  0.0956 -1.9028  0.0331 -0.001822  2.1704  0.3174  0.2821  0.1454
 0.16 -2.9711  1.8735 -0.1360 -1.3507  0.1428 -1.3141  0.0915 -1.9872  0.0290 -0.001508  2.2948  0.3097  0.2745  0.1433
  0.2 -3.4163  1.9839 -0.1439 -1.3080  0.1393 -1.2687  0.0872 -2.0567  0.0256 -0.001243  2.3514  0.3023  0.2657  0.1441
 0.25 -3.9043  2.1039 -0.1522 -1.2667  0.1347 -1.2260  0.0829 -2.1103  0.0228 -0.001030  2.3495  0.2954  0.2563  0.1470
 0.31 -4.4356  2.2302 -0.1606 -1.2230  0.1286 -1.1838  0.0783 -2.1517  0.0202 -0.000850  2.2892  0.2889  0.2462  0.1512
  0.4 -4.9975  2.3558 -0.1683 -1.1762  0.1213 -1.1419  0.0736 -2.1841  0.0178 -0.000694  2.1896  0.2827  0.2355  0.1563
  0.5 -5.5468  2.4664 -0.1741 -1.1287  0.1135 -1.1038  0.0693 -2.2080  0.0155 -0.000560  2.0648  0.2770  0.2248  0.1618
 0.63 -6.0465  2.5499 -0.1771 -1.0857  0.1067 -1.0742  0.0663 -2.2253  0.0133 -0.000442  1.9685  0.2719  0.2144  0.1673
 0.79 -6.4705  2.5968 -0.1765 -1.0512  0.1016 -1.0584  0.0655 -2.2384  0.0115 -0.000334  1.8968  0.2676  0.2044  0.1726
    1 -6.7771  2.5981 -0.1719 -1.0343  0.1002 -1.0642  0.0681 -2.2491  0.0102 -0.000239  1.8893  0.2640  0.1954  0.1775
 1.25 -6.9495  2.5538 -0.1637 -1.0411  0.1032 -1.0957  0.0748 -2.2593  0.0101 -0.000157  1.9356  0.2610  0.1872  0.1819
 1.59 -6.9977  2.4597 -0.1513 -1.0802  0.1121 -1.1604  0.0866 -2.2724  0.0117 -0.000086  2.0388  0.2580  0.1787  0.1862
    2 -6.9298  2.3348 -0.1370 -1.1486  0.1257 -1.2477  0.1018 -2.2897  0.0158 -0.000043  2.1604  0.2550  0.1703  0.1898
  2.5 -6.7909  2.1932 -0.1220 -1.2383  0.1424 -1.3473  0.1184 -2.3139  0.0230 -0.000029  2.2903  0.2517  0.1616  0.1930
 3.13 -6.6206  2.0449 -0.1069 -1.3397  0.1604 -1.4492  0.1350 -2.3503  0.0340 -0.000047  2.4199  0.2480  0.1523  0.1957
    4 -6.4512  1.8930 -0.0918 -1.4444  0.1782 -1.5462  0.1501 -2.4088  0.0503 -0.000098  2.5430  0.2440  0.1423  0.1982
    5 -6.3504  1.7758 -0.0801 -1.5184  0.1896 -1.6103  0.1596 -2.4808  0.0678 -0.000161  2.6018  0.2407  0.1339  0.2001
    """)

    CONSTS = {"r0": 10.0,
              "r1": 50.0,
              "r2": 100.0}


class RietbrockEdwards2019Low(RietbrockEdwards2019Mean):
    COEFFS = CoeffsTable(sa_damping=5, table="""\
  IMT        c1        c2        c3        c4        c5        c6        c7        c8        c9       c10       c11   total     tau     phi
  pgv -4.050789  1.464279 -0.089983 -1.601674  0.203569 -1.631609  0.158215 -2.350490  0.073923 -0.001023  2.586154  0.2704  0.2199  0.1573
  pga -1.602600  1.372858 -0.103539 -1.812823  0.213073 -1.825891  0.164323 -2.000910  0.074914 -0.002077  2.114503  0.3323  0.2858  0.1695
 0.03 -0.790036  1.283008 -0.099421 -2.144925  0.235832 -2.098336  0.181157 -1.746444  0.095772 -0.003049  1.586174  0.3642  0.2951  0.2133
 0.04 -0.906116  1.287112 -0.095811 -1.869237  0.192674 -1.824192  0.145697 -1.561070  0.089274 -0.003506  1.442346  0.3573  0.2977  0.1975
 0.05 -1.047114  1.304685 -0.095302 -1.718532  0.173286 -1.684453  0.129369 -1.558280  0.076518 -0.003353  1.477278  0.3506  0.2976  0.1853
 0.06 -1.225291  1.334566 -0.096194 -1.591443  0.158739 -1.568253  0.116837 -1.615303  0.063388 -0.003017  1.552572  0.3422  0.2959  0.1718
 0.08 -1.433217  1.376769 -0.098557 -1.498502  0.149998 -1.482202  0.108457 -1.705298  0.053426 -0.002621  1.672666  0.3336  0.2928  0.1598
  0.1 -1.696528  1.437020 -0.102635 -1.425589  0.144472 -1.412740  0.102258 -1.807380  0.046042 -0.002219  1.814939  0.3250  0.2880  0.1506
 0.12 -2.001843  1.512088 -0.108088 -1.370848  0.140990 -1.358351  0.097572 -1.896326  0.040947 -0.001882  1.947594  0.3174  0.2821  0.1454
 0.16 -2.389539  1.611400 -0.115493 -1.323602  0.138439 -1.308238  0.093184 -1.975279  0.036790 -0.001581  2.083505  0.3097  0.2745  0.1433
  0.2 -2.853373  1.732364 -0.124532 -1.280205  0.135511 -1.261162  0.088805 -2.038277  0.033263 -0.001331  2.179432  0.3023  0.2657  0.1441
 0.25 -3.364498  1.865762 -0.134369 -1.240574  0.132088 -1.217502  0.084424 -2.085034  0.030185 -0.001131  2.228441  0.2954  0.2563  0.1470
 0.31 -3.926917  2.009717 -0.144692 -1.199840  0.127369 -1.174620  0.079845 -2.119388  0.027230 -0.000964  2.216469  0.2889  0.2462  0.1512
  0.4 -4.531461  2.158406 -0.154864 -1.156084  0.121167 -1.132080  0.075091 -2.144637  0.024287 -0.000820  2.144979  0.2827  0.2355  0.1563
  0.5 -5.135576  2.297300 -0.163647 -1.112090  0.114455 -1.093263  0.070734 -2.161615  0.021350 -0.000696  2.051407  0.2770  0.2248  0.1618
 0.63 -5.703343  2.413949 -0.170001 -1.070070  0.107758 -1.061769  0.067407 -2.172911  0.018486 -0.000586  1.944523  0.2719  0.2144  0.1673
 0.79 -6.207284  2.498075 -0.173076 -1.035716  0.102617 -1.043028  0.066077 -2.180726  0.015791 -0.000483  1.864091  0.2676  0.2044  0.1726
    1 -6.600271  2.537527 -0.172119 -1.017080  0.100573 -1.044345  0.067905 -2.187061  0.013600 -0.000389  1.829097  0.2640  0.1954  0.1775
 1.25 -6.856601  2.528594 -0.167155 -1.021087  0.102771 -1.070451  0.073611 -2.193911  0.012399 -0.000305  1.844186  0.2610  0.1872  0.1819
 1.59 -6.987493  2.467754 -0.157662 -1.056388  0.110727 -1.129109  0.084539 -2.204473  0.012864 -0.000229  1.911293  0.2580  0.1787  0.1862
    2 -6.983067  2.366916 -0.145352 -1.121234  0.123631 -1.211810  0.099039 -2.220237  0.015936 -0.000178  2.011335  0.2550  0.1703  0.1898
  2.5 -6.885276  2.239661 -0.131332 -1.209222  0.140025 -1.309217  0.115543 -2.244450  0.022303 -0.000154  2.117389  0.2517  0.1616  0.1930
 3.13 -6.733710  2.096126 -0.116301 -1.310276  0.157796 -1.411122  0.132373 -2.282364  0.032795 -0.000161  2.200571  0.2480  0.1523  0.1957
    4 -6.557265  1.938255 -0.100190 -1.417275  0.176102 -1.511310  0.148479 -2.344235  0.049037 -0.000200  2.295618  0.2440  0.1423  0.1982
    5 -6.427828  1.806941 -0.086864 -1.496519  0.189163 -1.580867  0.159253 -2.421209  0.067257 -0.000255  2.370543  0.2407  0.1339  0.2001
    """)


class RietbrockEdwards2019Up(RietbrockEdwards2019Mean):
    COEFFS = CoeffsTable(sa_damping=5, table="""\
  IMT        c1        c2        c3        c4        c5        c6        c7        c8        c9       c10       c11   total     tau     phi
  pgv -4.981684  1.878978 -0.122569 -1.643356  0.214777 -1.644371  0.154776 -2.280684  0.060683 -0.001094  3.263968  0.2704  0.2199  0.1573
  pga -2.889044  1.943094 -0.149585 -1.847270  0.220942 -1.829099  0.159762 -1.937059  0.063218 -0.002155  2.536970  0.3323  0.2858  0.1695
 0.03 -2.115693  1.870543 -0.147206 -2.162455  0.235406 -2.092884  0.175793 -1.672453  0.086058 -0.003181  1.656856  0.3642  0.2951  0.2133
 0.04 -2.287706  1.893869 -0.145364 -1.869818  0.190807 -1.805317  0.138882 -1.500749  0.079550 -0.003606  1.548389  0.3573  0.2977  0.1975
 0.05 -2.446015  1.917613 -0.145433 -1.716653  0.171551 -1.663766  0.122327 -1.507668  0.066122 -0.003418  1.611714  0.3506  0.2976  0.1853
 0.06 -2.629831  1.949240 -0.146492 -1.591547  0.158201 -1.548603  0.109961 -1.571862  0.052205 -0.003050  1.746983  0.3422  0.2959  0.1718
 0.08 -2.830706  1.988156 -0.148546 -1.505846  0.152296 -1.465736  0.102084 -1.665320  0.041534 -0.002633  1.986910  0.3336  0.2928  0.1598
  0.1 -3.077407  2.040398 -0.151802 -1.439795  0.148929 -1.399674  0.096351 -1.769936  0.033553 -0.002214  2.211167  0.3250  0.2880  0.1506
 0.12 -3.358808  2.103258 -0.155966 -1.389538  0.146602 -1.347961  0.092033 -1.860671  0.027998 -0.001863  2.383604  0.3174  0.2821  0.1454
 0.16 -3.712548  2.184174 -0.161388 -1.341531  0.143250 -1.299220  0.087846 -1.941688  0.023493 -0.001551  2.482992  0.3097  0.2745  0.1433
  0.2 -4.126654  2.279004 -0.167641 -1.298645  0.139947 -1.254046  0.083760 -2.006836  0.019741 -0.001290  2.558665  0.3023  0.2657  0.1441
 0.25 -4.574128  2.378899 -0.173920 -1.255899  0.135133 -1.211366  0.079602 -2.055888  0.016617 -0.001081  2.556151  0.2954  0.2563  0.1470
 0.31 -5.053253  2.479932 -0.179736 -1.210697  0.128764 -1.169323  0.075279 -2.092892  0.013818 -0.000907  2.488110  0.2889  0.2462  0.1512
  0.4 -5.550797  2.574752 -0.184331 -1.160946  0.120681 -1.127581  0.070869 -2.121025  0.011259 -0.000758  2.357324  0.2827  0.2355  0.1563
  0.5 -6.024928  2.650266 -0.186670 -1.112021  0.112487 -1.090386  0.067039 -2.141286  0.008965 -0.000630  2.214113  0.2770  0.2248  0.1618
 0.63 -6.442512  2.696143 -0.185979 -1.067464  0.105073 -1.062017  0.064522 -2.156032  0.006992 -0.000518  2.077460  0.2719  0.2144  0.1673
 0.79 -6.778511  2.703961 -0.181648 -1.033764  0.100231 -1.048646  0.064395 -2.167265  0.005454 -0.000418  1.999468  0.2676  0.2044  0.1726
    1 -6.999152  2.668100 -0.173598 -1.018809  0.099665 -1.057664  0.067790 -2.176429  0.004644 -0.000329  2.020849  0.2640  0.1954  0.1775
 1.25 -7.094791  2.591830 -0.162522 -1.027936  0.104119 -1.092984  0.075215 -2.185386  0.004984 -0.000256  2.142086  0.2610  0.1872  0.1819
 1.59 -7.073314  2.470200 -0.147786 -1.068542  0.115151 -1.162018  0.087904 -2.196997  0.007238 -0.000196  2.391041  0.2580  0.1787  0.1862
    2 -6.953357  2.327134 -0.132177 -1.141334  0.132392 -1.255280  0.103880 -2.212836  0.011914 -0.000163  2.751502  0.2550  0.1703  0.1898
  2.5 -6.780811  2.176579 -0.116747 -1.239755  0.153487 -1.361503  0.121240 -2.236528  0.019511 -0.000156  3.125958  0.2517  0.1616  0.1930
 3.13 -6.597814  2.028414 -0.102111 -1.352330  0.175412 -1.468453  0.138054 -2.272683  0.030609 -0.000178  3.436732  0.2480  0.1523  0.1957
    4 -6.431232  1.885300 -0.088318 -1.484766  0.200454 -1.572520  0.153408 -2.331412  0.046326 -0.000227  3.783623  0.2440  0.1423  0.1982
    5 -6.357532  1.782921 -0.078404 -1.568280  0.213472 -1.635864  0.162220 -2.400811  0.062760 -0.000290  3.879334  0.2407  0.1339  0.2001
""")

{'fraction_non_alphanumeric': 0.13325213154689403, 'fraction_numerical': 0.41352009744214374, 'mean_word_length': 2.009070918086861, 'pattern_counts': {'":': 8, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2645593', 'n_tokens_mistral': 22270, 'n_tokens_neox': 15750, 'n_words': 3436}