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.
Files changed (35) hide show
  1. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/PKG-INFO +1 -1
  2. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/PKG-INFO +1 -1
  3. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/__init__.py +1 -1
  4. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/denoising.py +58 -17
  5. daspy_toolbox-1.2.6/daspy/advanced_tools/fdct.py +658 -0
  6. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/strain2vel.py +75 -17
  7. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/preprocessing.py +1 -1
  8. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/read.py +7 -6
  9. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/section.py +12 -6
  10. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/util.py +4 -4
  11. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/main.py +1 -1
  12. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/setup.py +1 -1
  13. daspy_toolbox-1.2.5/daspy/advanced_tools/fdct.py +0 -789
  14. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/SOURCES.txt +0 -0
  15. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/dependency_links.txt +0 -0
  16. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/entry_points.txt +0 -0
  17. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/requires.txt +0 -0
  18. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/DASPy_toolbox.egg-info/top_level.txt +0 -0
  19. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/LICENSE +0 -0
  20. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/README.md +0 -0
  21. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/__init__.py +0 -0
  22. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/channel.py +0 -0
  23. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/advanced_tools/decomposition.py +0 -0
  24. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/__init__.py +0 -0
  25. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/filter.py +0 -0
  26. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/freqattributes.py +0 -0
  27. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/basic_tools/visualization.py +0 -0
  28. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/__init__.py +0 -0
  29. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/collection.py +0 -0
  30. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/dasdatetime.py +0 -0
  31. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/example.pkl +0 -0
  32. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/make_example.py +0 -0
  33. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/daspy/core/write.py +0 -0
  34. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/pyproject.toml +0 -0
  35. {daspy_toolbox-1.2.5 → daspy_toolbox-1.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DASPy-toolbox
3
- Version: 1.2.5
3
+ Version: 1.2.6
4
4
  Summary: DASPy is an open-source Python package for Distributed Acoustic Sensing (DAS) data processing.
5
5
  Home-page: https://github.com/HMZ-03/DASPy
6
6
  Author: Minzhe Hu, Zefeng Li
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: DASPy-toolbox
3
- Version: 1.2.5
3
+ Version: 1.2.6
4
4
  Summary: DASPy is an open-source Python package for Distributed Acoustic Sensing (DAS) data processing.
5
5
  Home-page: https://github.com/HMZ-03/DASPy
6
6
  Author: Minzhe Hu, Zefeng Li
@@ -10,4 +10,4 @@ from daspy.core.read import read
10
10
  from daspy.core.section import Section
11
11
 
12
12
  __all__ = ["Section", "Collection", "read", "DASDateTime", "local_tz", "utc"]
13
- __version__ = "1.2.5"
13
+ __version__ = "1.2.6"
@@ -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
- ratio = absdata / medians # comparisons matrix
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
- out_i, out_j = np.where(ratio > thresh)
35
- for j in set(out_j):
36
- bch = out_i[out_j == j]
37
- gch = list(set(range(len(data))) - set(bch))
38
- f = interp1d(gch, data[gch, j], bounds_error=False,
39
- fill_value=(data[gch[0], j], data[gch[-1], j]))
40
- data_dn[bch, j] = f(bch)
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
- vmin = -vmax
149
- vmax = -vmin
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
- # first do a hard threshold
236
- C[s][w] = C[s][w] * (abs(C[s][w]) > abs(E[s][w]))
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 existing coefficients
239
- C[s][w] = np.sign(C[s][w]) * (abs(C[s][w]) - abs(E[s][w]))
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
- velocity = _velocity_bin(nbangles, fs, dx)
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]