pyswapp.utils package

Submodules

pyswapp.utils.interactive module

class pyswapp.utils.interactive.DCPickingInteractive(ax, points=None, data=None, freq=None, vel=None, power=None, offsets=None, picks=None, **kwargs)[source]

Bases: DraggablePoints

class for drawing boundaries for dispersion curve extraction

interact()[source]

extract dispersion curve within boundary

property picks
property polygons
class pyswapp.utils.interactive.DraggablePoints(ax, points=None, **kwargs)[source]

Bases: object

property points
class pyswapp.utils.interactive.FKFilterInteractive(ax, points=None, data=None, picks=None, **kwargs)[source]

Bases: DraggablePoints

property key
property picks
property terminate
update_plot()[source]
class pyswapp.utils.interactive.TXInteractive(ax, receiver=None, points=None, data=None, picks=None, **kwargs)[source]

Bases: DraggablePoints

property key
property picks
property reset
property reset_last
property terminate
update_plot()[source]

pyswapp.utils.inversion module

pyswapp.utils.inversion.compute_chi2(data, resp, error)[source]

compute rms and chi^2

Search for optimum weight

Parameters:
  • f (float, frequency value of the analysis)

  • A (np.ndarray, design matrix)

  • dphi (np.ndarray, phase differences)

  • w (np.ndarray, weights)

  • scale (float, percentage value to decrease lambda)

  • lam_max (int, maximum value of lambda)

Returns:

lam

Return type:

int, optimal lambda

pyswapp.utils.inversion.linear_LSQR(x, y, w=None)[source]

Estimate coefficients of a line y = k*x+phi0

Parameters:
  • x (np.ndarray, offsets)

  • y (np.ndarray, phases)

  • w (np.ndarray, weights)

Returns:

  • k (float, wavenumber)

  • phi0 (float, shift)

pyswapp.utils.inversion.phase_response(x, k, phi0)[source]

return the phase

pyswapp.utils.inversion.tomo2D_phasediff(lam, f, A, dphi, w)[source]

Tomographic like approach (Barone et al., 2019)

Parameters:
  • lam (int, regularization strength)

  • f (float, frequency value of the analysis)

  • A (np.ndarray, design matrix)

  • dphi (np.ndarray, phase differences)

  • w (np.ndarray, weights)

Returns:

  • phi_vel (np.ndarray, phase velocities)

  • phi_model (np.ndarray, predicted phase differences)

pyswapp.utils.physics module

pyswapp.utils.physics.frequency(lam, vel)[source]

compute frequency

pyswapp.utils.physics.lorentzian_err(offsets, vel, f, nchannels=24, dx=1, **kwargs)[source]

Estimate dispersion-curve uncertainty after O’Neill et al. (2003).

Parameters:
  • offsets (array-like or None) – Receiver offsets. If provided, dx and nchannels are inferred from it.

  • vel (float or array-like) – Phase velocity.

  • f (float or array-like) – Frequency.

  • nchannels (int, optional) – Number of channels (ignored if offsets provided).

  • dx (float, optional) – Receiver spacing (ignored if offsets provided).

  • maxerr (float) – Maximum relative velocity error (e.g., 0.4 means ≤40% of velocity).

  • minvelerr (float) – Minimum absolute velocity error (m/s).

  • a (float) – Parameter controlling error-bar tightening.

Returns:

deltac – Estimated dispersion-curve error.

Return type:

float or np.ndarray

References

O’Neill, A., Dentith, M., & List, R., 2003. Full-waveform P-SV reflectivity inversion of surface waves for shallow engineering applications, Exploration Geophysics, 34(3), 158–173.

pyswapp.utils.physics.phase_velocity(f, k)[source]

compute phase velocity

pyswapp.utils.physics.slowness(vel)[source]

compute seismic slowness

pyswapp.utils.physics.wavelength(f, vel)[source]

compute wavelength

pyswapp.utils.physics.wavenumber(f, vel)[source]

compute wavenumber

pyswapp.utils.plot_settings module

pyswapp.utils.plotting module

pyswapp.utils.plotting.calculate_new_limit(fixed, dependent, limit)[source]

Calculates the min/max of the dependent axis given a fixed axis with limits

pyswapp.utils.plotting.discrete_cmap(N, base_cmap=None)[source]

Create an N-bin discrete colormap from the specified input map

pyswapp.utils.plotting.draw1DColumn(ax, x, val, thk=None, depth=None, width=1, vmin=1, vmax=1000, cmap=None)[source]

draw a 1D column based on thicknesses or depths

pyswapp.utils.plotting.get_xy(artist)[source]

get the xy coordinates of a given artist

pyswapp.utils.plotting.plot_colorBar(ax, vmin, vmax, orientation='vertical', size=0.2, pad=None, **kwargs)[source]

create and plot a colorbar

pyswapp.utils.plotting.plot_tomo2D(dphi, phi_model, recs_plot, phi_vel, f, axes=None, outfile=None)[source]

plot tomographic like approach

pyswapp.utils.plotting.plot_vphase(ax, val, f, lam=None, xmid=0, vmin=100, vmax=1000, y_value='lam', width=1, **kwargs)[source]

draw dispersion curve as 1D column

pyswapp.utils.settings module

pyswapp.utils.settings.create_settings(zero_padding=False, freq_step=1, normalize=True, local_max=True, fmin=0, fmax=100, vmin=100, vmax=1000, velstep=1, SFR_time=2, kmin=0, kmax=None, normalize_power=True, local_max_power=False, window_length=10, window_min_offset=-inf, window_max_offset=inf, window_move_increment=1)[source]

create settings dictionary

Parameters:
  • zero_padding (bool, add zeros to increase signal length)

  • freq_step (int, desired frequency step for zero padding)

  • normalize (bool, normalize amplitudes)

  • local_max (bool, normalize each trace based on local maximum)

  • fmin (float, minimum frequency to analyse)

  • fmax (float, maximum frequency to analyse)

  • vmin (float, minimum testing velocity)

  • vmax (float, maximum testing velocity)

  • velstep (float, velocity increment)

  • SFR_time (float, time for computing swept-frequency record (SFR))

  • kmin (float, minimum wavenumber)

  • kmax (float, maximum wavenumber)

  • normalize_power (bool, normalize amplitudes)

  • local_max_power (bool, normalize each trace based on local maximum)

  • window_length (int, spatial window length)

  • window_min_offset (float, minimum offset to exclude near-field)

  • window_max_offset (float, maximum offset to exclude near-field)

  • window_move_increment (int, move increment of spatial window)

pyswapp.utils.sql module

class pyswapp.utils.sql.SQL(database)[source]

Bases: object

Handle an SQLite database.

array_to_blob(arr)[source]

Serialize ndarray to BLOB.

blob_to_array(blob)[source]

Deserialize SQLite BLOB to numpy array.

check_data(table, params)[source]

Check if entry exists already in database.

delete_data(table, params)[source]

Delete entry from database.

drop_table(name)[source]

Drop table.

duplicate_data(data, sin, rep, wid=-1)[source]
get_connection()[source]

Create database connection.

get_geometry(sin, rep=1)[source]

Return source/receiver coordinates for one source location and shot index.

get_proc_labels()[source]
get_settings()[source]

Return the settings DataFrame

get_shotfile(sin, rep=1)[source]

Return the name of one shot file

get_table(name)[source]

Return a table form the database as DataFrame.

get_tables()[source]

Get all table names.

get_trafo_labels(procset, use_windows=False)[source]
get_wids(sin, rep, procset)[source]

return the window ids for a sin/rep pair

group_pd(sin, procset='proc1', by='AVG')[source]

Group repeated measurements for a given sin.

read_FV(sin, rep, procset='proc1', method='phaseshift', wid=-1)[source]

read dispersive energy data from SQL table ‘dispersive_energy’

read_curve(params, cols='*')[source]

Write dispersion curve data from SQL table ‘curves’.

read_curve_cc(params, cols='*')[source]

Write dispersion curve data from SQL table ‘curves’.

read_data(sin, rep, procset='proc1', wid=-1)[source]

Read amplitude data from table ‘amplitudes’.

read_f_from_pd(procset='proc1', calc='NONE')[source]
read_filter(params)[source]

Read filter from SQL table ‘filter’.

read_geometry(geometry_file)[source]

Read geometry CSV file and populate geometry, shots, and receivers tables.

read_pd(sin, procset='proc1', calc='NONE', columns='*')[source]

Read phase-difference data from SQL table ‘phase_differences’.

read_setting(settings)[source]

Read settings and add to database

read_sql(sql)[source]

Write SQL query or table into DataFrame.

show_tables()[source]

Print all table names in the database.

to_sql(df, name, if_exists='fail', **kwargs)[source]

Write data stored in a DataFrame to a SQL database.

wids_exist(procset)[source]

check if windows exist

write_FV(data, sin, rep, procset='proc1', wid=-1)[source]

write dispersive energy data to SQL table ‘dispersive_energy’

write_curve(data, sin, rep, procset='proc1', wid=-1, xmid=0)[source]

Write dispersion curve data to SQL table ‘curves’.

write_data(data, sin, rep, procset, wid=-1)[source]

Write amplitude data in TX domain to SQL table ‘amplitudes’.

write_filter(points, sin, rep, key='t', procset='proc1', wid=-1, type='FK')[source]

Write filter to SQL table ‘filter’.

write_pd(fids, freq, pd_data, sin, rep, procset='proc1')[source]

Write phase-difference data to SQL table ‘phase_differences’.

class pyswapp.utils.sql.StdevFunc[source]

Bases: object

SQLITE aggregate stdev.

finalize()[source]
step(value)[source]

pyswapp.utils.utils module

pyswapp.utils.utils.assert_exists(path, check, kind)[source]

assert a path exists

pyswapp.utils.utils.combine_dict(d1, d2)[source]

combine two dictionaries

pyswapp.utils.utils.create_geometry(path2raw: str, path2geom: str = 'geometry.csv') None[source]

create a geometry.csv from seismic shot files (.sgy and .sg2 file formats)

This function can be used to convert the source and geophone coordinate information contained in the seismic raw data to the geometry file format. The geometry file is a csv file that stores an abstract representation of the survey layout, that can be optionally passed to some modules. Check out docs/geometry_file.pdf for a description of the format.

Parameters:
  • path2raw (str, paths to shot files)

  • path2geom (str, path to geometry file)

pyswapp.utils.utils.create_logging(name)[source]

create logger

pyswapp.utils.utils.create_projectdir(prjdir='')[source]

create project directory

pyswapp.utils.utils.filter_df2dict(df)[source]
pyswapp.utils.utils.get_fileList(path2raw)[source]

get the paths to the shot files from the geometry.csv file

pyswapp.utils.utils.get_num_from_str(string)[source]

extract numbers from string

pyswapp.utils.utils.get_shotfiles_from_geometry(path2raw, shot_files, extension='.sg2', sort_ascending=True)[source]

get the paths to the shot files from the geometry.csv file

pyswapp.utils.utils.interp(x, y, xx, yerr=None, kind='cubic', **kwargs)[source]

interpolate data

pyswapp.utils.utils.natural_sort(l)[source]

sort list based on numbers in ascending order

pyswapp.utils.utils.nextpow2(A)[source]

exponent of next higher power of 2

pyswapp.utils.utils.print_inventory(dct)[source]

print the dictionary items to console

pyswapp.utils.utils.read_DC_csv(fname)[source]

read a dispersion curve file from a csv file

pyswapp.utils.utils.read_filter(fname)[source]

import existing filters from file

pyswapp.utils.utils.rename_files(path2raw, extension='.sg2', prjdir='', channel_nr=1000, rename=False)[source]

copy & optionally rename file for easier handling of geometry

pyswapp.utils.utils.safe_makedirs(*args)[source]

safe generation of directories

pyswapp.utils.utils.save2csv(outfile, freq, vel, err)[source]

save dispersion curve in csv format

pyswapp.utils.utils.write_filter(fname, points, key)[source]

export filter to file

Module contents