Exemplo n.º 1
0
def manage_imts(imt_str):
    if imt_str is None:
        return None, None
    elif imt_str == 'PGA':
        imt_obj = PGA()
        imt_label = 'PGA (%g)'
    elif imt_str == 'PGV':
        imt_obj = PGV()
        imt_label = 'PGV (cm/s)'
    elif 'SA' in imt_str:
        prd = float(imt_str.split('(')[1].split(')')[0])
        imt_obj = SA(prd)
        imt_label = str(imt_obj) + ' (%g)'
    elif 'FAS' in imt_str:
        prd = float(imt_str.split('(')[1].split(')')[0])
        imt_obj = None
        imt_label = str(imt_obj) + ' (%g)'
    elif imt_str == 'DURATION':
        imt_obj = RSD595()
        imt_label = 'Duration (s)'
    elif imt_str == 'ARIAS':
        imt_obj = IA()
        imt_label = 'Arias intensity (cm/s)'
    else:
        raise ValueError('IMT %s is not supported' % imt_str)

    return imt_obj, imt_label
Exemplo n.º 2
0
 def __init__(self):
     self._pga = PGA()
     self._pgv = PGV()
     self._pgd = PGD()
     self._ia = IA()
     self._ih = IH()
     self._sa03 = SA(0.3)
     self._sa10 = SA(1.0)
     self._sa30 = SA(3.0)
Exemplo n.º 3
0
 def __init__(self):
     self._pga = PGA()
     self._pgv = PGV()
     self._pgd = PGD()
     self._ia = IA()
     self._ih = IH()
     self._sa03 = SA(0.3)
     self._sa10 = SA(1.0)
     self._sa30 = SA(3.0)
     self.DEFINED_FOR_INTENSITY_MEASURE_TYPES = set()
Exemplo n.º 4
0
    def _getParamsFromIMT(self, imt):
        """
        Helper function to return (possibly interpolated) conversion
        parameters for a given IMT.

        Args:
            imt (OpenQuake IMT): The intensity measure type of the input
                ground motions. Valid IMTs are PGA, PGV, and SA.

        Returns:
            (float, float, float, float, float): Coeffients for conversion.
        """
        if imt == PGA():
            sigma = self.pars['sigma'][0]
            c0 = self.pars['c0smooth'][0]
            r1 = self.pars['r1smooth'][0]
            m1 = self.pars['m1smooth'][0]
            m2 = self.pars['m2smooth'][0]
        elif imt == PGV():
            sigma = self.pars['sigma'][1]
            c0 = self.pars['c0smooth'][1]
            r1 = self.pars['r1smooth'][1]
            m1 = self.pars['m1smooth'][1]
            m2 = self.pars['m2smooth'][1]
        elif imt == IA():
            sigma = self.pars['sigma'][3]
            c0 = self.pars['c0smooth'][3]
            r1 = self.pars['r1smooth'][3]
            m1 = self.pars['m1smooth'][3]
            m2 = self.pars['m2smooth'][3]
        elif imt == PGD():
            sigma = self.pars['sigma'][4]
            c0 = self.pars['c0smooth'][4]
            r1 = self.pars['r1smooth'][4]
            m1 = self.pars['m1smooth'][4]
            m2 = self.pars['m2smooth'][4]
        elif imt == IH():
            sigma = self.pars['sigma'][5]
            c0 = self.pars['c0smooth'][5]
            r1 = self.pars['r1smooth'][5]
            m1 = self.pars['m1smooth'][5]
            m2 = self.pars['m2smooth'][5]
        elif 'SA' in imt:
            imt_per = imt.period
            pa = self.pars['per'][2:]
            sigma = np.interp(imt_per, pa, self.pars['sigma'][2:])
            c0 = np.interp(imt_per, pa, self.pars['c0smooth'][2:])
            r1 = np.interp(imt_per, pa, self.pars['r1smooth'][2:])
            m1 = np.interp(imt_per, pa, self.pars['m1smooth'][2:])
            m2 = np.interp(imt_per, pa, self.pars['m2smooth'][2:])
        else:
            raise ValueError("Unknown IMT: %s" % str(imt))
        return (sigma, c0, r1, m1, m2)
Exemplo n.º 5
0
def filter_gmpe_list(gmpes, wts, imt):
    """
    Method to remove GMPEs from the GMPE list that are not applicable
    to a specific IMT. Rescales the weights to sum to one.

    Args:
        gmpes (list): List of GMPE instances.
        wts (list): List of floats indicating the weight of the GMPEs.
        imt (IMT): OQ IMT to filter GMPE list for.

    Returns:
        tuple: List of GMPE instances and list of weights.

    """
    if wts is None:
        n = len(gmpes)
        wts = [1 / n] * n

    per_max = [np.max(get_gmpe_sa_periods(g)) for g in gmpes]
    per_min = [np.min(get_gmpe_sa_periods(g)) for g in gmpes]
    if imt == PGA():
        sgmpe = [g for g in gmpes if imt in
                 get_gmpe_coef_table(g).non_sa_coeffs]
        swts = [w for g, w in zip(gmpes, wts) if imt in
                get_gmpe_coef_table(g).non_sa_coeffs]
    elif imt == PGV():
        sgmpe = []
        swts = []
        for i in range(len(gmpes)):
            if (imt in get_gmpe_coef_table(gmpes[i]).non_sa_coeffs) or\
               (per_max[i] >= 1.0 and per_min[i] <= 1.0):
                sgmpe.append(gmpes[i])
                swts.append(wts[i])
    elif imt == IA():
        sgmpe = []
        swts = []
        for i in range(len(gmpes)):
            if (imt in get_gmpe_coef_table(gmpes[i]).non_sa_coeffs) or\
               (per_max[i] >= 1.0 and per_min[i] <= 1.0):
                sgmpe.append(gmpes[i])
                swts.append(wts[i])
    elif imt == PGD():
        sgmpe = []
        swts = []
        for i in range(len(gmpes)):
            if (imt in get_gmpe_coef_table(gmpes[i]).non_sa_coeffs) or\
               (per_max[i] >= 1.0 and per_min[i] <= 1.0):
                sgmpe.append(gmpes[i])
                swts.append(wts[i])
    elif imt == IH():
        sgmpe = []
        swts = []
        for i in range(len(gmpes)):
            if (imt in get_gmpe_coef_table(gmpes[i]).non_sa_coeffs) or\
               (per_max[i] >= 1.0 and per_min[i] <= 1.0):
                sgmpe.append(gmpes[i])
                swts.append(wts[i])
    else:
        per = imt.period
        sgmpe = []
        swts = []
        for i in range(len(gmpes)):
            if (per_max[i] >= per and per_min[i] <= per):
                sgmpe.append(gmpes[i])
                swts.append(wts[i])

    if len(sgmpe) == 0:
        raise Exception('No applicable GMPEs from GMPE list for %s' % imt)

    # Scale weights to sum to one
    swts = np.array(swts)
    swts = swts / np.sum(swts)

    return sgmpe, swts
Exemplo n.º 6
0
def _parse_csv_line(headers, values):
    """
    Parse a single line from data file.

    :param headers:
        A list of header names, the strings from the first line of csv file.
    :param values:
        A list of values of a single row to parse.
    :returns:
        A tuple of the following values (in specified order):

        sctx
            An instance of :class:`openquake.hazardlib.gsim.base.SitesContext`
            with attributes populated by the information from in row in a form
            of single-element numpy arrays.
        rctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.RuptureContext`.
        dctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.DistancesContext`.
        stddev_types
            An empty list, if the ``result_type`` column says "MEAN"
            for that row, otherwise it is a list with one item --
            a requested standard deviation type.
        expected_results
            A dictionary mapping IMT-objects to one-element arrays of expected
            result values. Those results represent either standard deviation
            or mean value of corresponding IMT depending on ``result_type``.
        result_type
            A string literal, one of ``'STDDEV'`` or ``'MEAN'``. Value
            is taken from column ``result_type``.
    """
    rctx = RuptureContext()
    sctx = SitesContext()
    dctx = DistancesContext()
    expected_results = {}
    stddev_types = result_type = damping = None

    for param, value in zip(headers, values):
        if param == 'result_type':
            value = value.upper()
            if value.endswith('_STDDEV'):
                # the row defines expected stddev results
                result_type = 'STDDEV'
                stddev_types = [getattr(const.StdDev, value[:-len('_STDDEV')])]
            else:
                # the row defines expected exponents of mean values
                assert value == 'MEAN'
                stddev_types = []
                result_type = 'MEAN'
        elif param == 'damping':
            damping = float(value)
        elif param.startswith('site_'):
            # value is sites context object attribute
            if (param == 'site_vs30measured') or (param == 'site_backarc'):
                value = float(value) != 0
            else:
                value = float(value)
            setattr(sctx, param[len('site_'):], numpy.array([value]))
        elif param.startswith('dist_'):
            # value is a distance measure
            value = float(value)
            setattr(dctx, param[len('dist_'):], numpy.array([value]))
        elif param.startswith('rup_'):
            # value is a rupture context attribute
            value = float(value)
            setattr(rctx, param[len('rup_'):], value)
        elif param == 'component_type':
            pass
        else:
            # value is the expected result (of result_type type)
            value = float(value)
            if param == 'pga':
                imt = PGA()
            elif param == 'pgv':
                imt = PGV()
            elif param == 'pgd':
                imt = PGD()
            elif param == 'cav':
                imt = CAV()
            elif param == 'mmi':
                imt = MMI()
            elif param == "arias":
                imt = IA()
            elif param == "rsd595":
                imt = RSD595()
            elif param == "rsd575":
                imt = RSD575()
            elif param == "rsd2080":
                imt = RSD2080()
            else:
                period = float(param)
                assert damping is not None
                imt = SA(period, damping)

            expected_results[imt] = numpy.array([value])

    assert result_type is not None
    return sctx, rctx, dctx, stddev_types, expected_results, result_type
Exemplo n.º 7
0
from openquake.hazardlib.gsim.base import DistancesContext
from openquake.hazardlib.gsim.base import RuptureContext
from openquake.hazardlib import const

# Create an instance of the gmpe and input contexts.
trav2003 = TravasarouEtAl2003()
sx = SitesContext()
rx = RuptureContext()
dx = DistancesContext()

# Import data frame.
df = pd.read_csv(
    '/Users/tnye/PROJECTS/Duration/data/dataframes/select_data.csv')

# Define IMTs and standard deviations.
imt = IA()
sd_types = [const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT]

# List of event IDs.
eventids = [
    'usp000a1b0', 'usp000d6vk', 'usp000fg9t', 'usp000g9h6', 'us2000gge9',
    'us1000etmq', 'us2000dwh6', 'nc30228270', 'nc72282711', 'ci14383980',
    'ci14607652', 'usp0009eq0'
]

# Calculate mean Arias intensity and the standard deviations.
Trav_Ia_mean = []
interSD = []
intraSD = []

for event in eventids: