hyperdd 0.1__py3-none-any.whl → 0.2.1.dev1__py3-none-any.whl

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.
hyperdd/core/datatypes.py CHANGED
@@ -41,7 +41,7 @@ class HypoDDConfig:
41
41
  maxgap: float = -999.0
42
42
  istart: int = 0 # 1=single source, 2=catalog
43
43
  isolv: int = 0 # 1=SVD, 2=LSQR
44
- iaq: int = 0 # airquake removal
44
+ iaq: int = 0 # airquakes: 0 = held at depth 0, 1 = removed (HypoDD), 2 = no test, events move above sea level
45
45
  nset: int = 0 # number of iteration sets
46
46
  imod: int = 0 # velocity model type
47
47
  iclust: int = 0 # cluster to relocate (0=all)
@@ -61,5 +61,6 @@ class HypoDDConfig:
61
61
  # GraphDD extensions
62
62
  gnc_kernel: str = "" # "" = off, "tls", "huber", "cauchy"
63
63
  gnc_threshold: float = 3.0 # MAD multiplier for kernel threshold
64
- solver_backend: str = "lsqr" # "lsqr", "lsmr", "cholesky", "pcg"
64
+ solver_backend: str = "lsqr" # "lsqr", "lsmr", "cholesky", "pcg", "schur"
65
65
  robust_loss: str = None # None, "huber", "cauchy", "tukey"
66
+ max_partition_size: int = 5000 # max events per Schur partition
hyperdd/core/dtres.py CHANGED
@@ -2,14 +2,14 @@ import numpy as np
2
2
 
3
3
 
4
4
  def compute_residuals(ndt, nsrc, dt_dt, dt_idx, dt_ista, dt_ic1, dt_ic2,
5
- src_t, tmp_ttp, tmp_tts):
5
+ src_t, pp):
6
6
  """Compute double-difference residuals (vectorized).
7
7
 
8
8
  dt_dt: observed differential times
9
9
  dt_idx: phase type (1=cc-P, 2=cc-S, 3=ct-P, 4=ct-S)
10
10
  dt_ista, dt_ic1, dt_ic2: station and event pair indices (0-indexed)
11
11
  src_t: source origin time corrections in milliseconds
12
- tmp_ttp, tmp_tts: travel time arrays (nsta, nsrc)
12
+ pp: the travel times of the observed (station, event) pairs (PairPartials)
13
13
 
14
14
  Returns: dt_cal, dt_res arrays
15
15
  """
@@ -25,19 +25,10 @@ def compute_residuals(ndt, nsrc, dt_dt, dt_idx, dt_ista, dt_ic1, dt_ic2,
25
25
  idx = dt_idx[:ndt]
26
26
 
27
27
  s_mask = (idx == 2) | (idx == 4)
28
- p_mask = ~s_mask
29
-
30
- # P-phase
31
- if np.any(p_mask):
32
- tt1_p = tmp_ttp[ista[p_mask], ic1[p_mask]] - src_t[ic1[p_mask]] / 1000.0
33
- tt2_p = tmp_ttp[ista[p_mask], ic2[p_mask]] - src_t[ic2[p_mask]] / 1000.0
34
- dt_cal[p_mask] = tt1_p - tt2_p
35
-
36
- # S-phase
37
- if np.any(s_mask):
38
- tt1_s = tmp_tts[ista[s_mask], ic1[s_mask]] - src_t[ic1[s_mask]] / 1000.0
39
- tt2_s = tmp_tts[ista[s_mask], ic2[s_mask]] - src_t[ic2[s_mask]] / 1000.0
40
- dt_cal[s_mask] = tt1_s - tt2_s
28
+
29
+ tt1 = pp.travel_time(s_mask, pp.k1) - src_t[ic1] / 1000.0
30
+ tt2 = pp.travel_time(s_mask, pp.k2) - src_t[ic2] / 1000.0
31
+ dt_cal[:ndt] = tt1 - tt2
41
32
 
42
33
  dt_res[:ndt] = dt_dt[:ndt] - dt_cal[:ndt]
43
34
 
hyperdd/core/jacobian.py CHANGED
@@ -4,8 +4,8 @@ Builds the weighted sparse Jacobian matrix J and data vector d from
4
4
  observation arrays and partial derivatives. This is the core matrix
5
5
  that all solver backends (LSQR, Cholesky, PCG) operate on.
6
6
 
7
- Factored out from sparse_chol.py so it can be shared across solvers
8
- and eventually accept per-observation partials directly (no nsta x nsrc arrays).
7
+ Factored out from sparse_chol.py so it can be shared across solvers. The partials
8
+ arrive per observed (station, event) pair (PairPartials); there are no nsta x nsrc arrays.
9
9
  """
10
10
 
11
11
  import numpy as np
@@ -24,8 +24,7 @@ _FIX_WEIGHTS = {
24
24
 
25
25
 
26
26
  def build_dd_system(ndt, nev, nsrc, dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_idx,
27
- tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs,
28
- ev_fix, use_float32=True):
27
+ pp, ev_fix, use_float32=True):
29
28
  """Build weighted sparse Jacobian G and data vector d for the DD system.
30
29
 
31
30
  Returns
@@ -49,12 +48,15 @@ def build_dd_system(ndt, nev, nsrc, dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_i
49
48
  if fix in _FIX_WEIGHTS:
50
49
  n_fix_entries += len(_FIX_WEIGHTS[fix])
51
50
 
51
+ # n_meanshift = 4 * nev # 4 constraint rows, nev entries each
52
+ # max_nnz = 8 * ndt + n_meanshift + n_fix_entries
52
53
  max_nnz = 8 * ndt + n_fix_entries
53
54
  rows = np.empty(max_nnz, dtype=np.int32)
54
55
  cols = np.empty(max_nnz, dtype=np.int32)
55
56
  vals = np.empty(max_nnz, dtype=np.float64)
56
57
 
57
58
  nndt = ndt
59
+ # max_rows = ndt + 4 + n_fix_entries # +4 for mean-shift constraints
58
60
  max_rows = ndt + n_fix_entries
59
61
  d = np.zeros(max_rows, dtype=np.float64)
60
62
  d[:ndt] = dt_res[:ndt] * 1000.0 * wt
@@ -64,22 +66,11 @@ def build_dd_system(ndt, nev, nsrc, dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_i
64
66
  ic2 = dt_ic2[:ndt]
65
67
  ista = dt_ista[:ndt]
66
68
 
67
- if nsrc == 1:
68
- k1_arr = np.zeros(ndt, dtype=np.int32)
69
- k2_arr = np.zeros(ndt, dtype=np.int32)
70
- else:
71
- k1_arr = ic1.copy()
72
- k2_arr = ic2.copy()
73
-
74
69
  s_mask = (dt_idx[:ndt] == 2) | (dt_idx[:ndt] == 4)
75
70
 
76
- # Vectorized partial extraction
77
- xp1 = np.where(s_mask, tmp_xs[ista, k1_arr], tmp_xp[ista, k1_arr]).astype(np.float64)
78
- yp1 = np.where(s_mask, tmp_ys[ista, k1_arr], tmp_yp[ista, k1_arr]).astype(np.float64)
79
- zp1 = np.where(s_mask, tmp_zs[ista, k1_arr], tmp_zp[ista, k1_arr]).astype(np.float64)
80
- xp2 = np.where(s_mask, tmp_xs[ista, k2_arr], tmp_xp[ista, k2_arr]).astype(np.float64)
81
- yp2 = np.where(s_mask, tmp_ys[ista, k2_arr], tmp_yp[ista, k2_arr]).astype(np.float64)
82
- zp2 = np.where(s_mask, tmp_zs[ista, k2_arr], tmp_zp[ista, k2_arr]).astype(np.float64)
71
+ # The partials of each observation's two (station, event) pairs
72
+ xp1, yp1, zp1 = pp.partials(s_mask, pp.k1)
73
+ xp2, yp2, zp2 = pp.partials(s_mask, pp.k2)
83
74
 
84
75
  # Fill 8 blocks (weighted)
85
76
  ptr = 0
@@ -92,6 +83,20 @@ def build_dd_system(ndt, nev, nsrc, dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_i
92
83
  rows[ptr:ptr+ndt] = idx; cols[ptr:ptr+ndt] = ic2*4+2; vals[ptr:ptr+ndt] = -zp2*wt; ptr += ndt
93
84
  rows[ptr:ptr+ndt] = idx; cols[ptr:ptr+ndt] = ic2*4+3; vals[ptr:ptr+ndt] = -wt; ptr += ndt
94
85
 
86
+ # Mean-shift constraint rows: sum(dx)=0, sum(dy)=0, sum(dz)=0, sum(dt)=0
87
+ # Matches SVD solver (svd.py lines 194-202). Prevents centroid drift.
88
+ # NOTE: commented out for now -- complicates Schur partition (dense coupling).
89
+ # Damping provides a soft centroid constraint instead.
90
+ # for p in range(4):
91
+ # row_idx = nndt
92
+ # d[row_idx] = 0.0
93
+ # for j in range(nev):
94
+ # rows[ptr] = row_idx
95
+ # cols[ptr] = j * 4 + p
96
+ # vals[ptr] = 1.0
97
+ # ptr += 1
98
+ # nndt += 1
99
+
95
100
  # Add ev_fix constraint rows
96
101
  k = 0
97
102
  for i in range(nev):
@@ -1,27 +1,52 @@
1
- """Observation-centric travel time and partial derivative computation.
2
-
3
- Instead of computing travel times for ALL (station, event) pairs -- O(nsta * nsrc) --
4
- this module computes only the pairs that appear in actual observations -- O(n_unique_pairs).
5
-
6
- For 308 events, 175 stations, 157K observations:
7
- Old: 308 * 175 = 53,900 ttime calls
8
- New: ~20,000 unique (station, event) pairs (from deduplication)
9
- Savings: ~2.7x fewer ttime calls, and NO (nsta, nsrc) arrays allocated
10
-
11
- The savings grow dramatically at scale:
12
- 100K events, 1000 stations: old = 100M calls, new = ~2M unique pairs = 50x savings
1
+ """Travel times and partial derivatives for the (station, event) pairs that carry observations, and nothing else.
2
+
3
+ A double-difference observation (events i and j at station k) needs the travel time and the partials of i at k and of j
4
+ at k. HypoDD computes them for every station and every event into tmp_ttp(MAXSTA, MAXEVE) and reads two cells per
5
+ observation; at statewide scale those tables have stations x events cells of which under 1% hold an observation (a
6
+ block of 134,533 events over 3,096 stations: eight float32 tables of 13 GB per iteration, 60 GB peak). Here the values
7
+ are computed and kept per unique pair, and each observation keeps the positions of its two pairs, so a block's memory
8
+ follows its observations.
13
9
  """
14
10
 
15
11
  import numpy as np
16
12
 
17
- from ..geodesy.coordinates import delaz
18
- from ..geodesy.delaz_vec import delaz_vec
13
+ from ..models.eikonal import partials_from_gradients
19
14
  from ..models.velocity import ttime
20
15
  from ..models.velocity_numba import ttime_numba, HAS_NUMBA
21
16
 
22
17
  _ttime = ttime_numba if HAS_NUMBA else ttime
23
18
 
24
19
 
20
+ class PairPartials:
21
+ """Travel times and partials at the unique (station, source) pairs of the observations, and each observation's two
22
+ positions in them.
23
+
24
+ sta, evt: (n,) the pairs (evt is the source index: the event's, or 0 when every event shares one source, nsrc = 1)
25
+ ttp, tts: (n,) P and S travel times (s), float32; xp, yp, zp, xs, ys, zs: (n,) the P and S partials (s/km), float32
26
+ k1, k2: (ndt,) the position of (station, event 1) and of (station, event 2) of each observation
27
+ """
28
+ __slots__ = ("sta", "evt", "ttp", "tts", "xp", "yp", "zp", "xs", "ys", "zs", "k1", "k2")
29
+
30
+ def __init__(self, sta, evt, k1, k2, ttp, tts, xp, yp, zp, xs, ys, zs):
31
+ self.sta, self.evt, self.k1, self.k2 = sta, evt, k1, k2
32
+ self.ttp, self.tts = ttp, tts; self.xp, self.yp, self.zp, self.xs, self.ys, self.zs = xp, yp, zp, xs, ys, zs
33
+
34
+ def compact(self, keep):
35
+ """Keep the positions of the observations `keep` (indices), after observations are dropped. The pairs' sta and evt
36
+ keep the numbering of the iteration they were computed in (skipping renumbers events and stations); only the
37
+ positions are used afterwards, and the next iteration computes the pairs afresh."""
38
+ self.k1 = self.k1[keep]; self.k2 = self.k2[keep]
39
+
40
+ def travel_time(self, s_mask, k):
41
+ """The travel time (float32) of the pairs at positions k, S where s_mask, P elsewhere."""
42
+ return np.where(s_mask, self.tts[k], self.ttp[k])
43
+
44
+ def partials(self, s_mask, k):
45
+ """The x, y, z partials (float64) of the pairs at positions k, S where s_mask, P elsewhere."""
46
+ return (np.where(s_mask, self.xs[k], self.xp[k]).astype(np.float64), np.where(s_mask, self.ys[k], self.yp[k]).astype(np.float64),
47
+ np.where(s_mask, self.zs[k], self.zp[k]).astype(np.float64))
48
+
49
+
25
50
  def _delaz_pairs(alat, alon, blat, blon):
26
51
  """Vectorized distance and azimuth for paired points (not broadcast).
27
52
 
@@ -70,52 +95,37 @@ def _delaz_pairs(alat, alon, blat, blon):
70
95
  return dist, az
71
96
 
72
97
 
98
+ def unique_pairs(nsrc, ndt, dt_ista, dt_ic1, dt_ic2):
99
+ """The unique (station, source) pairs of the observations and each observation's two positions in them."""
100
+ ista = dt_ista[:ndt].astype(np.int64)
101
+ if nsrc > 1:
102
+ e1 = dt_ic1[:ndt].astype(np.int64); e2 = dt_ic2[:ndt].astype(np.int64)
103
+ else: # one source for every event
104
+ e1 = e2 = np.zeros(ndt, np.int64)
105
+ keys, inv = np.unique(np.concatenate([ista * nsrc + e1, ista * nsrc + e2]), return_inverse=True); inv = inv.astype(np.int32)
106
+ return keys // nsrc, keys % nsrc, inv[:ndt], inv[ndt:]
107
+
108
+
73
109
  def compute_partials_obs(nsrc, src_lat, src_lon, src_dep,
74
110
  nsta, sta_lat, sta_lon, sta_elv,
75
111
  mod_nl, mod_ratio, mod_v, mod_top,
76
- ndt, dt_ista, dt_ic1, dt_ic2, dt_idx,
77
- imod=1):
78
- """Compute travel times and partials ONLY for observed (station, event) pairs.
112
+ ndt, dt_ista, dt_ic1, dt_ic2,
113
+ imod=1, tables=None):
114
+ """Travel times and partials for the observed (station, source) pairs only, as a PairPartials.
79
115
 
80
- Returns the same (nsta, nsrc) arrays as compute_partials, but only fills
81
- the entries that are actually used by observations. Unused entries are zero.
82
-
83
- Additional parameters vs compute_partials:
84
- ndt, dt_ista, dt_ic1, dt_ic2, dt_idx: observation arrays
116
+ ndt, dt_ista, dt_ic1, dt_ic2: the observations; imod 5 is the straight-ray model, else the 1-D model, by HypoDD's ray
117
+ tracer or, with `tables`, by eikonal tables (hyperdd.models.eikonal).
85
118
  """
86
119
  PI = np.float32(3.141593)
87
120
  vs = mod_v / mod_ratio
88
121
 
89
- ttp = np.zeros((nsta, nsrc), dtype=np.float32)
90
- tts = np.zeros((nsta, nsrc), dtype=np.float32)
91
- xp = np.zeros((nsta, nsrc), dtype=np.float32)
92
- yp = np.zeros((nsta, nsrc), dtype=np.float32)
93
- zp = np.zeros((nsta, nsrc), dtype=np.float32)
94
- xs = np.zeros((nsta, nsrc), dtype=np.float32)
95
- ys = np.zeros((nsta, nsrc), dtype=np.float32)
96
- zs = np.zeros((nsta, nsrc), dtype=np.float32)
97
-
98
122
  # Make sure hypocenters don't fall on layer boundaries
99
123
  for j in range(nsrc):
100
124
  for k in range(mod_nl):
101
125
  if abs(src_dep[j] - mod_top[k]) < 0.0001:
102
126
  src_dep[j] = src_dep[j] - 0.001
103
127
 
104
- # Find unique (station, event) pairs from observations
105
- ista = dt_ista[:ndt]
106
- ic1 = dt_ic1[:ndt]
107
- ic2 = dt_ic2[:ndt]
108
-
109
- # Each observation needs (station, event_i) and (station, event_j)
110
- sta_arr = np.concatenate([ista, ista])
111
- evt_arr = np.concatenate([ic1, ic2])
112
-
113
- # Deduplicate
114
- pairs = np.stack([sta_arr, evt_arr], axis=1)
115
- unique_pairs = np.unique(pairs, axis=0)
116
- n_unique = len(unique_pairs)
117
- u_sta = unique_pairs[:, 0]
118
- u_evt = unique_pairs[:, 1]
128
+ u_sta, u_evt, k1, k2 = unique_pairs(nsrc, ndt, dt_ista, dt_ic1, dt_ic2); n_unique = len(u_sta)
119
129
 
120
130
  if imod == 5:
121
131
  # Straight-ray: vectorized over unique pairs
@@ -155,17 +165,7 @@ def compute_partials_obs(nsrc, src_lat, src_lon, src_dep,
155
165
  u_zp[below] = -u_zp[below]
156
166
  u_zs[below] = -u_zs[below]
157
167
 
158
- # Scatter back to (nsta, nsrc) arrays
159
- ttp[u_sta, u_evt] = u_ttp
160
- tts[u_sta, u_evt] = u_tts
161
- xp[u_sta, u_evt] = u_xp
162
- yp[u_sta, u_evt] = u_yp
163
- zp[u_sta, u_evt] = u_zp
164
- xs[u_sta, u_evt] = u_xs
165
- ys[u_sta, u_evt] = u_ys
166
- zs[u_sta, u_evt] = u_zs
167
-
168
- return ttp, tts, xp, yp, zp, xs, ys, zs
168
+ return PairPartials(u_sta, u_evt, k1, k2, u_ttp, u_tts, *(np.asarray(a, np.float32) for a in (u_xp, u_yp, u_zp, u_xs, u_ys, u_zs)))
169
169
 
170
170
  # 1D layered model (imod=0 or 1)
171
171
  v_p = np.ascontiguousarray(mod_v, dtype=np.float64)
@@ -182,6 +182,11 @@ def compute_partials_obs(nsrc, src_lat, src_lon, src_dep,
182
182
  src_lat[u_evt], src_lon[u_evt], sta_lat[u_sta], sta_lon[u_sta]
183
183
  )
184
184
 
185
+ if tables is not None: # eikonal tables in place of the ray tracer
186
+ u_ttp, u_tts, gpr, gpz, gsr, gsz = tables.pairs(u_dist, src_dep[u_evt], u_sta, sta_elv[:nsta])
187
+ u_xp, u_yp, u_zp = partials_from_gradients(u_az, gpr, gpz); u_xs, u_ys, u_zs = partials_from_gradients(u_az, gsr, gsz)
188
+ return PairPartials(u_sta, u_evt, k1, k2, *(np.asarray(a, np.float32) for a in (u_ttp, u_tts, u_xp, u_yp, u_zp, u_xs, u_ys, u_zs)))
189
+
185
190
  # Compute travel times for unique pairs
186
191
  u_ainp = np.empty(n_unique, dtype=np.float64)
187
192
  u_ains = np.empty(n_unique, dtype=np.float64)
@@ -230,14 +235,4 @@ def compute_partials_obs(nsrc, src_lat, src_lon, src_dep,
230
235
  u_yp = sin_ainp * cos_az / vp_src
231
236
  u_ys = sin_ains * cos_az / vs_src
232
237
 
233
- # Scatter back to (nsta, nsrc) arrays
234
- ttp[u_sta, u_evt] = u_ttp
235
- tts[u_sta, u_evt] = u_tts
236
- xp[u_sta, u_evt] = u_xp
237
- yp[u_sta, u_evt] = u_yp
238
- zp[u_sta, u_evt] = u_zp
239
- xs[u_sta, u_evt] = u_xs
240
- ys[u_sta, u_evt] = u_ys
241
- zs[u_sta, u_evt] = u_zs
242
-
243
- return ttp, tts, xp, yp, zp, xs, ys, zs
238
+ return PairPartials(u_sta, u_evt, k1, k2, u_ttp, u_tts, *(np.asarray(a, np.float32) for a in (u_xp, u_yp, u_zp, u_xs, u_ys, u_zs)))
hyperdd/core/skip.py CHANGED
@@ -7,9 +7,13 @@ def skip_outliers(ndt, nev, nsrc, nsta, minwght,
7
7
  ev_cusp, src_cusp, src_lat, src_lon, src_dep,
8
8
  src_x, src_y, src_z, src_t,
9
9
  sta_lab, sta_lat, sta_lon, sta_elv,
10
- tmp_ttp, tmp_tts, tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs):
10
+ pp, ev_arrays=()):
11
11
  """Skip data with weight < minwght. Compact arrays and reindex.
12
- Returns new ndt, nev, nsrc, nsta."""
12
+ Returns new ndt, nev, nsrc, nsta. pp (PairPartials) keeps the positions of the observations kept.
13
+
14
+ ev_arrays: every other per-event array (date, time, lat, lon, dep, mag, herr, zerr, res, fix, x, y, z).
15
+ Fortran skip.f compacts them together with ev_cusp; leaving them behind attaches dates, times,
16
+ magnitudes and fix flags to the wrong events once any event has been dropped."""
13
17
 
14
18
  # Keep mask for observations
15
19
  mask = dt_wt[:ndt] >= minwght
@@ -23,6 +27,7 @@ def skip_outliers(ndt, nev, nsrc, nsta, minwght,
23
27
  for arr in [dt_dt, dt_qual, dt_c1, dt_c2, dt_idx, dt_ista, dt_ic1, dt_ic2,
24
28
  dt_offs, dt_cal, dt_res, dt_wt]:
25
29
  arr[:new_ndt] = arr[indices]
30
+ pp.compact(indices)
26
31
 
27
32
  # Find events still in data
28
33
  used_ic = np.union1d(dt_ic1[:new_ndt], dt_ic2[:new_ndt])
@@ -36,7 +41,7 @@ def skip_outliers(ndt, nev, nsrc, nsta, minwght,
36
41
  old_to_new[old_idx] = new_idx
37
42
 
38
43
  # Compact event arrays
39
- for arr in [ev_cusp]:
44
+ for arr in [ev_cusp, *ev_arrays]:
40
45
  arr[:new_nev] = arr[used_ic]
41
46
 
42
47
  # Compact source arrays
@@ -48,11 +53,6 @@ def skip_outliers(ndt, nev, nsrc, nsta, minwght,
48
53
  # Remap ic1, ic2 indices (vectorized)
49
54
  dt_ic1[:new_ndt] = old_to_new[dt_ic1[:new_ndt]]
50
55
  dt_ic2[:new_ndt] = old_to_new[dt_ic2[:new_ndt]]
51
-
52
- # Compact travel time arrays (columns)
53
- if nsrc > 1:
54
- for arr in [tmp_ttp, tmp_tts, tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs]:
55
- arr[:, :new_nsrc] = arr[:, used_ic]
56
56
  else:
57
57
  new_nsrc = nsrc
58
58
 
@@ -73,10 +73,6 @@ def skip_outliers(ndt, nev, nsrc, nsta, minwght,
73
73
  sta_elv[idx_new] = sta_elv[idx_old]
74
74
  sta_lab[:new_nsta] = new_labs
75
75
 
76
- # Compact travel time arrays (rows)
77
- for arr in [tmp_ttp, tmp_tts, tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs]:
78
- arr[:new_nsta, :] = arr[used_ista, :]
79
-
80
76
  # Remap ista indices (vectorized)
81
77
  dt_ista[:new_ndt] = old_to_new_sta[dt_ista[:new_ndt]]
82
78
 
hyperdd/core/weighting.py CHANGED
@@ -77,7 +77,8 @@ def weighting(ndt, mbad_cusps, idata, maxres_cross, maxres_net, maxdcc, maxdct,
77
77
  np.clip(ratio, 0, 1, out=ratio)
78
78
  wt[cc_mask] *= (1 - ratio**5)**5
79
79
 
80
- if maxres_cross > 0 and np.any(cc_mask):
80
+ # a residual cutoff of 0 (every residual equal to the median, as exact data can reach) cuts nothing; dividing by it gave 0/0 = NaN weights
81
+ if maxres_cross > 0 and maxres_cc > 0 and np.any(cc_mask):
81
82
  active = cc_mask & (wt > 0.000001)
82
83
  if np.any(active):
83
84
  ratio = abs_res[active] / maxres_cc
@@ -90,7 +91,7 @@ def weighting(ndt, mbad_cusps, idata, maxres_cross, maxres_net, maxdcc, maxdct,
90
91
  np.clip(ratio, 0, 1, out=ratio)
91
92
  wt[ct_mask] *= (1 - ratio**3)**3
92
93
 
93
- if maxres_net > 0 and np.any(ct_mask):
94
+ if maxres_net > 0 and maxres_ct > 0 and np.any(ct_mask):
94
95
  active = ct_mask & (wt > 0.000001)
95
96
  if np.any(active):
96
97
  ratio = abs_res[active] / maxres_ct