# -*- coding: utf-8 -*-# vim: tabstop=4 shiftwidth=4 softtabstop=4## Copyright (C) 2012-2023 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 :mod:`openquake.hazardlib.imt` defines different intensity measuretypes."""importreimportcollectionsimportnumpyFREQUENCY_PATTERN='^(EAS|FAS|DRVT|AvgSA)\\((\\d+\\.*\\d*)\\)'
[docs]defpositivefloat(val):""" Raise a ValueError if val <= 0 """ifval<=0:raiseValueError(val)
[docs]defimt2tup(string):""" >>> imt2tup('PGA') ('PGA',) >>> imt2tup('SA(1.0)') ('SA(1.0)', 1.0) >>> imt2tup('SA(1)') ('SA(1.0)', 1.0) """s=string.strip()name,*rest=s.split('(')ifnamenotinglobals():raiseKeyError(name)eliflen(name)>12:raiseNameError('IMT class name longer than 12 chars: %s'%name)elifnotrest:ifname=='SA':raiseValueError('Missing period in SA')# no parenthesis, PGA is considered the same as PGA()return(s,)period=float(rest[0][:-1])return('SA(%s)'%period,period)
[docs]deffrom_string(imt,_damping=5.0):""" Convert an IMT string into an hazardlib object. :param str imt: Intensity Measure Type. """m=re.match(FREQUENCY_PATTERN,imt)ifm:# passed float interpreted as frequencyifm.group(1)=='EAS':im=EAS(float(m.group(2)))elifm.group(1)=='FAS':im=FAS(float(m.group(2)))elifm.group(1)=='DRVT':im=DRVT(float(m.group(2)))elifm.group(1)=='AvgSA':im=AvgSA(float(m.group(2)))returnimelifre.match(r'^SDi\((\d+\.?\d*),(\d+\.?\d*)\)$',imt):m=re.match(r'^SDi\((\d+\.?\d*),(\d+\.?\d*)\)$',imt)returnSDi(float(m.group(1)),float(m.group(2)))elifre.match(r'[ \+\d\.]+',imt):# passed float interpreted as periodreturnSA(float(imt))returnIMT(*imt2tup(imt))
[docs]defsort_by_imt(imtls):""" :param imtls: a dictionary keyed by IMT string :returns: a new dictionary with the keys sorted by period >>> sort_by_imt({'SA(10.0)': 1, 'SA(2.0)': 2}) {'SA(2.0)': 2, 'SA(10.0)': 1} """imts=sorted(imtls,key=lambdaimt:from_string(imt).period)return{imt:imtls[imt]forimtinimts}
IMT=collections.namedtuple('IMT','string period damping strength_ratio')IMT.__new__.__defaults__=(0.,5.0,None)IMT.__lt__=lambdaself,other:self[1]<other[1]IMT.__gt__=lambdaself,other:self[1]>other[1]IMT.__le__=lambdaself,other:self[1]<=other[1]IMT.__ge__=lambdaself,other:self[1]>=other[1]IMT.__repr__=reprIMT.frequency=property(lambdaself:1./self.period)
[docs]defPGA():""" Peak ground acceleration during an earthquake measured in units of ``g``, times of gravitational acceleration. """returnIMT('PGA')
[docs]defPGV():""" Peak ground velocity during an earthquake measured in units of ``cm/sec``. """returnIMT('PGV')
[docs]defPGD():""" Peak ground displacement during an earthquake measured in units of ``cm``. """returnIMT('PGD')
[docs]defEAS(frequency):""" Effective Amplitude Spectrum in terms of a frequency (in Hz). """period=1./frequencyreturnIMT('EAS(%.6f)'%frequency,period,5.0)
[docs]defFAS(frequency):""" Fourier Amplitude Spectrum in terms of a frequency (in Hz). """period=1./frequencyreturnIMT('FAS(%.6f)'%frequency,period,5.0)
[docs]defDRVT(frequency):""" Duration as defined in Bora et al. (2019) """period=1./frequencyreturnIMT('DRVT(%.6f)'%frequency,period,5.0)
[docs]defSA(period,damping=5.0):""" Spectral acceleration, defined as the maximum acceleration of a damped, single-degree-of-freedom harmonic oscillator. Units are ``g``, times of gravitational acceleration. """period=float(period)returnIMT('SA(%s)'%period,period,damping)
[docs]defSDi(period,strength_ratio,damping=5.0):""" Inelastic spectral displacement, defined as the maximum displacement of a damped, single-degree-of-freedom inelastic oscillator. Units are ``cm``. """period=float(period)strength_ratio=float(strength_ratio)returnIMT('SDi(%s,%s)'%(period,strength_ratio),period,damping,strength_ratio)
[docs]defAvgSA(period=None,damping=5.0):""" Dummy spectral acceleration to compute average ground motion over several spectral ordinates. Depending on the choice of AvgSA GMPE, this can operate as a scalar value or as a vector quantity. """returnIMT('AvgSA(%s)'%period,period,damping)\
ifperiodelseIMT('AvgSA')
[docs]defIA():""" Arias intensity. Determines the intensity of shaking by measuring the acceleration of transient seismic waves. Units are ``m/s``. """returnIMT('IA')
[docs]defCAV():""" Cumulative Absolute Velocity. Defins the integral of the absolute acceleration time series. Units are "g-sec" """returnIMT('CAV')
[docs]defRSD():""" Relative significant duration, 5-95% of :class:`Arias intensity<IA>`, in seconds. """returnIMT('RSD')
[docs]defRSD595():""" Alias for RSD """returnIMT('RSD595')
[docs]defRSD575():""" Relative significant duration, 5-75% of :class:`Arias intensity<IA>`, in seconds. """returnIMT('RSD575')
[docs]defRSD2080():""" Relative significant duration, 20-80% of :class:`Arias intensity<IA>`, in seconds. """returnIMT('RSD2080')
[docs]defMMI():""" Modified Mercalli intensity, a Roman numeral describing the severity of an earthquake in terms of its effects on the earth's surface and on humans and their structures. """returnIMT('MMI')
[docs]defJMA():""" Modified Mercalli intensity, a Roman numeral describing the severity of an earthquake in terms of its effects on the earth's surface and on humans and their structures. """returnIMT('JMA')
# Volcanic IMTs
[docs]defASH():""" Level of the ash fall in millimeters """returnIMT('ASH')
[docs]defDispProb():""" Displacement probability """returnIMT('RSD595')
[docs]defLiqProb():""" Liquefaction probability """returnIMT('LiqProb')
[docs]defLiqOccur():""" Liquefaction occurrence class """returnIMT('LiqOccur')
[docs]defLSE():""" Liquefaction or Landslide spatial extent. """returnIMT('LSE')
[docs]defPGDMax(vert_settlement,lat_spread):""" Maximum between vert_settlement and lat_spread """returnnumpy.maximum(vert_settlement,lat_spread)
[docs]defLSD():""" Liquefaction-induced lateral spread displacements measured in units of ``m``. """returnIMT('LSD')
[docs]defPGDGeomMean(vert_settlement,lat_spread):""" Geometric mean between vert_settlement and lat_spread """returnnumpy.sqrt(vert_settlement*lat_spread)
[docs]defLsProb():""" Probability of landsliding. """returnIMT('LsProb')