DASPy-toolbox 1.2.5__tar.gz → 1.2.6__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.
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/PKG-INFO +1 -1
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/PKG-INFO +1 -1
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/__init__.py +1 -1
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/denoising.py +58 -17
- daspy_toolbox-1.2.6/daspy/advanced_tools/fdct.py +658 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/strain2vel.py +75 -17
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/preprocessing.py +1 -1
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/read.py +7 -6
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/section.py +12 -6
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/util.py +4 -4
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/main.py +1 -1
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/setup.py +1 -1
- daspy_toolbox-1.2.5/daspy/advanced_tools/fdct.py +0 -789
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/SOURCES.txt +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/dependency_links.txt +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/entry_points.txt +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/requires.txt +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/top_level.txt +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/LICENSE +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/README.md +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/__init__.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/channel.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/decomposition.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/__init__.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/filter.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/freqattributes.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/visualization.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/__init__.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/collection.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/dasdatetime.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/example.pkl +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/make_example.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/write.py +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/pyproject.toml +0 -0
- {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/setup.cfg +0 -0
|
@@ -5,8 +5,8 @@ Email: hmz2018@mail.ustc.edu.cn"""
|
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
from copy import deepcopy
|
|
8
|
+
from functools import lru_cache
|
|
8
9
|
from scipy.ndimage import median_filter
|
|
9
|
-
from scipy.interpolate import interp1d
|
|
10
10
|
from daspy.basic_tools.preprocessing import padding
|
|
11
11
|
from daspy.advanced_tools.fdct import fdct_wrapping, ifdct_wrapping
|
|
12
12
|
|
|
@@ -27,17 +27,47 @@ def spike_removal(data, nch=50, nsp=5, thresh=10):
|
|
|
27
27
|
|
|
28
28
|
medians1 = median_filter(absdata, (nch, 1))
|
|
29
29
|
medians = median_filter(medians1, (1, nsp))
|
|
30
|
-
|
|
30
|
+
with np.errstate(divide='ignore', invalid='ignore'):
|
|
31
|
+
bad = absdata / medians > thresh
|
|
31
32
|
|
|
32
33
|
# find the bad values and interpolate with their neighbors
|
|
33
34
|
data_dn = data.copy()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
if not np.any(bad):
|
|
36
|
+
return data_dn
|
|
37
|
+
|
|
38
|
+
nch = data.shape[0]
|
|
39
|
+
channel_idx = np.arange(nch, dtype=np.int32)[:, None]
|
|
40
|
+
prev_good = np.where(~bad, channel_idx, -1)
|
|
41
|
+
np.maximum.accumulate(prev_good, axis=0, out=prev_good)
|
|
42
|
+
next_good = np.where(~bad, channel_idx, nch)
|
|
43
|
+
next_good = np.minimum.accumulate(next_good[::-1], axis=0)[::-1]
|
|
44
|
+
|
|
45
|
+
out_i, out_j = np.nonzero(bad)
|
|
46
|
+
lo = prev_good[out_i, out_j]
|
|
47
|
+
hi = next_good[out_i, out_j]
|
|
48
|
+
has_lo = lo >= 0
|
|
49
|
+
has_hi = hi < nch
|
|
50
|
+
|
|
51
|
+
if np.any(~has_lo & ~has_hi):
|
|
52
|
+
raise ValueError('Cannot interpolate when all channels are outliers.')
|
|
53
|
+
|
|
54
|
+
both = has_lo & has_hi
|
|
55
|
+
if np.any(both):
|
|
56
|
+
i = out_i[both]
|
|
57
|
+
j = out_j[both]
|
|
58
|
+
lo_b = lo[both]
|
|
59
|
+
hi_b = hi[both]
|
|
60
|
+
weight = (i - lo_b) / (hi_b - lo_b)
|
|
61
|
+
data_dn[i, j] = data[lo_b, j] + \
|
|
62
|
+
(data[hi_b, j] - data[lo_b, j]) * weight
|
|
63
|
+
|
|
64
|
+
right = ~has_lo & has_hi
|
|
65
|
+
if np.any(right):
|
|
66
|
+
data_dn[out_i[right], out_j[right]] = data[hi[right], out_j[right]]
|
|
67
|
+
|
|
68
|
+
left = has_lo & ~has_hi
|
|
69
|
+
if np.any(left):
|
|
70
|
+
data_dn[out_i[left], out_j[left]] = data[lo[left], out_j[left]]
|
|
41
71
|
|
|
42
72
|
return data_dn
|
|
43
73
|
|
|
@@ -142,11 +172,18 @@ def _velocity_bin(nbangles, fs, dx):
|
|
|
142
172
|
return velocity
|
|
143
173
|
|
|
144
174
|
|
|
175
|
+
@lru_cache(maxsize=128)
|
|
176
|
+
def _velocity_factors(nbangles, fs, dx, vmin, vmax, flag):
|
|
177
|
+
velocity = _velocity_bin(nbangles, fs, dx)
|
|
178
|
+
return _mask_factor(velocity, vmin, vmax, flag=flag)
|
|
179
|
+
|
|
180
|
+
|
|
145
181
|
def _mask_factor(velocity, vmin, vmax, flag=0):
|
|
146
182
|
if flag:
|
|
147
183
|
if flag == -1:
|
|
148
|
-
|
|
149
|
-
|
|
184
|
+
old_vmin, old_vmax = vmin, vmax
|
|
185
|
+
vmin = -old_vmax
|
|
186
|
+
vmax = -old_vmin
|
|
150
187
|
else:
|
|
151
188
|
half = len(velocity) // 8
|
|
152
189
|
for i in range(half):
|
|
@@ -232,11 +269,16 @@ def curvelet_denoising(data, choice=0, pad=0.3, noise=None, noise_perc=95,
|
|
|
232
269
|
nbangles=nbangles, percentile=noise_perc)
|
|
233
270
|
for s in range(1, len(C)):
|
|
234
271
|
for w in range(len(C[s])):
|
|
235
|
-
|
|
236
|
-
|
|
272
|
+
threshold = abs(E[s][w])
|
|
273
|
+
coeff = C[s][w]
|
|
274
|
+
mag = abs(coeff)
|
|
275
|
+
mask = mag > threshold
|
|
237
276
|
if soft_thresh:
|
|
238
|
-
# soften the
|
|
239
|
-
C[s][w] = np.
|
|
277
|
+
# first do a hard threshold, then soften the coefficients.
|
|
278
|
+
C[s][w] = np.where(mask,
|
|
279
|
+
np.sign(coeff) * (mag - threshold), 0)
|
|
280
|
+
else:
|
|
281
|
+
C[s][w] = coeff * mask
|
|
240
282
|
|
|
241
283
|
# apply velocity filtering
|
|
242
284
|
if choice in (1, 2):
|
|
@@ -254,8 +296,7 @@ def curvelet_denoising(data, choice=0, pad=0.3, noise=None, noise_perc=95,
|
|
|
254
296
|
|
|
255
297
|
for s in range(scale_begin - 1, len(C) - finest + 1):
|
|
256
298
|
nbangles = len(C[s])
|
|
257
|
-
|
|
258
|
-
factors = _mask_factor(velocity, vmin, vmax, flag=flag)
|
|
299
|
+
factors = _velocity_factors(nbangles, fs, dx, vmin, vmax, flag)
|
|
259
300
|
for w in range(nbangles):
|
|
260
301
|
if mode == 'retain':
|
|
261
302
|
C[s][w] *= factors[w]
|