Skip to content

Commit fad8d29

Browse files
author
Marius Isken
committed
update
1 parent 68febb4 commit fad8d29

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

src/qseek/distance_weights.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def _station_weights(
9999
def distance_weights(
100100
distances: np.ndarray,
101101
station_weights: np.ndarray,
102-
station_weight_plateau: float = 4.0,
103-
station_weight_taper: float = 12.0,
102+
weight_plateau: float = 4.0,
103+
weight_taper: float = 12.0,
104104
) -> np.ndarray:
105105
"""Calculate distance weights with plateau and taper based on station weights.
106106
@@ -112,10 +112,10 @@ def distance_weights(
112112
in meters.
113113
station_weights: Array of shape (n_stations,) with station weights between
114114
0 and 1.
115-
station_weight_plateau: Station weight value to define the plateau distance.
116-
Default is 4.0.
117-
station_weight_taper: Station weight value to define the taper distance.
118-
Default is 8.0.
115+
weight_plateau: Cumulative station weight theshold to define the plateau
116+
distance. Default is 4.0.
117+
weight_taper: Cumulative Station weight threshold to define the taper
118+
distance. Default is 12.0.
119119
120120
Returns:
121121
Array of shape (n_nodes, n_stations) with weights between 0 and 1.
@@ -124,20 +124,23 @@ def distance_weights(
124124

125125
distance_sort = np.argsort(distances, axis=1)
126126
sorted_distances = np.take_along_axis(distances, distance_sort, axis=1)
127-
sorted_weights = station_weights[distance_sort]
127+
sorted_station_weights = station_weights[distance_sort]
128128

129-
weights_cum = np.cumsum(sorted_weights, axis=1)
129+
cum_station_weights = np.cumsum(sorted_station_weights, axis=1)
130130

131131
# First index where cumulative weights exceed plateau and taper weights
132-
idxs_plateau = np.argmax(weights_cum >= station_weight_plateau, axis=1)
133-
idxs_taper = np.argmax(weights_cum >= station_weight_taper, axis=1)
132+
idxs_plateau = np.argmax(cum_station_weights >= weight_plateau, axis=1)
133+
idxs_taper = np.argmax(cum_station_weights >= weight_taper, axis=1)
134134

135135
# If total cumulative weight is less than plateau/taper, set to last index
136-
idxs_plateau[weights_cum[:, -1] < station_weight_plateau] = distances.shape[1] - 1
137-
idxs_taper[weights_cum[:, -1] < station_weight_taper] = distances.shape[1] - 1
136+
idx_last_station = distances.shape[1] - 1
137+
idxs_plateau[cum_station_weights[:, -1] < weight_plateau] = idx_last_station
138+
idxs_taper[cum_station_weights[:, -1] < weight_taper] = idx_last_station
138139

139140
plateau_distances = sorted_distances[np.arange(n_nodes), idxs_plateau, np.newaxis]
140141
taper_distance = sorted_distances[np.arange(n_nodes), idxs_taper, np.newaxis]
142+
# We use half sigma here, more weight will estimate better geometry of the
143+
# station distribution
141144
taper_sigma = taper_distance / 2
142145

143146
distance_weights = np.exp(
@@ -208,20 +211,20 @@ def weights_gaussian(
208211

209212

210213
class DistanceWeights(BaseModel):
211-
effective_plateau_weight: PositiveFloat = Field(
214+
plateau_weight: PositiveFloat = Field(
212215
default=4.0,
213216
description="The cumulative station weight required to define the"
214217
"'Core Aperture' (Plateau). A value of 4.0 ensures the location is constrained"
215218
"by the equivalent of 4 independent, high-quality stations.",
216219
)
217-
taper_decay_factor: PositiveFloat = Field(
218-
default=3.0,
219-
description="Controls the gradualness of the spatial filter's edge (Gamma). "
220-
"Where the 'Core Aperture' ends, the Gaussian spatial taper extends further"
221-
" based on this factor with sigma = (Gamma * R_plateau) / 2."
222-
"A higher value (e.g., 5.0) creates a 'softer' taper, retaining more "
223-
"influence from distant stations to improve stability. "
224-
"A lower value (e.g., 1.0) creates a 'sharper' cutoff.",
220+
taper_weight: PositiveFloat = Field(
221+
default=12.0,
222+
description="The cumulative station weight threshold that defines where the "
223+
"Gaussian taper reaches its effective limit. This value determines how many "
224+
"equivalent stations contribute to the location estimate beyond the core "
225+
"aperture. Higher values (e.g., 20.0) include more distant stations with "
226+
"gradually decreasing weights, while lower values (e.g., 8.0) create a "
227+
"more localized influence zone. Default is 12.0.",
225228
)
226229

227230
_node_distance_lut: ArrayLRUCache[bytes] = PrivateAttr()
@@ -283,9 +286,8 @@ async def get_weights(
283286
weights_distance = distance_weights(
284287
distances=np.asarray(distances),
285288
station_weights=weights_stations,
286-
station_weight_plateau=self.effective_plateau_weight,
287-
station_weight_taper=self.effective_plateau_weight
288-
* self.taper_decay_factor,
289+
weight_plateau=self.plateau_weight,
290+
weight_taper=self.taper_weight,
289291
)
290292
weights = weights_distance * weights_stations
291293
return weights / weights.max(axis=1, keepdims=True)

test/test_distance_weights.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def test_distance_weights():
173173
distance_weight = distance_weights(
174174
distances,
175175
station_weight,
176-
station_weight_plateau=station_weight_plateau,
177-
station_weight_taper=4 * station_weight_plateau,
176+
weight_plateau=station_weight_plateau,
177+
weight_taper=4 * station_weight_plateau,
178178
)
179179
total_weight = distance_weight * station_weight[np.newaxis, :]
180180

0 commit comments

Comments
 (0)