ADFWI.utils
ADFWI.utils.assessment_metric
- ADFWI.utils.assessment_metric.MAPE(true_v, inv_v)[source]
Computes the Mean Absolute Percentage Error (MAPE) between the true velocity model and the inverted velocity model.
- Parameters:
true_v (numpy.ndarray) – The ground truth velocity model. Shape can be (nz, nx) or (batch, nz, nx).
inv_v (numpy.ndarray) – The inverted velocity model. Shape should match true_v.
- Returns:
If true_v has one less dimension than inv_v, returns an array of MAPE values for each sample in the batch. Otherwise, returns a single MAPE value.
- Return type:
numpy.ndarray or float
- ADFWI.utils.assessment_metric.MSE(true_v, inv_v)[source]
Computes the Mean Squared Error (MSE) between the true velocity model and the inverted velocity model.
- Parameters:
true_v (numpy.ndarray) – The ground truth velocity model of shape (nz, nx).
inv_v (numpy.ndarray) – The inverted velocity model of shape (nz, nx).
- Returns:
The sum of squared differences between the true and inverted velocity models.
- Return type:
float
- ADFWI.utils.assessment_metric.RMSE(true_v, inv_v)[source]
Computes the Root Mean Squared Error (RMSE) between the true velocity model and the inverted velocity model.
- Parameters:
true_v (numpy.ndarray) – The ground truth velocity model. Shape can be (nz, nx) or (batch, nz, nx).
inv_v (numpy.ndarray) – The inverted velocity model. Shape should match true_v.
- Returns:
If true_v has one less dimension than inv_v, returns an array of RMSE values for each sample in the batch. Otherwise, returns a single RMSE value.
- Return type:
numpy.ndarray or float
- ADFWI.utils.assessment_metric.SNR(true_v, inv_v)[source]
Computes the Signal-to-Noise Ratio (SNR) between the true velocity model and the inverted velocity model.
- Parameters:
true_v (numpy.ndarray) – The ground truth velocity model. Shape can be (nz, nx) or (batch, nz, nx).
inv_v (numpy.ndarray) – The inverted velocity model. Shape should match true_v.
- Returns:
If true_v has one less dimension than inv_v, returns a list of SNR values for each sample in the batch. Otherwise, returns a single SNR value.
- Return type:
list or float
- ADFWI.utils.assessment_metric.SSIM(true_v, inv_v, win_size=11)[source]
Computes the Structural Similarity Index (SSIM) between the true velocity model and the inverted velocity model.
- Parameters:
true_v (numpy.ndarray) – The ground truth velocity model. Shape can be (nz, nx) or (batch, nz, nx).
inv_v (numpy.ndarray) – The inverted velocity model. Shape should match true_v.
win_size (int, optional) – The size of the sliding window used for computing SSIM, by default 11.
- Returns:
If true_v has one less dimension than inv_v, returns a list of SSIM values for each sample in the batch. Otherwise, returns a single SSIM value.
- Return type:
list or float
ADFWI.utils.first_arrivel_picking
- ADFWI.utils.first_arrivel_picking.apply_mute(mute_late_window, shot, dt)[source]
Applies a time window mute based on the first arrival pick for each trace.
- Parameters:
mute_late_window (float) – The time window for late arrival muting.
shot (torch.Tensor) – A 2D tensor of shape (nt, nrcv), representing the seismic shot gather.
dt (float) – The time sampling interval.
- Returns:
The muted shot gather with applied time window muting.
- Return type:
torch.Tensor
- ADFWI.utils.first_arrivel_picking.brutal_picker(trace)[source]
Picks the first arrival time of seismic traces using a simple thresholding method.
- Parameters:
trace (numpy.ndarray) – A 2D array of seismic traces with shape (n_traces, n_samples), where each row represents a single seismic trace.
- Returns:
A 1D array containing the first arrival index for each trace.
- Return type:
numpy.ndarray
- ADFWI.utils.first_arrivel_picking.mask(itmin, itmax, nt, length)[source]
Constructs a tapered mask that can be applied to a seismic trace to mute early or late arrivals.
- Parameters:
itmin (int) – The starting index for tapering.
itmax (int) – The ending index for tapering.
nt (int) – The total number of time samples in the trace.
length (int) – The length of the tapering window.
- Returns:
A 1D mask array of shape (nt,) with tapered values applied to the specified range.
- Return type:
numpy.ndarray
- ADFWI.utils.first_arrivel_picking.mute_arrival(trace, itmin, itmax, mutetype, nt, length)[source]
Applies a tapered mask to a seismic record section, muting early or late arrivals.
- Parameters:
trace (torch.Tensor) – A 1D or 2D tensor representing the seismic trace or record section.
itmin (int) – The starting index for muting.
itmax (int) – The ending index for muting.
mutetype (str) – Unused parameter, potentially for future expansion.
nt (int) – The total number of time samples in the trace.
length (int) – The length of the tapering window.
- Returns:
The muted seismic trace with the applied mask.
- Return type:
torch.Tensor
ADFWI.utils.frequency_domin_process
- ADFWI.utils.frequency_domin_process.calculate_spectrum(rcv, dt)[source]
Perform frequency spectrum analysis of seismic data and return the spectrum data.
- Parameters:
rcv (np.ndarray) – Seismic data with shape (n_receivers, n_samples).
dt (float) – Time sampling interval in seconds.
- Returns:
freqs (np.ndarray) – Array of positive frequencies with shape (n_samples // 2,).
amplitude_spectrum (np.ndarray) – Amplitude spectrum of the seismic data with shape (n_receivers, n_samples // 2).
power_spectrum (np.ndarray) – Power spectrum (amplitude squared) of the seismic data with shape (n_receivers, n_samples // 2).
Notes
The function applies FFT along the last axis (time axis) of rcv.
Only the positive frequency components are returned.
- ADFWI.utils.frequency_domin_process.filter_low_frequencies_zero_phase(data, dt, cutoff_freq=5)[source]
Apply zero-phase low-pass filtering to retain frequencies below the cutoff frequency.
- Parameters:
data (np.ndarray) – Seismic data with shape (shot, t, rcv), where:
dt (float) – Time step (sampling interval) in seconds.
cutoff_freq (float, optional) – The cutoff frequency in Hz. Frequencies above this value will be attenuated. Default is 5 Hz.
- Returns:
filtered_data – Zero-phase low-pass filtered seismic data with the same shape as data (shot, t, rcv).
- Return type:
np.ndarray
Notes
This function applies a 6th-order Butterworth low-pass filter.
Filtering is done trace-by-trace using scipy.signal.filtfilt to ensure zero-phase distortion.
The cutoff frequency is normalized by the Nyquist frequency (0.5 / dt).
- ADFWI.utils.frequency_domin_process.plot_filtered_data(original_data, filtered_data, shot_idx=0, cutoff_freq=5, save_path='', show=True)[source]
Plot original and filtered seismic data for a specific shot.
ADFWI.utils.noise
- ADFWI.utils.noise.add_gaussian_noise(data, std_noise, mean_bias_factor=0.1, seed=1234)[source]
Add Gaussian noise to seismic data with a specified standard deviation and optional mean bias.
- Parameters:
data (np.ndarray) – Input data with shape (shot, time, trace).
std_noise (float) – Standard deviation of the Gaussian noise, controlling the noise intensity.
mean_bias_factor (float, optional) – Factor to scale the mean of each trace to serve as the mean of the Gaussian noise. Default is 0.1, meaning the noise mean is 10% of the trace mean.
seed (int or None, optional) – Random seed for reproducibility. If None, the noise will be different on each execution. Default is 1234.
- Returns:
noisy_data – Noisy data with the same shape as data (shot, time, trace).
- Return type:
np.ndarray
ADFWI.utils.offset_mute
- ADFWI.utils.offset_mute.mute_offset(rcv_x, src_x, dx, waveform, distance_threshold=400)[source]
Mute seismic data based on source-receiver offset.
- Parameters:
rcv_x (torch.Tensor or np.ndarray) – Receiver positions, shape (n_shots, n_receivers).
src_x (torch.Tensor or np.ndarray) – Source positions, shape (n_shots,).
dx (float) – Spatial sampling interval (unit: meters).
waveform (torch.Tensor) – Seismic waveform data, shape (n_shots, n_time, n_receivers).
distance_threshold (float, optional) – Offset threshold for muting (unit: meters). Default is 400 m.
- Returns:
waveform – Muted waveform with the same shape as the input.
- Return type:
torch.Tensor
ADFWI.utils.utils
ADFWI.utils.velocityDemo
- ADFWI.utils.velocityDemo.build_anomaly_background_model(x, y, step)[source]
Construct a model with an anomaly background based on step profiles.
- Parameters:
x (np.ndarray) – The x-coordinates for the model.
y (np.ndarray) – The y-coordinates (depths) for the model.
step (float) – The step size used to generate the profile.
- Returns:
model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.build_layer_model(x, y, step)[source]
Construct a layered model using specified x and y coordinates and a step size.
- Parameters:
x (array) – Array of x-coordinates defining the spatial extent.
y (array) – Array of y-coordinates defining the depth levels.
step (float) – The step size for the layer profile.
- Returns:
new_model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.download_marmousi_model(in_dir)[source]
Download marmousi2 model automatically
- ADFWI.utils.velocityDemo.get_anomaly_model(layer_model, n_pml)[source]
Generate a model with anomalies based on the given layer model.
- Parameters:
layer_model (dict) – The base model containing ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, and ‘dy’.
n_pml (int) – The number of PML cells.
- Returns:
new_model – A new model with modified ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, and ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_linear_hess_model(model, smooth_kernel=50, idx=None)[source]
Generate a linear velocity model based on the input model by averaging along the chosen axis.
- Parameters:
model (dict) – The original model containing ‘vp’, ‘rho’, ‘delta’, ‘epsilon’, ‘x’, ‘z’, ‘dx’, and ‘dz’.
smooth_kernel (int, optional) – The size of the Gaussian smoothing kernel, default is 50.
idx (int, optional) – Index to slice the model along the z-axis, if None, average across all values.
- Returns:
new_model – A new model dictionary with linearly varying velocities and original density.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_linear_marmousi2_model(model, smooth_kernel=10, idx=None, mask_depth=10)[source]
Generate a linear velocity model based on the input Marmousi model.
- Parameters:
model (dict) – The original Marmousi model containing ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
smooth_kernel (int, optional) – Standard deviation for the Gaussian smoothing filter (default is 10).
idx (int, optional) – Index for selecting a specific model column for velocities and density (default is None).
mask_depth (int, optional) – Depth of the masking region (default is 10).
- Returns:
new_model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_linear_vel_model(model, vp_min=None, vp_max=None, vs_min=None, vs_max=None, mask_depth=10)[source]
Generate a linear velocity model based on the input Marmousi model.
- Parameters:
model (dict) – The original Marmousi model containing ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
vp_min (float, optional) – Minimum value for the primary wave velocity (default is None).
vp_max (float, optional) – Maximum value for the primary wave velocity (default is None).
vs_min (float, optional) – Minimum value for the shear wave velocity (default is None).
vs_max (float, optional) – Maximum value for the shear wave velocity (default is None).
mask_depth (int, optional) – Depth of the masking region (default is 10).
- Returns:
new_model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_smooth_hess_model(model, gaussian_kernel=10)[source]
Smooth the Hess model using a Gaussian filter.
- Parameters:
model (dict) – A dictionary containing the ‘vp’, ‘rho’, ‘delta’, ‘epsilon’, ‘x’, ‘z’, ‘dx’, and ‘dz’.
gaussian_kernel (int, optional) – The size of the Gaussian kernel for smoothing, default is 10.
- Returns:
new_model – A dictionary containing the smoothed ‘vp’, ‘rho’, ‘delta’, ‘epsilon’, ‘x’, ‘z’, ‘dx’, and ‘dz’.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_smooth_layer_model(model, smooth_kernel=10)[source]
Apply Gaussian smoothing to the velocity and density fields of the input model.
- Parameters:
model (dict) – A dictionary containing the properties of the model (vp, vs, rho, x, y, dx, dy).
smooth_kernel (int, optional) – The standard deviation for Gaussian kernel smoothing. Defaults to 10.
- Returns:
new_model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_smooth_marmousi_model(model, gaussian_kernel=10, mask_extra_detph=2, rcv_depth=10)[source]
Smooth the Marmousi model using a Gaussian filter.
- Parameters:
model (dict) – The original Marmousi model containing ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
gaussian_kernel (int, optional) – Standard deviation for the Gaussian kernel (default is 10).
mask_extra_detph (int, optional) – Additional depth levels to mask during smoothing (default is 2).
rcv_depth (int, optional) – Depth of the receiver (default is 10).
- Returns:
new_model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.get_smooth_valhall_model(model, gaussian_kernel=10)[source]
Smooth the velocity and density models using a Gaussian filter.
- Parameters:
model (dict) – The model containing ‘vp’, ‘rho’, ‘x’, ‘z’, ‘dx’, and ‘dz’.
gaussian_kernel (int, optional) – The size of the Gaussian kernel used for smoothing, default is 10.
- Returns:
new_model – A dictionary containing the smoothed ‘vp’, ‘rho’, ‘x’, ‘z’, ‘dx’, and ‘dz’.
- Return type:
dict
- ADFWI.utils.velocityDemo.load_hess_model(in_dir)[source]
Load the Hess model from SEG-Y files, including velocity, density, and anisotropic properties.
- Parameters:
in_dir (str) – Directory where the Hess model files are stored.
- Returns:
hess_model – A dictionary containing the ‘vp’, ‘rho’, ‘delta’, ‘epsilon’, ‘dx’, ‘dz’, ‘x’, and ‘z’.
- Return type:
dict
- ADFWI.utils.velocityDemo.load_marmousi_model(in_dir)[source]
Load the Marmousi model data from SEGY files.
- Parameters:
in_dir (str) – The directory where the Marmousi model files are stored.
- Returns:
A model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.load_overthrust_initial_model(in_dir)[source]
Load and process the Overthrust 2D initial model.
- Parameters:
in_dir (str) – The directory where the model file is stored.
- Returns:
overthrust_model – A dictionary containing the processed model with ‘vp’, ‘rho’, ‘x’, and ‘z’.
- Return type:
dict
- ADFWI.utils.velocityDemo.load_overthrust_model(in_dir)[source]
Load and process the Overthrust 2D true model.
- Parameters:
in_dir (str) – The directory where the model file is stored.
- Returns:
overthrust_model – A dictionary containing the processed model with ‘vp’, ‘rho’, ‘x’, and ‘z’.
- Return type:
dict
- ADFWI.utils.velocityDemo.load_valhall_model(in_dir)[source]
Load the Valhall model data from binary files.
- Parameters:
in_dir (str) – The directory containing the Valhall model data files.
- Returns:
valhall_model – A dictionary containing the model’s ‘vp’, ‘rho’, ‘dx’, ‘dz’, ‘x’, and ‘z’.
- Return type:
dict
- ADFWI.utils.velocityDemo.resample_marmousi_model(x, y, model)[source]
Resample the Marmousi model to a new grid defined by x and y.
- Parameters:
x (np.ndarray) – The new x coordinates for resampling.
y (np.ndarray) – The new y coordinates for resampling.
model (dict) – The original Marmousi model, containing: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’
- Returns:
new_model – A new model dictionary with model params: ‘vp’, ‘vs’, ‘rho’, ‘x’, ‘y’, ‘dx’, ‘dy’.
- Return type:
dict
- ADFWI.utils.velocityDemo.resample_overthrust_model(model, subsampling=2)[source]
Resample the Overthrust model with a given subsampling factor.
- Parameters:
model (dict) – The original model containing ‘vp’ and ‘rho’ data.
subsampling (int, optional) – The factor by which to subsample the model (default is 2).
- Returns:
overthrust_model – A resampled model with ‘vp’, ‘rho’, ‘x’, and ‘y’.
- Return type:
dict
- ADFWI.utils.velocityDemo.step_profile_anomaly(x_range, y_range, step)[source]
Generate a stepped profile with anomalies in velocity and density.
- Parameters:
x_range (np.array) – The range of x-coordinates (not used in this function).
y_range (np.array) – The range of y-coordinates defining the depth.
step (float) – The step size for creating the profile.
- Returns:
y_step (np.array) – Array of depth values.
vp_step (np.array) – Array of primary wave velocity values.
vs_step (np.array) – Array of shear wave velocity values.
rho_step (np.array) – Array of density values
- ADFWI.utils.velocityDemo.step_profile_layerModel(x_range, y_range, step)[source]
Generate a step-profile layer model based on specified ranges and step size.
- Parameters:
x_range (list) – The x-coordinate range (not used in calculations).
y_range (list) – The y-coordinate range defining the depth limits.
step (float) – The step size for the profile.
- Returns:
y_step (np.array) – Array of depth values.
vp_step (np.array) – Array of primary wave velocity values.
vs_step (np.array) – Array of shear wave velocity values.
rho_step (np.array) – Array of density values
ADFWI.utils.wavelets
- ADFWI.utils.wavelets.wavelet(nt, dt, f0, amp0=1, t0=None, type='Ricker')[source]
Generate a source time function (wavelet).
- Parameters:
nt (int) – The number of time steps.
dt (float) – The time step size.
f0 (float) – The central frequency of the wavelet.
amp0 (float, optional) – The amplitude of the wavelet (default is 1).
t0 (float, optional) – The center time of the wavelet. If None, defaults to 1.2 / f0 (default is None).
type ({'Ricker', 'Gaussian', 'Ramp'}, optional) – The type of the wavelet to generate. Options are ‘Ricker’, ‘Gaussian’, or ‘Ramp’ (default is ‘Ricker’).
- Returns:
t (numpy.ndarray) – The time array.
wavelet (numpy.ndarray) – The generated wavelet.
- Raises:
ValueError – If an unsupported wavelet type is specified.