signal.py
#
Utility functions for acoustic signals.
SNR(x, noise)
#
Signal-to-noise ratio (SNR).
Parameters:
-
x
(ndarray
) –Original signal.
-
noise
(ndarray
) –Noisy signal.
Returns:
-
float
–Signal-to-noise ratio between arrays (in dB).
References#
-
Yang et al. (2012) Curvelet-based POCS interpolation of nonuniformly sampled seismic records ↩
Source code in pseudo_3D_interpolation\functions\signal.py
PSNR(x, noise, max_pixel=1.0)
#
Peak signal-to-noise ratio (SNR).
Parameters:
-
x
(ndarray
) –Original signal.
-
noise
(ndarray
) –Noisy signal.
-
max_pixel
(float
, default:1.0
) –Maximum fluctuation in input image type. For
float
: 1,uint8
: 255. If None, compute and use max(x).
Returns:
-
float
–Peak signal-to-noise ratio between arrays (in dB).
Source code in pseudo_3D_interpolation\functions\signal.py
estimate_noise_level(img)
#
Estimate image noise level based on Immerkær (1996) "Fast Noise Variance Estimation".
Parameters:
-
img
(ndarray
) –Input image.
Returns:
-
sigma
(float
) –Noise level factor.
References#
-
https://stackoverflow.com/a/25436112 ↩
Source code in pseudo_3D_interpolation\functions\signal.py
gain(data, twt, tpow=0.0, epow=0.0, etpow=1.0, ebase=None, gpow=0.0, agc=False, agc_win=0.05, agc_kind='rms', agc_sqrt=False, clip=None, pclip=None, nclip=None, qclip=None, linear=None, pgc=None, bias=None, scale=1.0, norm=False, norm_rms=False, copy=True, axis=-1)
#
Apply various different types of gain for either single trace (1D array) or seismic section (2D array).
Copyright
This function is a Python implementation of the Seismic Unix sugain
module.
Please refer to the license file LICENSE_SeismicUnix
!
Parameters:
-
data
(ndarray
) –Seismic trace (nsamples,) or section (nsamples, ntraces).
-
twt
(ndarray
) –Array of samples (in seconds TWT) appropriate spacing of sample rate (
dt
). -
tpow
(float
, default:0.0
) –Multiply data by t^tpow (default:
0.0
). -
epow
(float
, default:0.0
) –Multiply data by exp(epow*t) (default:
0.0
). -
etpow
(float
, default:1.0
) –Multiply data by exp(epow*t^etpow) (default:
1.0
). -
ebase
(float
, default:None
) –Base of exponential function (default:
e
). -
gpow
(float
, default:0.0
) –Take signed gpowth power of scaled data (default:
0.0
). -
agc
(bool
, default:False
) –Whether to apply Automatic Gain Control (AGC) (default:
False
). -
agc_win
(float
, default:0.05
) –AGC window length (in seconds) (default:
0.05
). -
agc_kind
(str
, default:'rms'
) –Kind of AGC:
rms
(default), 'mean', or 'median'. -
agc_sqrt
(bool
, default:False
) –Whether to square AGC values (default:
False
). Use with caution: Reduces noise but also weak amplitudes! -
clip
(float
, default:None
) –Clip any value whose magnitude exceeds clipval (default:
None
). -
pclip
(float
, default:None
) –Clip any value greater than clipval (default:
None
). -
nclip
(float
, default:None
) –Clip any value less than clipval (default:
None
). -
qclip
(float
, default:None
) –Clip by quantile on absolute values on trace (default:
None
). -
linear
(tuple
, default:None
) –Apply linear gain function by multiplying trace(s) with linearly interpolated array between (start, stop).
-
pgc
(dict
, default:None
) –Apply Programmed Gain Control (PGC) function using defined dict(TWT:GAIN) pairs.
-
bias
(float
, default:None
) –Bias data by adding an overall bias value (default:
None
). -
scale
(float
, default:1.0
) –Multiply data by overall scale factor (default:
1.0
). -
norm
(bool
, default:False
) –Divide data by overall scale factor (default:
False
). -
norm_rms
(bool
, default:False
) –Normalize using RMS amplitude (default:
False
). -
copy
(bool
, default:True
) –Copy input data (no change of input data) (default:
True
). -
axis
(int
, default:-1
) –Axis along which to gain (default:
-1
).
Returns:
-
data
(ndarray
) –Input data with applied gain function(s) along
axis
.
Notes#
By default, the input array will be copied (copy=True
) to avoid updating of the input data in place.
References#
-
sugain
module help, http://sepwww.stanford.edu/oldsep/cliner/files/suhelp/sugain.txt ↩
Source code in pseudo_3D_interpolation\functions\signal.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
get_AGC_samples(win, dt)
#
Convert AGC window length from TWT (seconds) to number of samples. In case of even number of samples, the window length is increased by one (1) sample.
Parameters:
-
win
((int | float, ndarray)
) –AGC window length (in seconds).
-
dt
(float
) –Sampling interval (in seconds).
Returns:
-
samples
((int | float, ndarray)
) –Number of samples in AGC window.
Source code in pseudo_3D_interpolation\functions\signal.py
AGC(x, win, kind='rms', pad=True, pad_mode='constant', squared=False, return_gain_func=False, axis=-1)
#
Apply Automatic Gain Control (AGC) function to input data (1D trace, 2D profile, or 3D cube).
Parameters:
-
x
(ndarray
) –Input trace (1D), profile/iline/xline (2D) or cube (3D).
-
win
(int
) –Samples (i.e. values) in AGC window.
-
kind
(str
, default:'rms'
) –AGC kind (default:
'rms'
). Available are'rms'
,'mean'
, or'median'
. -
pad
(bool
, default:True
) –Pad time axis at top and bottom (default:
True
). Time axis will be truncated if not set! -
pad_mode
(str
, default:'constant'
) –Pad mode (default:
'constant'
). Refer tonp.pad
documentation for more details. -
squared
(bool
, default:False
) –Compute squared AGC to enhance major amplitudes and redue noise (default:
False
). Use with caution! -
return_gain_func
(bool
, default:False
) –Whether to return gain function for later AGC removal (default:
False
). -
axis
(int
, default:-1
) –Index of time axis (default:
-1
).
Returns:
-
ndarray
–Input data with applied AGC function.
Source code in pseudo_3D_interpolation\functions\signal.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
programmed_gain_control(twt, twt_gain)
#
Compute Programmed Gain Control (PGC) function using linear interpolation between twt_gain
pairs.
Parameters:
-
twt
(ndarray
) –TWT values (in seconds).
-
twt_gain
(dict
) –Dictionary of TWT (keys) and corresponding gain values (vals).
Returns:
-
g
(TYPE
) –DESCRIPTION.
Source code in pseudo_3D_interpolation\functions\signal.py
rms(array, axis=None)
#
Calculate the RMS amplitude(s) of a given array.
Parameters:
-
array
(ndarray
) –Amplitude array.
-
axis
((int, tuple, list(optional))
, default:None
) –Axis for RMS amplitude calculation (default:
None
, i.e. single value for whole array).
Returns:
-
rms
(ndarray
) –Root mean square (RMS) amplitude(s).
Source code in pseudo_3D_interpolation\functions\signal.py
rms_normalization(signal, axis=None)
#
Normalize signal using RMS amplitude of input array.
Parameters:
-
signal
(ndarray
) –Input trace(s).
-
axis
(int
, default:None
) –Axis used for RMS amplitude calculation (default:
None
, i.e. whole array).
Returns:
-
ndarray
–Normalized signal using RMS amplitude.
References#
Source code in pseudo_3D_interpolation\functions\signal.py
balance_traces(traces, scale='rms', n_traces=None, axis_samples=None)
#
Balance (i.e. scale) adjacent seismic traces. This function uses one of the following reference amplitude(s) per trace(s):
rms
(default)peak
(absolute value)mean
(absolute value)median
(absolute value)
The reference amplitude is computed
- for the whole dataset (
axis_samples = None
), - for each individual trace (
axis_samples >= 0
), or - in moving windows of
n_traces
length.
Parameters:
-
traces
(ndarray
) –Input traces, e.g. with shape: (nsamples x ntraces).
-
scale
(str
, default:'rms'
) –Amplitude scaling (balancing) mode (default:
rms
). -
n_traces
(int
, default:None
) –Number of traces used for windowed balacning (default:
None
). -
axis_samples
(int
, default:None
) –Axis for balancing computation (default:
0
, for nsamples x ntraces).
Returns:
-
traces_eq
(ndarray
) –Equalized (i.e. balanced) traces.
Source code in pseudo_3D_interpolation\functions\signal.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
|
calc_reference_amplitude(traces, axis=None, scale='rms')
#
Calculate reference amplitude per trace using user-defined scaling (rms
or max
).
Parameters:
-
traces
(ndarray
) –Input traces.
-
axis
(int
, default:None
) –Axis along that reference amplitudes will be calculated (default:
None
). -
scale
(str
, default:'rms'
) –Scale using either
rms
(default) ormax
amplitudes.
Returns:
-
amp_ref
(ndarray
) –Reference amplitude array.
Source code in pseudo_3D_interpolation\functions\signal.py
envelope(signal, axis=-1)
#
Compute envelope of a seismic trace (1D), section (2D) or cube (3D) using the Hilbert transform.
Parameters:
-
signal
(ndarray
) –Seismic trace (1D) or section (2D).
-
axis
(int
, default:-1
) –Axis along which to do the transformation (default:
-1
).
Returns:
-
ndarray
–Amplitude envelope of input array along
axis
.
Source code in pseudo_3D_interpolation\functions\signal.py
get_resampled_twt(twt, n_resamples, n_samples)
#
Return resampled TWT array.
Parameters:
-
twt
(ndarray
) –Orignial TWT array.
-
n_resamples
(int
) –Number of resampled trace samples.
-
n_samples
(int
) –Number of original trace samples.
Returns:
-
ndarray
–Resampled twt.
Source code in pseudo_3D_interpolation\functions\signal.py
freq_spectrum(signal, Fs, n=None, taper=True, return_minmax=False)
#
Compute frequency spectrum of input signal given a sampling rate (Fs
).
Parameters:
-
signal
(ndarray
) –1D signal array.
-
Fs
(int
) –Sampling rate/frequency (Hz).
-
n
(int
, default:None
) –Length of FFT, i.e. number of points (default: len(signal)).
-
taper
(TYPE
, default:True
) –Window function applied to time signal to improve frequency domain properties (default:
True
)
Returns:
-
f
(ndarray
) –Array of signal frequencies.
-
a_norm
(ndarray
) –Magnitude of amplitudes per frequency.
-
f_min
(float
) –Minimum frequency with actual signal content.
-
f_max
(float
) –Maximum frequency with actual signal content.