<commit_before># -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2014-2021 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:'ClimentEtAl1994'.
"""
import numpy as np
# standard acceleration of gravity in m/s**2
from scipy.constants import g


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


def _compute_term_1_2(ctx, C):
    """
    Compute terms 1 and 2 in equation 1 page 1.
    """
    return C['c1'] + C['c2'] * ctx.mag


def _compute_term_3_4(ctx, C):
    """
    Compute term 3 and 4 in equation 1 page 1.
    """
    cutoff = 6.056877878
    rhypo = ctx.rhypo.copy()
    rhypo[rhypo <= cutoff] = cutoff
    return C['c3'] * np.log(rhypo) + C['c4'] * rhypo


def _get_site_amplification(ctx, imt, C):
    """
    Compute the fith term of the equation (1), p. 1:
    ``c5 * S``
    """
    S = _get_site_type_dummy_variables(ctx)
    return (C['c5'] * S)


def _get_site_type_dummy_variables(ctx):
    """
    Get site type dummy variables, ``S`` (for rock and soil ctx)
    """
    S = np.zeros_like(ctx.vs30)
    # S=0 for rock ctx, S=1 otherwise pag 1.
    idxS = (ctx.vs30 < 760.0)
    S[idxS] = 1
    return S


def _compute_mean(C, ctx, imt):
    """
    Compute mean value for PGA and pseudo-velocity response spectrum,
    as given in equation 1. Converts also pseudo-velocity response
    spectrum values to SA, using:

      SA = (PSV * W)/ratio(SA_larger/SA_geo_mean)
       W = (2 * pi / T)
       T = period (sec)
    """
    mean = (_compute_term_1_2(ctx, C) +
            _compute_term_3_4(ctx, C) +
            _get_site_amplification(ctx, imt, C))

    # convert from m/s**2 to g for PGA and from m/s to g for PSV
    # and divided this value for the ratio(SA_larger/SA_geo_mean)
    if imt.string == "PGA":
        mean = (np.exp(mean) / g) / C['r_SA']
    else:
        W = (2. * np.pi)/imt.period
        mean = ((np.exp(mean) * W) / g) / C['r_SA']
    return np.log(mean)


class ClimentEtAl1994(GMPE):
    """
    Implements GMPE developed by Climent, A, <NAME>, <NAME>,
    <NAME>, <NAME>, <NAME>, and <NAME>. Published as a
    NORSAR report: "Spectral strong motion attenuation in Central Ame-
    rica", NORSAR Technical Report No. 2-17, 46 pp.
    The original formulation predict PGA (m/s*s) and 5% damped PSV (m/s)
    for the largest component of horizontal ground motion.
    In this implementation:
    Spectral acceleration (SA) values are obtained from PSV ones using<commit_msg>Cleanup [ci skip]<commit_after># -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2014-2021 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:'ClimentEtAl1994'.
"""
import numpy as np
# standard acceleration of gravity in m/s**2
from scipy.constants import g


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


def _compute_term_1_2(ctx, C):
    """
    Compute terms 1 and 2 in equation 1 page 1.
    """
    return C['c1'] + C['c2'] * ctx.mag


def _compute_term_3_4(ctx, C):
    """
    Compute term 3 and 4 in equation 1 page 1.
    """
    cutoff = 6.056877878
    rhypo = ctx.rhypo.copy()
    rhypo[rhypo <= cutoff] = cutoff
    return C['c3'] * np.log(rhypo) + C['c4'] * rhypo


def _get_site_amplification(ctx, imt, C):
    """
    Compute the fith term of the equation (1), p. 1:
    ``c5 * S``
    """
    S = _get_site_type_dummy_variables(ctx)
    return (C['c5'] * S)


def _get_site_type_dummy_variables(ctx):
    """
    Get site type dummy variables, ``S`` (for rock and soil sites)
    """
    S = np.zeros_like(ctx.vs30)
    # S=0 for rock sites, S=1 otherwise pag 1.
    idxS = (ctx.vs30 < 760.0)
    S[idxS] = 1
    return S


def _compute_mean(C, ctx, imt):
    """
    Compute mean value for PGA and pseudo-velocity response spectrum,
    as given in equation 1. Converts also pseudo-velocity response
    spectrum values to SA, using:

      SA = (PSV * W)/ratio(SA_larger/SA_geo_mean)
       W = (2 * pi / T)
       T = period (sec)
    """
    mean = (_compute_term_1_2(ctx, C) +
            _compute_term_3_4(ctx, C) +
            _get_site_amplification(ctx, imt, C))

    # convert from m/s**2 to g for PGA and from m/s to g for PSV
    # and divided this value for the ratio(SA_larger/SA_geo_mean)
    if imt.string == "PGA":
        mean = (np.exp(mean) / g) / C['r_SA']
    else:
        W = (2. * np.pi) / imt.period
        mean = np.exp(mean) * W / g / C['r_SA']
    return np.log(mean)


class ClimentEtAl1994(GMPE):
    """
    Implements GMPE developed by Climent, A, <NAME>, <NAME>,
    <NAME>, <NAME>, <NAME>, and <NAME>. Published as a
    NORSAR report: "Spectral strong motion attenuation in Central Ame-
    rica", NORSAR Technical Report No. 2-17, 46 pp.
    The original formulation predict PGA (m/s*s) and 5% damped PSV (m/s)
    for the largest component of horizontal ground motion.
    In this implementation:
    Spectral acceleration (SA) values are obtained from PSV ones using
{'fraction_non_alphanumeric': 0.11114589855979963, 'fraction_numerical': 0.024420788979336257, 'mean_word_length': 3.0309148264984227, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '810268', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2152, 'n_words': 774}