Commit dce96698 authored by g-weatherill's avatar g-weatherill
Browse files

Merge remote-tracking branch 'upstream/master'

parents da3e4ed3 90456796
image: python:3-buster image: debian:buster-slim
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
before_script: before_script:
- python3 -V - apt-get update
- apt-get install -y python3 git python3-pip
- pip3 install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip3 install .
- pip3 install pytest-cov - pip3 install pytest-cov
- pip3 install .[tests] - pip3 install .[tests]
- pip3 install .
formatting: formatting:
script: script:
......
SOURCES=shakyground2 *.py SOURCES=shakyground2 tests *.py
LENGTH=96 LENGTH=96
check: $(SOURCES) check: $(SOURCES)
......
...@@ -10,7 +10,10 @@ setup( ...@@ -10,7 +10,10 @@ setup(
description="", description="",
license="AGPLv3+", license="AGPLv3+",
extras_require={"tests": test_requirements}, extras_require={"tests": test_requirements},
install_requires=[], install_requires=[
"openquake.engine",
"geopandas",
],
packages=find_packages(), packages=find_packages(),
python_requires=">=3.7", python_requires=">=3.7",
) )
...@@ -204,7 +204,7 @@ class Earthquake(object): ...@@ -204,7 +204,7 @@ class Earthquake(object):
width: float, width: float,
lsd: float, lsd: float,
usd: float = 0.0, usd: float = 0.0,
hypo_loc: Tuple[float, float] = (0.5, 0.5) hypo_loc: Tuple[float, float] = (0.5, 0.5),
): ):
""" """
From a set of rupture properties returns a planar surface whose dimensions From a set of rupture properties returns a planar surface whose dimensions
...@@ -266,12 +266,8 @@ class Earthquake(object): ...@@ -266,12 +266,8 @@ class Earthquake(object):
updip_dir = (dip - 90.0) % 360 updip_dir = (dip - 90.0) % 360
mid_left = centroid.point_at(left_length, 0.0, (strike + 180.0) % 360.0) mid_left = centroid.point_at(left_length, 0.0, (strike + 180.0) % 360.0)
mid_right = centroid.point_at(right_length, 0.0, strike) mid_right = centroid.point_at(right_length, 0.0, strike)
top_left = mid_left.point_at( top_left = mid_left.point_at(updip_surface_length, -updip_depth_change, updip_dir)
updip_surface_length, -updip_depth_change, updip_dir top_right = mid_right.point_at(updip_surface_length, -updip_depth_change, updip_dir)
)
top_right = mid_right.point_at(
updip_surface_length, -updip_depth_change, updip_dir
)
bottom_left = mid_left.point_at( bottom_left = mid_left.point_at(
downdip_surface_length, downdip_depth_change, downdip_dir downdip_surface_length, downdip_depth_change, downdip_dir
) )
...@@ -288,7 +284,7 @@ class Earthquake(object): ...@@ -288,7 +284,7 @@ class Earthquake(object):
extended_error_message = [ extended_error_message = [
"Rupture surface failed to build with the following properties:", "Rupture surface failed to build with the following properties:",
"Strike: %.2f, Dip: %.2f, Length: %.2f, Width: %.2f, Hypo. Pos: %s" "Strike: %.2f, Dip: %.2f, Length: %.2f, Width: %.2f, Hypo. Pos: %s"
% (strike, dip, length, width, str(hypo_loc)) % (strike, dip, length, width, str(hypo_loc)),
] ]
for pnt in [top_left, top_right, bottom_right, bottom_left]: for pnt in [top_left, top_right, bottom_right, bottom_left]:
extended_error_message.append(str(pnt)) extended_error_message.append(str(pnt))
......
...@@ -12,10 +12,17 @@ class BaseScalingRelation(metaclass=abc.ABCMeta): ...@@ -12,10 +12,17 @@ class BaseScalingRelation(metaclass=abc.ABCMeta):
Abstract base class representing an implementation of a magnitude scaling relation Abstract base class representing an implementation of a magnitude scaling relation
""" """
@abc.abstractmethod @abc.abstractmethod
def get_rupture_dimensions(self, magnitude: float, rake: float = 0.0, dip: float = 90.0, def get_rupture_dimensions(
aspect: float = 1.0, thickness: float = 20.0, self,
epsilon: float = 0.0) -> Tuple[float, float, float]: magnitude: float,
rake: float = 0.0,
dip: float = 90.0,
aspect: float = 1.0,
thickness: float = 20.0,
epsilon: float = 0.0,
) -> Tuple[float, float, float]:
""" """
Args: Args:
magnitude: magnitude:
...@@ -41,9 +48,15 @@ class PEERScalingRelation(BaseScalingRelation): ...@@ -41,9 +48,15 @@ class PEERScalingRelation(BaseScalingRelation):
updated by the synthetic rupture generator updated by the synthetic rupture generator
""" """
def get_rupture_dimensions(self, magnitude: float, rake: float = 0.0, dip: float = 90.0, def get_rupture_dimensions(
aspect: float = 1.0, thickness: float = 20.0, self,
epsilon: float = 0.0) -> Tuple[float, float, float]: magnitude: float,
rake: float = 0.0,
dip: float = 90.0,
aspect: float = 1.0,
thickness: float = 20.0,
epsilon: float = 0.0,
) -> Tuple[float, float, float]:
""" """
Returns the area (km^2), length (km) and width (km) of the rupture using the PEER Returns the area (km^2), length (km) and width (km) of the rupture using the PEER
Magnitude-Area scaling relation and constrained by the crustal thickness Magnitude-Area scaling relation and constrained by the crustal thickness
...@@ -80,6 +93,7 @@ class StrasserEtAl2010Interface(PEERScalingRelation): ...@@ -80,6 +93,7 @@ class StrasserEtAl2010Interface(PEERScalingRelation):
Interface and Intraslab Subduction-zone Earthquakes with Moment Magnitude", Seismological Interface and Intraslab Subduction-zone Earthquakes with Moment Magnitude", Seismological
Research Letters, 81: 941 - 950, doi:10.1785/gssrl.81.6.941 Research Letters, 81: 941 - 950, doi:10.1785/gssrl.81.6.941
""" """
@staticmethod @staticmethod
def get_area(magnitude: float) -> float: def get_area(magnitude: float) -> float:
""" """
...@@ -97,6 +111,7 @@ class StrasserEtAl2010Inslab(PEERScalingRelation): ...@@ -97,6 +111,7 @@ class StrasserEtAl2010Inslab(PEERScalingRelation):
Interface and Intraslab Subduction-zone Earthquakes with Moment Magnitude", Seismological Interface and Intraslab Subduction-zone Earthquakes with Moment Magnitude", Seismological
Research Letters, 81: 941 - 950, doi:10.1785/gssrl.81.6.941 Research Letters, 81: 941 - 950, doi:10.1785/gssrl.81.6.941
""" """
@staticmethod @staticmethod
def get_area(magnitude: float) -> float: def get_area(magnitude: float) -> float:
""" """
...@@ -117,27 +132,39 @@ class Stafford2014(BaseScalingRelation): ...@@ -117,27 +132,39 @@ class Stafford2014(BaseScalingRelation):
# Model coefficients for the specific style of faulting # Model coefficients for the specific style of faulting
COEFFS = { COEFFS = {
# Coefficients from Table 1 # Coefficients from Table 1
1: {"U": {"a0": -27.4922, "a1": 4.6656, "a2": -0.2033}, 1: {
"U": {"a0": -27.4922, "a1": 4.6656, "a2": -0.2033},
"SS": {"a0": -30.8395, "a1": 5.4184, "a2": -0.3044}, "SS": {"a0": -30.8395, "a1": 5.4184, "a2": -0.3044},
"N": {"a0": -36.9770, "a1": 6.3070, "a2": -0.1696}, "N": {"a0": -36.9770, "a1": 6.3070, "a2": -0.1696},
"R": {"a0": -35.8239, "a1": 5.0680, "a2": -0.0457}}, "R": {"a0": -35.8239, "a1": 5.0680, "a2": -0.0457},
},
# Coefficients from Table 2 # Coefficients from Table 2
2: {"U": {"b0": -2.300, "b1": 0.7167, "sigma": 0.2337}, 2: {
"U": {"b0": -2.300, "b1": 0.7167, "sigma": 0.2337},
"SS": {"b0": -2.300, "b1": 0.7167, "sigma": 0.2337}, "SS": {"b0": -2.300, "b1": 0.7167, "sigma": 0.2337},
"N": {"b0": -4.1055, "b1": 1.0370, "sigma": 0.2509}, "N": {"b0": -4.1055, "b1": 1.0370, "sigma": 0.2509},
"R": {"b0": -3.8300, "b1": 0.9982, "sigma": 0.2285}}, "R": {"b0": -3.8300, "b1": 0.9982, "sigma": 0.2285},
},
# Coefficients from Table 3 # Coefficients from Table 3
3: {"U": {"gamma0": -9.3137, "sigma": 0.3138, "rho": 0.3104}, 3: {
"U": {"gamma0": -9.3137, "sigma": 0.3138, "rho": 0.3104},
"SS": {"gamma0": -9.3137, "sigma": 0.3138, "rho": 0.3104}, "SS": {"gamma0": -9.3137, "sigma": 0.3138, "rho": 0.3104},
"N": {"gamma0": -9.2483, "sigma": 0.3454, "rho": 0.4336}, "N": {"gamma0": -9.2483, "sigma": 0.3454, "rho": 0.4336},
"R": {"gamma0": -9.2749, "sigma": 0.2534, "rho": 0.1376}}, "R": {"gamma0": -9.2749, "sigma": 0.2534, "rho": 0.1376},
},
# Coefficients from Table 4 # Coefficients from Table 4
4: {"U": 0.7574, "SS": 0.7574, "N": 0.8490, "R": 0.7496} 4: {"U": 0.7574, "SS": 0.7574, "N": 0.8490, "R": 0.7496},
} }
def get_rupture_dimensions(self, magnitude: float, rake: float = 0.0, dip: float = 90.0, def get_rupture_dimensions(
aspect: float = 1.0, thickness: float = 20.0, self,
epsilon: float = 0.0) -> Tuple[float, float, float]: magnitude: float,
rake: float = 0.0,
dip: float = 90.0,
aspect: float = 1.0,
thickness: float = 20.0,
epsilon: float = 0.0,
) -> Tuple[float, float, float]:
""" """
Gets the rupture dimensions from for the given magnitude subject to the physical Gets the rupture dimensions from for the given magnitude subject to the physical
constaints. constaints.
...@@ -193,8 +220,9 @@ class Stafford2014(BaseScalingRelation): ...@@ -193,8 +220,9 @@ class Stafford2014(BaseScalingRelation):
# normal # normal
return "N" return "N"
def get_rupture_width(self, magnitude: float, dip: float, sof: str, thickness: float) ->\ def get_rupture_width(
Tuple[float, float, float, float]: self, magnitude: float, dip: float, sof: str, thickness: float
) -> Tuple[float, float, float, float]:
""" """
Returns the parameters needed to define the censored rupture width Returns the parameters needed to define the censored rupture width
distribution defined in equations 8 to 14 distribution defined in equations 8 to 14
...@@ -206,44 +234,45 @@ class Stafford2014(BaseScalingRelation): ...@@ -206,44 +234,45 @@ class Stafford2014(BaseScalingRelation):
""" """
# Gets the probability of a full width rupture # Gets the probability of a full width rupture
rw_max = thickness / sin(radians(dip)) rw_max = thickness / sin(radians(dip))
z_i = self.COEFFS[1][sof]["a0"] + \ z_i = (
self.COEFFS[1][sof]["a1"] * magnitude +\ self.COEFFS[1][sof]["a0"]
self.COEFFS[1][sof]["a2"] * rw_max + self.COEFFS[1][sof]["a1"] * magnitude
+ self.COEFFS[1][sof]["a2"] * rw_max
)
# Probability of rupturing full seismogenic thickness from logistic regression # Probability of rupturing full seismogenic thickness from logistic regression
p_i = 1.0 / (1.0 + exp(-z_i)) p_i = 1.0 / (1.0 + exp(-z_i))
# Median width from equation 16 # Median width from equation 16
ln_rw = self.COEFFS[2][sof]["b0"] + \ ln_rw = self.COEFFS[2][sof]["b0"] + self.COEFFS[2][sof]["b1"] * magnitude
self.COEFFS[2][sof]["b1"] * magnitude
# Equations 18 - 20 # Equations 18 - 20
phi_rw = (log(rw_max) - ln_rw) / self.COEFFS[2][sof]["sigma"] phi_rw = (log(rw_max) - ln_rw) / self.COEFFS[2][sof]["sigma"]
phi_rw_ncdf = norm.cdf(phi_rw) phi_rw_ncdf = norm.cdf(phi_rw)
ln_rw_trunc = ln_rw - self.COEFFS[2][sof]["sigma"] *\ ln_rw_trunc = ln_rw - self.COEFFS[2][sof]["sigma"] * (norm.pdf(phi_rw) / phi_rw_ncdf)
(norm.pdf(phi_rw) / phi_rw_ncdf)
mean_rw = p_i * log(rw_max) + (1.0 - p_i) * ln_rw_trunc mean_rw = p_i * log(rw_max) + (1.0 - p_i) * ln_rw_trunc
# Equations 21 - 22 # Equations 21 - 22
stddev_rw = self._get_rupture_width_sigma(self.COEFFS[2][sof]["sigma"], stddev_rw = self._get_rupture_width_sigma(
phi_rw, self.COEFFS[2][sof]["sigma"], phi_rw, phi_rw_ncdf, p_i
phi_rw_ncdf, )
p_i)
return mean_rw, stddev_rw, rw_max, p_i return mean_rw, stddev_rw, rw_max, p_i
@staticmethod @staticmethod
def _get_rupture_width_sigma(sigma: float, phi_rw: float, phi_rw_ncdf: float, def _get_rupture_width_sigma(
p_i: float) -> float: sigma: float, phi_rw: float, phi_rw_ncdf: float, p_i: float
) -> float:
""" """
Returns the variabiliy in the rupture width described by equations 21 and 22 Returns the variabiliy in the rupture width described by equations 21 and 22
""" """
denom = sqrt(2.0 * pi) * phi_rw_ncdf denom = sqrt(2.0 * pi) * phi_rw_ncdf
if phi_rw_ncdf >= 0.0: if phi_rw_ncdf >= 0.0:
elem1 = sqrt(pi / 2.) * (1.0 + chi2.cdf(phi_rw, 3)) elem1 = sqrt(pi / 2.0) * (1.0 + chi2.cdf(phi_rw, 3))
else: else:
elem1 = sqrt(pi / 2.) * (1.0 - chi2.cdf(phi_rw, 3)) elem1 = sqrt(pi / 2.0) * (1.0 - chi2.cdf(phi_rw, 3))
elem2 = exp(-(phi_rw ** 2)) / denom elem2 = exp(-(phi_rw ** 2)) / denom
sigma_truncated = sqrt(((sigma ** 2.) / denom) * (elem1 - elem2)) sigma_truncated = sqrt(((sigma ** 2.0) / denom) * (elem1 - elem2))
return (1.0 - p_i) * sigma_truncated return (1.0 - p_i) * sigma_truncated
def get_rupture_area(self, magnitude: float, sof: str, rw_max: float, def get_rupture_area(
sigma_lnrw: float) -> Tuple[float, float]: self, magnitude: float, sof: str, rw_max: float, sigma_lnrw: float
) -> Tuple[float, float]:
""" """
Returns the rupture area conditioned upon the maximum rupture width and style of Returns the rupture area conditioned upon the maximum rupture width and style of
faulting faulting
...@@ -258,15 +287,16 @@ class Stafford2014(BaseScalingRelation): ...@@ -258,15 +287,16 @@ class Stafford2014(BaseScalingRelation):
ln_ra: Natural logarithm of rupture area ln_ra: Natural logarithm of rupture area
sigma_ra: Standard deviation of the natural logarithm of rupture area sigma_ra: Standard deviation of the natural logarithm of rupture area
""" """
mw_crit = (log(rw_max) - self.COEFFS[2][sof]["b0"]) /\ mw_crit = (log(rw_max) - self.COEFFS[2][sof]["b0"]) / self.COEFFS[2][sof]["b1"]
self.COEFFS[2][sof]["b1"] ln_ra = self.COEFFS[3][sof]["gamma0"] + log(10.0) * magnitude
ln_ra = self.COEFFS[3][sof]["gamma0"] + log(10.) * magnitude
if magnitude > mw_crit: if magnitude > mw_crit:
# Equation 23 # Equation 23
ln_ra -= ((log(10.) / 4.) * (magnitude - mw_crit)) ln_ra -= (log(10.0) / 4.0) * (magnitude - mw_crit)
# Get the sigma log rupture area (equation 28) # Get the sigma log rupture area (equation 28)
sigma = self.COEFFS[3][sof]["sigma"] sigma = self.COEFFS[3][sof]["sigma"]
sigma_ra = sqrt( sigma_ra = sqrt(
(sigma ** 2.) + (sigma_lnrw ** 2.) + (sigma ** 2.0)
(2.0 * self.COEFFS[3][sof]["rho"] * sigma_lnrw * sigma)) + (sigma_lnrw ** 2.0)
+ (2.0 * self.COEFFS[3][sof]["rho"] * sigma_lnrw * sigma)
)
return ln_ra, sigma_ra return ln_ra, sigma_ra
...@@ -17,6 +17,7 @@ class DIP_RANGES(Enum): ...@@ -17,6 +17,7 @@ class DIP_RANGES(Enum):
for each style-of-faulting is provided and they are assumed to be uniformly for each style-of-faulting is provided and they are assumed to be uniformly
distributed. distributed.
""" """
R = (20.0, 45.0) R = (20.0, 45.0)
SS = (75.0, 91.0) SS = (75.0, 91.0)
N = (45.0, 75.0) N = (45.0, 75.0)
...@@ -40,6 +41,7 @@ class RuptureMechanism(object): ...@@ -40,6 +41,7 @@ class RuptureMechanism(object):
of :class:`openquake.hazardlib.pmf.PMF` of :class:`openquake.hazardlib.pmf.PMF`
""" """
def __init__(self, mechanism: Optional[PMF] = None): def __init__(self, mechanism: Optional[PMF] = None):
if mechanism: if mechanism:
assert isinstance(mechanism, PMF) assert isinstance(mechanism, PMF)
...@@ -76,8 +78,12 @@ class RuptureMechanism(object): ...@@ -76,8 +78,12 @@ class RuptureMechanism(object):
return strikes, dips, rakes return strikes, dips, rakes
@classmethod @classmethod
def from_strike_dip_rake(cls, strike: Optional[float] = None, dip: Optional[float] = None, def from_strike_dip_rake(
rake: Optional[float] = None) -> RuptureMechanism: cls,
strike: Optional[float] = None,
dip: Optional[float] = None,
rake: Optional[float] = None,
) -> RuptureMechanism:
""" """
Constructs the rupture mechanism distribution from a simple strike, dip Constructs the rupture mechanism distribution from a simple strike, dip
and rake combination, permitting None values if undefined and rake combination, permitting None values if undefined
...@@ -87,13 +93,14 @@ class RuptureMechanism(object): ...@@ -87,13 +93,14 @@ class RuptureMechanism(object):
dip: Dip of fault (in decimal degrees between 0 and 90) dip: Dip of fault (in decimal degrees between 0 and 90)
rake: Rake of fault (in decimal degrees between -180 and 180) rake: Rake of fault (in decimal degrees between -180 and 180)
""" """
return cls(cls.build_mechanism_distribution(valid.strike(strike), return cls(
valid.dip(dip), cls.build_mechanism_distribution(
valid.rake(rake))) valid.strike(strike), valid.dip(dip), valid.rake(rake)
)
)
@classmethod @classmethod
def from_nodal_planes(cls, nodal_plane_1: Dict, nodal_plane_2: Dict)\ def from_nodal_planes(cls, nodal_plane_1: Dict, nodal_plane_2: Dict) -> RuptureMechanism:
-> RuptureMechanism:
""" """
Constructs the rupture mechanism distribution from either one single Constructs the rupture mechanism distribution from either one single
valid rupture plane or two valud nodal planes valid rupture plane or two valud nodal planes
...@@ -108,13 +115,21 @@ class RuptureMechanism(object): ...@@ -108,13 +115,21 @@ class RuptureMechanism(object):
strike_2 = valid.strike(nodal_plane_2["strike"]) strike_2 = valid.strike(nodal_plane_2["strike"])
dip_2 = valid.dip(nodal_plane_2["dip"]) dip_2 = valid.dip(nodal_plane_2["dip"])
rake_2 = valid.rake(nodal_plane_2["rake"]) rake_2 = valid.rake(nodal_plane_2["rake"])
return cls(PMF([(0.5, NodalPlane(strike_1, dip_1, rake_1)), return cls(
(0.5, NodalPlane(strike_2, dip_2, rake_2))])) PMF(
[
(0.5, NodalPlane(strike_1, dip_1, rake_1)),
(0.5, NodalPlane(strike_2, dip_2, rake_2)),
]
)
)
@staticmethod @staticmethod
def build_mechanism_distribution(strike: Optional[float] = None, def build_mechanism_distribution(
dip: Optional[float] = None, strike: Optional[float] = None,
rake: Optional[float] = None) -> PMF: dip: Optional[float] = None,
rake: Optional[float] = None,
) -> PMF:
""" """
Builds a mechanism distribution from a partial (or complete) characterisation of the Builds a mechanism distribution from a partial (or complete) characterisation of the
rupture mechanism rupture mechanism
......
...@@ -23,8 +23,8 @@ SITE_PROPERTIES = { ...@@ -23,8 +23,8 @@ SITE_PROPERTIES = {
"xvf": np.float64, # Distance (km) to the volcanic front "xvf": np.float64, # Distance (km) to the volcanic front
"backarc": np.bool, # Site is in the subduction backarc (True) or else "backarc": np.bool, # Site is in the subduction backarc (True) or else
"region": np.int32, # Region to which the site belongs "region": np.int32, # Region to which the site belongs
"geology": (np.string_, 20) # Geological classification for the site "geology": (np.string_, 20), # Geological classification for the site
} }
# In some cases reasonable default values can be used for relevant ground motion models # In some cases reasonable default values can be used for relevant ground motion models
...@@ -218,15 +218,11 @@ class SiteModel(object): ...@@ -218,15 +218,11 @@ class SiteModel(object):
if key not in dframe.columns: if key not in dframe.columns:
# Use the default # Use the default
if SITE_PROPERTIES[key] in ((np.bytes_, 20),): if SITE_PROPERTIES[key] in ((np.bytes_, 20),):
site_array[key] = cls._get_string_array( site_array[key] = cls._get_string_array(nsites, value, SITE_PROPERTIES[key])
nsites, value, SITE_PROPERTIES[key]
)
elif SITE_PROPERTIES[key] == np.bool: elif SITE_PROPERTIES[key] == np.bool:
site_array[key] = cls._get_boolean_array(nsites, value) site_array[key] = cls._get_boolean_array(nsites, value)
else: else:
site_array[key] = value * np.ones( site_array[key] = value * np.ones(nsites, dtype=SITE_PROPERTIES[key])
nsites, dtype=SITE_PROPERTIES[key]
)
return cls(site_array) return cls(site_array)
@staticmethod @staticmethod
...@@ -277,9 +273,7 @@ class SiteModel(object): ...@@ -277,9 +273,7 @@ class SiteModel(object):
if japan: if japan:
c1 = 412.0 ** 2.0 c1 = 412.0 ** 2.0
c2 = 1360.0 ** 2.0 c2 = 1360.0 ** 2.0
return np.exp( return np.exp((-5.23 / 2.0) * np.log((np.power(vs30, 2.0) + c1) / (c2 + c1)))
(-5.23 / 2.0) * np.log((np.power(vs30, 2.0) + c1) / (c2 + c1))
)
else: else:
c1 = 571.0 ** 4.0 c1 = 571.0 ** 4.0
c2 = 1360.0 ** 4.0 c2 = 1360.0 ** 4.0
......
...@@ -4,8 +4,7 @@ consistent quantities ...@@ -4,8 +4,7 @@ consistent quantities
""" """
from typing import Tuple, Optional, Union from typing import Tuple, Optional, Union
from openquake.hazardlib.geo.nodalplane import NodalPlane from openquake.hazardlib.geo.nodalplane import NodalPlane
from shakyground2.magnitude_scaling_relations import (BaseScalingRelation, from shakyground2.magnitude_scaling_relations import BaseScalingRelation, PEERScalingRelation
PEERScalingRelation)
def longitude(lon: float) -> float: def longitude(lon: float) -> float:
...@@ -93,8 +92,10 @@ def seismogenic_thickness( ...@@ -93,8 +92,10 @@ def seismogenic_thickness(
usd = positive_float(upper_seismo_depth, "upper seismogenic depth") usd = positive_float(upper_seismo_depth, "upper seismogenic depth")
lsd = positive_float(lower_seismo_depth, "lower seismogenic depth") lsd = positive_float(lower_seismo_depth, "lower seismogenic depth")
if lsd < usd: if lsd < usd:
raise ValueError("Lower seismogenic depth %.2f km shallower than upper seismogenic " raise ValueError(
"depth %.2f km" % (lsd, usd)) "Lower seismogenic depth %.2f km shallower than upper seismogenic "
"depth %.2f km" % (lsd, usd)
)
return usd, lsd return usd, lsd
...@@ -105,8 +106,9 @@ def hypocenter_position(hypo_pos: Tuple[float, float]) -> Tuple[float, float]: ...@@ -105,8 +106,9 @@ def hypocenter_position(hypo_pos: Tuple[float, float]) -> Tuple[float, float]:
""" """
along_strike, down_dip = hypo_pos along_strike, down_dip = hypo_pos
if along_strike < 0.0 or along_strike > 1.0: if along_strike < 0.0 or along_strike > 1.0:
raise ValueError("Along strike position %.3f should be in the range 0 to 1" raise ValueError(
% along_strike) "Along strike position %.3f should be in the range 0 to 1" % along_strike
)
if down_dip < 0.0 or down_dip > 1.0: if down_dip < 0.0 or down_dip > 1.0:
raise ValueError("Down dip position %.3f should be in the range 0 to 1" % down_dip) raise ValueError("Down dip position %.3f should be in the range 0 to 1" % down_dip)
return along_strike, down_dip return along_strike, down_dip
...@@ -121,6 +123,7 @@ def scaling_relation(msr: Optional[BaseScalingRelation]): ...@@ -121,6 +123,7 @@ def scaling_relation(msr: Optional[BaseScalingRelation]):
# If no relation is defined then use the default # If no relation is defined then use the default
return PEERScalingRelation() return PEERScalingRelation()
if not isinstance(msr, BaseScalingRelation): if not isinstance(msr, BaseScalingRelation):
raise TypeError("Magnitude Scaling Relation %s not instance of BaseScalingRelation" % raise TypeError(
str(msr)) "Magnitude Scaling Relation %s not instance of BaseScalingRelation" % str(msr)
)
return msr return msr
...@@ -11,7 +11,6 @@ from shakyground2.magnitude_scaling_relations import PEERScalingRelation ...@@ -11,7 +11,6 @@ from shakyground2.magnitude_scaling_relations import PEERScalingRelation
class EarthquakeTestCase(unittest.TestCase): class EarthquakeTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.lon = 35.0