pyCWD

Submodules

pyCWD.CWD module

Created on Mon Jun 4 14:42:02 2018

@author: rwilson

class pyCWD.CWD.utilities[source]

Bases: object

Some helper functions

src_rec_pairs(channels, exclude=None, reciprocity=False, randSample=None)[source]

Generate a list of source receiver pairs for all excluding a certain channels.

Parameters:

channels : list

list of channels from which src rec pairs should be generated

exclude : list (Default = None)

list of channels which should be excluded from the list of channels

reciprocity : bool (Default = False)

Include reciprocal pairs.

randSample : int (Default = None)

Extract a random subset from the list of length randSample

Returns:

src_rec : list

list of unique source receiver pairs

read_channelPos(file, dimensions)[source]

Read in csv containing each channel position. Currently expecting that the channel position csv is of a specific type and needs shifting to bottom zeroed coord. system.

Parameters:

file : str

Location of csv containing the channel locations

dimensions : dict

The height of the mesh.

Returns:

dfChan : DataFrame

Database of each channel location

HDF5_data_save(HDF5File, group, name, data, attrb={'attr': 0}, ReRw='w')[source]

Saves data into a hdf5 database, if data name already exists, then an attempt to overwrite the data will be made

Parameters:

HDF5File : str

Relative location of database

group : str

The expected group name

name : str

The name of the data to be saved within group

attrb : dict

attribute dictionary to store along with the database.

ReRw : str (Default = ‘w’)

The read/write format

HDF5_data_read(HDF5File, group, name, ReRw='r')[source]

Saves data into a hdf5 database

Parameters:

HDF5File : str

Relative location of database

group : str

The expected group name

attrb : tuple/list

attribute to store along with the database.

ReRw : str (Default = ‘w’)

The read/write format

Returns:

dset : ()

Data contained within group/name

HDF5_attri_read(HDF5File, group, name, ReRw='r')[source]

Read keys and attributes from hdf5 database.

Parameters:

HDF5File : str

Relative location of database

group : str

The expected group name

attrb : tuple/list

attribute to store along with the database.

ReRw : str (Default = ‘w’)

The read/write format

Returns:

dic : dict

A dictionary of all the attributes stored within the group/name.

WindowTcent(TS, wdws)[source]

Determine the centre of each correlation window in time from the input time-series database.

Parameters:

TS : float

Sampling period

wdws : list(str)

Containing the windows range in sample points separated by -

DiffRegress(Tseries, dfChan, Emaxt0, plotOut=False)[source]

Perform linear regression to fit the 1D diffusion equation to an input time series. The output of this function is an estimation of the diffusivity and dissipation. (P. Anguonda et. al. 2001)

Parameters:

Tseries : array-like

The input time series

dfChan : DataFrame

Containing the channel positsion columns x, y, z

Emaxt0 : int

The index corresponding to the arrival time (onset of) maximum energy

Returns:

popt[1] : float

The diffusitivty determined from the least squared fit. Units depends upon input t and z units check units

popt[2] : float

The Dissipation

src_recNo(CCdata)[source]

Extract the source receiver paris within CCdata, excluding common pairs.

Parameters:

CCdata : dataframe

CCdata dataframe

Returns:

src_recNo : list

List of the source receiver numbers

traceAttributes(SurveyDB, Col)[source]

Extract a single trace and its attributes from single survey dataframe, into a dictionary.

Parameters:

TStrace : DataFrame

Containing all traces for a single survey.

Col : int

The column to extract from the database.

Returns:

traceDict: dict

Containing the trace along with all header information.

d_obs_time(CCdata, src_rec, lag, window, parameter='CC', staTime=None, stopTime=None)[source]

Construct the d_obs dataframe over time from the input CCdata, for a select list of source-receiver pairs.

Parameters:

CCdata : dataframe

CCdata dataframe

src_rec : list(tuples)

A list of tuples for each source receiver pair.

lag : list(tuples)

The lag value from which the extraction is made.

window : str/list(str)

string of windows or list of str of windows.

parameter : str (Default=’CC’)

Parameter from which to extract from the dataframe

staTime : str

The start time from which d_obs is extracted

stopTime : str

The stop time before which d_obs is extracted.

Returns:

d_obs_time : dataframe

dataframe containing the in each row the d_obs vector for all requested source-receiver pairs, increasing with time.

measNorange(CCdata, staTime, endTime)[source]

Determines the measurement survey number between given time interval. This function is intended to allow the user to quickly determine the measurement number range of interest, thereby allowing the reporcessing of the raw data over this region only. This requires that the user passes a CCdata which represents the entire raw dataset.

Parameters:

CCdata : dataframe

CCdata dataframe

staTime : str

The start time of the interval/.

endTime : str

The start time of the interval/.

Returns:

None : tuple

Measurement survey numbers within the range given.

surveyNorange(TSsurveys, staTime, endTime)[source]

Determines the survey number between given time interval. This function is intended to allow the user to quickly determine the survey number range of interest, thereby allowing the reporcessing of the raw data over this region only. This requires that the user passes a CCdata which represents the entire raw dataset.

Parameters:

TSsurveys : list

The survey folder numbers

staTime : str

The start time of the interval/.

endTime : str

The start time of the interval/.

Returns:

None : tuple

Measurement survey numbers within the range given.

Data_on_mesh(mesh_obj, data, loc='')[source]

Place data onto the mesh, and store each mesh file in subfolder.

Parameters:

mesh_obj : mesh.object

mesh object as generated by the class mesh, containing the mesh as well as the functions for setting and saving that mesh.

data : array

Data containing mesh data stored in rows for each time step in columns. Separate mesh file will be generated for each n column.

loc : str (Default = ‘’)

Location to which the output vtu files will be saved.

inversionSetup(mesh_param, channelPos, noise_chan, drop_ch, noiseCutOff, database, CCdataTBL, Emaxt0, TS_idx, inversion_param, verbose=False)[source]

Run function intended to cluster the steps required to setup the inversion mesh and the associated sensitivity kernels. If the mesh_param dictionary key “makeMSH” is true, a new mesh will be constructed, otherweise an attempt to load it from disk will be made.

class pyCWD.CWD.decorrTheory(src_rec, channels, X_b, t, param, mesh_obj=None)[source]

Bases: object

Calculate the theoretical decorrelation ceofficient between each source receiver pair, based on the Code-Wave Diffusion method (Rossetto2011).

Parameters:

src_rec : list(tuples)

List of each source-receiver pair.

channels : DataFrame

Index of channel numbers and the corresponding x,y,z (columns) positions corresponding to the ‘src’ and corresponding ‘rec’ numbers. Units should be according to the physical parameters of D and sigma.

X_b : array(x,y,z)

Location coords of perturbation within model domain in SI units.

t : float or list(float)

Centre time of the correlation windows with which the comparison is to be made.

param : dict

Expected parameters of medium, for example D (diffusion coefficient) and sigma (scattering cross-section).

mesh_obj : object

Mesh object generated from the mesh class.

srRx_df : DataFrame

Calculated based on the input src_rec, channels, and X_b data. Multi-index df of s,r, and R, and Kt columns for each src, rec, tetraNo.

G : np.array

Matrix G of row.No = len(src_rec) * len(t).

Kt_run()[source]

Run sequence of functions to produce the required inputs for inversion.

Kt(t_no=0)[source]

The theoretical decorrelation coefficient between a single source-receiver pair.

Parameters:

t_no : int (Default=0)

The time at which the kernel is calculated

Notes

The ‘_b’ notation signifies a vector in cartesian coordinates

Kt_mat()[source]

Construct the kernel matrix or rows for each source/receiver pair and columns for each tet. cell centre.

src_rec_srR()[source]

Calculates the corresponding s, r, and R for all source receiver pairs found in self.src_rec.

s = |S_b-X_b| r = |r_b-X_b| R = |S_b-r_b|

K_on_mesh(loc='')[source]

Place each source-receiver kernel onto the mesh and save to file.

Parameters:

loc : str (Default = ‘’)

Location to which the output vtu files will be saved.

class pyCWD.CWD.decorrInversion(G, d_obs, L_0, L_c, sigma_m, cell_cents, verbose=True)[source]

Bases: object

Perform the inversion(Rossetto2011).

Parameters:

G : np.array

Matrix containing each sensitivity kernel stored roweise for each mesh cell stored columnweise.

d_obs : np.array

Data vector or length equal to the number or source/receiver pairs by the number of windows implemented.

L_0 : float

Should correspond to the size of a model cell.

L_c : float

The correlation distance between cells

sigma_m : float

The standard deviation of the model cells

cell_cents : float

The correlation distance between cells

paramUpdate(V_0, f_0, factor=8)[source]

Update the L_0 of material parameters. output in [mm] Paerameters ———– V_0 : float

Velocity of the bulk material [m/s]
f_0 : float
The dominante frequency of the wavefield [Hz]
static C_M_speed(vecNorm, G, sigma_m, L_c, L_0)[source]

Write jitted function for increasing the speed of L_curve operations

inv_Lcurve[source]

The L-curve dedicated incersion jit’ed for increased speed.

invTuning(L_crange, sigma_mrange, runs, d_obs_idx=0)[source]

Perform the L-curve trade-off turning base of free param L_0 and sigma_m

Parameters:

L_0range : tuple

Range of L_0 parameters (min, max, num).

sigma_mrange : tuple

Range of sigma_m parameters (min, max, num).

runs : int

The number of ramdom samples extracted from each tuning param

d_obs_idx : int

The index of the d_obs step on which turning is performed

inv[source]

Estimation of the model parameters, for each time-step found in d_obs, where each row of ‘d_obs’ contains a single time step.

Parameters:

d_obs : array

rows of observed data at each time-step

G : array

Sensntivity matrix G

C_M : array

Covarience matrix of the model param

m_prior : array

Prior model param

m_tildes : array

empty matrix into which each time-step generated model param is stored along the columns.

error_thresh : float.32

The error threashold below which the inversion resultes are accepted

no_interation : int

The max. number of repeat inversion steps.

Returns:

m_tildes : array

The model response from each of the time-step inversions with rows: of the number of model cells and columns: of the number of time-steps.

rms : float

The root-mean-square diference after inforcing the positivity constraint.

invRun(L_c=None, sigma_m=None, Database='CWD_Inversion.h5', m_tildes=None, error_thresh=100.0, no_iteration=10, chunk=False, d_obs_time=None)[source]

Overhead inversion function to perform time-lapse inversion operations for each time-step in parallel

Parameters:

L_c : float (default = None)

Define the final L_c to use during the entire inversion

sigma_m : float (default = None)

Define the final sigma_m to use during the entire inversion

Database : h5 object

The database to which all inversion related param are stored.

m_tildes : floats (default = None)

model space vector

error_thresh : float.32 (default = 100.0)

The error threashold below which the inversion resultes are accepted

no_interation : int (default = 10)

The max. number of repeat inversion steps enforcing non-negative cond.

chunk : bool or int (default = False)

Defines the t-step chunks which to perform the inversion. This is intended to reduce the RAM requirements when many time-steps given.

d_obs_time : array[str] (default = None)

The time corresponding to each inversion, should be equal to the number of rows in self.d_obs.

pyCoda.mesh module

Created on Mon Jun 4 11:19:57 2018

@author: rwilson

class pyCWD.mesh.mesher(mesh_param)[source]

Bases: object

Mesh generator class using pygmsh to gmsh code.

Parameters:

mesh_param : dict

Expected parameters defining the mesh, char_len, height, radius

cell_data : dict

Contains line, tetra, triangle, vertex ‘gmsh:physical’ and ‘gmsh:geometrical’.

cells : dict

Contains line, tetra, triangle, vertex of the point indicies as defined in points.

points : array(float)

Matrix of xyz coords for each point in the mesh domain

Notes

Understanding the mesh structure

Points are a list of each point or verticies in x,y,z positions. cell_data[‘tetra’][‘gmsh:physical’] : the physical values of each tetra * cell[‘tetra’] : list of lists of each tetrahedral verticies index referencing to

the coords inside the points. [points[i1],
points[i2], points[i3], points[i4]]
meshIt()[source]

Produces the mesh.

saveMesh(name)[source]

Save the mesh to file.

Parameters:

name : str

Name of the mesh file saved to the current directory.

setCellsVal(cell_values)[source]

Set each cell physical value.

Parameters:

cell_values : array/list

physical values of each tetra cell within the mesh domain in order corresponding to points.

meshOjtoDisk()[source]

Save the entire mesh object to disk

meshOjfromDisk()[source]

Save the entire mesh object to disk