Skip to content

Commit

Permalink
Bugfix for r_power_n_segmented branch (#63)
Browse files Browse the repository at this point in the history
* Fixed bug in geom_spread_power_n_segmented function related to 'hinge_distances' argument.

* Removed brackets from 'geom_spread_n_exponents' and 'geom_spread_n_distances' example in comments.

* Require 'hinge_distances' argument of geom_spread_r_power_n_segmented function to correspond to start of each segment instead of distances separating segments.

* Updated check on length of hinge distances for segmented geometrical spreading model in _geometrical_spreading_coefficient function.

* Updated example and comment related to 'geom_spread_n_exponents' and 'geom_spread_n_distances' configuration parameters for segmented geometrical spreading model.

* Small fix in explanation of 'geom_spread_n_distances' configuration parameter.

* Fix a line too long

---------

Co-authored-by: Claudio Satriano <satriano@gmail.com>
  • Loading branch information
krisvanneste and claudiodsf authored Jan 9, 2025
1 parent 0e5197f commit 8634634
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
13 changes: 8 additions & 5 deletions sourcespec/config_files/configspec.conf
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,17 @@ geom_spread_model = option('r_power_n', 'r_power_n_segmented', 'boatwright', def
# geom_spread_n_exponent = 1 (default, body wave in a homogeneous full-space)
# geom_spread_n_exponent = 0.5 (surface wave in a homogeneous half-space)
geom_spread_n_exponent = float(min=0, default=1)
# Exponents and distances (in km) separating segments with different exponents
# Exponents and hypocentral distances (in km) defining different segments
# for the "r_power_n_segmented" geometrical spreading function.
# The number of exponents must be one more than the number of distances.
# The number of exponents must be equal to the number of distances.
# Distances correspond to the start of each segment.
# Note that no geometrical spreading correction is considered
# below the smallest distance. This distance is generally set to 1 km.
# Example:
# geom_spread_n_exponents = [1., 0., 0.5]
# geom_spread_n_distances = [70, 130]
# geom_spread_n_exponents = 1., 0., 0.5
# geom_spread_n_distances = 1, 70, 130
geom_spread_n_exponents = float_list(min=0, default=None)
geom_spread_n_distances = float_list(default=None)
geom_spread_n_distances = float_list(min=0, default=None)
# Geometrical spreading cutoff hypocentral distance, in km, for the
# "boatwright" model:
geom_spread_cutoff_distance = float(min=0.01, default=50)
Expand Down
8 changes: 4 additions & 4 deletions sourcespec/ssp_build_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def _geometrical_spreading_coefficient(config, spec):
if config.geom_spread_model == 'r_power_n_segmented':
exponents = config.geom_spread_n_exponents
hinge_distances = config.geom_spread_n_distances
if len(hinge_distances) != len(exponents) - 1:
if len(hinge_distances) != len(exponents):
raise ValueError(
f'The number of exponents must be one more than the number of '
f'hinge distances. You provided {len(exponents)} exponents and '
f'{len(hinge_distances)} hinge distances'
f'The number of exponents must be equal to the number of '
f'hinge distances. You provided {len(exponents)} exponents '
f'and {len(hinge_distances)} hinge distances'
)
return geom_spread_r_power_n_segmented(hypo_dist_in_km, exponents,
hinge_distances)
Expand Down
8 changes: 4 additions & 4 deletions sourcespec/ssp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ def geom_spread_r_power_n_segmented(hypo_dist_in_km, exponents,
:param hypo_dist_in_km: Hypocentral distance (km).
:type hypo_dist_in_km: float
:param exponents: Exponents for different powerlaw segments
:type exponents: numpy.ndarray
:param hinge_distances: Distances defining start of powerlaw segments
:type hinge_distances: numpy.ndarray
:param hinge_distances: Distances between different powerlaw segments
:type exponent: numpy.ndarray
:return: Geometrical spreading correction (for distance in m)
:rtype: float
"""
Expand All @@ -288,8 +288,8 @@ def geom_spread_r_power_n_segmented(hypo_dist_in_km, exponents,
else:
hypo_dist_in_km = np.asarray(hypo_dist_in_km, dtype='float')
is_scalar = False
Rref = 1.
hinge_distances = np.hstack([[Rref], hinge_distances or []])
hinge_distances = np.asarray(hinge_distances)
Rref = hinge_distances[0]
exponents = -np.asarray(exponents)
# Do not allow distances less than Rref (1 km)
hypo_dist_in_km = np.maximum(Rref, hypo_dist_in_km)
Expand Down

0 comments on commit 8634634

Please sign in to comment.