gamma-wadati 0.1.0.dev1__tar.gz → 0.1.0.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamma-wadati
3
- Version: 0.1.0.dev1
3
+ Version: 0.1.0.dev2
4
4
  Summary: Earthquake phase association and location as a Bayesian Gaussian mixture on the Wadati transform
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -16,7 +16,7 @@ Earthquake phase **association** and **location** solved together as a
16
16
  form
17
17
 
18
18
  ```
19
- M = (t_P + t_S)/2 = t0 + p·r D = (t_S − t_P)/2 = q·r
19
+ M = (t_P + t_S)/2 = t0 + p·r D = t_S − t_P = q·r
20
20
  ```
21
21
 
22
22
  which are linear in source distance `r`. The transform decouples origin time
@@ -6,7 +6,7 @@ Earthquake phase **association** and **location** solved together as a
6
6
  form
7
7
 
8
8
  ```
9
- M = (t_P + t_S)/2 = t0 + p·r D = (t_S − t_P)/2 = q·r
9
+ M = (t_P + t_S)/2 = t0 + p·r D = t_S − t_P = q·r
10
10
  ```
11
11
 
12
12
  which are linear in source distance `r`. The transform decouples origin time
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gamma-wadati"
7
- version = "0.1.0.dev1"
7
+ version = "0.1.0.dev2"
8
8
  description = "Earthquake phase association and location as a Bayesian Gaussian mixture on the Wadati transform"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gamma-wadati
3
- Version: 0.1.0.dev1
3
+ Version: 0.1.0.dev2
4
4
  Summary: Earthquake phase association and location as a Bayesian Gaussian mixture on the Wadati transform
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -16,7 +16,7 @@ Earthquake phase **association** and **location** solved together as a
16
16
  form
17
17
 
18
18
  ```
19
- M = (t_P + t_S)/2 = t0 + p·r D = (t_S − t_P)/2 = q·r
19
+ M = (t_P + t_S)/2 = t0 + p·r D = t_S − t_P = q·r
20
20
  ```
21
21
 
22
22
  which are linear in source distance `r`. The transform decouples origin time
@@ -21,7 +21,7 @@ from sklearn.cluster import KMeans
21
21
  from sklearn.utils._param_validation import StrOptions
22
22
  from sklearn.utils.extmath import row_norms
23
23
 
24
- from .forward import DEFAULT_VELOCITY, Velocity, estimate_t0, locate, predict_mean
24
+ from .forward import D_SIGMA, DEFAULT_VELOCITY, Velocity, estimate_t0, locate, predict_mean
25
25
  from .windowing import init_event_seeds
26
26
 
27
27
  ###############################################################################
@@ -402,7 +402,7 @@ def _estimate_wadati_parameters(
402
402
  "tied": _estimate_gaussian_covariances_tied,
403
403
  "diag": _estimate_gaussian_covariances_diag,
404
404
  "spherical": _estimate_gaussian_covariances_spherical,
405
- }[covariance_type](resp, X, nk, means, reg_covar)
405
+ }[covariance_type](resp, X, nk, means, reg_covar if covariance_type == "spherical" else reg_covar * np.array([1.0, D_SIGMA**2])) # D's variance is D_SIGMA**2 times M's
406
406
  return nk, centers, t0, means, covariances
407
407
 
408
408
 
@@ -435,7 +435,7 @@ def _init_responsibilities(
435
435
  M, D, station_locs, n_components, velocity
436
436
  )
437
437
  means = predict_mean(centers, t0, station_locs, velocity.p, velocity.q)
438
- labels = np.argmin(np.sum((X[:, None, :] - means) ** 2, axis=2), axis=1)
438
+ labels = np.argmin(np.sum(((X[:, None, :] - means) / [1.0, D_SIGMA]) ** 2, axis=2), axis=1)
439
439
  else: # "kmeans"
440
440
  u = M - velocity.alpha * D
441
441
  km_to_s = 1.0 / velocity.vp # station km -> s (P travel time), so that
@@ -3,7 +3,7 @@
3
3
  The (M, D) Wadati coordinates of a pick are linear in source--station distance::
4
4
 
5
5
  M = t0 + p * r p = (1/v_p + 1/v_s) / 2 (mean slowness)
6
- D = q * r q = (1/v_s - 1/v_p) / 2 (differential slowness)
6
+ D = q * r q = 1/v_s - 1/v_p (differential slowness)
7
7
 
8
8
  with derived constants ``alpha = p / q`` (Wadati slope) and ``beta = 1 / q``
9
9
  (distance per unit D). See ``formulation.md``.
@@ -21,6 +21,11 @@ from scipy.optimize import least_squares
21
21
  VP = 6.0
22
22
  VS = VP / 1.75
23
23
 
24
+ # For equal, independent P and S pick errors of variance s^2: Var(M) = s^2 / 2 and
25
+ # Var(D) = 2 s^2, so a D residual carries twice the standard deviation of an M
26
+ # residual. Least squares and distances in (M, D) divide the D residual by this.
27
+ D_SIGMA = 2.0
28
+
24
29
 
25
30
  @dataclass(frozen=True)
26
31
  class Velocity:
@@ -35,11 +40,11 @@ class Velocity:
35
40
 
36
41
  @property
37
42
  def q(self) -> float:
38
- return 0.5 * (1.0 / self.vs - 1.0 / self.vp)
43
+ return 1.0 / self.vs - 1.0 / self.vp
39
44
 
40
45
  @property
41
46
  def alpha(self) -> float:
42
- """Wadati slope p / q = (vp + vs) / (vp - vs)."""
47
+ """Wadati slope p / q = (vp + vs) / (2 (vp - vs))."""
43
48
  return self.p / self.q
44
49
 
45
50
  @property
@@ -122,7 +127,7 @@ def estimate_t0(M, D, resp, alpha):
122
127
  def _locate_one(M, D, w, t0_k, station_locs, p, q, x0, bounds):
123
128
  """Weighted nonlinear least squares for one event's hypocenter.
124
129
 
125
- Minimizes ``sum_n w_n [(t0_k + p r_n - M_n)^2 + (q r_n - D_n)^2]``.
130
+ Minimizes ``sum_n w_n [(t0_k + p r_n - M_n)^2 + ((q r_n - D_n) / D_SIGMA)^2]``.
126
131
  """
127
132
  sw = np.sqrt(w)
128
133
 
@@ -130,7 +135,7 @@ def _locate_one(M, D, w, t0_k, station_locs, p, q, x0, bounds):
130
135
  d = station_locs - xi[None, :]
131
136
  r = np.sqrt(np.sum(d * d, axis=1))
132
137
  res_m = sw * (t0_k + p * r - M)
133
- res_d = sw * (q * r - D)
138
+ res_d = sw * (q * r - D) / D_SIGMA
134
139
  return np.concatenate([res_m, res_d])
135
140
 
136
141
  def jacobian(xi):
@@ -140,7 +145,7 @@ def _locate_one(M, D, w, t0_k, station_locs, p, q, x0, bounds):
140
145
  # d r / d xi = (xi - s) / r = -d / r
141
146
  grad_r = -d / r_safe[:, None] # (n, 3)
142
147
  jac_m = (sw * p)[:, None] * grad_r
143
- jac_d = (sw * q)[:, None] * grad_r
148
+ jac_d = (sw * q / D_SIGMA)[:, None] * grad_r
144
149
  return np.vstack([jac_m, jac_d])
145
150
 
146
151
  if bounds is None:
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Wadati model needs, per event and station, a matched P and S arrival:
4
4
 
5
- M = (t_P + t_S) / 2 , D = (t_S - t_P) / 2 .
5
+ M = (t_P + t_S) / 2 , D = t_S - t_P .
6
6
 
7
7
  Association has not happened yet, so pairing must be done from raw picks without
8
8
  knowing events. Per station we take, in order of increasing S-P time (the
@@ -49,7 +49,7 @@ def pair_ps(station_id, t, phase_type, score=None, dt_max=25.0, method="monotoni
49
49
  score : array of shape (n_picks,) or None
50
50
  Pick quality in [0, 1]; the pair weight is ``min(score_P, score_S)``.
51
51
  dt_max : float
52
- Maximum S-P time (s); ``D <= dt_max/2``, i.e. distance <= beta*dt_max/2.
52
+ Maximum S-P time (s); ``D <= dt_max``, i.e. distance <= beta*dt_max.
53
53
  method : {"monotonic", "greedy"}
54
54
  "monotonic" (default): order-preserving matching -- the i-th P pairs with
55
55
  the earliest still-available S after it, so interleaved arrivals from
@@ -91,7 +91,7 @@ def pair_ps(station_id, t, phase_type, score=None, dt_max=25.0, method="monotoni
91
91
  while j < len(tS) and tS[j] <= tP[i]:
92
92
  j += 1
93
93
  if j < len(tS) and tS[j] - tP[i] <= dt_max:
94
- rows.append((0.5 * (tP[i] + tS[j]), 0.5 * (tS[j] - tP[i]),
94
+ rows.append((0.5 * (tP[i] + tS[j]), tS[j] - tP[i],
95
95
  min(sP[i], sS[j]), gp[i], gs[j]))
96
96
  j += 1
97
97
  continue
@@ -119,7 +119,7 @@ def pair_ps(station_id, t, phase_type, score=None, dt_max=25.0, method="monotoni
119
119
  rows.append(
120
120
  (
121
121
  0.5 * (tP[ip] + tS[is_]), # M
122
- 0.5 * (tS[is_] - tP[ip]), # D
122
+ tS[is_] - tP[ip], # D
123
123
  min(sP[ip], sS[is_]), # weight
124
124
  gp[ip], # iP
125
125
  gs[is_], # iS